[algogeeks] use of static

2012-08-30 Thread Puneet Gautam
#includeiostream.h
int main()
{static char names[5][20]={pascal,ada,cobol,fortran,perl};
int i;
char *t;
t=names[3];
names[3]=names[4];
names[4]=t;
for (i=0;i=4;i++)
coutnames[i]endl;
getchar();
return 0;
}


Whats the importance of static keyword here..?

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] use of static

2012-08-30 Thread Romil .......
It should give an error in the line  names[3] = names[4] 
These are fixed address values..you cannot change them.

On Thu, Aug 30, 2012 at 12:44 PM, Puneet Gautam puneet.nsi...@gmail.comwrote:

 #includeiostream.h
 int main()
 {static char names[5][20]={pascal,ada,cobol,fortran,perl};
 int i;
 char *t;
 t=names[3];
 names[3]=names[4];
 names[4]=t;
 for (i=0;i=4;i++)
 coutnames[i]endl;
 getchar();
 return 0;
 }


 Whats the importance of static keyword here..?

  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




-- 
Romil
Software Engineer,
Winshuttle Softwares India Pvt. Ltd.
Chandigarh

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] use of static

2012-08-30 Thread rahul
old style C, where you can't have auto array. just that.

On Thu, Aug 30, 2012 at 12:52 PM, Romil ... vamosro...@gmail.comwrote:

 It should give an error in the line  names[3] = names[4] 
 These are fixed address values..you cannot change them.


 On Thu, Aug 30, 2012 at 12:44 PM, Puneet Gautam 
 puneet.nsi...@gmail.comwrote:

 #includeiostream.h
 int main()
 {static char names[5][20]={pascal,ada,cobol,fortran,perl};
 int i;
 char *t;
 t=names[3];
 names[3]=names[4];
 names[4]=t;
 for (i=0;i=4;i++)
 coutnames[i]endl;
 getchar();
 return 0;
 }


 Whats the importance of static keyword here..?

  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




 --
 Romil
 Software Engineer,
 Winshuttle Softwares India Pvt. Ltd.
 Chandigarh


  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] LOGIC!!!

2012-08-30 Thread ashish mann
Q. A company organizes two foreign trips for its employees yearly. Aim of
the trip is to increase interaction among the employees of the company and
hence company wants each of his employee to see new people on the trip and
not even a single person with whom he has worked in past. Therefore it is a
rule in company that in any of the trips, all the employees should be new
to each other and no two of them should have worked together in past.


Given the work history of each employee (which people he has worked with
sometimes in past), you have to tell whether all of the employees can be
accommodated within trips without violating the above rule or not. Each
employee is given a unique integer ID by which they are recognized. You can
also assume that each employee has worked with at least one other employee
in past.



*Note: *No employee can be in both trips and every employee must be part of
one trip.


*Example: *

i) Suppose the work history is given as follows: {(1,2),(2,3),(3,4)}; then
it is possible to accommodate all the four employees in two trips (one trip
consisting of employees 1 3 and other having employees 2  4). Neither of
the two employees in the same trip have worked together in past.

ii) Suppose the work history is given as {(1,2),(1,3),(2,3)} then there is
no way possible to have two trips satisfying the company rule and
accommodating all the employees.

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] use of static

2012-08-30 Thread Puneet Gautam
Well, its gives error in every array assignment..ISO forbids this type of
assignment.
@rahul: But whats with the static here. how  does it affect any string
declared..? I couldnt get your answer ..pls explain
On Thu, Aug 30, 2012 at 12:54 PM, rahul rahulr...@gmail.com wrote:

 old style C, where you can't have auto array. just that.


 On Thu, Aug 30, 2012 at 12:52 PM, Romil ... vamosro...@gmail.comwrote:

 It should give an error in the line  names[3] = names[4] 
 These are fixed address values..you cannot change them.


 On Thu, Aug 30, 2012 at 12:44 PM, Puneet Gautam 
 puneet.nsi...@gmail.comwrote:

 #includeiostream.h
 int main()
 {static char names[5][20]={pascal,ada,cobol,fortran,perl};
 int i;
 char *t;
 t=names[3];
 names[3]=names[4];
 names[4]=t;
 for (i=0;i=4;i++)
 coutnames[i]endl;
 getchar();
 return 0;
 }


 Whats the importance of static keyword here..?

  --
 You received this message because you are subscribed to the Google
 Groups Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




 --
 Romil
 Software Engineer,
 Winshuttle Softwares India Pvt. Ltd.
 Chandigarh


  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Snapdeal Paper Pattern

