You are on page 1of 24

Discrete Math 07

Graph

Today’s Tree
Menu:
Their implementation in
IT/CS
TL;DR: How we represent
relationship among discrete
objects
What the We represent them as nodes and
junk is edges indicating relationship
among nodes
Graph?
We can also put some weight on
edges (later!)
A tiny bit of history

• Leonhard Euler (OY-ler), a Swiss, asked a question over Konigsberg aka


Kaliningrad and its seven bridges whether it is possible to go through each
bridge and back where we started
• Spoiler alert: impossibru
• We will discuss Euler circuit later this chapter!
A graph is defined as a paired
set vertices and edges in which
each edges connect two nodes
and the vertex set is not empty
Mathematical
Definitions
Graph of one node is called
“trivial graph”
Simple Graph

Un-directed graph
Types of Directed graph
Graphs
Multigraph

Pseudograph
Electrical and electronics circuit

Carbon compound isomers


• Recall your high school (organic) chemistry!
Application Concurrent data transactions on database
s of Graphs: Automata
• Sadly, you wouldn’t get Formal Language and
Automata

Flowchart
Adjacent
Incident
Isolated Vertex
Null/Empty Graph
Degree
Path
Terminologies: Circuit/Cycle
Connected
Subgraph
Spanning Subgraph
Cut-Set
Weighted Graph
Complete Graphs
Some
special Circular Graphs
simple Regular Graphs
graphs
Bipartite Graphs
Using adjacency Matrix
How do we
represent Incidence Matrix
graph in
Adjacency List
our field?
• Same deal with DS&A
TL;DR: is a graph that have
same representation
Isomorphic • Shapes may differ, but adjacency
Graph is the same

You can make out which


vertex correspond to which
vertex
Planar Graph • TL;DR: graph with NO intersecting edges
Euler Path: Path that passes through each edges
exactly once

Eulerian Euler Circuit: Euler Path that returns to itself

Path and You can make Euler Circuit if and only if all vertices has
even degree

Circuit There’s also Semi-Euler graph which has exactly two


odd degreed vertices

In case of directed graph, Euler Circuit is only possible


if every vertex has same inbound and outgoing degrees
Hamiltonian
• Like Eulerian, with a difference: Euler focus
Path and on edges, Hamilton focus on vertices
Circuit
This generally uses weighted graph
• Each weight of edge

Shortest Your goal is to figure out the shortest path in a


graph

Path • Since you had AI already, can I skip this?

Dijkstra Algorithm: Please read more about


Problem this!

Another similar problem: Traveling Sales


Problem
• This is similar, but with a twist: you had to visit all vertices
AND go back to where you start as well
Tree is some sort of
specialized graph in which it
must not contain any circuit
Tree
Several trees form a forest
Each node pair of tree needs to
have single path

Tree Tree does not contain circuit


Properties
Each node is connected to other
nodes and only one path in that
node
TL;DR: This is the reduction of a connected
graph into a tree

Spanning There is a thing called “Minimum Spanning


Tree” in which the total weight of the entire

Tree
tree must be minimum, but the tree must be
formed

You construct the tree using Prim algorithm


and Kruskal algorithm
A tree with central node

Rooted • All nodes in the tree would lead to such


node

Tree
• Officially, this is directed, but normally
is omitted

One tree can have different


form factor depend on which
node you choose to be the root
Children-Parent relationship

Path

Descendant and Ancestor

Some Sibling

Subtree
terminologies Degree

of rooted tree Leaf

Internal Nodes

Level

Height or Depth
Is a tree that each
internal node has at
most M children
M-ary tree
Full M-ary tree:
Where all nodes are
full
Is crucial for our
field in IT
Binary Tree
Recall M-ary tree,
in binary tree, M =
2
Language parsing tree
• Both computer language (which you don’t get

Application
now) and Human Language

Expression Tree
of Tree Decision tree
structure: Huffman Coding (in data
compression)
Binary Search Tree
Tree Traversal Strategies
• Pre-order: root first
• In-order: First child first, then root, then all other children
• Post-order: Children first, then root
• Often made easy with binary tree

You might also like