Login
Register
@
Dark Mode
Profile
Edit my Profile
Messages
My favorites
Register
Activity
Q&A
Questions
Unanswered
Tags
Subjects
Users
Ask
Previous Years
Blogs
New Blog
Exams
Dark Mode
median of two sorted Arrays
Himanshu1
asked
in
Algorithms
Dec 16, 2015
edited
Jul 17, 2022
by
makhdoom ghaya
1,602
views
3
votes
3
votes
algorithms
time-complexity
sorting
test-series
Himanshu1
asked
in
Algorithms
Dec 16, 2015
edited
Jul 17, 2022
by
makhdoom ghaya
by
Himanshu1
1.6k
views
answer
comment
Follow
share this
share
3 Comments
by
Sandip Shaw
commented
Dec 16, 2015
reply
Follow
share this
Option C?
0
0
by
Umang Raman
commented
Dec 16, 2015
reply
Follow
share this
http://www.geeksforgeeks.org/median-of-two-sorted-arrays/
3
3
by
Rajesh Jaiswal
commented
Nov 6, 2016
reply
Follow
share this
option A is correct because without merging (union) both array median can be obtain in O(logn)
0
0
Please
log in
or
register
to add a comment.
Please
log in
or
register
to answer this question.
3
Answers
1
vote
1
vote
Finding median of array A takes O(1) time and same is for array B. Once we find both medians :
If Median (A) > Median (B) then find median of First half of A and Second half of B because these 2 portions contain the values between Median (A) and Median (B)
If Median (A) < Median (B) then consider Second half of A and First half of B for the same reason as above
In either case we are left with an array of size ($\frac{N}{2}$ + $\frac{N}{2}$) = N.
Now repeat the procedure for these half arrays then again for their halves until we are left with just 2 elements . The mean of those 2 numbers is the median of A U B
As the procedure has to be repeated for max LogN times the worst case time complexity would be O(logN). so ans is A
Heisenberg
answered
Mar 23, 2017
by
Heisenberg
comment
Follow
share this
0 Comments
Please
log in
or
register
to add a comment.
0
votes
0
votes
if we do AUB then it can or can not be sorted array so, sorting of AUB will take NlogN time in worst case. Once AUB is sorted then finding the median will take O(1) hence it will be O(NlogN)
answer should be (C)
cse23
answered
Jun 4, 2016
by
cse23
comment
Follow
share this
2 Comments
by
Himanshu1
commented
Jun 5, 2016
reply
Follow
share this
nopes, answer is (A).
1
1
by
hkcgate2017
commented
Sep 2, 2016
reply
Follow
share this
ans c is correct ........see A &B are sorted arr right
A U B will might be unsorted...then sort them O(nlogn) and find median O(n)
T(n)=O(nlogn)+O(n)=O(nlogn)
0
0
Please
log in
or
register
to add a comment.
0
votes
0
votes
Both A and B are sorted array.
Merging of A and B takes O(n) times. [Applying merge algorithm of Merge sort]
Finding median takes O(1) times.
Answer is Option B. O(n).
Arnab Bhadra
answered
Mar 23, 2017
by
Arnab Bhadra
comment
Follow
share this
0 Comments
Please
log in
or
register
to add a comment.
← Previous
Next →
← Previous in category
Next in category →
Related questions
0
votes
0
votes
2
answers
1
nehab.sairam
asked
in
Algorithms
Jul 18, 2015
3,263
views
Let s be a sorted array of n integers. Let t(n) denote the time taken for the most efficient algorithm to determined if there are two elements with sum less than 1000 in s.What will be the time complexity???????
nehab.sairam
asked
in
Algorithms
Jul 18, 2015
by
nehab.sairam
3.3k
views
algorithms
sorting
time-complexity
0
votes
0
votes
1
answer
2
Sanjay Sharma
asked
in
Algorithms
Jan 19, 2017
793
views
efficient algo for nearly sorted array
Sanjay Sharma
asked
in
Algorithms
Jan 19, 2017
by
Sanjay Sharma
793
views
algorithms
sorting
test-series
1
vote
1
vote
2
answers
3
Akriti sood
asked
in
Algorithms
Dec 27, 2016
1,985
views
Consider the array of size n. the first (n – 1) elements are already sorted.
Consider the array of size n. the first (n – 1) elements are already sorted. What is the worst case time complexity to insert a nth element in an array after insertion the array should be in sorted order O(1) O(n) O(n log n) O(n2)
Akriti sood
asked
in
Algorithms
Dec 27, 2016
by
Akriti sood
2.0k
views
algorithms
sorting
time-complexity
2
votes
2
votes
1
answer
4
yes
asked
in
Algorithms
Oct 6, 2015
1,353
views
the minimum no of comparisons required to find Majority Element in a sorted array (note that key is not given).
yes
asked
in
Algorithms
Oct 6, 2015
by
yes
1.4k
views
algorithms
sorting
time-complexity
Subscribe to GATE CSE 2024 Test Series
Subscribe to GO Classes for GATE CSE 2024
Quick search syntax
tags
tag:apple
author
user:martin
title
title:apple
content
content:apple
exclude
-tag:apple
force match
+apple
views
views:100
score
score:10
answers
answers:2
is accepted
isaccepted:true
is closed
isclosed:true
Recent Posts
Post GATE 2024 Guidance [Counseling tips and resources]
GATE CSE 2024 Result Responses
[Project Contest] Pytorch backend support for MLCommons Cpp Inference implementation
Participating in MLCommons Inference v4.0 submission (deadline is February 23 12pm IST)
IIITH PGEE 2024 Test Series by GO Classes
Subjects
All categories
General Aptitude
(3.5k)
Engineering Mathematics
(10.4k)
Digital Logic
(3.6k)
Programming and DS
(6.2k)
Algorithms
(4.8k)
Theory of Computation
(6.9k)
Compiler Design
(2.5k)
Operating System
(5.2k)
Databases
(4.8k)
CO and Architecture
(4.0k)
Computer Networks
(4.9k)
Artificial Intelligence
(79)
Machine Learning
(48)
Data Mining and Warehousing
(25)
Non GATE
(1.4k)
Others
(2.7k)
Admissions
(684)
Exam Queries
(1.6k)
Tier 1 Placement Questions
(17)
Job Queries
(80)
Projects
(11)
Unknown Category
(870)
64.3k
questions
77.9k
answers
244k
comments
80.0k
users
Recent Blog Comments
category ?
Hi @Arjun sir, I have obtained a score of 591 in ...
download here
Can you please tell about IIT-H mtech CSE self...
Please add your admission queries here:...
Twitter
WhatsApp
Facebook
Reddit
LinkedIn
Email
Link Copied!
Copy