2012-08-30 Thread JITESH KUMAR
Get yourself prepared for DS and Algo.. Thats it.

On Fri, Aug 24, 2012 at 5:10 PM, vaibhav shukla vaibhav200...@gmail.comwrote:

 its DU . please guide with watever details you have.
 thanks


 On Fri, Aug 24, 2012 at 4:42 PM, JITESH KUMAR jkhas...@gmail.com wrote:

 Which college?
 I can help you.


 On Wed, Aug 22, 2012 at 11:23 PM, Arun Kindra arunkin...@gmail.comwrote:

 Anyone know the paper pattern or ques of snapdeal? And What they
 demand(any specific language)?

 --
 Regards:

 *Arun Kindra*


  --
 You received this message because you are subscribed to the Google
 Groups Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




 --
 *Regards
 Jitesh Kumar

 There is only one 'YOU' in this world. You are Unique and Special.*
 *Don't Ever Forget it.*

  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




 --
 best wishes!!
  Vaibhav

  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




-- 
*Regards
Jitesh Kumar

There is only one 'YOU' in this world. You are Unique and Special.*
*Don't Ever Forget it.*

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Snapdeal Paper Pattern

2012-08-30 Thread Rabi Chandra Shah
@Jitesh .. What about the question pattern ???
Does the question pattern include aptitude section ??

On Thu, Aug 30, 2012 at 7:51 PM, JITESH KUMAR jkhas...@gmail.com wrote:

 Get yourself prepared for DS and Algo.. Thats it.


 On Fri, Aug 24, 2012 at 5:10 PM, vaibhav shukla 
 vaibhav200...@gmail.comwrote:

 its DU . please guide with watever details you have.
 thanks


 On Fri, Aug 24, 2012 at 4:42 PM, JITESH KUMAR jkhas...@gmail.com wrote:

 Which college?
 I can help you.


 On Wed, Aug 22, 2012 at 11:23 PM, Arun Kindra arunkin...@gmail.comwrote:

 Anyone know the paper pattern or ques of snapdeal? And What they
 demand(any specific language)?

 --
 Regards:

 *Arun Kindra*


  --
 You received this message because you are subscribed to the Google
 Groups Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




 --
 *Regards
 Jitesh Kumar

 There is only one 'YOU' in this world. You are Unique and Special.*
 *Don't Ever Forget it.*

  --
 You received this message because you are subscribed to the Google
 Groups Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




 --
 best wishes!!
  Vaibhav

  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




 --
 *Regards
 Jitesh Kumar

 There is only one 'YOU' in this world. You are Unique and Special.*
 *Don't Ever Forget it.*

  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] ip traceback

2012-08-30 Thread muthulakshmi
can stochastic diffusion search be applied for ip traceback mechanism??? if 
yes please explain me...

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/algogeeks/-/Pw9bgAb4FRQJ.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: give the algo or program to find second largest element in a list using tournament method

2012-08-30 Thread Don
The second largest element is the largest element beaten by the
winner.
So if you implement a tournament in which each element keeps track of
the largest element it has beaten, you'll get the second largest
naturally.
Don

On Aug 29, 9:15 am, Sangeeta sangeeta15...@gmail.com wrote:
 give the algo or program to find second largest element in a list using
 tournament method

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: LOGIC!!!

2012-08-30 Thread Don
For each employee, keep track of which vacation he is assigned to, if
any.
Start with all employees unassigned.

