Question 41
MediumFor a sparse graph with V = 10⁵ and E = 2 × 10⁵, which representation is better?
- A.
Popular companies
Prepare company by company
Hiring pattern, syllabus, past questions and mocks for each company.
All companiesPractice by subject
Data Structures and Algorithms
For a sparse graph with V = 10⁵ and E = 2 × 10⁵, which representation is better?
Adjacency list
Edge list sorted by weight only
Incidence matrix
Adjacency matrix
Sign up free to see the answer and a step-by-step explanation.
How can DFS detect a cycle in a directed graph?
By counting edges
By finding an edge to a vertex that is still on the recursion stack (a back edge)
It cannot
By finding any visited vertex
Sign up free to see the answer and a step-by-step explanation.
Which algorithm finds shortest paths from one source when some edges have negative weights (but no negative cycles)?
Prim
Bellman–Ford
BFS
Dijkstra
Sign up free to see the answer and a step-by-step explanation.
How does Bellman–Ford detect a negative-weight cycle?
If Dijkstra fails
If the graph has more edges than vertices
If any edge can still be relaxed after V − 1 rounds
It cannot
Sign up free to see the answer and a step-by-step explanation.
What is the time complexity of Dijkstra's algorithm with a binary heap?
O((V + E) log V)
O(V²) always
O(E)
O(VE)
Sign up free to see the answer and a step-by-step explanation.
What is the time complexity of Floyd–Warshall?
O(VE)
O(V³)
O(E log V)
O(V²)
Sign up free to see the answer and a step-by-step explanation.
A directed graph has edges A → B, B → C, C → A and C → D. How many strongly connected components does it have?
3
1
2
4
Sign up free to see the answer and a step-by-step explanation.
Which algorithm finds strongly connected components using two DFS passes, the second on the reversed graph?
Kosaraju's algorithm
Bellman–Ford
Prim's algorithm
Kruskal's algorithm
Sign up free to see the answer and a step-by-step explanation.
Which of these graphs is bipartite?
A complete graph with 4 vertices
A cycle with 5 vertices
A cycle with 6 vertices
A triangle
Sign up free to see the answer and a step-by-step explanation.
Which traversal finds the shortest path in an unweighted grid maze?
BFS
Binary search
Inorder traversal
DFS
Sign up free to see the answer and a step-by-step explanation.