Find the second largest element in an array with minimum no of comparisons and give the minimum no of comparisons needed on an array of size N to do the same.



Find the second largest element in an array with minimum no of comparisons and give the minimum no o..

Answer / Nisheet Kumar Nigam

The second largest element can be found using a binary search algorithm. You first find the largest element and then iterate through the array again to find the second largest element. The number of comparisons is log2(n) + n/2, which is approximately 1.414 * sqrt(n) for large arrays.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C Interview Questions

pgm to find number of words starting with capital letters in a file(additional memory usage not allowed)(if a word starting with capital also next letter in word is capital cann't be counted twice)

2 Answers   Subex, Wipro,


What is the difference between new and malloc functions?

1 Answers   InterGraph,


Explain union. What are its advantages?

1 Answers  


What is the benefit of using an enum rather than a #define constant?

1 Answers  


Write a c program to print the sizes and ranges of different data types in c?

1 Answers  


Tell us the difference between these two : #include"stdio.h" #include<stdio.h> define in detial.

5 Answers  


what is diognisis?

1 Answers  


Explain what is meant by high-order and low-order bytes?

1 Answers  


which will return integer? a) int*s ( ) b) ( int* ) s( ) c) int ( *s ) ( )

1 Answers   C DAC,


Find if a number is power of two or not?

1 Answers  


What is return in c programming?

1 Answers  


Is there a way to jump out of a function or functions?

1 Answers  


Categories