1. Pick the first pair who have worked together and are currently
unassigned. Assign one to Trip A and the other to Trip B.
2. Loop over all pairs. If a pair are assigned to the same trip,
return failure. If one is assigned and the other is not assigned,
assign the unassigned one to the other trip.
3. If all employees are assigned, return success. If Step 2 produced
results, repeat step 2. Else return to step 1.

Don

On Aug 30, 12:13 am, ashish mann ashishman...@gmail.com wrote:
 Q. A company organizes two foreign trips for its employees yearly. Aim of
 the trip is to increase interaction among the employees of the company and
 hence company wants each of his employee to see new people on the trip and
 not even a single person with whom he has worked in past. Therefore it is a
 rule in company that in any of the trips, all the employees should be new
 to each other and no two of them should have worked together in past.

 Given the work history of each employee (which people he has worked with
 sometimes in past), you have to tell whether all of the employees can be
 accommodated within trips without violating the above rule or not. Each
 employee is given a unique integer ID by which they are recognized. You can
 also assume that each employee has worked with at least one other employee
 in past.

 *Note: *No employee can be in both trips and every employee must be part of
 one trip.

 *Example: *

 i) Suppose the work history is given as follows: {(1,2),(2,3),(3,4)}; then
 it is possible to accommodate all the four employees in two trips (one trip
 consisting of employees 1 3 and other having employees 2  4). Neither of
 the two employees in the same trip have worked together in past.

 ii) Suppose the work history is given as {(1,2),(1,3),(2,3)} then there is
 no way possible to have two trips satisfying the company rule and
 accommodating all the employees.

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] use of static

2012-08-30 Thread rahul
static doing nothing, just to make a candidate confuse in interview.
static comes into picture, when u calling same function again and again and
u need some variable to retain the old value, and another scenario when u
have to define the scope of variable.


On Thu, Aug 30, 2012 at 6:02 PM, Puneet Gautam puneet.nsi...@gmail.comwrote:

 Well, its gives error in every array assignment..ISO forbids this type of
 assignment.
 @rahul: But whats with the static here. how  does it affect any string
 declared..? I couldnt get your answer ..pls explain

 On Thu, Aug 30, 2012 at 12:54 PM, rahul rahulr...@gmail.com wrote:

 old style C, where you can't have auto array. just that.


 On Thu, Aug 30, 2012 at 12:52 PM, Romil ... vamosro...@gmail.comwrote:

 It should give an error in the line  names[3] = names[4] 
 These are fixed address values..you cannot change them.


 On Thu, Aug 30, 2012 at 12:44 PM, Puneet Gautam puneet.nsi...@gmail.com
  wrote:

 #includeiostream.h
 int main()
 {static char names[5][20]={pascal,ada,cobol,fortran,perl};
 int i;
 char *t;
 t=names[3];
 names[3]=names[4];
 names[4]=t;
 for (i=0;i=4;i++)
 coutnames[i]endl;
 getchar();
 return 0;
 }


 Whats the importance of static keyword here..?

  --
 You received this message because you are subscribed to the Google
 Groups Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




 --
 Romil
 Software Engineer,
 Winshuttle Softwares India Pvt. Ltd.
 Chandigarh


  --
 You received this message because you are subscribed to the Google
 Groups Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Microsoft online exam pattern

2012-08-30 Thread Abhi
Can anyone tell me the type of questions asked in Microsoft's online exam, 
their difficulty level and especially the questions related to test cases 
(pls also post some examples) ?

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/algogeeks/-/TOZP5gPhnnMJ.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] LOGIC!!!

2012-08-30 Thread Saurabh Kumar
I think, if the Graph is 2-colorable (i.e. Bipartite) trip can be arranged.

