SlideShare una empresa de Scribd logo
1 de 24
CS 6213 –
Advanced
Data
Structures
Lecture 2
GRAPHS AND THEIR
REPRESENTATION
TREES, PATHS, CYCLES
TOPOLOGICAL SORTING
 Instructor
Prof. Amrinder Arora
amrinder@gwu.edu
Please copy TA on emails
Please feel free to call as well
 TA
Iswarya Parupudi
iswarya2291@gwmail.gwu.edu
CS 6213 – Arora – L2 Advanced Data Structures - Graphs 2
LOGISTICS
L4 - BTrees CS 6213 - Advanced Data Structures - Arora 3
CS 6213
Basics
Record /
Struct
Arrays / Linked
Lists / Stacks
/ Queues
Graphs / Trees
/ BSTs
Advanced
Trie, B-Tree
Splay Trees
R-Trees
Heaps and PQs
Union Find
 Graphs – Basics
 Degrees, Number of Edges, Min/Max Degree
 Kinds of Graphs
 How to Represent in Data Structures
 Trees, Paths, Cycles
 Journeys
 Topological Sorting, DAGs
CS 6213 – Arora – L2 Advanced Data Structures - Graphs 4
AGENDA
 A graph G=(V,E) consists of a finite set V, which is the
set of vertices, and set E, which is the set of edges.
Each edge in E connects two vertices v1 and v2,
which are in V.
 Can be directed or undirected
Not to be confused with a bar graph!!!! 
CS 6213 – Arora – L2 Advanced Data Structures - Graphs 5
GRAPH
A core data structure that shows up in many
circumstances:
 Transportation and Logistics (paths, etc.)
 Circuit Design
 Social Networking – Model connections between people
 Sociology – Model influence
 Zoology and Wildlife
 Project Task Management
 Job Scheduling and Resource Assignment (matching)
 Time table scheduling
 Task parallelization (graph coloring)
CS 6213 – Arora – L2 Advanced Data Structures - Graphs 6
GRAPH – APPLICATIONS
 (Undirected) Degree of a node
 (Directed) Indegree / Outdegree
 Min degree in a graph: 
 Max degree in a graph: 
 Basic observations
 (Undirected) Sum of degrees = 2 x number of edges
 (Directed) Sum of indegree = Sum of outdegree = number of
edges
CS 6213 – Arora – L2 Advanced Data Structures - Graphs 7
DEGREE
 If (x,y) is an edge, then x is said to be adjacent to y, and y is adjacent
from x.
 In the case of undirected graphs, if (x,y) is an edge, we just say that x
and y are adjacent (or x is adjacent to y, or y is adjacent to x). Also, we
say that x is the neighbor of y.
 The indegree of a node x is the number of nodes adjacent to x
 The outdegree of a node x is the number of nodes adjacent from x
 The degree of a node x in an undirected graph is the number of
neighbors of x
 A path from a node x to a node y in a graph is a sequence of node x,
x1,x2,...,xn,y, such that x is adjacent to x1, x1 is adjacent to x2, ..., and xn
is adjacent to y.
 The length of a path is the number of its edges.
 A cycle is a path that begins and ends at the same node
 The distance from node x to node y is the length of the shortest path
from x to y.
CS 6213 – Arora – L2 Advanced Data Structures - Graphs 8
GRAPH DEFINITIONS
 Using a matrix A[1..n,1..n] where A[i,j] = 1 if (i,j) is an
edge, and is 0 otherwise. This representation is called
the adjacency matrix representation. If the graph is
undirected, then the adjacency matrix is symmetric about
the main diagonal.
 Using an array Adj[1..n] of pointers, which Adj[i] is a
linked list of nodes which are adjacent to i.
 The matrix representation requires more memory, since it
has a matrix cell for each possible edge, whether that
edge exists or not. In adjacency list representation, the
space used is directly proportional to the number of
edges.
 If the graph is sparse (very few edges), then adjacency
list may be a more efficient choice.
CS 6213 – Arora – L2 Advanced Data Structures - Graphs 9
GRAPH REPRESENTATIONS
 A very practical choice is to use graphing libraries,
such as:
 JGraphT (Java)
 Boost (C++)
 GraphStream (Java)
 JUNG (Java)
CS 6213 – Arora – L2 Advanced Data Structures - Graphs 10
GRAPH REPRESENTATION (CONT.)
 Graphs can be characterized in many ways. Two
important ones being:
 Directed or Undirected
 Weighted or Unweighted
 Both Adjacency Matrix (AM) and Adjacency List (AL)
representations can be used for graphs – weighted
or unweighted, directed or undirected.
 A[i,j] = A[j,i] if graph is undirected. So, we could decide to use
just the upper triangle.
 If graph is weighted, in adjacency list, we can also store the
weight. AL[i] = [(j,w(i,j)), (k,w(i,k)), …]
CS 6213 – Arora – L2 Advanced Data Structures - Graphs 11
GRAPH CHARACTERIZATIONS
 A tree is a connected acyclic graph (i.e., it has no
cycles)
 Rooted tree: A tree in which one node is designated
as a root (the top node)
CS 6213 – Arora – L2 Advanced Data Structures - Graphs 12
TREE
Example:
Node A is root node
F and D are child nodes of A.
P and Q are child nodes of J.
Etc.
 Definitions
 Leaf is a node that has no children
 Ancestors of a node x are all the nodes on the path from x to
the root, including x and the root
 Subtree rooted at x is the tree consisting of x, its children and
their children, and so on and so forth all the way down
 Height of a tree is the maximum distance from the root to any
