GateAI
Asymptotic Analysis

GATE CSE 2024 Set 1 · Q17

MCQ1 markEasy

Time

Given an integer array of size NN, we want to check if the array is sorted (in either ascending or descending order). An algorithm solves this problem by making a single pass through the array and comparing each element of the array only with its adjacent elements. The worst-case time complexity of this algorithm is

Select one answerSingle correct

Pick an option to check

Solution

Step-by-step verified solution

Official answer: A) both O(N) and (N)

Asymptotic Analysis

To determine whether an array of size NN is sorted, a single-pass algorithm compares each element with its adjacent element.

  • In the worst case (e.g., when the array is sorted or the unsorted order is detected at the very last pair), the algorithm makes N−1N - 1 comparisons.

  • Thus, the worst-case running time is Tworst(N)=cN+d=Θ(N)T_{\text{worst}}(N) = cN + d = \Theta(N) for some constants c>0c > 0 and dd.

  • By definition of asymptotic notations, any function that is Θ(N)\Theta(N) is both O(N)\text{O}(N) (asymptotically upper-bounded by NN) and Ω(N)\Omega(N) (asymptotically lower-bounded by NN).

Therefore, the worst-case time complexity is both O(N)\text{O}(N) and Ω(N)\Omega(N), corresponding to option (A).

Try the question first, then check your work.

Think the official key or this write-up is wrong?

Report error or challenge

Examiner trap

The misconception this question tests

This Asymptotic Analysis previous year question is Q17 of the GATE CSE 2024 Set 1 paper. Find more GATE CSE PYQs on Asymptotic Analysis in Algorithms, or browse all GATE CSE PYQs.

Free diagnostic

Where do you stand for GATE?

Take the 20-minute diagnostic: the 3 topics that cost you the most marks, and a rank range. Or sit 5 related Asymptotic Analysis PYQs now with no account.

One GATE CSE PYQ every morning

An official question by email at 7 AM IST, with a link to its verified solution. Unsubscribe in one click.

Asymptotic Analysis in GATE CSE

Asymptotic Analysis has 31 GATE CSE PYQs across 19 papers from 2011 to 2026. 15 of them are 1-mark MCQs like this one, and GATE CSE 2024 Set 1 has 2.

How GATE tests Asymptotic Analysis

More from GATE CSE 2024 Set 1

Share this solution

A plain-text card for WhatsApp or Telegram study groups.

GateAI solution cardGATE CSE 2024 Set 1 · Q17 · MCQ

Given an integer array of size N, we want to check if the array is sorted (in either ascending or descending order). An algorithm solves this problem by making a single pass through the array and comparing each element of the array only with its adjacent elements. The worst-case time complexity of this algorithm is

Topic-wise GATE CS PYQs with verified steps

Independent practice explanation verified by the GateAI team. GATE is conducted by the IITs; question text follows the official paper.