ProgrammingHard
Bubble sort on the records of 4 keys {4, 3, 2, 1} with a swap count: how many swaps are made?
- A. 6
- B. 4
- C. 5
- D. 3
Correct answer: A. 6
Every pair of the four keys is out of order and is swapped exactly once, and there are C(4,2) = 6 pairs.
More C Programming questions
- A struct array holds records with an int key; the program calls qsort with the comparator (int)(a->key - b->key) for keys near INTMAX and…
- A bsearch call uses a key of type int but the array holds struct records with an int field. What is the correct way to compare?
- Which comparator for qsort on int array is correct for ALL int values (no overflow, no wrong sign)?
- int m[3][4]; int f = &m[0][0]; Which expression refers to the same element as m[2][1]?
- int m[3][4]; What is sizeof(m) / sizeof(m[0][0])?
- int a[] = {1, 2}; int b[] = {3, 4}; int x = a, y = b; void swap(int p, int q) { int t = p; p = q; q = t; } After swap(&x, &y) runs, what…