A Heap Is Efficiently Represented As An Array
9 8 7 6 7 2 6 5 1
1 2 3 4 5 6 7 8 9 10 9 8 6 7 2 6 5 1 7
A Heap Is Efficiently Represented As An Array 9 8 7 6 7 2 6 5 - - PowerPoint PPT Presentation
A Heap Is Efficiently Represented As An Array 9 8 7 6 7 2 6 5 1 9 8 7 6 7 2 6 5 1 0 1 2 3 4 5 6 7 8 9 10 Moving Up And Down A Heap 1 9 2 3 8 7 4 7 5 6 6 7 2 6 5 1 8 9 Putting An Element Into A Max
A Heap Is Efficiently Represented As An Array
9 8 7 6 7 2 6 5 1
1 2 3 4 5 6 7 8 9 10 9 8 6 7 2 6 5 1 7
9 8 6 7 2 6 5 1 7 1 2 3 4 5 6 7 8 9
Putting An Element Into A Max Heap
Complete binary tree with 10 nodes.
9 8 6 7 2 6 5 1 7 7
Putting An Element Into A Max Heap
New element is 5.
9 8 6 7 2 6 5 1 7 7 5
Putting An Element Into A Max Heap
New element is 20.
9 8 6 7 2 6 5 1 7 7 7
Putting An Element Into A Max Heap
New element is 20.
Putting An Element Into A Max Heap
New element is 20.
9 8 6 7 2 6 5 1 7 7 7
Putting An Element Into A Max Heap
New element is 20.
9 8 6 7 2 6 5 1 7 7 7 20
Putting An Element Into A Max Heap
Complete binary tree with 11 nodes.
9 8 6 7 2 6 5 1 7 7 7 20
Putting An Element Into A Max Heap
New element is 15.
9 8 6 7 2 6 5 1 7 7 7 20
Putting An Element Into A Max Heap
New element is 15.
9 8 6 7 2 6 5 1 7 7 7 20 8
Putting An Element Into A Max Heap
New element is 15.
8 6 7 2 6 5 1 7 7 7 20 8 9 15
Complexity is O(log n), where n is heap size.
8 6 7 2 6 5 1 7 7 7 20 8 9 15
Max element is in the root.
8 6 7 2 6 5 1 7 7 7 20 8 9 15
After max element is removed.
8 6 7 2 6 5 1 7 7 7 8 9 15
Heap with 10 nodes.
8 6 7 2 6 5 1 7 7 7 8 9 15
Reinsert 8 into the heap.
6 7 2 6 5 1 7 7 7 9 15
Reinsert 8 into the heap.
6 7 2 6 5 1 7 7 7 9 15
Reinsert 8 into the heap.
6 7 2 6 5 1 7 7 7 9 15 8
Max element is 15.
6 7 2 6 5 1 7 7 7 9 15 8
After max element is removed.
6 7 2 6 5 1 7 7 7 9 8
Heap with 9 nodes.
6 7 2 6 5 1 7 7 7 9 8
Reinsert 7.
6 2 6 5 1 7 9 8
Reinsert 7.
6 2 6 5 1 7 9 8
Reinsert 7.
6 2 6 5 1 7 9 8 7
Complexity Of Remove Max Element
Complexity is O(log n).
6 2 6 5 1 7 9 8 7
Heap is not a search data-structure
You are interested in minimum or maximum
There are efficient ways to convert an array
Requires O(n) time to convert an array into a
TA Office Hours
Wednesdays 3 to 5 pm in the PC lab
Homework 2
Updated the PDF document
Made a few things clear; Corrected a few things
Updated the .zip file
Makefiles in both directories Changes to hashT
emplate.c file
EE717: Advanced Computing foR ELECTRICAL Engineers Lecture 8
Graphs
Shankar Balachandran, IIT Bombay (shankarb@ee.iitb.ac.in)
24 Aug 2014
G = (V,E) V is the vertex set. Vertices are also called nodes and points. E is the edge set.
Each edge connects two different vertices. Captures relationships between vertices
Directed edge has an orientation (u,v).
Adjacency Matrix Adjacency Lists
0/1 n x n matrix, where n = # of vertices A(i,j) = 1 iff (i,j) is an edge
2 3 1 4 5
2 3 1 4 5
1 2 3 4 5 1 2 3 4 5 1 1 1 1 1 1 1 1 1 1
2 3 1 4 5
1 2 3 4 5 1 2 3 4 5 1 1 1 1 1 1
n2 bits of space For an undirected graph, may store only lower
O(n) time to find vertex degree and/or
Adjacency list for vertex i is a linear list of vertices adjacent from vertex i. An array of n adjacency lists.
2 3 1 4 5
Each adjacency list is a chain.
2 3 1 4 5
aList[1] aList[5] [2] [3] [4] 2 4 1 5 5 5 1 2 4 3
Each adjacency list is an array list.
2 3 1 4 5
aList[1] aList[5] [2] [3] [4] 2 4 1 5 5 5 1 2 4 3
Cost adjacency matrix.
Adjacency lists => each list element is a pair
2 3 8 10 1 4 5 9 11 6 7
2 3 8 1 1 4 5 9 11 6 7