Dastal DEMO
Dastal DEMO
Ponteras
DATA
STRUCTURES &
ALGORITHMS
Algorithm
an algorithm is any well-defined computational procedure that takes
input and produces output.
Applications
Terminology
Digraphs
Undirected Graph
Weighted graphs
Trees
Definition
Tree traversal
Graph
A graph is a pair (V, E), where
V is a set of nodes, called vertices
E is a collection of pairs of vertices, called edges
Vertices and edges are positions and store elements
Example:
A vertex represents a town and stores the three-letter town
code
An edge represents a route between two towns and stores
the mileage of the route
849 SC
1843 SAG 2
BAC 14
7 43 802 KAB
337
1 8 7 10
2555 13
PUL 1233 99
BAG HIN 1120
BIN
Edge Types
Directed edge
ordered pair of vertices (u,v)
first vertex u is the origin
second vertex v is the
destination trip
BAC AA 1206 SC
e.g., a trip
Undirected edge
unordered pair of vertices
(u,v) 849
BAC SC
e.g., a trip route miles
Directed graph
all the edges are directed
e.g., trip network
Undirected graph
all the edges are undirected
e.g., route network
Applications
Electronic circuits cslab1a cslab1b
Printed circuit board
math.brown.edu
Integrated circuit
Transportation networks
cs.brown.edu
Highway network
Flight network
brown.edu
Computer networks qwest.net
Local area network att.net
Internet
Web
cox.net
Databases John
of a
Edges incident on a vertex V
a, d, and b are incident on a b
V h j
Adjacent vertices U d X Z
U and V are adjacent c e i
Degree of a vertex W g
X has degree 5
Parallel edges f
Y
h and i are parallel edges
Self-loop
j is a self-loop
Terminology (continued)
Path
sequence of alternating
A
Digraph Properties
C
B
A
Undirected Graph
849 SC
1843 SAG 2
BAC 14
802
1205
43 KAB
17
337
7
PUL 2555 138 10
99
1233
BAG HIN 1120
BIN
Shortest Path Problem
Given a weighted graph and two vertices u and v, we want to
find a path of minimum total weight between u and v.
Length of a path is the sum of the weights of its edges.
Example:
Shortest path between Pulupandan and San Carlos
849 SC
1843 SAG 2
BAC 14
802
1205
7 43 KAB
337
1 8 7 10
2555 13
PUL 1233 99
BAG HIN 1120
BIN
Tree
preorder
inorder
postorder
Preorder traversal
F, B, A, D, C, E, G, I, H
Inorder traversal
A, B, C, D, E, F, G, H, I
Postorder traversal
A, C, E, D, B, H, I, G, F
END