MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / _get_valid_parent

Method _get_valid_parent

data_structures/heap/heap_generic.py:49–63  ·  view source on GitHub ↗

Returns index of valid parent as per desired ordering among given index and both it's children

(self, i: int)

Source from the content-addressed store, hash-verified

47 return self.arr[i][1] < self.arr[j][1]
48
49 def _get_valid_parent(self, i: int) -> int:
50 """
51 Returns index of valid parent as per desired ordering among given index and
52 both it&#x27;s children
53 """
54 left = self._left(i)
55 right = self._right(i)
56 valid_parent = i
57
58 if left is not None and not self._cmp(left, valid_parent):
59 valid_parent = left
60 if right is not None and not self._cmp(right, valid_parent):
61 valid_parent = right
62
63 return valid_parent
64
65 def _heapify_up(self, index: int) -> None:
66 """Fixes the heap in upward direction of given index"""

Callers 1

_heapify_downMethod · 0.95

Calls 3

_leftMethod · 0.95
_rightMethod · 0.95
_cmpMethod · 0.95

Tested by

no test coverage detected