15 GRAPHS Flashcards
What is a graph in computer science?
A fundamental data structure composed of a set of nodes and a set of edges.
How do graphs differ from other data structures?
Graphs arise naturally from the data itself, mirroring the data they represent.
What are the two main components of a graph?
- Nodes
- Edges
What do undirected edges represent?
Two-way relationships, such as roads or friendships.
What do directed edges indicate?
A flow in a single direction, like one-way streets.
What is an example of using directed edges in a task?
Modeling task dependencies, such as the order of brewing coffee.
What are weighted edges used for in graphs?
To capture the cost of the link between nodes.
What are the two common representations of graphs in memory?
- Adjacency matrices
- Adjacency lists
How does an adjacency list represent a graph?
Stores a separate list of neighbors for each node.
What does an adjacency matrix consist of?
A matrix with one row and one column for each node, representing edge weights.
What is the purpose of searching graphs?
To explore nodes and find specific information or paths.
What is a depth-first search?
A graph search method that explores paths deeply before backtracking.
What is a breadth-first search?
A graph search method that explores nodes closer to the starting point first.
What is Dijkstra’s algorithm used for?
Finding the shortest path from a starting node to all other nodes in a graph.
What is a key constraint for Dijkstra’s algorithm?
All edge weights must be non-negative.
What data structures does Dijkstra’s algorithm maintain?
- Array of distances
- Array indicating the last node visited
- Set of unvisited nodes
What happens in each iteration of Dijkstra’s algorithm?
The closest unvisited node is visited and distances to its unvisited neighbors are updated.
True or False: Dijkstra’s algorithm can work on graphs with negative edge weights.
False
What is the initial distance setup in Dijkstra’s algorithm?
All distances are set to infinity except for the starting node, which is set to zero.
Fill in the blank: Dijkstra’s algorithm uses a ______ to improve efficiency.
min-heap
What does the adjacency list representation provide?
A localized view of neighbor relationships.
What type of relationships do weighted edges allow us to model?
Complex interrelations among nodes.
What is an example of a real-world system modeled as a graph?
Social networks, transportation networks, and computer networks.
What is the initial configuration of distances in Dijkstra’s algorithm?
All distances at infinity except for node A, which is set to zero.