On 30 August 2012 09:43, ashish mann ashishman...@gmail.com wrote:

 Q. A company organizes two foreign trips for its employees yearly. Aim of
 the trip is to increase interaction among the employees of the company and
 hence company wants each of his employee to see new people on the trip and
 not even a single person with whom he has worked in past. Therefore it is a
 rule in company that in any of the trips, all the employees should be new
 to each other and no two of them should have worked together in past.


 Given the work history of each employee (which people he has worked with
 sometimes in past), you have to tell whether all of the employees can be
 accommodated within trips without violating the above rule or not. Each
 employee is given a unique integer ID by which they are recognized. You can
 also assume that each employee has worked with at least one other employee
 in past.



 *Note: *No employee can be in both trips and every employee must be part
 of one trip.


 *Example: *

 i) Suppose the work history is given as follows: {(1,2),(2,3),(3,4)}; then
 it is possible to accommodate all the four employees in two trips (one trip
 consisting of employees 1 3 and other having employees 2  4). Neither of
 the two employees in the same trip have worked together in past.

 ii) Suppose the work history is given as {(1,2),(1,3),(2,3)} then there is
 no way possible to have two trips satisfying the company rule and
 accommodating all the employees.

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: give the algo or program to find second largest element in a list using tournament method

2012-08-30 Thread sangeeta goyal
@Don can you give the algorithm for the same??
how would you implement it??

On Thu, Aug 30, 2012 at 10:03 PM, Don dondod...@gmail.com wrote:

 The second largest element is the largest element beaten by the
 winner.
 So if you implement a tournament in which each element keeps track of
 the largest element it has beaten, you'll get the second largest
 naturally.
 Don

 On Aug 29, 9:15 am, Sangeeta sangeeta15...@gmail.com wrote:
  give the algo or program to find second largest element in a list using
  tournament method

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.



-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: give the algo or program to find second largest element in a list using tournament method

2012-08-30 Thread Navin Kumar
@sangeeta: n-1 comparison required to choose winner. By tournament approach
winner has played match with logn team and winner must have beaten second
largest element. So among logn number we can select maximum in logn - 1
comparison.

So total comparison required is: n + logn -2

On Thu, Aug 30, 2012 at 10:23 PM, sangeeta goyal sangeeta15...@gmail.comwrote:

 @Don can you give the algorithm for the same??
 how would you implement it??


 On Thu, Aug 30, 2012 at 10:03 PM, Don dondod...@gmail.com wrote:

 The second largest element is the largest element beaten by the
 winner.
 So if you implement a tournament in which each element keeps track of
 the largest element it has beaten, you'll get the second largest
 naturally.
 Don

 On Aug 29, 9:15 am, Sangeeta sangeeta15...@gmail.com wrote:
  give the algo or program to find second largest element in a list using
  tournament method

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: give the algo or program to find second largest element in a list using tournament method

2012-08-30 Thread Don
While the list length is more than one
   Take 2 elements from the head
   Select the larger of the two
   If the smaller is greater than the largest beaten by the larger
  Then set the largest beaten by the larger to the value of
the smaller
   Add the larger to the tail of the list

When this completes, you'll have one element containing the largest
and second largest values.

typedef struct
{
unsigned int value;
unsigned int largestBeaten;
} element;

unsigned int secondLargest(queueelement elements)
{
   while(elements.length()  1)
   {
  element A = elements.dequeue();
  element B = elements.dequeue();
  if (A.value  B.value) swap(A,B);
  if (A.largestBeaten  B.value) A.largestBeaten = B.value;
  elements.enqueue(A);
   }
   return queue.head().largestBeaten;
}

On Aug 30, 12:53 pm, sangeeta goyal sangeeta15...@gmail.com wrote:
 @Don can you give the algorithm for the same??
 how would you implement it??







 On Thu, Aug 30, 2012 at 10:03 PM, Don dondod...@gmail.com wrote:
  The second largest element is the largest element beaten by the
  winner.
  So if you implement a tournament in which each element keeps track of
  the largest element it has beaten, you'll get the second largest
  naturally.
  Don

  On Aug 29, 9:15 am, Sangeeta sangeeta15...@gmail.com wrote:
   give the algo or program to find second largest element in a list using
   tournament method

  --
  You received this message because you are subscribed to the Google Groups
  Algorithm Geeks group.
  To post to this group, send email to algogeeks@googlegroups.com.
  To unsubscribe from this group, send email to
  algogeeks+unsubscr...@googlegroups.com.
  For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.