node
CS 6213 – Arora – L2 Advanced Data Structures - Graphs 13
TREE (CONT.)
Option 1
•Trees are
graphs, so we
can use
standard graph
representation
– Adjacency
Matrix or
Adjacency List
Option 2
•Use parent
node and list
for child nodes
Option 3
•Use parent
node, and two
pointers – one
for first child
and the other
for nextSibling
CS 6213 – Arora – L2 Advanced Data Structures - Graphs 14
REPRESENTING TREES
3 Basic Options
 We can use standard graph representation –
Adjacency Matrix or Adjacency List
 These options are overkill for trees, but in some
instances, the graph is not known to be a tree
beforehand, so this option works.
CS 6213 – Arora – L2 Advanced Data Structures - Graphs 15
TREE REPRESENTATION – OPTION 1
 Rather than using Adjacency Matrix
or Adjacency List representation,
we can use a simpler representation
 Each node has a pointer to parent,
and a linked list of child nodes
 The root node’s parent pointer is null
 This representation works for “rooted” trees. If the
tree is not rooted, we can designate one node as
root.
CS 6213 – Arora – L2 Advanced Data Structures - Graphs 16
TREE REPRESENTATION – OPTION 2
Node {
Node parent,
List<Node> childNodes
}
 Another representation for Trees: Left
Child, Right Sibling representation for a
tree. Each node has 3 pointers:
 Parent – Points to parent (null if this is the root
node)
 Left pointer – Points to first child (null if this is
a leaf node)
 Right pointer – Points to right sibling (null if no
more siblings)
 For example:
 is represented by
CS 6213 – Arora – L2 Advanced Data Structures - Graphs 17
TREE REPRESENTATION – OPTION 3
Node {
Node parent,
Node firstChild,
Node nextSibling
}
 When updating values in a tree, such as the size of the
subtree rooted at a node, the weight of the subtree
rooted at a node, etc, there are two main methods:
 Recompute whenever there is a modify operation (addition of a
node, deletion of a node, changing the weight of a node, etc).
Recomputations usually only need to propagate from the change
node upwards to the root. [Advantage: Values always up to date,
Disadvantages: Lot of time spent in Recompute, Method cannot
be run concurrently.]
 Use a dirty flag and set to true when there is a change. Set dirty
