Skills101
← All practice quizzes

Quiz: Searching and Sorting in C

5 questions · new set on every retakeNo time limitPass: 60%+10 XP on first pass

The searching and sorting programs every C lab and viva asks for, written cleanly and traced step by step — with the number of comparisons, time complexity and when to use each one.

Log in to take the quiz

Free account · see your score, answers and explanations, earn XP

  1. Question 1

    What must be true before you can use binary search?

  2. Question 2

    At most how many comparisons does binary search need for 1,000 sorted elements?

  3. Question 3

    What does this print?

    #include <stdio.h>
    int main(void) {
        int a[] = {3, 1, 2};
        int n = 3, swaps = 0;
        for (int p = 0; p < n - 1; p++)
            for (int j = 0; j < n - 1 - p; j++)
                if (a[j] > a[j + 1]) {
                    int t = a[j]; a[j] = a[j + 1]; a[j + 1] = t;
                    swaps++;
                }
        printf("%d %d%d%d", swaps, a[0], a[1], a[2]);
        return 0;
    }
    
  4. Question 4

    Which sort makes the same number of comparisons whether the input is sorted or not?

  5. Question 5

    What is the best-case time of insertion sort, and when does it happen?

🎯 Today’s placement challenge — 10 questions, no login. Can you score 10/10?Take today’s challenge →