Graphs Flashcards
Define Graph
- abstract data type that can be used to represent complex, non-linear relationships between objects
- contains nodes and edges
Define neighbour
two nodes connected by an edge
Define degree
number of other nodes that a node is connected to
Define loop
edge that connects node to itself
Define cycle
closed path
Uses of graphs
- social networking
- transport networks
- the internet
- World wide web
Define undirected graph
allows you to traverse in either direction between nodes
Define directed graph
edges have direction, you move between nodes in specified direction
Define weighted graph
values associated with the edges
Define adjacency matrix
- table
- 0s if unweighted
- infinity if weighted
Define adjacency list
- dictionary
- unweighted: B - D; H
- weighted: B - D,15; H,40
Advantages of adjacency lists
-space efficient for graphs with few edges (sparse graphs)
Disadvantages of adjacency lists
-requires linear search when determining presence of an edge
Advantages of adjacency matrix
- space efficient for graphs with a lot of edges (denser graphs)
- good when frequently testing for prescence of edges