Graphs (Discussion 12) (Biểu diễn đồ thị và thuật toán Dijkstra) - Christine Zhou
Đang tạo bản xem trước...
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.
Mô tả
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óm tắt AI
- Tên tài liệu
- Graphs (Discussion 12) (Biểu diễn đồ thị và thuật toán Dijkstra) - Christine Zhou
- Trường / Môn
- University of California, Berkeley · Lập trình Java
- Nội dung
- 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.
- Mục lục
- 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
- Số trang
- 15 trang
- Người đăng
- Uni24h
Câu hỏi thường gặp
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ề.
Graphs (Discussion 12) (Biểu diễn đồ thị và thuật toán Dijkstra) - Christine Zhou
Đang tạo bản xem trước...
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
Đọc toàn bộ tài liệu
- Tên tài liệu
- Graphs (Discussion 12) (Biểu diễn đồ thị và thuật toán Dijkstra) - Christine Zhou
- Trường / Môn
- University of California, Berkeley · Lập trình Java
- Nội dung
- 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.
- Mục lục
- 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
- Số trang
- 15 trang
- Người đăng
- Uni24h
Bình luận (0)
Chưa có bình luận nào. Hãy là người đầu tiên!
Java DataBase Connectivity - Kết nối kho dữ liệu Java
Asymptotic Analysis (Discussion 7) (Phân tích tiệm cận) - Christine Zhou
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
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
Bình luận (0)
Chưa có bình luận nào. Hãy là người đầu tiên!