flag to true for all ancestors (navigate to parent, until the root).
Recompute when there is a need, or as per a schedule.
[Advantages: Efficient, Methods (other than the “recomputed”
operation can be run concurrently. Disadvantages: Values are out
of date at times.]
CS 6213 – Arora – L2 Advanced Data Structures - Graphs 18
UPDATING VALUES
 Able to hold the entire graph in memory?
 If your graph is large and changing fast, like the
Facebook interconnection graph, you simply cannot
hold it in memory using traditional methods. You
need to replicate it across multiple servers and use
reliable services to get partial data out from the
graph. Your graph may simply be backed by a
database with which you interact directly (without
ever loading a complete “graph” object.)
CS 6213 – Arora – L2 Advanced Data Structures - Graphs 19
LARGE GRAPHS
 Given each of the graph representations, how do we
find a path?
 Shortest path algorithms
 Dijkstra
 All Pairs Shortest Paths
 [Refer to CS 6212 Notes for details]
CS 6213 – Arora – L2 Advanced Data Structures - Graphs 20
PATHS
 Path, spread over time
 Useful concept if the graph changes over time
 Specifically, consider this scenario:
 Edge e1 existed from x to y at time t1
 Edge e2 existed from y to z at time t2
 t1 < t2
 Then, we say that there exists a journey from x to z
CS 6213 – Arora – L2 Advanced Data Structures - Graphs 21
JOURNEY
 How can we detect cycles in a graph?
CS 6213 – Arora – L2 Advanced Data Structures - Graphs 22
CYCLES
 Assuming a graph is a Directed Acyclic Graph,
topological ordering can be produced in linear time.
O(n + m)
CS 6213 – Arora – L2 Advanced Data Structures - Graphs 23
TOPOLOGICAL SORTING
 Graphs are important data structures with numerous
applications
 Graphs can be of different kinds
 Many convenient ways to model graphs
 Adjacency Matrix
 Adjacency List
 Special structures for trees
 Many commercial and open source libraries exist, such as
JGraphT
CS 6213 – Arora – L2 Advanced Data Structures - Graphs 24
SUMMARY

Más contenido relacionado

La actualidad más candente

Breadth first search and depth first search
Breadth first search and  depth first searchBreadth first search and  depth first search
Breadth first search and depth first searchHossain Md Shakhawat
 
Graph in data structure
Graph in data structureGraph in data structure
Graph in data structureAbrish06
 
Tree in data structure
Tree in data structureTree in data structure
Tree in data structureghhgj jhgh
 
Data structures and algorithms short note (version 14).pd
Data structures and algorithms short note (version 14).pdData structures and algorithms short note (version 14).pd
Data structures and algorithms short note (version 14).pdNimmi Weeraddana
 
Bfs and dfs in data structure
Bfs and dfs in  data structure Bfs and dfs in  data structure
Bfs and dfs in data structure Ankit Kumar Singh
 
Data structure tries
Data structure triesData structure tries
Data structure triesMd. Naim khan
 
1.1 binary tree
1.1 binary tree1.1 binary tree
1.1 binary treeKrish_ver2
 
Connectivity of graphs
Connectivity of graphsConnectivity of graphs
Connectivity of graphssana younas
 
Red black tree
Red black treeRed black tree
Red black treeRajendran
 
Biconnected components (13024116056)
Biconnected components (13024116056)Biconnected components (13024116056)
Biconnected components (13024116056)Akshay soni
 
Prims and kruskal algorithms
Prims and kruskal algorithmsPrims and kruskal algorithms
Prims and kruskal algorithmsSaga Valsalan
 
Shell sort in Data Structure Using C
Shell sort in Data Structure Using CShell sort in Data Structure Using C
Shell sort in Data Structure Using CAshish Gaurkhede
 
B trees in Data Structure
B trees in Data StructureB trees in Data Structure
B trees in Data StructureAnuj Modi
 

La actualidad más candente (20)

Breadth first search and depth first search
Breadth first search and  depth first searchBreadth first search and  depth first search
Breadth first search and depth first search
 
Red black tree
Red black treeRed black tree
Red black tree
 
Graph in data structure
Graph in data structureGraph in data structure
Graph in data structure
 
Graph theory
Graph theory Graph theory
Graph theory
 
Binary tree traversal ppt - 02.03.2020
Binary tree traversal   ppt - 02.03.2020Binary tree traversal   ppt - 02.03.2020
Binary tree traversal ppt - 02.03.2020
 
Tree in data structure
Tree in data structureTree in data structure
Tree in data structure
 
Data structures and algorithms short note (version 14).pd
Data structures and algorithms short note (version 14).pdData structures and algorithms short note (version 14).pd
Data structures and algorithms short note (version 14).pd
 
Bfs and dfs in data structure
Bfs and dfs in  data structure Bfs and dfs in  data structure
Bfs and dfs in data structure
 
Data structure tries
Data structure triesData structure tries
Data structure tries
 
1.1 binary tree
1.1 binary tree1.1 binary tree
1.1 binary tree
 
Connectivity of graphs
Connectivity of graphsConnectivity of graphs
Connectivity of graphs
 
Tree traversal techniques
Tree traversal techniquesTree traversal techniques
Tree traversal techniques
 
Red black tree
Red black treeRed black tree
Red black tree
 
Splay Tree
Splay TreeSplay Tree
Splay Tree
 
Biconnected components (13024116056)
Biconnected components (13024116056)Biconnected components (13024116056)
Biconnected components (13024116056)
 
Tree and Binary Search tree
Tree and Binary Search treeTree and Binary Search tree
Tree and Binary Search tree
 
Prims and kruskal algorithms
Prims and kruskal algorithmsPrims and kruskal algorithms
Prims and kruskal algorithms
 
B trees dbms
B trees dbmsB trees dbms
B trees dbms
 
Shell sort in Data Structure Using C
Shell sort in Data Structure Using CShell sort in Data Structure Using C
Shell sort in Data Structure Using C
 
B trees in Data Structure
B trees in Data StructureB trees in Data Structure
B trees in Data Structure
 

Destacado

Discrete maths assignment
Discrete maths assignmentDiscrete maths assignment
Discrete maths assignmentKeshav Somani
 
Talk on Graph Theory - I
Talk on Graph Theory - ITalk on Graph Theory - I
Talk on Graph Theory - IAnirudh Raja
 
Talk on Standard Template Library
Talk on Standard Template LibraryTalk on Standard Template Library
Talk on Standard Template LibraryAnirudh Raja
 
Vertex Edge Graphs
Vertex Edge GraphsVertex Edge Graphs
Vertex Edge Graphsmrwilliams
 
Vertex edge graphs
Vertex edge graphsVertex edge graphs
Vertex edge graphsemteacher
 
Cinterviews Binarysearch Tree
Cinterviews Binarysearch TreeCinterviews Binarysearch Tree
Cinterviews Binarysearch Treecinterviews
 
Time complexity of union find
Time complexity of union findTime complexity of union find
Time complexity of union findWei (Terence) Li
 
17 Trees and graphs
17 Trees and graphs17 Trees and graphs
17 Trees and graphsmaznabili
 
Euclid's Algorithm for Greatest Common Divisor - Time Complexity Analysis
Euclid's Algorithm for Greatest Common Divisor - Time Complexity AnalysisEuclid's Algorithm for Greatest Common Divisor - Time Complexity Analysis
Euclid's Algorithm for Greatest Common Divisor - Time Complexity AnalysisAmrinder Arora
 
Convex Hull - Chan's Algorithm O(n log h) - Presentation by Yitian Huang and ...
Convex Hull - Chan's Algorithm O(n log h) - Presentation by Yitian Huang and ...Convex Hull - Chan's Algorithm O(n log h) - Presentation by Yitian Huang and ...
Convex Hull - Chan's Algorithm O(n log h) - Presentation by Yitian Huang and ...Amrinder Arora
 
Dynamic Programming - Part II
Dynamic Programming - Part IIDynamic Programming - Part II
Dynamic Programming - Part IIAmrinder Arora
 
Solving Problems with Graphs
Solving Problems with GraphsSolving Problems with Graphs
Solving Problems with GraphsMarko Rodriguez
 
Dynamic Programming - Part 1
Dynamic Programming - Part 1Dynamic Programming - Part 1
Dynamic Programming - Part 1Amrinder Arora
 
Online algorithms in Machine Learning
Online algorithms in Machine LearningOnline algorithms in Machine Learning
Online algorithms in Machine LearningAmrinder Arora
 
Graph Traversal Algorithms - Depth First Search Traversal
Graph Traversal Algorithms - Depth First Search TraversalGraph Traversal Algorithms - Depth First Search Traversal
Graph Traversal Algorithms - Depth First Search TraversalAmrinder Arora
 
Matrix Representation Of Graph
Matrix Representation Of GraphMatrix Representation Of Graph
Matrix Representation Of GraphAbhishek Pachisia
 
Graph Theory,Graph Terminologies,Planar Graph & Graph Colouring
Graph Theory,Graph Terminologies,Planar Graph & Graph ColouringGraph Theory,Graph Terminologies,Planar Graph & Graph Colouring
Graph Theory,Graph Terminologies,Planar Graph & Graph ColouringSaurabh Kaushik
 

Destacado (20)

Discrete maths assignment
Discrete maths assignmentDiscrete maths assignment
Discrete maths assignment
 
Talk on Graph Theory - I
Talk on Graph Theory - ITalk on Graph Theory - I
Talk on Graph Theory - I
 
Talk on Standard Template Library
Talk on Standard Template LibraryTalk on Standard Template Library
Talk on Standard Template Library
 
Graph theory1234
Graph theory1234Graph theory1234
Graph theory1234
 
Vertex Edge Graphs
Vertex Edge GraphsVertex Edge Graphs
Vertex Edge Graphs
 
Vertex edge graphs
Vertex edge graphsVertex edge graphs
Vertex edge graphs
 
Cinterviews Binarysearch Tree
Cinterviews Binarysearch TreeCinterviews Binarysearch Tree
Cinterviews Binarysearch Tree
 
Time complexity of union find
Time complexity of union findTime complexity of union find
Time complexity of union find
 
17 Trees and graphs
17 Trees and graphs17 Trees and graphs
17 Trees and graphs
 
Algorithmic Puzzles
Algorithmic PuzzlesAlgorithmic Puzzles
Algorithmic Puzzles
 
Euclid's Algorithm for Greatest Common Divisor - Time Complexity Analysis
Euclid's Algorithm for Greatest Common Divisor - Time Complexity AnalysisEuclid's Algorithm for Greatest Common Divisor - Time Complexity Analysis
Euclid's Algorithm for Greatest Common Divisor - Time Complexity Analysis
 
Convex Hull - Chan's Algorithm O(n log h) - Presentation by Yitian Huang and ...
Convex Hull - Chan's Algorithm O(n log h) - Presentation by Yitian Huang and ...Convex Hull - Chan's Algorithm O(n log h) - Presentation by Yitian Huang and ...
Convex Hull - Chan's Algorithm O(n log h) - Presentation by Yitian Huang and ...
 
Dynamic Programming - Part II
Dynamic Programming - Part IIDynamic Programming - Part II
Dynamic Programming - Part II
 
Solving Problems with Graphs
Solving Problems with GraphsSolving Problems with Graphs
Solving Problems with Graphs
 
NP completeness
NP completenessNP completeness
NP completeness
 
Dynamic Programming - Part 1
Dynamic Programming - Part 1Dynamic Programming - Part 1
Dynamic Programming - Part 1
 
Online algorithms in Machine Learning
Online algorithms in Machine LearningOnline algorithms in Machine Learning
Online algorithms in Machine Learning
 
Graph Traversal Algorithms - Depth First Search Traversal
Graph Traversal Algorithms - Depth First Search TraversalGraph Traversal Algorithms - Depth First Search Traversal
Graph Traversal Algorithms - Depth First Search Traversal
 
Matrix Representation Of Graph
Matrix Representation Of GraphMatrix Representation Of Graph
Matrix Representation Of Graph
 
Graph Theory,Graph Terminologies,Planar Graph & Graph Colouring
Graph Theory,Graph Terminologies,Planar Graph & Graph ColouringGraph Theory,Graph Terminologies,Planar Graph & Graph Colouring
Graph Theory,Graph Terminologies,Planar Graph & Graph Colouring
 

Similar a Graphs, Trees, Paths and Their Representations

Lecture 2.3.1 Graph.pptx
Lecture 2.3.1 Graph.pptxLecture 2.3.1 Graph.pptx
Lecture 2.3.1 Graph.pptxking779879
 
Tries - Tree Based Structures for Strings
Tries - Tree Based Structures for StringsTries - Tree Based Structures for Strings
Tries - Tree Based Structures for StringsAmrinder Arora
 
Lecture 5b graphs and hashing
Lecture 5b graphs and hashingLecture 5b graphs and hashing
Lecture 5b graphs and hashingVictor Palmar
 
Asymptotic Notation and Data Structures
Asymptotic Notation and Data StructuresAsymptotic Notation and Data Structures
Asymptotic Notation and Data StructuresAmrinder Arora
 
data structures and algorithms Unit 2
data structures and algorithms Unit 2data structures and algorithms Unit 2
data structures and algorithms Unit 2infanciaj
 
Set Operations - Union Find and Bloom Filters
Set Operations - Union Find and Bloom FiltersSet Operations - Union Find and Bloom Filters
Set Operations - Union Find and Bloom FiltersAmrinder Arora
 
Splay Trees and Self Organizing Data Structures
Splay Trees and Self Organizing Data StructuresSplay Trees and Self Organizing Data Structures
Splay Trees and Self Organizing Data StructuresAmrinder Arora
 
Graph Data Structure
Graph Data StructureGraph Data Structure
Graph Data StructureKeno benti
 
Skiena algorithm 2007 lecture10 graph data strctures
Skiena algorithm 2007 lecture10 graph data strcturesSkiena algorithm 2007 lecture10 graph data strctures
Skiena algorithm 2007 lecture10 graph data strctureszukun
 
Chapter9 graph data structure
Chapter9  graph data structureChapter9  graph data structure
Chapter9 graph data structureMahmoud Alfarra
 
Binary Search Trees - AVL and Red Black
Binary Search Trees - AVL and Red BlackBinary Search Trees - AVL and Red Black
Binary Search Trees - AVL and Red BlackAmrinder Arora
 
Start From A MapReduce Graph Pattern-recognize Algorithm
Start From A MapReduce Graph Pattern-recognize AlgorithmStart From A MapReduce Graph Pattern-recognize Algorithm
Start From A MapReduce Graph Pattern-recognize AlgorithmYu Liu
 
Spanning Tree in data structure and .pptx
Spanning Tree in data structure and .pptxSpanning Tree in data structure and .pptx
Spanning Tree in data structure and .pptxasimshahzad8611
 

Similar a Graphs, Trees, Paths and Their Representations (20)

UNIT 4_DSA_KAVITHA_RMP.ppt
UNIT 4_DSA_KAVITHA_RMP.pptUNIT 4_DSA_KAVITHA_RMP.ppt
UNIT 4_DSA_KAVITHA_RMP.ppt
 
Lecture 2.3.1 Graph.pptx
Lecture 2.3.1 Graph.pptxLecture 2.3.1 Graph.pptx
Lecture 2.3.1 Graph.pptx
 
Tries - Tree Based Structures for Strings
Tries - Tree Based Structures for StringsTries - Tree Based Structures for Strings
Tries - Tree Based Structures for Strings
 
Lecture 5b graphs and hashing
Lecture 5b graphs and hashingLecture 5b graphs and hashing
Lecture 5b graphs and hashing
 
Asymptotic Notation and Data Structures
Asymptotic Notation and Data StructuresAsymptotic Notation and Data Structures
Asymptotic Notation and Data Structures
 
data structures and algorithms Unit 2
data structures and algorithms Unit 2data structures and algorithms Unit 2
data structures and algorithms Unit 2
 
Set Operations - Union Find and Bloom Filters
Set Operations - Union Find and Bloom FiltersSet Operations - Union Find and Bloom Filters
Set Operations - Union Find and Bloom Filters
 
Splay Trees and Self Organizing Data Structures
Splay Trees and Self Organizing Data StructuresSplay Trees and Self Organizing Data Structures
Splay Trees and Self Organizing Data Structures
 
Graph Data Structure
Graph Data StructureGraph Data Structure
Graph Data Structure
 
Graphs data structures
Graphs data structuresGraphs data structures
Graphs data structures
 
Graph in data structures
Graph in data structuresGraph in data structures
Graph in data structures
 
Dijkstra
DijkstraDijkstra
Dijkstra
 
d
dd
d
 
Graph clustering
Graph clusteringGraph clustering
Graph clustering
 
Skiena algorithm 2007 lecture10 graph data strctures
Skiena algorithm 2007 lecture10 graph data strcturesSkiena algorithm 2007 lecture10 graph data strctures
Skiena algorithm 2007 lecture10 graph data strctures
 
Chapter9 graph data structure
Chapter9  graph data structureChapter9  graph data structure
Chapter9 graph data structure
 
26 spanning
26 spanning26 spanning
26 spanning
 
Binary Search Trees - AVL and Red Black
Binary Search Trees - AVL and Red BlackBinary Search Trees - AVL and Red Black
Binary Search Trees - AVL and Red Black
 
Start From A MapReduce Graph Pattern-recognize Algorithm
Start From A MapReduce Graph Pattern-recognize AlgorithmStart From A MapReduce Graph Pattern-recognize Algorithm
Start From A MapReduce Graph Pattern-recognize Algorithm
 
Spanning Tree in data structure and .pptx
Spanning Tree in data structure and .pptxSpanning Tree in data structure and .pptx
Spanning Tree in data structure and .pptx
 

Más de Amrinder Arora

Graph Traversal Algorithms - Breadth First Search
Graph Traversal Algorithms - Breadth First SearchGraph Traversal Algorithms - Breadth First Search
Graph Traversal Algorithms - Breadth First SearchAmrinder Arora
 
Bron Kerbosch Algorithm - Presentation by Jun Zhai, Tianhang Qiang and Yizhen...
Bron Kerbosch Algorithm - Presentation by Jun Zhai, Tianhang Qiang and Yizhen...Bron Kerbosch Algorithm - Presentation by Jun Zhai, Tianhang Qiang and Yizhen...
Bron Kerbosch Algorithm - Presentation by Jun Zhai, Tianhang Qiang and Yizhen...Amrinder Arora
 
Arima Forecasting - Presentation by Sera Cresta, Nora Alosaimi and Puneet Mahana
Arima Forecasting - Presentation by Sera Cresta, Nora Alosaimi and Puneet MahanaArima Forecasting - Presentation by Sera Cresta, Nora Alosaimi and Puneet Mahana
Arima Forecasting - Presentation by Sera Cresta, Nora Alosaimi and Puneet MahanaAmrinder Arora
 
Stopping Rule for Secretory Problem - Presentation by Haoyang Tian, Wesam Als...
Stopping Rule for Secretory Problem - Presentation by Haoyang Tian, Wesam Als...Stopping Rule for Secretory Problem - Presentation by Haoyang Tian, Wesam Als...
Stopping Rule for Secretory Problem - Presentation by Haoyang Tian, Wesam Als...Amrinder Arora
 
Proof of O(log *n) time complexity of Union find (Presentation by Wei Li, Zeh...
Proof of O(log *n) time complexity of Union find (Presentation by Wei Li, Zeh...Proof of O(log *n) time complexity of Union find (Presentation by Wei Li, Zeh...
Proof of O(log *n) time complexity of Union find (Presentation by Wei Li, Zeh...Amrinder Arora
 
Proof of Cook Levin Theorem (Presentation by Xiechuan, Song and Shuo)
Proof of Cook Levin Theorem (Presentation by Xiechuan, Song and Shuo)Proof of Cook Levin Theorem (Presentation by Xiechuan, Song and Shuo)
Proof of Cook Levin Theorem (Presentation by Xiechuan, Song and Shuo)Amrinder Arora
 
Divide and Conquer - Part II - Quickselect and Closest Pair of Points
Divide and Conquer - Part II - Quickselect and Closest Pair of PointsDivide and Conquer - Part II - Quickselect and Closest Pair of Points
Divide and Conquer - Part II - Quickselect and Closest Pair of PointsAmrinder Arora
 
Divide and Conquer - Part 1
Divide and Conquer - Part 1Divide and Conquer - Part 1
Divide and Conquer - Part 1Amrinder Arora
 
Introduction to Algorithms and Asymptotic Notation
Introduction to Algorithms and Asymptotic NotationIntroduction to Algorithms and Asymptotic Notation
Introduction to Algorithms and Asymptotic NotationAmrinder Arora
 
Binomial Heaps and Fibonacci Heaps
Binomial Heaps and Fibonacci HeapsBinomial Heaps and Fibonacci Heaps
Binomial Heaps and Fibonacci HeapsAmrinder Arora
 
R-Trees and Geospatial Data Structures
R-Trees and Geospatial Data StructuresR-Trees and Geospatial Data Structures
R-Trees and Geospatial Data StructuresAmrinder Arora
 
BTrees - Great alternative to Red Black, AVL and other BSTs
BTrees - Great alternative to Red Black, AVL and other BSTsBTrees - Great alternative to Red Black, AVL and other BSTs
BTrees - Great alternative to Red Black, AVL and other BSTsAmrinder Arora
 
Stacks, Queues, Binary Search Trees - Lecture 1 - Advanced Data Structures
Stacks, Queues, Binary Search Trees -  Lecture 1 - Advanced Data StructuresStacks, Queues, Binary Search Trees -  Lecture 1 - Advanced Data Structures
Stacks, Queues, Binary Search Trees - Lecture 1 - Advanced Data StructuresAmrinder Arora
 
Online Algorithms - An Introduction
Online Algorithms - An IntroductionOnline Algorithms - An Introduction
Online Algorithms - An IntroductionAmrinder Arora
 

Más de Amrinder Arora (17)

NP-Completeness - II
NP-Completeness - IINP-Completeness - II
NP-Completeness - II
 
Graph Traversal Algorithms - Breadth First Search
Graph Traversal Algorithms - Breadth First SearchGraph Traversal Algorithms - Breadth First Search
Graph Traversal Algorithms - Breadth First Search
 
Bron Kerbosch Algorithm - Presentation by Jun Zhai, Tianhang Qiang and Yizhen...
Bron Kerbosch Algorithm - Presentation by Jun Zhai, Tianhang Qiang and Yizhen...Bron Kerbosch Algorithm - Presentation by Jun Zhai, Tianhang Qiang and Yizhen...
Bron Kerbosch Algorithm - Presentation by Jun Zhai, Tianhang Qiang and Yizhen...
 
Arima Forecasting - Presentation by Sera Cresta, Nora Alosaimi and Puneet Mahana
Arima Forecasting - Presentation by Sera Cresta, Nora Alosaimi and Puneet MahanaArima Forecasting - Presentation by Sera Cresta, Nora Alosaimi and Puneet Mahana
Arima Forecasting - Presentation by Sera Cresta, Nora Alosaimi and Puneet Mahana
 
Stopping Rule for Secretory Problem - Presentation by Haoyang Tian, Wesam Als...
Stopping Rule for Secretory Problem - Presentation by Haoyang Tian, Wesam Als...Stopping Rule for Secretory Problem - Presentation by Haoyang Tian, Wesam Als...
Stopping Rule for Secretory Problem - Presentation by Haoyang Tian, Wesam Als...
 
Proof of O(log *n) time complexity of Union find (Presentation by Wei Li, Zeh...
Proof of O(log *n) time complexity of Union find (Presentation by Wei Li, Zeh...Proof of O(log *n) time complexity of Union find (Presentation by Wei Li, Zeh...
Proof of O(log *n) time complexity of Union find (Presentation by Wei Li, Zeh...
 
Proof of Cook Levin Theorem (Presentation by Xiechuan, Song and Shuo)
Proof of Cook Levin Theorem (Presentation by Xiechuan, Song and Shuo)Proof of Cook Levin Theorem (Presentation by Xiechuan, Song and Shuo)
Proof of Cook Levin Theorem (Presentation by Xiechuan, Song and Shuo)
 
Greedy Algorithms
Greedy AlgorithmsGreedy Algorithms
Greedy Algorithms
 
Divide and Conquer - Part II - Quickselect and Closest Pair of Points
Divide and Conquer - Part II - Quickselect and Closest Pair of PointsDivide and Conquer - Part II - Quickselect and Closest Pair of Points
Divide and Conquer - Part II - Quickselect and Closest Pair of Points
 
Divide and Conquer - Part 1
Divide and Conquer - Part 1Divide and Conquer - Part 1
Divide and Conquer - Part 1
 
Introduction to Algorithms and Asymptotic Notation
Introduction to Algorithms and Asymptotic NotationIntroduction to Algorithms and Asymptotic Notation
Introduction to Algorithms and Asymptotic Notation
 
Binomial Heaps and Fibonacci Heaps
Binomial Heaps and Fibonacci HeapsBinomial Heaps and Fibonacci Heaps
Binomial Heaps and Fibonacci Heaps
 
R-Trees and Geospatial Data Structures
R-Trees and Geospatial Data StructuresR-Trees and Geospatial Data Structures
R-Trees and Geospatial Data Structures
 
BTrees - Great alternative to Red Black, AVL and other BSTs
BTrees - Great alternative to Red Black, AVL and other BSTsBTrees - Great alternative to Red Black, AVL and other BSTs
BTrees - Great alternative to Red Black, AVL and other BSTs
 
Stacks, Queues, Binary Search Trees - Lecture 1 - Advanced Data Structures
Stacks, Queues, Binary Search Trees -  Lecture 1 - Advanced Data StructuresStacks, Queues, Binary Search Trees -  Lecture 1 - Advanced Data Structures
Stacks, Queues, Binary Search Trees - Lecture 1 - Advanced Data Structures
 
Online Algorithms - An Introduction
Online Algorithms - An IntroductionOnline Algorithms - An Introduction
Online Algorithms - An Introduction
 
Learning to learn
Learning to learnLearning to learn
Learning to learn
 

Último

Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfAyushMahapatra5
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxVishalSingh1417
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxnegromaestrong
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docxPoojaSen20
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 

Último (20)

Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 

Graphs, Trees, Paths and Their Representations

  • 1. CS 6213 – Advanced Data Structures Lecture 2 GRAPHS AND THEIR REPRESENTATION TREES, PATHS, CYCLES TOPOLOGICAL SORTING
  • 2.  Instructor Prof. Amrinder Arora amrinder@gwu.edu Please copy TA on emails Please feel free to call as well  TA Iswarya Parupudi iswarya2291@gwmail.gwu.edu CS 6213 – Arora – L2 Advanced Data Structures - Graphs 2 LOGISTICS
  • 3. L4 - BTrees CS 6213 - Advanced Data Structures - Arora 3 CS 6213 Basics Record / Struct Arrays / Linked Lists / Stacks / Queues Graphs / Trees / BSTs Advanced Trie, B-Tree Splay Trees R-Trees Heaps and PQs Union Find
  • 4.  Graphs – Basics  Degrees, Number of Edges, Min/Max Degree  Kinds of Graphs  How to Represent in Data Structures  Trees, Paths, Cycles  Journeys  Topological Sorting, DAGs CS 6213 – Arora – L2 Advanced Data Structures - Graphs 4 AGENDA
  • 5.  A graph G=(V,E) consists of a finite set V, which is the set of vertices, and set E, which is the set of edges. Each edge in E connects two vertices v1 and v2, which are in V.  Can be directed or undirected Not to be confused with a bar graph!!!!  CS 6213 – Arora – L2 Advanced Data Structures - Graphs 5 GRAPH
  • 6. A core data structure that shows up in many circumstances:  Transportation and Logistics (paths, etc.)  Circuit Design  Social Networking – Model connections between people  Sociology – Model influence  Zoology and Wildlife  Project Task Management  Job Scheduling and Resource Assignment (matching)  Time table scheduling  Task parallelization (graph coloring) CS 6213 – Arora – L2 Advanced Data Structures - Graphs 6 GRAPH – APPLICATIONS
  • 7.  (Undirected) Degree of a node  (Directed) Indegree / Outdegree  Min degree in a graph:   Max degree in a graph:   Basic observations  (Undirected) Sum of degrees = 2 x number of edges  (Directed) Sum of indegree = Sum of outdegree = number of edges CS 6213 – Arora – L2 Advanced Data Structures - Graphs 7 DEGREE
  • 8.  If (x,y) is an edge, then x is said to be adjacent to y, and y is adjacent from x.  In the case of undirected graphs, if (x,y) is an edge, we just say that x and y are adjacent (or x is adjacent to y, or y is adjacent to x). Also, we say that x is the neighbor of y.  The indegree of a node x is the number of nodes adjacent to x  The outdegree of a node x is the number of nodes adjacent from x  The degree of a node x in an undirected graph is the number of neighbors of x  A path from a node x to a node y in a graph is a sequence of node x, x1,x2,...,xn,y, such that x is adjacent to x1, x1 is adjacent to x2, ..., and xn is adjacent to y.  The length of a path is the number of its edges.  A cycle is a path that begins and ends at the same node  The distance from node x to node y is the length of the shortest path from x to y. CS 6213 – Arora – L2 Advanced Data Structures - Graphs 8 GRAPH DEFINITIONS
  • 9.  Using a matrix A[1..n,1..n] where A[i,j] = 1 if (i,j) is an edge, and is 0 otherwise. This representation is called the adjacency matrix representation. If the graph is undirected, then the adjacency matrix is symmetric about the main diagonal.  Using an array Adj[1..n] of pointers, which Adj[i] is a linked list of nodes which are adjacent to i.  The matrix representation requires more memory, since it has a matrix cell for each possible edge, whether that edge exists or not. In adjacency list representation, the space used is directly proportional to the number of edges.  If the graph is sparse (very few edges), then adjacency list may be a more efficient choice. CS 6213 – Arora – L2 Advanced Data Structures - Graphs 9 GRAPH REPRESENTATIONS
  • 10.  A very practical choice is to use graphing libraries, such as:  JGraphT (Java)  Boost (C++)  GraphStream (Java)  JUNG (Java) CS 6213 – Arora – L2 Advanced Data Structures - Graphs 10 GRAPH REPRESENTATION (CONT.)
  • 11.  Graphs can be characterized in many ways. Two important ones being:  Directed or Undirected  Weighted or Unweighted  Both Adjacency Matrix (AM) and Adjacency List (AL) representations can be used for graphs – weighted or unweighted, directed or undirected.  A[i,j] = A[j,i] if graph is undirected. So, we could decide to use just the upper triangle.  If graph is weighted, in adjacency list, we can also store the weight. AL[i] = [(j,w(i,j)), (k,w(i,k)), …] CS 6213 – Arora – L2 Advanced Data Structures - Graphs 11 GRAPH CHARACTERIZATIONS
  • 12.  A tree is a connected acyclic graph (i.e., it has no cycles)  Rooted tree: A tree in which one node is designated as a root (the top node) CS 6213 – Arora – L2 Advanced Data Structures - Graphs 12 TREE Example: Node A is root node F and D are child nodes of A. P and Q are child nodes of J. Etc.
  • 13.  Definitions  Leaf is a node that has no children  Ancestors of a node x are all the nodes on the path from x to the root, including x and the root  Subtree rooted at x is the tree consisting of x, its children and their children, and so on and so forth all the way down  Height of a tree is the maximum distance from the root to any node CS 6213 – Arora – L2 Advanced Data Structures - Graphs 13 TREE (CONT.)
  • 14. Option 1 •Trees are graphs, so we can use standard graph representation – Adjacency Matrix or Adjacency List Option 2 •Use parent node and list for child nodes Option 3 •Use parent node, and two pointers – one for first child and the other for nextSibling CS 6213 – Arora – L2 Advanced Data Structures - Graphs 14 REPRESENTING TREES 3 Basic Options
  • 15.  We can use standard graph representation – Adjacency Matrix or Adjacency List  These options are overkill for trees, but in some instances, the graph is not known to be a tree beforehand, so this option works. CS 6213 – Arora – L2 Advanced Data Structures - Graphs 15 TREE REPRESENTATION – OPTION 1
  • 16.  Rather than using Adjacency Matrix or Adjacency List representation, we can use a simpler representation  Each node has a pointer to parent, and a linked list of child nodes  The root node’s parent pointer is null  This representation works for “rooted” trees. If the tree is not rooted, we can designate one node as root. CS 6213 – Arora – L2 Advanced Data Structures - Graphs 16 TREE REPRESENTATION – OPTION 2 Node { Node parent, List<Node> childNodes }
  • 17.  Another representation for Trees: Left Child, Right Sibling representation for a tree. Each node has 3 pointers:  Parent – Points to parent (null if this is the root node)  Left pointer – Points to first child (null if this is a leaf node)  Right pointer – Points to right sibling (null if no more siblings)  For example:  is represented by CS 6213 – Arora – L2 Advanced Data Structures - Graphs 17 TREE REPRESENTATION – OPTION 3 Node { Node parent, Node firstChild, Node nextSibling }
  • 18.  When updating values in a tree, such as the size of the subtree rooted at a node, the weight of the subtree rooted at a node, etc, there are two main methods:  Recompute whenever there is a modify operation (addition of a node, deletion of a node, changing the weight of a node, etc). Recomputations usually only need to propagate from the change node upwards to the root. [Advantage: Values always up to date, Disadvantages: Lot of time spent in Recompute, Method cannot be run concurrently.]  Use a dirty flag and set to true when there is a change. Set dirty flag to true for all ancestors (navigate to parent, until the root). Recompute when there is a need, or as per a schedule. [Advantages: Efficient, Methods (other than the “recomputed” operation can be run concurrently. Disadvantages: Values are out of date at times.] CS 6213 – Arora – L2 Advanced Data Structures - Graphs 18 UPDATING VALUES
  • 19.  Able to hold the entire graph in memory?  If your graph is large and changing fast, like the Facebook interconnection graph, you simply cannot hold it in memory using traditional methods. You need to replicate it across multiple servers and use reliable services to get partial data out from the graph. Your graph may simply be backed by a database with which you interact directly (without ever loading a complete “graph” object.) CS 6213 – Arora – L2 Advanced Data Structures - Graphs 19 LARGE GRAPHS
  • 20.  Given each of the graph representations, how do we find a path?  Shortest path algorithms  Dijkstra  All Pairs Shortest Paths  [Refer to CS 6212 Notes for details] CS 6213 – Arora – L2 Advanced Data Structures - Graphs 20 PATHS
  • 21.  Path, spread over time  Useful concept if the graph changes over time  Specifically, consider this scenario:  Edge e1 existed from x to y at time t1  Edge e2 existed from y to z at time t2  t1 < t2  Then, we say that there exists a journey from x to z CS 6213 – Arora – L2 Advanced Data Structures - Graphs 21 JOURNEY
  • 22.  How can we detect cycles in a graph? CS 6213 – Arora – L2 Advanced Data Structures - Graphs 22 CYCLES
  • 23.  Assuming a graph is a Directed Acyclic Graph, topological ordering can be produced in linear time. O(n + m) CS 6213 – Arora – L2 Advanced Data Structures - Graphs 23 TOPOLOGICAL SORTING
  • 24.  Graphs are important data structures with numerous applications  Graphs can be of different kinds  Many convenient ways to model graphs  Adjacency Matrix  Adjacency List  Special structures for trees  Many commercial and open source libraries exist, such as JGraphT CS 6213 – Arora – L2 Advanced Data Structures - Graphs 24 SUMMARY