1 / 16

Data Structures - Graph

Data Structures - Graph . Graphs are simply a collection of nodes (points) and edges connecting the nodes. Typical notation lookslike this G = { N, E }. G = the graph. N = node set E = edge set Nodes represent items under consideration - can be anything.

gizi
Download Presentation

Data Structures - Graph

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Data Structures - Graph • Graphs are simply a collection of nodes (points) and edges connecting the nodes. • Typical notation lookslike this G = { N, E }. • G = the graph. • N = node set • E = edge set • Nodes represent items under consideration - can be anything. • Edges represent relationships between the items - can be anything. • Edges can be undirected, meaning the relationship holds both ways between nodes. • Edges can be directed, meaning the relationship is only one way.

  2. Data Structures - Graph

  3. Data Structures - Graph THESE ARE ALL GRAPHS.

  4. Graph Problems • There are literally thousands of graph problems, but we will focus on three that are occur very commonly and show the diversity of the graph structure: • The Traveling Salesman Problem. • Graph Coloring Problem. • Maximum Flow Problem. • At least one of these problems is solved by you every day without you realizing it (until now). • The fact that the nodes and edges can represent anything means that the graph structure is very versatile and virtually any problem can be mapped to a graph problem.

  5. Example Graph Problem - Puzzle • This is an old puzzle and has many variants: A man is returning home from market with a wolf, bag of corn, and goose. He has to cross a lttle river on the way and the only way is to use a little boat. The boats holds him and one other item. • He cannot leave the wolf and goose alone, as the wolf eats the goose. • He cannot leave the corn and goose alone as the goose eats the corn. • He can leave the corn and wolf alone. • How does he get everything across the river and bring everything home (uneaten)? • Build a graph: • N = the set of possible arrangements of man, wolf, goose, corn, and river. • E = Possible transitions due to one boat trip.

  6. wgc| m mwgc| mwg|c mwc| g mgc| w mc| wg mg| wc mw|gc | mwgc wg|mc wc| mg gc| mw c| mwg g| mwc w|mgc m| wgc Example Graph Problem - Puzzle

  7. wgc| m mwgc| mwg|c mwc| g mgc| w mc| wg mg| wc mw|gc | mwgc wg|mc wc| mg gc| mw c| mwg g| mwc w|mgc m| wgc Example Graph Problem - Puzzle Solved

  8. Graph Problems • There are literally thousands of graph problems, but we will focus on three that are occur very commonly and show the diversity of the graph structure: • The Traveling Salesman Problem. • Graph Coloring Problem. • Maximum Flow Problem. • Each problem has a decision form and an optimization form. The decision form asks "Can we do it?" and the optimization form asks "How well can we do it?" • At least one of these problems is solved by you every day without you realizing it (until now). • The fact that the nodes and edges can represent anything means that the graph structure is very versatile and virtually any problem can be mapped to a graph problem.

  9. Graph Problems - Traveling Salesman • Description: Given a graph, G = {N, E}, where • N = a set of cities. • E = travel routes between the cities, each having a cost associated with it. • One special node, s. • You must begin at city sand travel to each of the other cities exactly once and then return to city s. Thus you make a complete cycle of all cities in the graph. • Decision form of the problem: Can a route be found where the total cost of the trip is less than X? (Answer is yes or no). • Optimization form of the problem: What is the absolute lowest cost?

  10. Graph Problems - Graph Coloring • Description: Given a graph, G = {N, E}, where • N = a set of nodes. • E = edges between the nodes. • The object is to color the graph such that no nodes connecte by an edge have the same color. • Decision form of the problem: Can the graph be colored with X or less colors? (Answer is yes or no). • Optimization form of the problem: What is the fewest number of colors required to color the graph?

  11. Graph Problems - Maximum Flow • Description: Given a graph, G = {N, E}, where • N = a set of nodes. • E = edges representing pipes, each assigned a given capacity. • Two special nodes. Node s is a source node that can potentially spit out an infinite amount of material. Node f is a sink node that can potentially absorb an infinite amount of material. • The object is to determine the maximum amount of material that can flow through the network for the source to the sink. • Decision form of the problem: Can X amount of material be pushed through the network from the source to the sink? (Answer is yes or no). • Optimization form of the problem: What is the maximum amount of material that can flow through the material from the source to the sink?

  12. Cost of Graph Problems

  13. Data Structures - Tree

  14. Data Structures - Tree ROOT - has no parent, only one in the tree. LEAVES - have no children.

  15. Data Structures - Heap

  16. Data Structures - Graph THESE ARE TREES (ABOVE). ARE THEY HEAPS? THESE ARE NOT TREES (ABOVE). ARE THEY HEAPS?

More Related