hotamul의 개발 이야기

[Data Structure][C++] Heap (Min Heap) 본문

myt-algorithm-practice/Samsung SW Certi Pro

[Data Structure][C++] Heap (Min Heap)

hotamul 2021. 11. 23. 18:26

Definition of Min Heap

  • Complete Binary Tree
  • The value of Parent <= The value of Child

https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSnOskp0-ZI2-EW5uy2BWXFM707kzbG-lVCT03EBY6kVCUHxAc_TeDlPHIprt-F16Ol5Nw&usqp=CAU

 

Method

  • Push(x) : push a element x to heap
  • Pop() : remove the smallest element from heap
  • Top() : return the smallest element from heap

 

Implement

  • Parent Index : i / 2
  • Left Child Index : i * 2
  • Right Child Index : i * 2 + 1

 

https://www.geeksforgeeks.org/wp-content/uploads/binaryheap.png

 

Comments