-
Notifications
You must be signed in to change notification settings - Fork 2
Data Structure
srivathsan K R edited this page Dec 2, 2017
·
11 revisions
mid = low + (high - low)/2
Ending condition - if low == high + low / 2 (Using binary search)
- hash[sum - val(i)] = val(i)
- if val(i) in hash
findCandidate(a[], size)
- Initialize index and count of majority element maj_index = 0, count = 1
- Loop for i = 1 to size – 1 (a) If a[maj_index] == a[i] count++ (b) Else count--; (c) If count == 0 maj_index = i; count = 1
- Return a[maj_index]
n * (n + 1) / 2