second highest number in a given set of numbers

Answer Posted / om

There are two good method to solve this problem; first one
takes 2n-3 comparison and second one takes n+lg(n)-2
comparison only.

1) Run bubble sort loop only for 2 times ..the first time it
will do n-1 comparison and put the largest element at the
end of the array.... then by running second time it will do
n-2 comparison and put the second largest element at the
second last position in the array... so n-1 + n-2 =2n-3
comparison. cool naa... I didn't sort the whole array and
found the second largest element.

2)http://www.seeingwithc.org/topic3html.html
check this site...

Is This Answer Correct ?    2 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is a stream?

659


main use of recursive function a) processing speed high b) reduce program length/reduce repeated statements c) if you do not, use iterative methods like, for, while or do-while d) all the above

621


How to get string length of given string in c?

619


What is the advantage of using #define to declare a constant?

628


Explain how do you list files in a directory?

624






What is the sizeof () operator?

630


How can I read data from data files with particular formats?

614


When is a null pointer used?

648


What is a 'null pointer assignment' error? Explain what are bus errors, memory faults, and core dumps?

739


differentiate built-in functions and user – defined functions.

641


Is it better to use a pointer to navigate an array of values, or is it better to use a subscripted array name?

661


What do the functions atoi(), itoa() and gcvt() do?

732


Can we assign string to char pointer?

600


What are the different properties of variable number of arguments?

669


What are variables and it what way is it different from constants?

797