Graphs (Network)

Graphs (Network) - A B C D E A F T T F F B T F F F T C T F...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: A B C D E A F T T F F B T F F F T C T F F T F D F F T F T E F T F T F 2D array 5x5 ○ Boolean matrix ○ Boolean[ ][ ] M=new boolean [5][5] ○ Adjacency matrix/table storage 1. need int or float matix ○ True=> edge weight ○ False=> -1 ○ Weighted/Directed graph 2. Storing a graph in a program O(n 2 ) ○ For graph with n vertices and e edges • Space? Is M[x][y] true? ○ Worst case time for adjacency matrix= O(1) • Is there an edge (x,y) [undirected graph] in the graph? Worst case time= O(n) • Best case time= O(n) • Scan row x • What are all the neighbors of x? Max # of edges= n(n-1) • 2 Simple graph with n verticies O(n logn)= dividing line • Dense vs Sparse Graphs Space: O(n 2 ) ○ O(1) □ Is edge (x,y) in graph? O(n) □ Find/List all neighbors of x Run time ○ Appropriate for dense graphs ○ For sparse graphs, waste a lot of space storing false values ○ Instead, store the neighbors for each of the vertices in a LL ○ Adjacency matrix 1. n+2e # of array spots=n 2e undirected □ E directed □ # of nodes= O(n+e) Space: ○ Is edge (x,y) in graph? Run time: ○ Adjacency LL 2. Storage Schemes A 0 C 2 B 1 D 3 E 4 Graphs (Network) Monday, April 04, 2011 3:49 PM Lecture Notes Page 1 O(min(n,e)) □ O(min(n,e)) □ Find/List all neighbors of x Much better for sparse graphs (generally considered default since graphs are usually more sparse) ○ O(1) Vertex num->name ○ Sequential search □ Worst case O(n) Vertex name-> num ○ Arrays 1....
View Full Document

This note was uploaded on 03/29/2012 for the course CS 112 taught by Professor Sesh during the Spring '07 term at Rutgers.

Page1 / 4

Graphs (Network) - A B C D E A F T T F F B T F F F T C T F...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online