CS2_40_Graphs_BFS_DFS

# CS2_40_Graphs_BFS_DFS - CS2 Module 40 Category: CS Concepts...

This preview shows pages 1–17. Sign up to view the full content.

CS2 Module 40 Category: CS Concepts Topic: Graphs Objectives Graphs Searching BFS - DFS

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
CS 2 Introduction to Object Oriented Programming Module 40 CS Concepts Graphs - BFS - DFS
Menu Graph Terminology Graph Modeling Searching Breadth First Search Depth First Search

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Graphs :: Terminology A Graph is a set of vertices (nodes) and a set of unordered edges (linked between these nodes). The order of a graph is the number of vertices and the size is the edge count. A path is a set of edges connecting two nodes. A digraph or directed graph has edges (arcs) that flow in only one direction. In an undirected graph, edges flow in either direction.
Graphs :: Terminology Vertices (nodes) Edges Still part of graph, even if not connected An undirected graph

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Graphs :: Terminology A directed graph A path
Graphs :: Contrasted to Simple Data Structures Australo- linkus-listus One ‘next’ node No cycles Cromagnan Tree Two children (for binary tree) No cycles Opposable thumb Modern Graph Cycles allowed Numerous adjacencies per node

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
~Graphs :: Terminology Review: A Graph Graph is a set of vertices vertices (nodes) and a set of unordered edges edges (linked between these nodes). The order order of a graph is the number of vertices and the size size is the edge count. A path path is a set of edges connecting two nodes. A digraph digraph or directed directed graph has edges (arcs) that flow in only one direction. In an undirected undirected graph, edges flow in either direction. This is great fodder for a quiz
Directed Graphs B F C A E G D Directed edges only allow movement in one direction.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Weighted Edges B F C A E G D 5 3 2 1 4 7 1 2 3 9 9 Edge weights represent cost.
Weighted Directed Graphs B F C A E G D Directed edges only allow movement in one direction. 5 3 2 1 4 7 1 2 3 9 9

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Representing Graphs How do we represent a graph that has any number of children or connections? Adjacency matrices, Nodes held in some structure, or Each node has list of children Links held in some kind of structure Each link points to two nodes Which way is best? Depends!
Adjacency Matrix To Nodes From Nodes Initially empty Each edge adds an entry Undirected graph can Put in 2 entries per edge Use just upper or lower diagonal Directed graph uses entire matrix Unweighted graph inserts ‘1’ Weighted graph inserts the weight Size is O(N 2 ) Memory is usually sparsely utilized

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Undirected A G B C D E F A G B C D E F - . 5 . . 1 3 5 1 - 7 . 4 . . . 7 - 9 . . . 3 . 9 - 9 . 1 2 4 . 9 - 2 3 . . . . 2 - . - 1 . 3 2 . Weighted Edges B F C A E G D 5 3 2 1 4 7 1 2 3 9 9 Edge weights represent cost.
Undirected A G B C D E F A G B C D E F - . 5 . . 1 3 1 - 7 . 4 . . - 9 . . 3 - 9 . 2 - 2 . - - Weighted Edges B F C A E G D 5 3 2 1 4 7 1 2 3 9 9 Edge weights represent cost.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Directed Weighted Directed Graphs B F C A E G D Directed edges only allow movement in one direction.
This is the end of the preview. Sign up to access the rest of the document.

## CS2_40_Graphs_BFS_DFS - CS2 Module 40 Category: CS Concepts...

This preview shows document pages 1 - 17. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online