Ejemplo n.º 1
0
 def test_find_min_rotate(self):
     array = [4, 5, 6, 7, 0, 1, 2]
     self.assertEqual(0, find_min_rotate(array))
     array = [10, 20, -1, 0, 1, 2, 3, 4, 5]
     self.assertEqual(-1, find_min_rotate(array))
     # Test find min using recursion
     array = [4, 5, 6, 7, 0, 1, 2]
     self.assertEqual(0, find_min_rotate_recur(array, 0, 6))
     array = [10, 20, -1, 0, 1, 2, 3, 4, 5]
     self.assertEqual(-1, find_min_rotate_recur(array, 0, 8))
Ejemplo n.º 2
0
"""
Suppose an array sorted in ascending order is rotated at some pivot unknown
to you beforehand. (i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).
Find the minimum element. The complexity must be O(logN)
You may assume no duplicate exists in the array.
"""

from algorithms.search import find_min_rotate, find_min_rotate_recur

alist = [0, 1, 2, 3, 4, 5, 6, 7]

print(find_min_rotate(alist))

print(find_min_rotate_recur(alist, 0, 7))