GATE Computer ScienceVery hardGATE CS
An undirected graph on vertices 0 to 7 has the edges 0-1, 0-2, 0-3, 1-2, 1-4, 2-3, 2-5, 3-4, 3-5, 4-5, 4-6, 5-6, 5-7, 6-7. Let A be its adjacency matrix. How many triangles does the graph contain?
- A. 12
- B. 8
- C. 6
- D. 36
Correct answer: C. 6
The diagonal entries of A³ count closed walks of length 3, and each triangle gives 6 of them (3 start vertices × 2 directions). Here trace(A³) = 36, so there are 36/6 = 6 triangles: 012, 023, 235, 345, 456 and 567.
Practise more Programming and Data Structures (GATE) questionsProgramming and Data Structures (GATE): notes and key points
More Programming and Data Structures (GATE) questions
- An m × n sparse matrix with m = 1000 rows is stored in coordinate form (three arrays row, col, val, each of length nnz) or in compressed…
- Bubble sort with early exit (the algorithm stops after a pass in which no swap occurs) sorts the array [6, 9, 3, 8, 0, 5, 2, 7, 1, 4] into…
- An LRU cache of capacity 3 (get and put both make a key the most recently used; put of an existing key updates its value; when a put adds…
- The standard nextpermutation algorithm (find the rightmost i with a[i] < a[i+1], swap a[i] with the rightmost larger a[j] to its right…
- A max-heap is stored in A[1..13] = [100, 60, 90, 50, 40, 85, 80, 20, 10, 30, 35, 70, 75]. The key at position 8 (the value 20) is deleted…
- Binary search (lo = 0, hi = n − 1, mid = ⌊(lo + hi)/2⌋; each loop iteration compares a[mid] once and ends the search on equality) is run…