Exam 3 Flashcards
(106 cards)
A graph comprises __, each of which holds some kind of __
Vertices, Data
Two vertices can be connected by an __
Edge
Neighbors
Connected vertices in a graph
Graphs are conceptually
Linked-node structures
T/F: An empty graph of no nodes can exist
True
Graphs differ from N-ary Trees and other tree structures in that
-there is no parent/child relationship between nodes
-any node can be connected to any other node
Graphs are ideal data structures for representing systems with ___ between entities
many-to-many
T/F: A binary tree is a type of graph
True. Any formation of nodes is.
Path
A series of edges that connect two vertices
If a path exists between vertices, they are part of the same __
Connected component
Search
An algorithm that determines if a path between vertices exists
Undirected Edges
Edges can be traversed in both directions
Directed Edges
Edges can only be traversed in one direction. Indicated by an arrow.
A graph should provide the following behavior
- Add value to graph
- Boolean check if value in graph
- Size
- Connect directed
- Connect undirected
- Boolean check if two values are connected
T/F: graphs can only be implemented with nodes
False. Can use arrays to get similar result
Adjacency List
Method for vertices to keep track of their unique neighbors. Can be represented by a table:
Vertex | Adjacency List
If no path exists between vertices, they are in __
Different connected components
Breadth-First Search
Path search algorithm. Creates queue with the start vertex. While the queue isn’t empty,
Dequeues next vertex
If value is the goal, return true
Otherwise, add the vertex’s neighbors to the queue (if not previously added)
Nodes should be searched in ___
Alphabetical/numeric order (for this class)
Depth-First Search
Path Finding Algorithm. Uses a queue to search vertices in order based on distance from start. One edge away will be searched first, two, three, etc.
BFS VS DFS
DFS explores deeper and deeper into the graph. BFS explores all nodes one edge away first.
When using DFS, if arrived at a vertex without any unexplored neighbors:
Backtracks along it’s path only as far as necessary to find a vertex with at least one unexplored neighbor
DFS can be implemented with
A stack or through recursion
BFS use a ___ to keep track of predecessors. DFS uses ___
A map. A recursive call.