MCPcopy Create free account
hub / github.com/subbarayudu-j/TheAlgorithms-Python / bottomToTop

Function bottomToTop

Graphs/minimum_spanning_tree_prims.py:36–58  ·  view source on GitHub ↗
(val, index, heap, position)

Source from the content-addressed store, hash-verified

34
35 # Update function if value of any node in min-heap decreases
36 def bottomToTop(val, index, heap, position):
37 temp = position[index]
38
39 while(index != 0):
40 if index % 2 == 0:
41 parent = int( (index-2) / 2 )
42 else:
43 parent = int( (index-1) / 2 )
44
45 if val < heap[parent]:
46 heap[index] = heap[parent]
47 position[index] = position[parent]
48 setPosition(position[parent], index)
49 else:
50 heap[index] = val
51 position[index] = temp
52 setPosition(temp, index)
53 break
54 index = parent
55 else:
56 heap[0] = val
57 position[0] = temp
58 setPosition(temp, 0)
59
60 def heapify(heap, positions):
61 start = len(heap) // 2 - 1

Callers 1

PrimsAlgorithmFunction · 0.85

Calls 1

setPositionFunction · 0.85

Tested by

no test coverage detected