ProgrammingModerate
A square matrix is symmetric when a[i][j] equals a[j][i]. What is the time needed to test an n x n matrix for symmetry in C?
- A. About n comparisons, since only the diagonal matters
- B. About n^3 comparisons
- C. About n^2 / 2 comparisons, since each pair with j > i is compared once
- D. About n^4 comparisons, since each row is compared with every column
Correct answer: C. About n^2 / 2 comparisons, since each pair with j > i is compared once
Each unordered pair (i, j) with i < j is checked once, which is about n^2 / 2 comparisons.
More C Programming questions
- A singly linked list is built by inserting 1, 2, 3 at the head. Then two nodes are popped from the head and their values printed. What is…
- A circular singly linked list holds 1 -> 2 -> 3 -> back to 1. Starting at the head node, the program prints six consecutive values. What…
- A sorted list 1, 1, 2, 3, 3 has its duplicates removed by a loop that unlinks a node whose value equals the previous node's value. How…
- A dynamic array starts with capacity 1 and doubles whenever it is full, until its capacity is at least 10. What is the final capacity?
- A complete binary tree has levels 0 to 2 (depth 3 in this count). How many nodes does it have?
- A chained hash bucket holds the nodes 30, 20, 10 in that order from the head. The node holding 20 is deleted and freed. How many nodes…