graph_questions_answers Flashcards

1
Q

What is a graph in computer science? How does it differ from other data structures like trees?

A

A graph is a collection of nodes (vertices) connected by edges. It differs from a tree because a tree is a special type of graph with no cycles, hierarchical structure, and a unique path between nodes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the different types of graphs? Explain each one briefly.

A

Undirected, Directed, Weighted, Unweighted.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the difference between a dense and a sparse graph?

A

Dense graphs have many edges (close to V^2), sparse graphs have few edges relative to the number of nodes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are the representations of graphs in computer science? Explain adjacency matrix and adjacency list.

A

Adjacency Matrix: 2D array representing connections. Adjacency List: Each vertex has a list of neighbors.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is a connected graph? What is a strongly connected and weakly connected graph in the case of directed graphs?

A

Connected graph: A path exists between any two vertices. Strongly connected (directed): A path exists between all pairs. Weakly connected: Connected only if edges were treated as undirected.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is a cyclic graph? How is it different from an acyclic graph?

A

Cyclic graph has at least one cycle, acyclic has none.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is a bipartite graph? How can you check if a given graph is bipartite?

A

A bipartite graph has vertices divided into two sets where no edges connect vertices in the same set. Use BFS/DFS for checking.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is a path in a graph? How does it differ from a simple path or a cycle?

A

A path is a sequence of edges connecting vertices, a simple path has no repeated vertices, and a cycle returns to the starting vertex.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What are the applications of graphs in real-world problems? Provide at least three examples.

A

Social networks (e.g., friends), GPS navigation, data routing in networks.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How do you perform a depth-first search (DFS) and breadth-first search (BFS) on a graph?

A

DFS uses a stack (or recursion), BFS uses a queue. DFS explores deeper first, BFS explores level by level.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is Dijkstra’s algorithm? Explain how it is used to find the shortest path in a graph.

A

Dijkstra’s finds the shortest path from a source to all vertices with non-negative weights using a priority queue.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is the Bellman-Ford algorithm? How does it compare with Dijkstra’s algorithm?

A

Bellman-Ford handles negative weights, has O(VE) time complexity, slower than Dijkstra but more flexible.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Explain Prim’s and Kruskal’s algorithms for finding the minimum spanning tree in a graph.

A

Prim’s adds edges greedily to grow the MST, Kruskal’s sorts edges and adds them if they don’t form a cycle.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is topological sorting in a directed acyclic graph (DAG), and why is it important?

A

Linear ordering of vertices where each directed edge points from an earlier to a later vertex.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How do you detect a cycle in a directed and undirected graph?

A

DFS/Recursion stack to detect cycles in directed graphs. In undirected graphs, a back edge during DFS indicates a cycle.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is the Floyd-Warshall algorithm, and how is it used to find shortest paths between all pairs of nodes?

A

Finds shortest paths between all pairs, has O(V^3) complexity.

17
Q

What is graph coloring? Explain the significance of the chromatic number of a graph.

A

Assign colors to vertices so no two adjacent vertices share the same color, chromatic number is the minimum needed.

18
Q

What are strongly connected components (SCCs) in a directed graph? How can Tarjan’s or Kosaraju’s algorithm be used to find them?

A

SCCs are maximal strongly connected subgraphs. Tarjan’s and Kosaraju’s algorithms use DFS to find SCCs.

19
Q

What is the concept of a ‘cut vertex’ or ‘cut edge’ in a graph? How do you find them?

A

Cut vertex increases the number of connected components if removed. Cut edge disconnects the graph if removed.

20
Q

What are Eulerian and Hamiltonian paths/cycles? How do you check if a graph contains one?

A

Eulerian path visits every edge once, Hamiltonian path visits every vertex once.

21
Q

What is the time complexity of common graph algorithms like DFS, BFS, Dijkstra’s, and Bellman-Ford?

A

DFS/BFS: O(V + E). Dijkstra: O((V + E) log V). Bellman-Ford: O(VE). Floyd-Warshall: O(V^3).

22
Q

How can graphs be used to represent and solve problems in social networks, like finding influencers or community detection?

A

Graphs represent social networks where nodes are people and edges are relationships. Algorithms can find influencers, communities.

23
Q

What is the max-flow/min-cut theorem? How does the Ford-Fulkerson algorithm solve the maximum flow problem in a flow network?

A

Max-flow/min-cut theorem states max flow equals min cut capacity in a flow network. Ford-Fulkerson finds max flow.

24
Q

Explain how graph partitioning can help in parallel computing. What are some common techniques for graph partitioning?

A

Graph partitioning divides a graph into subgraphs to minimize cut size, useful for parallelizing work.

25
What are planar graphs, and how does Kuratowski’s Theorem relate to them?
Planar graphs can be drawn without edge crossings. Kuratowski’s Theorem defines conditions for planarity.
26
How does the PageRank algorithm, used by search engines, apply graph theory?
PageRank measures node importance based on link structure, used in ranking web pages.
27
What are random graphs? How are they modeled in network science (e.g., Erdős–Rényi model)?
Random graphs have edges with a given probability, Erdős–Rényi model is one such type.
28
How can graphs be used in machine learning models? Explain graph neural networks (GNNs).
Graphs represent structured data. Graph neural networks (GNNs) are used for node classification, link prediction, etc.
29
Explain the importance of spectral graph theory and how it is used to understand the properties of a graph.
Spectral graph theory studies graphs using eigenvalues/eigenvectors of their matrices (adjacency, Laplacian).
30
What are dynamic graphs, and how can changes over time (e.g., edge/node insertion and deletion) be efficiently managed?
Dynamic graphs handle real-time changes in nodes and edges. Efficient algorithms track updates.