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

Can we declare variables anywhere in c?

583


praagnovation

1784


What is stack in c?

619


How can I dynamically allocate arrays?

601


how is the examination pattern?

1599






What is structure of c program?

609


Can the sizeof operator be used to tell the size of an array passed to a function?

622


#define f(g,h) g##h main O int i=0 int var=100 ; print f ("%d"f(var,10));} wat would be the output??

1547


Tell me when would you use a pointer to a function?

613


What does a pointer variable always consist of?

667


How does selection sort work in c?

629


In C, What is the #line used for?

1073


What are local static variables?

623


What does 4d mean in c?

951


What are compound statements?

633