Review Graph and Trees and New Topic On Trees
Review Graph and Trees and New Topic On Trees
Tree height
□ The height of the root of the
tree, or
□ The number of levels of a tree
-1.
□ The height of the given tree
is 3.
Special
Trees
□ Binary Tree
□ Binary Search Tree
□ Balanced Tree
□ Binary Heap/Priority
Queue
□ Red-Black Tree
□ All nodes rooted at the left child are smaller than the
current node value
□ All nodes rooted at the right child are smaller than the
current node value
25 – 10 – 12 – 7 – 8 –
15 – 5
CS 5002: Discrete ©Northeastern Fall 38
DFS Example
25 – 10 – 7 –8 – 12 –
15 – 5
CS 5002: Discrete ©Northeastern Fall 40
Tree Traversals
Example
Traverse the tree below, using:
□ Pre-order traversal: 25 – 10 – 7 – 8 – 12
– 15 – 5
Formal Definition:
□ A graph G is a pair (V, E ) where
□ V is a set of vertices or nodes
□ E is a set of edges that connect vertices
Simply put:
□ A graph is a collection of nodes (vertices) and
edges
□ Linked lists, trees, and heaps are all special cases
of graphs
v2), B
in□V V =2 { A , B , C , D, E , F }
□ E = { ( A , B ) , (A, D ) , ( B , C
C), D
(C, D ) , (C, E ) , ( D, E ) } A
□ directed vs
undirected
□ weighted vs
unweighted
□ simple vs non-
simple
□ sparse vs dense
□ cyclic vs acyclic
□ labeled vs unlabeled
□ otherwise directed
C
D
way) A
20 E
assigned a numerical B
10
value (weight). 8
4
□ A road network 15 C
2
might be labeled D
with: A
7
□ length
□ drive-time
□ speed-limit
□ In an unweighted graph,
there is no distinction
between edges.
E
make working with B
graphs complicated
□ A self-loop is an edge C
□ An edge (x, y) is a A
multiedge if it occurs
more than once in a
graph.
E
small fraction of vertex B
□ An acyclic graph F
E
contains no cycles B
cycle D