Data Structures & AlgorithmsEasyTCS NQT · Infosys pattern
What is the space needed by the adjacency-matrix representation of a graph with V vertices and E edges?
- A. O(V²)
- B. O(E log V)
- C. O(E)
- D. O(V + E)
Correct answer: A. O(V²)
The matrix has a V × V entry for every possible pair, whatever the number of edges, so O(V²). O(V + E) is the adjacency-list figure.
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
- Depth-first search is naturally implemented with which of the following?
- A binary tree has root 1; 1's children are 2 (left) and 3 (right); 2's children are 4 (left) and 5 (right); 3 has only a right child, 6…
- Keys 50, 30, 70, 20, 40, 60, 80 are inserted in that order into an empty BST. How many leaves does the tree have, and what is its height…
- What is the maximum number of nodes in a binary tree of height 4, where a single-node tree has height 0?
- What is the minimum possible height of a binary tree with 100 nodes (height of a single node = 0)?
- With the edges sorted first, what is the time complexity of Kruskal's algorithm using a union-find structure, for a graph with V vertices…