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.
描述
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
AI 摘要
- 文档名称
- Graphs (Discussion 12) (Biểu diễn đồ thị và thuật toán Dijkstra) - Christine Zhou
- 学校 / 课程
- University of California, Berkeley · Lập trình Java
- 内容
- 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.
- 目录
- 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
- 页数
- 15 页
- 上传者
- Uni24h
常见问题
此文档免费吗?
是的。“Graphs (Discussion 12) (Biểu diễn đồ thị và thuật toán Dijkstra) - Christine Zhou”是免费的 — 只需登录并点击“下载”即可获取原始文件。
这份文档有多少页?
该文档共有 15 页,适用于课程 Lập trình Java。您可以在下载前进行在线预览。
我可以在下载前预览吗?
是的。您可以通过在线阅读器直接在本页面预览此文档,然后再决定是否下载。
Graphs (Discussion 12) (Biểu diễn đồ thị và thuật toán Dijkstra) - Christine Zhou
正在生成预览...
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
阅读全文
- 文档名称
- Graphs (Discussion 12) (Biểu diễn đồ thị và thuật toán Dijkstra) - Christine Zhou
- 学校 / 课程
- University of California, Berkeley · Lập trình Java
- 内容
- 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.
- 目录
- 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
- 页数
- 15 页
- 上传者
- Uni24h
评论 (0)
暂无评论。快来抢沙发吧!
Misc.onclusion (Discussion 14-END) (Ôn tập cấu trúc dữ liệu) - Christine Zhou
Final Review Solutions (Cấu trúc dữ liệu heap, hàng đợi ưu tiên và duyệt đồ thị) - Ching and Christines
Giáo trình Lập trình Java
Inheritance (Discussion 4) (Kế thừa trong Java) - Christine Zhou
Asymptotic Analysis (Discussion 7) (Phân tích tiệm cận) - Christine Zhou
Chương 7.Cơ học lượng tử - Vật lý đại cương 3 - TS.Nguyễn Thị Trang
Chương 6.Quang học lượng tử - Vật lý đại cương 3 - TS.Nguyễn Thị Trang
Chương 5.Thuyết tương đối - Vật lý đại cương 3 - TS.Nguyễn Thị Trang
Chương 4. Tán xạ ánh sáng - Vật lý đại cương 3 - TS.Nguyễn Thị Trang
Chương 3.Phân cực ánh sáng - Vật lý đại cương 3 - TS.Nguyễn Thị Trang
评论 (0)
暂无评论。快来抢沙发吧!