2. Still With Tree Traversal
void BST::levelOrder(){
Queue<node*> q;
q.enqueue(root);
while(!q.isEmpty()){
node *p = q.dequeue();
cout<<p->item<<“ “;
if(p->left!=NULL)
q.enqueue(p->left);
if(p->right!=NULL)
q.enqueue(p->right);
}
}
3. Still On Search
Through the AVL, search was improved to
log n. But we perform better?
Hash Table
Hash function/ Hashing
An array of some fixed containing the keys
Each key is mapped into some number in
range 0 to H_SIZE-1
This mapping is called a hash function
8. Hash Table
The keys of the hash table are normally
strings
Hash functions
Sum up the ASCII codes of the characters
before performing %
(st[0] + 27*st[1] + 729*st[2]) % H_SIZE
10. Priority Queue (Heap)
A data structure allows at least the
following two operations
insert – similar to enqueue
deleteMin/deleteMax – heap’s equivalent of
dequeue
Implementation
Represent as a binary tree that is completely filled,
with the exception of the bottom level
Completely filled from left to right
Simplest way is to use an array
12. Heap
Heap order property
Every node X, the key in the parent of X is
smaller (or equal to) the key in X
With the exception of the root (which has no
parent)
min-heap