Source: CSE 214 – Computer Science II Graphs
What kind of data structure is the Internet? Ref:
What kind of data structure is used by game AI for pathfinding?
You guessed it, Graphs! What is a graph? –a non-linear data structure –consists of nodes & links between nodes –nodes can be linked in any pattern, not necessarily hierarchical –nodes can be directed, or undirected –can be weighted
This is a tree D A B GF C E
This is a graph D A B GF C E
And this is a graph D A B GF C E
D A B GF C E
D A B GF C E
Undirected Graphs A set of nodes –vertices And a set of links between the nodes –edges Each edge connects two vertices Graph walkers (like travelers) may move across undirected edges in both directions
An undirected graph D A B G F C E
Directed Graphs A set of nodes –vertices And a set of links between the nodes –edges Each edge is associated with 2 vertices: –a source vertex –a target vertex Graph walkers (like travelers) may move across directed edges only from source to target
A directed graph D A B G F C E
A weighted graph Can be an undirected or direct graph Each edge is weighted with some value –represents cost of edge Cost of what? –depends on application Might be: –distance, resistance, money. Etc.
A weighted graph D A B G F C E
How can we define a graph? Many options –nodes (we’ve seen this already, similar to trees) –an adjacency matrix –edge sets
Adjacency Matrix A 2D table –2D array –row for each node –column for each node Values in cells can be –boolean denoting are they connected OR –numeric representing weighting of connections
Adjacency Matrix ABCD A0560 B5093 C6907 D0370 A B D C
Edge sets List all the edges in a graph Advantage: –more efficient data management For what? –Graph walking –Graph manipulation Ex, 3D meshes: –vertex buffers & index buffers –render mesh needs graph traversal
3D Models/Meshes are textured graphs Ref:
Walking graphs Many problems: –Shortest path problems –Traveling salesman problems –Chinese postman problems –Etc. Many algorithms for calculating solutions: –Greedy, Djikstra’s algorithm, A*, etc.
Want to learn more? AMS 301: Finite Mathematical Structures CSE 352: Artificial Intelligence CSE 373: Analysis of Algorithms CSE 380: Computer Game Programming CSE 381: Advanced Game Programming