Monday, April 6, 2009

Just a giant heap of...

After talking about trees, and Binary Search Trees, I am going to expand upon that today and I will talk about a different kind of tree called a heap. A heap is a binary tree in which the root node is larger then both of its two children. It must also be a complete tree which means that every level has the maximum number of children and the bottom level is shifted as far left as possible. This way is easier to find the maximum value in the tree since it will be at the very top. This type of tree supports 3 different methods, which are heapify, heap_sort, and build_heap. Heapify compares a certain node to the number below it and if it is smaller, it swaps the 2 node's position. Heap_sort exchanges the last node in the tree with the largest node and then disconnects the largest number. By the end the tree is sorted from the smallest number at top to the largest number at the bottom right. Finally, build_heap uses an array and the uses the heapify method to make the heap tree.

No comments:

Post a Comment