1
COMP 250
Lecture 28
graphs
- Nov. 13, 2017
graphs Nov. 13, 2017 1 Example e g a c f d h b 2 Same - - PowerPoint PPT Presentation
COMP 250 Lecture 28 graphs Nov. 13, 2017 1 Example e g a c f d h b 2 Same Example different notation e g a c f d h b 3 Weighted Graph e g 9 a 12 11 4 c f 5 7 7 d 2 4 h b 4 Definition A directed graph is
1
2
3
4
6
7
8
9
11
12
13
14
16
303 Software Design 302 Program Lang 273 Comp. Sys. 251 Data Str & Alg 350 Num. Meth 421 Data- bases 424 Artif. Intel. 310 Oper. Sys. 360 Alg. Design 330 Theory Comp. 206 Software Sys 250 Intro CompSci 202 Intro Program 240 Disc.
223 Linear Alg. 222 Cal III 323 Prob. SYSTEMS (compilers, networks, distributed sys, concurrency, web,..) APPLICATIONS (graphics, vision, bioinf, games, machine learning..) THEORY (crypto, optimization, game theory, logic, correctness, computability..) MATH (prereqs for many upper level COMP courses)
19
// alternatively…. class TreeNode<T>{ T element; TreeNode<T> firstChild; TreeNode<T> nextSibling; : }
21
class Tree<T>{ TreeNode<T> root; : // inner class class TreeNode<T>{ T element; ArrayList< TreeNode<T> > children; TreeNode<T> parent; } }
22
Here each adjacency list is sorted, but that is not always possible (or necessary).
class Graph<T> { class Vertex<T> { ArrayList<Edge> adjList; T element; boolean visited; } class Edge { Vertex endVertex; double weight; : } } Unlike a rooted tree, there is no notion of a root vertex in a graph.
e.g. YUL for Trudeau airport, LAX for Los Angeles, …
25
26
27
Graph HashMap Vertex Vertex Edge Edge Edge Edge Edge Vertex ArrayList ArrayList ArrayList
28
Assume we have a mapping from vertex names to 0, 1, …. , n-1.
29
36