Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def validate(self):
- """
- Validates the heap. Returns True if the heap is a valid min-heap, and
- False otherwise.
- >>> h = MinHeap()
- >>> h._items = [1, 3, 5]
- >>> h.validate()
- True
- >>> h._items = [1, 3, 5, 8, 9, 6, 7, 11]
- >>> h.validate()
- True
- >>> h._items = [2, 3, 1, 7]
- >>> h.validate()
- False
- """
- if self._items[0] > self._items[1]:
- return False
- for i in range(1,len(self._items)/2):
- if self._items[i-1] > (self._items[2*i] or self._items[2*i+1]):
- return False
- return True
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement