Graphs (Discussion 12) (Biểu diễn đồ thị và thuật toán Dijkstra) - Christine Zhou
Tài liệu thảo luận về đồ thị: biểu diễn đồ thị, các thuật toán duyệt (DFS, BFS), sắp xếp tô-pô và thuật toán Dijkstra, kèm bài tập thực hành.
Generating preview...
Discussion 12: Graphs Christine Zhou Agenda Announcements Let’s try to get through all the worksheet! Announcements Congratulations on finishing the project and getting through these past few weeks! Stay strong, keep pushing through :) HW 7 has been released Threads for each section on Piazza Want to chat? Email me! Graphs Can represent relationships! Family trees, cities and roads, etc. Lots of terminology: Vertices/nodes: graphs are made up of a set of these Edges: connect two vertices together (can be (un)directed) Adjacent: vertices with an edge between them Labels/Weights: the value of a vertex or edge Path: vertices connected by edges Cycle: path whose first and last vertices are the same Connectivity: vertices are connected if there is a path in between them; graphs are connected if all vertices are connected How do we represent a graph? Adjacency matrix Edge set Adjacency list 1 Graph Representation Represent the graph above with an adjacency list and an adjacency matrix representation. General Graph Traversal Algorithm Stack fringe = new Stack(); Set visited = new Set(); fringe.push (startVertex); while (!fringe.isEmpty()) { Vertex v = fringe.pop(); if (!visited.contains(v)) { process(v); //do something with v for (Vertex neighbor: v.neighbors) { fringe.push(neighbor); } visited.add(v); } } Depth First Search (DFS) Explore as far as possible before going back Search down entire subgraph of a child before moving onto the next child If there are multiple children that you could explore, break ties alphabetically Preorder: mark the current vertex, then visit the children Postorder: visit the children, then mark the current vertex Fringe is a stack Runtime: O(V + E) Visualization: here RECURSIVE IMPLEMENTATION OF DFS private void dfs(Graph G, int v) { marked[v] = true; for (int w : G.adj(v)) { if (!marked[w]) { edgeTo[w] = v; dfs(G, w); } } } Breadth First Search (BFS) ITERATIVE IMPLEMENTATION OF BFS
… Tải file gốc để đọc toàn bộ tài liệu.
- Document name
- Graphs (Discussion 12) (Biểu diễn đồ thị và thuật toán Dijkstra) - Christine Zhou
- School / Course
- University of California, Berkeley · Lập trình Java
- Content
- Tài liệu giới thiệu về đồ thị, các cách biểu diễn, thuật toán duyệt (DFS, BFS), sắp xếp tôpô và thuật toán Dijkstra tìm đường đi ngắn nhất. Nó cung cấp cả lý thuyết và bài tập thực hành.
- Table of contents
- Agenda
- Announcements
- Graphs
- 1 Graph Representation
- General Graph Traversal Algorithm
- Depth First Search (DFS)
- RECURSIVE IMPLEMENTATION OF DFS
- Breadth First Search (BFS) ITERATIVE IMPLEMENTATION OF BFS
- 2 Searches and Traversals
- Topological Sorting
- 3 Topological Sorting
- Dijkstra’s Algorithm
- 4 Dijkstra’s Algorithm
- 5 Dijkstra’s Correctness
- Doc.pages
- 15 pages
- Uploaded by
- Giang Le
Frequently asked questions
Tài liệu này có miễn phí không?
Có. “Graphs (Discussion 12) (Biểu diễn đồ thị và thuật toán Dijkstra) - Christine Zhou” miễn phí — bạn chỉ cần đăng nhập rồi bấm Tải xuống để lấy file gốc.
Tài liệu dài bao nhiêu trang?
Tài liệu gồm 15 trang, thuộc môn Lập trình Java. Bạn có thể xem trước online trước khi tải.
Tôi có thể xem trước trước khi tải không?
Có. Bạn xem trước tài liệu ngay trên trang này bằng trình đọc online, rồi quyết định tải về.

Comments (0)
No comments yet. Be the first!