edited by
9,574 views
19 19 votes

​​​​Consider an unordered list of $N$ distinct integers.

What is the minimum number of element comparisons required to find an integer in the list that is NOT the largest in the list?
  1. $1$
  2. $N-1$
  3. $N$
  4. $2N-1$

 

7 Answers

19 19 votes
Pick any two numbers from a set of distinct numbers, one of them must be smaller than the other. The smaller of the two is guaranteed not to be the largest in the entire list. One comparison is enough find an element that is not the largest.
10 10 votes

Consider any array  and variable largest

    
23431311

 

largest 
23


 Variable largest be updated with currently seen maximum value  i.e.., we consider  first element of the array as the largest .Then here comes 2 cases :
  • while we see second element of the array ,if it is greater than first element then we update largest variable with second element of the array. ---> Means we have seen element which is not largest i.e.., first Element  --->Requires One Comparison

     

  • If  second element of the array is lesser than first element then we don't update largest variable.--> Means  we  have  seen  element   which  is  not  largest   i.e..,  Second Element   ---> Requires One Comparison

Hence Minimum no.of Comparisons required =1 to find the element which is not largest

 

 

edited by
10 10 votes

Since all elements are distinct, there is a unique largest element. The task is to identify any one element that is not the maximum, using the fewest comparisons in the worst case.

Select any two distinct elements from the list, say $a$ and $b$. Perform a single comparison:

  • If $a < b$, then $a$ cannot be the largest.
  • If $b < a$, then $b$ cannot be the largest.

In either case, the smaller of the two is guaranteed not to be the maximum. Thus, one comparison suffices to produce a valid answer.

No algorithm can do better than one comparison (since without any comparison, we have no information about relative order), and no additional comparisons are necessary.

Hence, the minimum number of comparisons required is 1.

Final Answer:  
$$
\boxed{\text{A. }1}
$$

2 2 votes
In any list, by comparing L[0] with L[1] we get an element which is the largest and another which is not the largest. So it takes only one comparision.
2 2 votes

Answer is OPTION A.

Consider a basic example of an array. We need to find the element that is not maximum. SO check the first two elements of the array (length of array >= 2).

Out of these two elements, it is guarenteed that one element is not the maximum, as all the elements are distinct.

Hence we need 1 comparison between first and second element.

Answer:
Position:
Show:

Related questions

8 8 votes
6 6 answers
3.8k
3.8k views
Arjun asked Feb 27, 2025
3,797 views
Suppose that insertion sort is applied to the array $[1,3,5,7,9,11, x, 15,13]$ and it takes exactly two swaps to sort the array. Select all possible values of $x$.$10$$12...
14 14 votes
5 5 answers
10.1k
10.1k views
admin asked Feb 27, 2025
10,106 views
Consider the following algorithm someAlgo that takes an undirected graph $G$ as input. ...
33 33 votes
3 3 answers
14.5k
14.5k views
Arjun asked Feb 27, 2025
14,514 views
​​​​Which of the following statements regarding Breadth First Search (BFS) and Depth First Search (DFS) on an undirected simple graph $G$ is/are TRUE?A DFS tree of $G$ is...
24 24 votes
3 3 answers
7.9k
7.9k views
Arjun asked Feb 27, 2025
7,861 views
​​​​Let $\text{G}$ be an edge-weighted undirected graph with positive edge weights. Suppose a positive constant $\alpha$ is added to the weight of every edge.Which ONE of...