Posted by: mrdyson2 | October 10, 2010

Lecture 17 10/8/10

(Guest post by Matt Dyson)

There was an announcement that next Friday there will be an “office hours-a-thon” to help answer any questions for the upcoming midterm on 10/18/10.  There is also a sample midterm posted online.
In Fridays lecture, we began with reviewing the DFS algorithm, which stands for Depth First Search.  The main idea of this algorithm is to pick any node in the graph to begin with, and go through all the neighbors recursively.  As it “explores” each node, it will mark it as “explored”.

The algorithm for DFS is:

DFS(u)

Mark u as “explored” and add u to R

For every “unexplored” edge (u,v) ε E

If v is not explored

DFS(v)

We also talked about but didn’t prove the theorem that every non-tree edge is between a node an its ancestor.  This means that an ancestor is a node directly above a child (Theorem 3.7 in text book).

After we reviewed the Depth First Search, we began to look at the run-time analysis for the Bredth First Search (BFS) algorithm, and if we had time we would look at the run-time analysis of the Depth First Search algorithm as well.  The two data structures we would use for this are stacks and queues, we reviewed that stacks work in a last in, first out order and queues work in a first in first out (FIFO) order.

We then talked about two different ways of representing graphs, the first way was using an adjacency matrix, and the second way was using an adjacency list.  An adjacency matrix is an n x n matrix (n being the amount of nodes) where the rows and columns are both all of the nodes in the graph.  If the nodes are adjacent, the number in the matrix will be a 1, if they are not adjacent then there will be a 0 in that position of the matrix.  An adjacency list is a slight variation of the adjacency matrix, it contains a list of all n nodes, which points to another list of all adjacent nodes.

After we went over the explanation of both graph representations, we compared various run times on both representations.  The first thing we looked at was finding any (u,v) in E.  For the adjacency matrix it would take O(1) time, and for the adjacency list it would take O(n_v) time, v being the number of neighbors of v.  The second thing we looked at was finding all neighbors of u.  For the adjacency matrix, this would take O(n) time and for the adjacency list, this would take O(n_u) time, u being the number of neighbors of u.  The last thing we looked at was Space.  For the adjacency matrix, it would take O(n²) time, and for the adjacency list it would take O(m+n) time.  From this we realized that the adjacency list is much better for sparse graphs and traversals.

We claimed that m ≤ (n choose 2) = n(n-1)/2 ≤ n²

(u,v) ε E <=> (v,u) ε E

|E| <= unordered pairs (u,v) ε VxV

G = (V,E)    E is a subset of VxV

We also pointed out that the space for the adjacency list is O(n + Σ n_u).  We claimed that Σ n_u = 2m.  We did not have time to do the proof for this though since class ended.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: