Re: [algogeeks] Re: give the algo or program to find second largest element in a list using tournament method
Heap's good but the i think problem clearly mentions Tournament sort use this https://blogs.oracle.com/malkit/entry/finding_kth_minimum_partial_ordering although you can do a Inplace tournament sort ...swapping the corresponding elements level 1. adjacent pairs level 2: between pairs apart by 1 place n so on (2,4,8..) until there is only one element left in there without a pair.this gives u least element Now instead of using a Multimap , use a simple array with size equal to original array and store the element that defeated each corresponding element. Get all those elements defeated by the least element ... that number should be of order O(n) get the second least element out of it in O(n) time. *Shashi Kant * *Think positive and find fuel in failure* http://thinkndoawesome.blogspot.com/ *System/Software Engineer* *Hewlett-Packard India Software Operations. * On Wed, Sep 5, 2012 at 4:11 AM, Dave dave_and_da...@juno.com wrote: @Don: Nope. Constructing a heap can be done in O(n). See, e.g., http://www.diku.dk/forskning/performance-engineering/Jesper/heaplab/heapsurvey_html/node9.html . Dave On Tuesday, September 4, 2012 10:24:25 AM UTC-5, Don wrote: Constructing a max-heap is O(n*log n) However, the problem asked for a solution using tournament method. If you ignore that requirement, an O(n) solution is trivial, and doesn't require the additional storage of a heap: int first = max(A[0], A[1]); int second = min(A[0], A[1]); for(i = 2; i N; ++i) { if (A[i] = first) { second = first; first = A[i]; } else if (A[i] second) second = A[i]; } // First and second now contain 1st and 2nd largest values in A Don On Sep 3, 5:04 am, bharat b bagana.bharatku...@gmail.com wrote: Construct a max-heap -- O(n).. call delete() 2 times .. -- O(logn).. === O(n) time.. -- 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/-/bKzs-wHLSoIJ. 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] Microsoft written test question
Is it required only to retain the BST property ?? or to retain the original BST (tree) *Shashi Kant * ***Think positive and find fuel in failure* http://thinkndoawesome.blogspot.com/ *System/Software Engineer* *Hewlett-Packard India Software Operations. * On Tue, Sep 4, 2012 at 1:56 PM, Rahul Kumar Patle patlerahulku...@gmail.com wrote: @atul: correctly caught... here you have to notice that if u get only one violation not second violation ill the last... then sure the violation is created because of swapping of previous and current of first violation... so when you got first violation and put first marker on previous time put second marker on current... suppose and the last if you don't get the second violation then 2nd marker will the current node of first violation... as in your case when we got first violation at node prev = 20 and current = 10.. mark first point at 20 and second pointer at 10.. at the last the 2nd pointer does not get change... i have checked this with other test cases.. this case is coming only when previous and current are the consecutive nodes(parent and its direct child) and one of the node is leaf node... On Tue, Sep 4, 2012 at 1:22 AM, atul anand atul.87fri...@gmail.comwrote: i guess i missed this part of bharat post :- /* If we don't get the violation for the second time .. means both are side-by-side elements .. swap them .. */ i was saying the same.so it will work. On 9/4/12, atul anand atul.87fri...@gmail.com wrote: @rahul : Here are the boundary cases need to be taken care of :- suppose given BST is the following :- root=allocate(70); root-right=allocate(75); root-left=allocate(50); root-left-left=allocate(20); root-left-left-right=allocate(25); root-left-left-left=allocate(10); root-left-right=allocate(60); root-left-right-right=allocate(65); root-left-right-left=allocate(55); now suppose node(20) and node(10) get swapped inorder of given tree is :- 20 10 25 50 55 60 65 70 75 now first violation is at node(20) but you wont get second voilation...because rest is in inc order. yes , it can be done by taking care of root of that first violation. On 9/3/12, Rahul Kumar Patle patlerahulku...@gmail.com wrote: @bharat: +1 i have tried some test cases.. working finely.. @anyone pls verify?? On Mon, Sep 3, 2012 at 11:58 AM, bharat b bagana.bharatku...@gmail.comwrote: while doing in-order traversal, we have to check if(prev current) -- then mark prev element for swapping in the first time violation.. if it happens for the second time..then mark current element for swapping. swap both .. If we don't get the violation for the second time .. means both are side-by-side elements .. swap them .. Hope works .. If I miss any case .. correct me thanks, On Sun, Sep 2, 2012 at 7:45 PM, Rahul Kumar Patle patlerahulku...@gmail.com wrote: @navin: can u explain ur algorithms in words pls.. On Sun, Sep 2, 2012 at 5:53 PM, Navin Kumar algorithm.i...@gmail.comwrote: void correctBST(struct node *root) { int flag =0; static struct node *temp1, *temp2, *temp3, *prev; static int found; if(found) return; if(root) { correctBST(root-left); if(!temp1 prev root-data prev-data) { temp1 = prev; temp2 = root; swap((temp1-data), (temp2-data)); flag = 1; prev = temp1; } else if(!temp3 prev root-data prev-data) { temp3 = root; swap((temp1-data), (temp2-data)); swap((temp1-data), (temp3-data)); found = 1; return; } if(!flag) prev = root; correctBST(root-right); } } On Sun, Sep 2, 2012 at 4:02 PM, Rahul Kumar Patle patlerahulku...@gmail.com wrote: help to solve the following.. Question: Two of the nodes of a BST are swapped. Correct the BST (taken from GeekforGeeks http://www.geeksforgeeks.org/archives/23272 2nd online test 3rd question) -- Thanks and Regards: Rahul Kumar Patle http://www.linkedin.com/profile/view?id=106245716trk=tab_pro M.Tech, School of Information Technology Indian Institute of Technology, Kharagpur-721302, Indiahttp://www.iitkgp.ac.in/ Mobile No: +91-8798049298, +91-9424738542 Alternate Email: rahulkumarpa...@hotmail.com -- 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,
Re: [algogeeks] Microsoft written test question
@Shashi : i dont see any differencebcoz only 2 nodes are swapped ..after correcting it...it shud maintain BST property wich automatically retain original tree -- 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] Microsoft written test question
well in that case there can be simpler ways to do it do an inorder traversal while checking prevcurnext ordering maintained if not then make it in proper order ,although whole tree has to be traversed to fix it. *Shashi Kant * ***Think positive and find fuel in failure* http://thinkndoawesome.blogspot.com/ *System/Software Engineer* *Hewlett-Packard India Software Operations. * On Wed, Sep 5, 2012 at 12:43 PM, atul anand atul.87fri...@gmail.com wrote: @Shashi : i dont see any differencebcoz only 2 nodes are swapped ..after correcting it...it shud maintain BST property wich automatically retain original tree -- 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] Microsoft written test question
@Shashi : please check previous discussion on this thread. On Wed, Sep 5, 2012 at 2:09 PM, shashi kant shashiski...@gmail.com wrote: well in that case there can be simpler ways to do it do an inorder traversal while checking prevcurnext ordering maintained if not then make it in proper order ,although whole tree has to be traversed to fix it. *Shashi Kant * ***Think positive and find fuel in failure* http://thinkndoawesome.blogspot.com/ *System/Software Engineer* *Hewlett-Packard India Software Operations. * On Wed, Sep 5, 2012 at 12:43 PM, atul anand atul.87fri...@gmail.comwrote: @Shashi : i dont see any differencebcoz only 2 nodes are swapped ..after correcting it...it shud maintain BST property wich automatically retain original tree -- 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] Enter in the loop challenge
Here is a question...and i am badly stuck at it how would you get into the loop int main() { while ( 0) { printf(hello); } return 0; } You cannot change the while loop and its condition and you have to print hello -- 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] Enter in the loop challenge
#define while(x) while(1) Cheers, -Bala On Wed, Sep 5, 2012 at 7:45 AM, Shashank Jain shashank29j...@gmail.com wrote: Here is a question...and i am badly stuck at it how would you get into the loop int main() { while ( 0) { printf(hello); } return 0; } You cannot change the while loop and its condition and you have to print hello -- 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] Enter in the loop challenge
it works thanks for your reply On Wed, Sep 5, 2012 at 6:19 PM, Bala cmb...@gmail.com wrote: #define while(x) while(1) Cheers, -Bala On Wed, Sep 5, 2012 at 7:45 AM, Shashank Jain shashank29j...@gmail.com wrote: Here is a question...and i am badly stuck at it how would you get into the loop int main() { while ( 0) { printf(hello); } return 0; } You cannot change the while loop and its condition and you have to print hello -- 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] Enter in the loop challenge
Source: http://gcc.gnu.org/onlinedocs/cpp/Macros.html You may define any valid identifier as a macro, even if it is a C keyword. The preprocessor does not know anything about keywords. This can be useful if you wish to hide a keyword such as const from an older compiler that does not understand it. However, the preprocessor operator defined (see Defined) can never be defined as a macro, and C++'s named operators (see C++ Named Operators) cannot be macros when you are compiling C++. Cheers, -Bala “Judge nothing, be happy. Forgive everything, be happier. Love everything, be happiest.” ~Sri Chinmoy On Wed, Sep 5, 2012 at 8:12 AM, Shashank Jain shashank29j...@gmail.com wrote: can you plz explain how it happens ...as valid macro names must not be key words. On Wed, Sep 5, 2012 at 6:24 PM, Shashank Jain shashank29j...@gmail.com wrote: it works thanks for your reply On Wed, Sep 5, 2012 at 6:19 PM, Bala cmb...@gmail.com wrote: #define while(x) while(1) Cheers, -Bala On Wed, Sep 5, 2012 at 7:45 AM, Shashank Jain shashank29j...@gmail.com wrote: Here is a question...and i am badly stuck at it how would you get into the loop int main() { while ( 0) { printf(hello); } return 0; } You cannot change the while loop and its condition and you have to print hello -- 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.
Re: [algogeeks] Enter in the loop challenge
thanks that was a really nice explanation shashank On Wed, Sep 5, 2012 at 6:48 PM, Bala cmb...@gmail.com wrote: Source: http://gcc.gnu.org/onlinedocs/cpp/Macros.html You may define any valid identifier as a macro, even if it is a C keyword. The preprocessor does not know anything about keywords. This can be useful if you wish to hide a keyword such as const from an older compiler that does not understand it. However, the preprocessor operator defined (see Defined) can never be defined as a macro, and C++'s named operators (see C++ Named Operators) cannot be macros when you are compiling C++. Cheers, -Bala “Judge nothing, be happy. Forgive everything, be happier. Love everything, be happiest.” ~Sri Chinmoy On Wed, Sep 5, 2012 at 8:12 AM, Shashank Jain shashank29j...@gmail.com wrote: can you plz explain how it happens ...as valid macro names must not be key words. On Wed, Sep 5, 2012 at 6:24 PM, Shashank Jain shashank29j...@gmail.com wrote: it works thanks for your reply On Wed, Sep 5, 2012 at 6:19 PM, Bala cmb...@gmail.com wrote: #define while(x) while(1) Cheers, -Bala On Wed, Sep 5, 2012 at 7:45 AM, Shashank Jain shashank29j...@gmail.com wrote: Here is a question...and i am badly stuck at it how would you get into the loop int main() { while ( 0) { printf(hello); } return 0; } You cannot change the while loop and its condition and you have to print hello -- 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. -- 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: Snapdeal placement proceedure
hey how was your snapdeal exam you also please give some details ... On Tuesday, 28 August 2012 22:26:48 UTC+5:30, [we]fork wrote: -- Forwarded message -- From: sachin singh sach...@gmail.com javascript: Date: Tue, Aug 28, 2012 at 10:23 PM Subject: Snapdeal placement proceedure To: algo...@googlegroups.com javascript: Can anyone tell about the recruitment process of snapdeal? I mean how to prepare for the written test?What kind of written test it would be? What are they asking in interview? And some pointers on what skills they are basically looking at when they come to hire at colleges -- 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/-/nJTLqRxkQNQJ. 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: Snapdeal Paper Pattern
hey i hope your test is over can you also please some info about the test was the test online or paper and how many questions from each round.. how was the interview process what to focus on among DS/OS/OOPS/DBMS.. please elaborate as much possible... On Wednesday, 22 August 2012 23:23:28 UTC+5:30, Arun Kindra wrote: 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 view this discussion on the web visit https://groups.google.com/d/msg/algogeeks/-/5s90J8zzgBUJ. 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: Snapdeal Paper Pattern
Thier aptitudes contain 11 logic puzzles(one can find these on the net) and 5 algo questions(easy). On Thu, Sep 6, 2012 at 1:47 AM, noname narayan.shiv...@gmail.com wrote: hey i hope your test is over can you also please some info about the test was the test online or paper and how many questions from each round.. how was the interview process what to focus on among DS/OS/OOPS/DBMS.. please elaborate as much possible... On Wednesday, 22 August 2012 23:23:28 UTC+5:30, Arun Kindra wrote: 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 view this discussion on the web visit https://groups.google.com/d/msg/algogeeks/-/5s90J8zzgBUJ. 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. -- *Anil Arya, Computer Science * *Motilal Nehru National Institute of Technology,Allahabad . * -- 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.