Min Heap Properties - PowerPoint PPT Presentation

1 / 4
About This Presentation
Title:

Min Heap Properties

Description:

Make a new node with children as the minimum, value equals the sum of the minimums ... Assign 1 to left child and 0 to right child ... – PowerPoint PPT presentation

Number of Views:92
Avg rating:3.0/5.0
Slides: 5
Provided by: pyun
Category:
Tags: child | heap | min | properties

less

Transcript and Presenter's Notes

Title: Min Heap Properties


1
Min Heap Properties
  • Stored in an array
  • First node starts at index 1
  • Drawn as a full binary tree
  • Parents always smaller than its children
  • Left child 2parent index
  • Right child 2parent index1
  • Parent (left child index right childindex)/2
  • Method
  • walkdown
  • heapify (Build Heap)
  • walkkup
  • Insert
  • remove

2
Heap Method
  • Walkdown
  • Compare the node to its children and if children
    are smaller it swaps with the smallest child.
    Continues until
  • Both children are larger
  • Both children are NULL
  • gt O(log2 N)
  • Heapify
  • Starts at the last internal node
  • Call walkdown and continue on all previous node
  • gt O(Nlog2 N)
  • Walkup
  • Swaps with parent if parent is larger
  • Continue until
  • Parent is smaller
  • Parents index to 0

1
3
Heap Method
  • Insert
  • Add to the new available location
  • (last element in array)
  • Call walkup on the new inserted node
  • Remove_Min
  • swaps first element with the last element
  • Remove the new last element
  • Call walkdown on the new first node

4
Huffman code algorithm
  • Count frequency for each character
  • Put frequency into heap order
  • Remove min twice
  • Make a new node with children as the minimum,
    value equals the sum of the minimums
  • Add new node into heap
  • Continue 3-5 while more than 1 value is in the
    heap
  • Assign 1 to left child and 0 to right child
  • Traverse the tree, if node is a leaf, you can
    extract its Huffman code
  • Replace text with code that have been found
Write a Comment
User Comments (0)
About PowerShow.com