1 / 8

Course Outline

This course covers the fundamentals of data structures and algorithms, including graph representations and algorithms, tree data structures, hash tables, and more. It also covers various graph algorithms such as topological sort, minimum spanning trees, and shortest-path algorithms.

lnugent
Download Presentation

Course Outline

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Course Outline • Introduction and Algorithm Analysis (Ch. 2) • Hash Tables: dictionary data structure (Ch. 5) • Heaps: priority queue data structures (Ch. 6) • Balanced Search Trees: general search structures (Ch. 4.1-4.5) • Union-Find data structure (Ch. 8.1–8.5) • Graphs: Representations and basic algorithms • Topological Sort (Ch. 9.1-9.2) • Minimum spanning trees (Ch. 9.5) • Shortest-path algorithms (Ch. 9.3.2) • B-Trees: External-Memory data structures (Ch. 4.7) • kD-Trees: Multi-Dimensional data structures (Ch. 12.6) • Misc.: Streaming data, randomization

  2. Graphs: directed and undirected and labeled a g a b b d e d c f h c e j i • A GRAPHG = (V, E) where V is a set of vertices (nodes), and E is a set of edges (arcs), i.e., pairs of vertices • DIRECTED graphs (digraphs): edges are directed • UNDIRECTED graphs: edges are undirected • Labeled graphs: edges have labels, directed or undirected

  3. Adjacency matrix • G=(V,E) and V={v1,…,vN} • A(i,j) = 1 if (vi,vj) is in E, A(i,j) = 0 otherwise • Space: O(N2) • Edge insertion/deletion: O(1) • Find all adjacent vertices to a vertex: O(N)

  4. Adjacency lists • All vertices adjacent to vi are stored in the list adj(vi) • Space: O(N+|E|) • Edge insertion/deletions • Find all adjacent vertices to a vertex adj(a) = (b, d) adj(b) = (c, f) adj(c) = (a, d, e) adj(d) = (e) adj(e) = () adj(f) = (c) adj(g) = (f, h) adj(h) = (f, j) adj(i) = (h) adj(j) = (I) adj(a) = (b, d, e) adj(b) = (a, c, d) adj(c) = (b, d, e) adj(d) = (a, b, c) adj(e) = (a, c)

  5. Paths and simple paths g a b a d c f h b d e e j i c • A PATH is a sequence of vertices v1, …, vkwhere each (vi , vi+1) is an edge • SIMPLEpath: vi ¹ vj, except that v1 may be equal tovk • Path LENGTH: number of edges in the path • A CYCLE: a path v1, …, vk such that v1 = vk • Examples: abdcea (undirected), hjihfcad (directed)

  6. Topological sort g a b h i d c f e • Ordering of vertices in a digraph such that if there is an edge from vi to vj, vi appears before vj in the ordering • Complexity: O(|V|+|E|) proc topsort() for each vertex v do if in[v]=0 then Enqueue(v,Q) while not empty(Q) do Dequeue(v,Q) print(v) for each vertex w in adj[v] do if (--in[w]=0) then Enqueue(w,Q) O(|V|) O(|E|)

  7. Unweighted shortest path g a b d c f h e j i • Find length of the shortest path from a vertex v • Naïve algorithm would take time O(|V|2) • AnO(|V|+|E|) algorithm: procedure shortest-path(v) for each vertex x do visited[x] = false dist[x] = infinity visited[v] = true dist[v] = 0 Enqueue(v,Q) while notEmpty(Q) do Dequeue(x,Q) for each w in adj[x] do if not visited[w] visited[w] = true dist[w] = dist[x]+1 Enqueue(w,Q)

  8. Graph traversal: breadth-first search g a a b b d e d c f h c e j i for each vertex v do visited[v] = false for each vertex v do if visited[v] = false BFS(v) • Complexity: O(N+|E|) proc BFS(v) // Q is a queue of vertices visited[v] = true Enqueue(v,Q) while notEmpty(Q) do Dequeue(x,Q) for each vertex win adj[x]do if not visited[w] visited[w] = true Enqueue(w,Q) O(|V|) O(|E|)

More Related