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

Method _parent

data_structures/heap/heap_generic.py:21–23  ·  view source on GitHub ↗

Returns parent index of given index if exists else None

(self, i: int)

Source from the content-addressed store, hash-verified

19 self.key = key or (lambda x: x)
20
21 def _parent(self, i: int) -> int | None:
22 """Returns parent index of given index if exists else None"""
23 return int((i - 1) / 2) if i > 0 else None
24
25 def _left(self, i: int) -> int | None:
26 """Returns left-child-index of given index if exists else None"""

Callers 1

_heapify_upMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected