heap

PPTX 38 pages 146.1 KB Free download

Page preview (5 pages)

Scroll down 👇
1 / 38
heap heap algorithms and data structures course data structures: heap heap is a specialized tree-based data structure: an almost complete tree. in a max heap, for any given node c, if p is a parent node of c, then the key (the value) of p is greater than or equal to the key of c. in a min heap, for any given node c, if p is a parent node of c, then the key (the value) of p is less than or equal to the key of c. algorithms and data structures course data structures: heap operations push: inserts item to the heap. time complexity is o(log(n)). pop: removes the min/max element from heap. time complexity is o(log(n)). top: returns the min/max element from heap. time complexity is o(1). empty: returns “true”, if heap is empty. time complexity is o(1). size: returns size of heap. time complexity is o(1). …
2 / 38
th its parent if parent key is lower, then algorithm is ended if parent key is greater, swap this element with parent and go to step 2. 6 data structures: heap operations: node adding algorithms and data structures course 2 5 4 3 5 9 10 40 12 need to add new element, for example, 4: adding element in the end of our tree comparing this element with its parent if parent key is lower, then algorithm is ended if parent key is greater, swap this element with parent and go to step 2. 6 data structures: heap operations: node adding algorithms and data structures course 2 4 5 3 5 9 10 40 12 need to add new element, for example, 4: adding element in the end of our tree comparing this element with its parent if parent key is lower, then algorithm is ended if parent key is …
3 / 38
es: heap operations: node deletion algorithms and data structures course 2 4 5 3 5 9 10 40 12 need to delete minimal element: 6 data structures: heap operations: node deletion algorithms and data structures course 2 4 5 3 5 9 10 40 12 need to delete minimal element: swap min element with the last element 6 data structures: heap operations: node deletion algorithms and data structures course 6 4 5 3 5 9 10 40 12 need to delete minimal element: swap min element with the last element 2 data structures: heap operations: node deletion algorithms and data structures course 6 4 5 3 5 9 10 40 12 need to delete minimal element: swap min element with the last element delete last element 2 data structures: heap operations: node deletion algorithms and data structures course 6 4 5 3 5 9 10 40 12 need to delete …
4 / 38
lement with smaller child and go to step 3. data structures: heap operations: node deletion algorithms and data structures course 3 4 5 6 5 9 10 40 12 need to delete minimal element: swap min element with the last element delete last element comparing just swapped element with its childs: if parent is smaller then all childs or there are no childs, then algorithm is ended else swap element with smaller child and go to step 3. data structures: heap operations: node deletion algorithms and data structures course 3 4 5 5 6 9 10 40 12 need to delete minimal element: swap min element with the last element delete last element comparing just swapped element with its childs: if parent is smaller then all childs or there are no childs, then algorithm is ended else swap element with smaller child and go to step 3. data structures: heap …
5 / 38
root index = 1 3 4 5 5 6 9 10 40 12 data structures: heap how to store? algorithms and data structures course we can use an array: left child index = parent index * 2 right child index = parent index * 2 + 1 parent index = child index / 2 root index = 1 3 4 5 5 6 9 10 40 12 index = 1 data structures: heap how to store? algorithms and data structures course we can use an array: left child index = parent index * 2 right child index = parent index * 2 + 1 parent index = child index / 2 root index = 1 3 4 5 5 6 9 10 40 12 index = 1 1*2 = 2 data structures: heap how to store? algorithms and data structures course we can use an array: left child index = …

Want to read more?

Download all 38 pages for free via Telegram.

Download full file

About "heap"

heap heap algorithms and data structures course data structures: heap heap is a specialized tree-based data structure: an almost complete tree. in a max heap, for any given node c, if p is a parent node of c, then the key (the value) of p is greater than or equal to the key of c. in a min heap, for any given node c, if p is a parent node of c, then the key (the value) of p is less than or equal to the key of c. algorithms and data structures course data structures: heap operations push: inserts item to the heap. time complexity is o(log(n)). pop: removes the min/max element from heap. time complexity is o(log(n)). top: …

This file contains 38 pages in PPTX format (146.1 KB). To download "heap", click the Telegram button on the left.

Tags: heap PPTX 38 pages Free download Telegram