We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 7
Discussion 11
Christine Zhou Agenda Announcements
Worksheet/Review (1-4)
Extra for Experts
Announcements - Hope you all had a restful and fun spring break! - Thank you for all your comments! - Popular one: try to finish more of the worksheet, will do my best! - Hashing HW 4 due Thursday - Labs will be midterm review - Topic based, can go to any lab - Midterm this Friday - 4-6 PM, room assignments posted on Piazza - Ungraded autograder is up - Attendance: shoutkey.com/feet Depth First Search (DFS) - Analogy from last time: RECURSIVE IMPLEMENTATION OF DFS searching a box in its entirety private void dfs(Graph G, int v) { before moving onto marked[v] = true; searching the next for (int w : G.adj(v)) { - Explore as far as possible if (!marked[w]) { before going back edgeTo[w] - Runtime: ϴ(V + E) = v; - Ex: want to find paths to all dfs(G, other vertices from some w); } starting vertex } } Graph Traversals - DFS Preorder: write down the vertex when you first see it - DFS Postorder: write down the vertex when all its outgoing neighbors have been explored - Help us if we want to find a topological sort of something! - Topological sort: - reverse DFS postorder is one way - just need to make sure all incoming vertices have been visited first (think of prerequisites) Breadth First Search (BFS) - Analogy from last time: ITERATIVE IMPLEMENTATION OF BFS private void bfs(Graph G, int s) { searching layers of Queue<Integer> fringe = new boxes and equally Queue<Integer>(); fringe.enqueue(s); exploring each box marked[s] = true; - Explore one-away while (!fringe.isEmpty()) { int v = fringe.dequeue(); neighbors, then two- for (int w : G.adj(v)) { away, then three- if (!marked[w]) { fringe.enqueue(w); away... marked[w] = true; - Runtime: ϴ(V + E) edgeTo[w] = v; - } Ex: can be helpful in } finding shortest paths } } Regular Expressions operation Order example matches Does not match (precedence)
Concatenation 3 AABAAB AABAAB Every other string
Or 4 AA|BABB AA or BABB Every other string
Closure (0 or more) 2 AB*A AA or ABBBBA AB or ABABA