Every line of 'maxheap python' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

By copying the Snyk Code Snippets you agree to

this disclaimer

51 def max_heapify(ls: list, heap_size: int, i: int) -> None: 52 """This operation is also sometimes called `push_down`, `shift_down` or `bubble_down`. 53 54 Time complexity: O(log(n)).""" 55 m = i 56 left = 2 * i + 1 57 right = 2 * i + 2 58 if left < heap_size and ls[left] > ls[m]: 59 m = left 60 if right < heap_size and ls[right] > ls[m]: 61 m = right 62 if i != m: 63 ls[i], ls[m] = ls[m], ls[i] 64 max_heapify(ls, heap_size, m)

Important

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

118 def buildMaxHeap(heap) : 119 lgth = length(heap) 120 for k in range(lgth // 2 - 1, 0-1, -1): 121 maxHeapify(heap, k, lgth) 122 123 124 return 0

164 def downheap(self): 165 tmp = 0 166 i = 0 167 while True: 168 left = (i << 1) + 1; 169 right = left + 1; 170 if left >= self.nheap: 171 return 172 if right >= self.nheap: 173 if self.heap[i] < self.heap[left]: 174 tmp = self.heap[left] 175 self.heap[left] = self.heap[i] 176 self.heap[i] = tmp 177 return 178 179 if self.heap[i] >= self.heap[left] and self.heap[i] >= self.heap[right]: 180 return 181 182 if self.heap[left] > self.heap[right]: 183 tmp = self.heap[left] 184 self.heap[left] = self.heap[i] 185 self.heap[i] = tmp 186 i = left 187 else: 188 tmp = self.heap[right] 189 self.heap[right] = self.heap[i] 190 self.heap[i] = tmp 191 i = right