2 votes 2 votes How many comparisons are needed for a binary search in a set of 64 elements? Algorithms algorithms binary-search numerical-answers + – Rohan Mundhey asked Nov 9, 2016 • retagged Jun 23, 2022 by Lakshman Bhaiya Rohan Mundhey 5.5k views answer comment Share Follow See all 0 reply Please log in or register to add a comment.
1 votes 1 votes in quetion not mentaioned that Array is sorted or not : I assume it is sorted . it will take log2n for n elements. So for 64 it takes 6 comparision atmost for any element. Comparision on elements 32, 16, 8, 4, 2,1 Prashant. answered Nov 9, 2016 • edited Nov 9, 2016 by Prashant. Prashant. comment Share Follow See all 19 Comments See all 19 19 Comments reply Show 16 previous comments Arjun commented Nov 9, 2016 reply Follow Share yes, we do not have more information here. At least choice could have helped. 1 votes 1 votes Kapil commented Nov 9, 2016 reply Follow Share A). 6 B). 14 C). 12 D). None of the above :) :) :) 0 votes 0 votes air1 commented Nov 9, 2016 reply Follow Share @kapil If we consider that one compare operation gives us all the information (wether the element being searched is to be searched on the left part or right or already found), then logN does represent the number of compare operations in the worst case for an array of $2^N$ elements. 1, 2, 3, 4, 5, 6, 7, 8 suppose we are searching for 0. first comparison with 4. now we know we have to search on left portion. so compare with 2, then with 1. total 3 comparisons. $2^3$ = $8$ 1 votes 1 votes Please log in or register to add a comment.
1 votes 1 votes we know that recurrance relation for binary search with n elements is: f(n) = f(n/2) + 2 now, f(64) = f(32) + 2 f(64) = (f(16) + 2) +2 f(64) = (f(8) + 4) +2 f(64) = (f(4) + 6) +2 f(64) = (f(2) + 8) +2 f(64) = (f(1) + 10) +2 now, f(1) equals to 2 since two comparisons are required for one number this gives f(64) = 14 Nirmal Gaur answered Apr 18, 2017 Nirmal Gaur comment Share Follow See all 0 reply Please log in or register to add a comment.