[algogeeks] Re: second highest elemt in an aary

2009-09-28 Thread harit agarwal
It will take n comparisons.observe this code #includeiostream using namespace std; int sec_largest(int ar[],int n) { int i,max=-32767,sec_max=0; for(i=0;in;i++) { if(ar[i]max) { sec_max=max;

[algogeeks] Re: second highest elemt in an aary

2009-09-28 Thread Shishir Mittal
Here is a pseudo code. Let the array be A[0..N-1]. Consider array B [0..2*N-2]. This array contains all the elements of the binary tree formed from the tournament. h = ceil ( log(N) base 2 ). p = pow(2,h); for( i=p-1,k=0; i2N-1 ; i++,k++) B[i] = A[k]; for(i=p-2, m =N-1; m=k ; m--,i--)

[algogeeks] Re: second highest elemt in an aary

2009-09-28 Thread Shishir Mittal
Here is a pseudo code. Let the array be A[0..N-1]. Consider array B [0..2*N-2]. This array contains all the elements of the binary tree formed from the tournament. h = ceil ( log(N) base 2 ). p = pow(2,h); for( i=p-1,k=0; i2N-1 ; i++,k++) B[i] = A[k]; for(i=p-2, m =N-1; m=k ; m--,i--)

[algogeeks] Re: second highest elemt in an aary

2009-09-28 Thread Shishir Mittal
On Mon, Sep 28, 2009 at 11:56 AM, harit agarwal agarwalha...@gmail.comwrote: It will take n comparisons.observe this code The code fails for the input 4 3 2 1. #includeiostream using namespace std; int sec_largest(int ar[],int n) { int i,max=-32767,sec_max=0;

[algogeeks] Re: second highest elemt in an aary

2009-09-28 Thread Pramod Negi
It won't try with [1,3,2] On Mon, Sep 28, 2009 at 11:56 AM, harit agarwal agarwalha...@gmail.comwrote: It will take n comparisons.observe this code #includeiostream using namespace std; int sec_largest(int ar[],int n) { int i,max=-32767,sec_max=0; for(i=0;in;i++)

[algogeeks] Re: random number...

2009-09-28 Thread manish bhatia
How are you picking ni from [a...b] range (length 7) ? From: avalon avalo...@gmail.com To: Algorithm Geeks algogeeks@googlegroups.com Sent: Saturday, 19 September, 2009 2:16:47 PM Subject: [algogeeks] Re: random number... Forgive me first if i am wrong since