Data Structures & AlgorithmsEasyAccenture · Cognizant pattern
A simple directed graph (no self-loops, at most one edge from u to v) has 6 vertices. What is the maximum number of edges?
- A. 15
- B. 36
- C. 12
- D. 30
Correct answer: D. 30
Every ordered pair (u, v) with u ≠ v can carry an edge: 6 × 5 = 30. 15 = C(6, 2) is the undirected count; 36 would include self-loops.
Practise more Trees, Graphs, Recursion and Dynamic Programming questionsTrees, Graphs, Recursion and Dynamic Programming: notes and key points
More Trees, Graphs, Recursion and Dynamic Programming questions
- Which algorithm finds shortest paths (by number of edges) from one source in an UNWEIGHTED graph in O(V + E) time?
- A binary tree is stored in level order in a 0-indexed array (children of i at 2i + 1 and 2i + 2; None = no node): [1, 2, 3, None, 4, 5]…
- The minimum is deleted from the min-heap [2, 5, 3, 9, 6, 4, 8] (0-indexed): the last element moves to the root and sifts down, swapping…
- An undirected graph has 6 vertices with degrees 3, 3, 2, 2, 2 and x, and it has 8 edges. What is x?
- Dijkstra's algorithm runs from S on the directed graph S→A (7), S→B (2), B→A (3), B→C (8), A→C (1), A→D (6), C→D (2). In what order are…
- What is the maximum number of edges in a directed ACYCLIC graph with 6 vertices (no parallel edges)?