Data Structures & AlgorithmsModerateGATE CS · TCS NQT
Problem: The path graph P4 has vertices 1–4 and edges 1-2, 2-3, 3-4. How many edges does its complement graph (on the same vertices, containing exactly the pairs not joined in P4) have?
- A. 4
- B. 2
- C. 3
- D. 5
Correct answer: C. 3
K4 has six edges, and P4 uses three of them, so its complement has three edges: 1-3, 1-4 and 2-4.
More Coding Interview Problems questions
- Problem: A complete binary tree has 15 nodes (height 3, all levels full). How many of its nodes are leaves?
- Problem: The string "abba" has how many palindromic substrings (counted by index range)?
- Problem: How many occurrences of "ab" are in "ababab" when occurrences may overlap?
- Problem: In the string "dvdf", what is the length of the longest substring with all distinct characters?
- Problem: The number of ways to tile a 1×4 strip completely using tiles of length 1 and length 2 (tiles of the same length are…
- Problem: In the binary string "0011100", what is the length of the longest contiguous substring that contains equal numbers of 0s and 1s?