Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Function checkMajority(c, M)
- i = count = 0
- While i less than length of M:
- if (M[i] is not actual c) and (equivalentTest(M[i], c) == true) then:
- count ++
- Endif
- Endwhil
- If count is greater than half the length of M then:
- Return true
- Else
- Return false
- Endif
- Function divide_and_find(M)
- If M.length = 1
- Return M[0]
- Else if M.length = 2
- If equivalentTest(M[0], M[1]) == true
- Return M[0] or M[1]
- Divide M
- M1 = assign first half
- M2 = assign second half
- c = divide_and_find(M1)
- if c is returned then
- found = checkMajority(c, M)
- If found = true then
- Return c
- Else
- c = divide_and_find(M2)
- found = checkMajority(c, M)
- If found = true then
- Return c
- Else
- Return ‘not found’
- Endif
- Endif
- Endif
- Return ‘not found’
Add Comment
Please, Sign In to add comment