Heap Data Structure #2: Max Heapify Function, Building Max-heap from an Array

Опубликовано: 04 Март 2023
на канале: KnowledgeCorridor
178
7

Strength of heap data structure is owing to Max-Heapify function. This function converts a heap into max-heap. If the sub-heaps of a node are already max-heap but the node itself violates max-heap property then we pass the index of that node to max-heapify function and it guarantees the entire tree rooted at the node to be max heap.
The time complexity of max heap is order of lgn (log base 2 of n). It recursively adjust the node, its left and right children and goes down the leaves.
The build max-heap function takes an array and converts it to max heap. It goes from n/2 to 1 and every time runs the max heap function in bottom-up fashion. Every time it renders the sub-tree rooted at the corresponding index a max heap. Finally it takes the root and converts it into max heap.
Thus build-max function is called n/2 times, where every time it runs max-heapify which has complexity of lg n, so the time complexity of build max is O(n/2. lgn) = O(nlgn)


На этой странице сайта вы можете посмотреть видео онлайн Heap Data Structure #2: Max Heapify Function, Building Max-heap from an Array длительностью часов минут секунд в хорошем качестве, которое загрузил пользователь KnowledgeCorridor 04 Март 2023, поделитесь ссылкой с друзьями и знакомыми, на youtube это видео уже посмотрели 178 раз и оно понравилось 7 зрителям. Приятного просмотра!