@@ -47,7 +47,6 @@ def get_child_right_position(position: int) -> int:
4747 return (2 * position ) + 2
4848
4949
50-
5150class MinPriorityQueue (Generic [T ]):
5251 """
5352 Minimum Priority Queue Class
@@ -128,6 +127,7 @@ def update_key(self, elem: T, weight: int) -> None:
128127 self ._bubble_down (elem )
129128 else :
130129 self ._bubble_down (elem )
130+
131131 def _bubble_up (self , elem : T ) -> None :
132132 """Place node at proper position (upward movement) - internal use only"""
133133 curr_pos = self .position_map [elem ]
@@ -146,7 +146,7 @@ def _bubble_down(self, elem: T) -> None:
146146 _ , weight = self .heap [curr_pos ]
147147 child_left_position = get_child_left_position (curr_pos )
148148 child_right_position = get_child_right_position (curr_pos )
149-
149+
150150 # Check if both children exist
151151 if child_left_position < self .elements and child_right_position < self .elements :
152152 _ , child_left_weight = self .heap [child_left_position ]
@@ -155,15 +155,15 @@ def _bubble_down(self, elem: T) -> None:
155155 self ._swap_nodes (child_right_position , curr_pos )
156156 self ._bubble_down (elem )
157157 return
158-
158+
159159 # Check left child
160160 if child_left_position < self .elements :
161161 _ , child_left_weight = self .heap [child_left_position ]
162162 if child_left_weight < weight :
163163 self ._swap_nodes (child_left_position , curr_pos )
164164 self ._bubble_down (elem )
165165 return
166-
166+
167167 # Check right child
168168 if child_right_position < self .elements :
169169 _ , child_right_weight = self .heap [child_right_position ]
@@ -270,7 +270,7 @@ def prims_algo(
270270 # Main algorithm loop
271271 while not priority_queue .is_empty ():
272272 node = priority_queue .extract_min ()
273-
273+
274274 # Explore neighbors of current node
275275 for neighbor , weight in graph .connections [node ].items ():
276276 # Update if found better connection to tree
0 commit comments