GATE CS 2024 Set 1 | Question 17

Algorithms › Sorting & Searching · MCQ · 1 mark · Answer: A

  1. Question 17Algorithmsmcq1 mark
    An algorithm checks if an array of size is sorted (ascending or descending) by a single pass comparing each element only with its adjacent elements. The worst-case time complexity is
    • A.
      both and
      ✓
    • B.
      but not
    • C.
      but not
    • D.
      neither nor

    Answer: A

    Solution

    Answer: (A) both and A single pass does up to comparisons, so it is . In the worst case it must examine essentially all elements (e.g. an array that is sorted except the last pair), so it is also . Thus the worst-case time is — both and .

More GATE PYQ on Sorting & Searching

All GATE CS Algorithms PYQ →

Attempt GATE CS 2024 Set 1 in real GATE exam mode

Full paper with a timer, the GATE interface and a topic-wise analysis — free.

Create free account →