retagged by
768 views
0 votes
0 votes
How many key comparisons are there , what is the lower bound and upper bound ?

 

For calculating the lower bound , should we consider the case when the keys are all in non-increasing fashion and then after n-k comparisons we shall find one of the K keys and then we are done , and for calculating upper bound then , what should be the case considered for the order of keys ?
retagged by

1 Answer

Best answer
2 votes
2 votes

I suppose here the upper bound and lower bound cases would be same.
To find one of the k smallest keys, we need to look at n-k+1 elements atleast to be sure that we have chosen one among k smallest keys.. So, total n-k comparisons
In the question nothing about the order of the keys is mentioned. so we must look for n-k+1 elements, so n-k comparisons.
Time complexity should be ϴ(n-k).

edited by

Related questions

8 votes
8 votes
2 answers
2
1 votes
1 votes
1 answer
4
radha gogia asked Jul 8, 2016
1,177 views
0 / \ 5 7 / \ / \ 6 4 1 3 \ 9Tree given in the form: (node value(left subtree)(right subtree))For tree given above: (0(5(6()())(4()(9()())))(7(1()())(3()())))Input forma...