Guest User

Untitled

a guest
Nov 14th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. Function checkMajority(c, M)
  2. i = count = 0
  3. While i less than length of M:
  4. if (M[i] is not actual c) and (equivalentTest(M[i], c) == true) then:
  5. count ++
  6. Endif
  7. Endwhil
  8. If count is greater than half the length of M then:
  9. Return true
  10. Else
  11. Return false
  12. Endif
  13.  
  14.  
  15. Function divide_and_find(M)
  16. If M.length = 1
  17. Return M[0]
  18. Else if M.length = 2
  19. If equivalentTest(M[0], M[1]) == true
  20. Return M[0] or M[1]
  21. Divide M
  22. M1 = assign first half
  23. M2 = assign second half
  24. c = divide_and_find(M1)
  25. if c is returned then
  26. found = checkMajority(c, M)
  27. If found = true then
  28. Return c
  29. Else
  30. c = divide_and_find(M2)
  31. found = checkMajority(c, M)
  32. If found = true then
  33. Return c
  34. Else
  35. Return ‘not found’
  36. Endif
  37. Endif
  38. Endif
  39. Return ‘not found’
Add Comment
Please, Sign In to add comment