Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
220 views
in Technique[技术] by (71.8m points)

In binary search if all elements are same .In that case the time complexity of Binary search will be O(N)

 Basically the time complexity of Binary Search is O(log N).
    What if all the elements are same.
    
    In the bottleneck step. 
    Assuming all the values in the array are the same, we get the following relation :
 T(N) = 2 * T(N/2) + constant
    = 4 * T(N/4) + constant ( 2 * constant = another constant )
    = 8 * T(N/8) + constant
    …
    = N * T(N/N) + constant
    = N + constant
    = O(N)

In that case the time complexity of Binary search will be O(N).

question from:https://stackoverflow.com/questions/65909473/in-binary-search-if-all-elements-are-same-in-that-case-the-time-complexity-of-b

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...