Sorting Algorithm
Sorting Algorithm
If by making a guess we are able to eliminate a large portion of answers then we can search faster.
Why a random guess in the range ?
In best case 70% search space discarded i.e. I.E (30% space we all able to find that no)
In worst case 30% search space will discard I.e. We have to find that number in 70% space which is tough
Finl iteration =
Dividing array into 3 part
Iteration * no of comparison In every iteration , 67% of search space
got discarded
Brute Force
To find:- max ( arr[i] < 12)
Binary search.
Q :- Search the array and find the frequency of that element
Frequency of 5 = P2 - P1 +1
TC :- O(log N ) + O(N)
In worst case we have to
go entire left side and
Due to which
entire right side( travelling
we are able to
the entire array will
land 5
require O(N) time
complexity.