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.
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 |
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)
What is the difference between new and malloc functions?
Explain union. What are its advantages?
What is the benefit of using an enum rather than a #define constant?
Write a c program to print the sizes and ranges of different data types in c?
Tell us the difference between these two : #include"stdio.h" #include<stdio.h> define in detial.
what is diognisis?
Explain what is meant by high-order and low-order bytes?
which will return integer? a) int*s ( ) b) ( int* ) s( ) c) int ( *s ) ( )
Find if a number is power of two or not?
What is return in c programming?
Is there a way to jump out of a function or functions?