Re: [algogeeks] Re: Problem: Longest Increasing Seq code
p[i] maintains previous index from which b[i] has reached longest sequence till i. to get the actual list of non-decrease sequence, p has to be traversed through back indices for (u = b.size(), v = b.back(); u--; v = p[v]) b[u] = v; surender On Sat, Jul 16, 2011 at 9:06 AM, Neeraj Gupta neeraj.gupta...@gmail.comwrote: Hi Can anyone help me in understanding the following code http://www.algorithmist.com/index.php/Longest_Increasing_Subsequence.cpp I am not able to understand what is the exact purpose of vector p in the above mentioned code. A little detail explanation will be helpful. I have already read this the basic idea of the algorithm * Let Ai,j be the smallest possible tail out of all increasing subsequences of length j using elements a1, a2, ... , ai. Observe that, for any particular i, Ai,1, Ai,2, ... , Ai,j. This suggests that if we want the longest subsequence that ends with ai + 1, we only need to look for a j such that Ai,j ai + 1 = Ai,j + 1 and the length will be j + 1. Notice that in this case, Ai + 1,j + 1 will be equal to ai + 1, and all Ai + 1,k will be equal to Ai,k for k!=j+1. Furthermore, there is at most one difference between the set Ai and the set Ai + 1, which is caused by this search. Since A is always ordered in increasing order, and the operation does not change this ordering, we can do a binary search for every single a 1, a2, ... , an. * ~Neeraj Hi, -- 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: Dynamic Programming Cormen
Someone please reply. -- 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/-/vBP5ZdFV9HEJ. 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: Dynamic Programming Cormen
Reply for what? On Sat, Jul 16, 2011 at 1:07 PM, Nitish Garg nitishgarg1...@gmail.comwrote: Someone please reply. -- 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/-/vBP5ZdFV9HEJ. 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 SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT 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.
Re: [algogeeks] C OUTPUT AGAIN
for problem1 you can use %hi or %hd .. while scanning .. On Thu, Jul 14, 2011 at 12:03 PM, Gaurav Jain gjainroor...@gmail.comwrote: @Nicks *Problem 1* %d is used to take a signed integer as input. To take a short integer as input, use %hi. That way, you would get the correct answer as 2. *Problem 2:* a:1 means that variable a is of width *1 bit* Similarly, b:2 means that b is of width *2 bits* b = 6 sets the two bits as 10, (last two bits of 110 considered), which is equal to -2 a = 2 sets the only bit as 0, (last bit of 10 considered), which is nothing but zero. Bit-fields like these however tend to be implementation-dependent and in the interest of portability should be avoided. t.b = 6 sets the last two bits of b as 10, which is -2 in 2's complement t.a = 2 sets the On Thu, Jul 14, 2011 at 1:18 AM, nicks crazy.logic.k...@gmail.com wrote: Hey Guys, plz help me in getting these 2 C output problems *PROBLEM 1.* * * *#*includestdio.h int main() { short int a,b,c; scanf(%d%d,a,b); c=a+b; printf(%d,c); return 0; } INPUT- 1 1 OUTPUT 1 i am not getting why 1 is coming in the output.what difference is using short making in the code ??? *PROBLEM 2.* * * * * #includestdio.h main() { struct { int a:1; int b:2; }t; t.b=6; t.a=2; printf(%d %d,t.a,t.b); } OUTPUT 0 -2 What does the statement a:1 and b:1 mean and what are they doing.i am seeing them first time ever...hence not able to get the outputif someone has any idea plz help !! -- 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. -- Gaurav Jain Associate Software Engineer VxVM Escalations Symantec Software India Pvt. Ltd. -- 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] Image Based Problem (Google)
OK :) On Sat, Jul 16, 2011 at 2:32 AM, Divye Kapoor divyekap...@gmail.com wrote: @Sagar: You misunderstand my concern. When I say hash collisions, I mean: Consider 2 very different images X and Y - both have the same hash value H. Such X and Y will always exist because you're mapping a larger informational space to a smaller one (by pigeonhole principle in a sense). Without accessing the pixels in X and Y, how can you distinguish between the two based solely on the value H? My proposition is that the best way to handle this problem is to store a lossless compression of the bits of the image. Hashing will never solve this problem in its entirety. Alternatively, relax the constraints of the problem to allow lossy compression techniques or to include a probability of error in the output. --- DK http://twitter.com/divyekapoor http://www.divye.in -- 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 SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT 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.
Re: [algogeeks] Printf ...
@Kamakhsi In my ubuntu gcc this o/p is coming with warning of undefined %# :) On Sat, Jul 16, 2011 at 5:43 AM, sukhmeet singh sukhmeet2...@gmail.comwrote: @Anatony the output will be compiler dependent res1 is not defined .. as C don't allow to change the value of a variable more than once between a sequence point.. A sequence point occur while assigning a value , calling a function or returning from it.. Hence both res1 and res2 would give arbitary results.. On Sat, Jul 16, 2011 at 1:45 AM, Antony Kotre antonyko...@gmail.comwrote: can any tell and explain the output of following code #includestdio.h main() { int a =5, b=5; int res1=(++a)+(++a)+(++a); int res2=(++b)+(++b)*10+(++b)*100; printf(%d\n%d\n,res1,res2); } -- 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. -- **Regards SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT 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.
Re: [algogeeks] Printf ...
and o/p is %#s Zi not %s Zi On Sat, Jul 16, 2011 at 2:18 PM, sagar pareek sagarpar...@gmail.com wrote: @Kamakhsi In my ubuntu gcc this o/p is coming with warning of undefined %# :) On Sat, Jul 16, 2011 at 5:43 AM, sukhmeet singh sukhmeet2...@gmail.comwrote: @Anatony the output will be compiler dependent res1 is not defined .. as C don't allow to change the value of a variable more than once between a sequence point.. A sequence point occur while assigning a value , calling a function or returning from it.. Hence both res1 and res2 would give arbitary results.. On Sat, Jul 16, 2011 at 1:45 AM, Antony Kotre antonyko...@gmail.comwrote: can any tell and explain the output of following code #includestdio.h main() { int a =5, b=5; int res1=(++a)+(++a)+(++a); int res2=(++b)+(++b)*10+(++b)*100; printf(%d\n%d\n,res1,res2); } -- 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. -- **Regards SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT ALLAHABAD -- **Regards SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT 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.
Re: [algogeeks] Printf ...
tell me your output pls On Sat, Jul 16, 2011 at 2:19 PM, sagar pareek sagarpar...@gmail.com wrote: and o/p is %#s Zi not %s Zi On Sat, Jul 16, 2011 at 2:18 PM, sagar pareek sagarpar...@gmail.comwrote: @Kamakhsi In my ubuntu gcc this o/p is coming with warning of undefined %# :) On Sat, Jul 16, 2011 at 5:43 AM, sukhmeet singh sukhmeet2...@gmail.comwrote: @Anatony the output will be compiler dependent res1 is not defined .. as C don't allow to change the value of a variable more than once between a sequence point.. A sequence point occur while assigning a value , calling a function or returning from it.. Hence both res1 and res2 would give arbitary results.. On Sat, Jul 16, 2011 at 1:45 AM, Antony Kotre antonyko...@gmail.comwrote: can any tell and explain the output of following code #includestdio.h main() { int a =5, b=5; int res1=(++a)+(++a)+(++a); int res2=(++b)+(++b)*10+(++b)*100; printf(%d\n%d\n,res1,res2); } -- 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. -- **Regards SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT ALLAHABAD -- **Regards SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT ALLAHABAD -- **Regards SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT 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.
Re: [algogeeks] Printf ...
@Antony res1=++a + ++a + ++a; Well it depends on the compiler but i know how gcc works :) from left to right it will first do addition of first two 'a' before addition it will increment the value of a by two cos of two pre increments. then resulting addition will then be added to the incremented value of last 'a'; step wise step it will be :- (++a + ++a) + ++a; //a=5 (7 + 7) + ++a; //a=7 14 + 8; //a=8 22; for multiplication it will skip the addition a's as:- ++b + ++b*10 + ++b*100; //b=5 now from left to right reach to rightmost * as ++b + ++b*10 + ++b*100; ^ ^ increment only ^ b's now ++b + ++b*10 + 7*100; ^ now increase ^ b also as 8 + 8*10 + 700 788 try different combinations also like a=5; ++a + (++a + ++a); // this give answer=24 :) On Sat, Jul 16, 2011 at 2:24 PM, sagar pareek sagarpar...@gmail.com wrote: tell me your output pls On Sat, Jul 16, 2011 at 2:19 PM, sagar pareek sagarpar...@gmail.comwrote: and o/p is %#s Zi not %s Zi On Sat, Jul 16, 2011 at 2:18 PM, sagar pareek sagarpar...@gmail.comwrote: @Kamakhsi In my ubuntu gcc this o/p is coming with warning of undefined %# :) On Sat, Jul 16, 2011 at 5:43 AM, sukhmeet singh sukhmeet2...@gmail.comwrote: @Anatony the output will be compiler dependent res1 is not defined .. as C don't allow to change the value of a variable more than once between a sequence point.. A sequence point occur while assigning a value , calling a function or returning from it.. Hence both res1 and res2 would give arbitary results.. On Sat, Jul 16, 2011 at 1:45 AM, Antony Kotre antonyko...@gmail.comwrote: can any tell and explain the output of following code #includestdio.h main() { int a =5, b=5; int res1=(++a)+(++a)+(++a); int res2=(++b)+(++b)*10+(++b)*100; printf(%d\n%d\n,res1,res2); } -- 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. -- **Regards SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT ALLAHABAD -- **Regards SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT ALLAHABAD -- **Regards SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT ALLAHABAD -- **Regards SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT 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.
[algogeeks] Merge unsorted arrays
Q2. Given m arrays of n size each, give an algorithm to combine these arrays into a single array with sorted elements. Also tell the time complexity of your solution. Aseem -- 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] what would be the output of following code??
Printf(“%d”,printf(“%d %d”,2,2) printf(“%d %d ”, 2, 2)); -- 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: Dynamic Programming Cormen
Because here we can not reOrder words, Greedy seems to work fine to me too, i am not able to come up with an contradictory example..will post if will get one... or post if any one can. but here http://mitpress.mit.edu/algorithms/solutions/chap15-solutions.pdfis the DP solution to the problem -- Sunny Aggrawal B-Tech IV year,CSI Indian Institute Of Technology,Roorkee -- 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] what would be the output of following code??
2 On Sat, Jul 16, 2011 at 2:51 PM, shiv narayan narayan.shiv...@gmail.comwrote: Printf(“%d”,printf(“%d %d”,2,2) printf(“%d %d ”, 2, 2)); -- 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: X-AmazoN
There is an infinitesimally small probability that it will continue to run forever. But I tested it for 10,000 runs and it ran in a flash on my archaic machine (5yrs old is archaic probably :) ) int generateRand() { int num = 1; for(int i=0;i10;i++) { int x = (int)pow(2.0,i); num += x * (rand() % 2 ); } if(num = 1000) return num; else return generateRand(); } On Jul 15, 2:31 pm, SkRiPt KiDdIe anuragmsi...@gmail.com wrote: You are provided with a bit generator which generates 1 and 0 with equal probabilities i.e. (1/2). You are required to design a function which generates numbers form 1-1000 with equal probabilities i.e. (1/1000). -- 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] what would be the output of following code??
what about this printf(\n%d,printf(%d %d,2,2)printf(%d%d ,2,2)); On Sat, Jul 16, 2011 at 3:04 PM, swetha rahul swetharahu...@gmail.comwrote: 2 On Sat, Jul 16, 2011 at 2:51 PM, shiv narayan narayan.shiv...@gmail.comwrote: Printf(“%d”,printf(“%d %d”,2,2) printf(“%d %d ”, 2, 2)); -- 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. -- **With Regards Deoki Nandan Vishwakarma * * -- 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] what would be the output of following code??
Well if there is a space btween the two %d's dn it should be 2 2 2 23 Otherwise fine. On Sat, Jul 16, 2011 at 3:08 PM, Deoki Nandan deok...@gmail.com wrote: what about this printf(\n%d,printf(%d %d,2,2)printf(%d%d ,2,2)); On Sat, Jul 16, 2011 at 3:04 PM, swetha rahul swetharahu...@gmail.comwrote: 2 On Sat, Jul 16, 2011 at 2:51 PM, shiv narayan narayan.shiv...@gmail.comwrote: Printf(“%d”,printf(“%d %d”,2,2) printf(“%d %d ”, 2, 2)); -- 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. -- **With Regards Deoki Nandan Vishwakarma * * -- 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. -- Saurabh Singh B.Tech (Computer Science) MNNIT 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.
[algogeeks] Re: A Tough Bit Manipulation
@Dave - Nice solution :) On Jul 10, 4:42 pm, Dave dave_and_da...@juno.com wrote: @Anurag: Seehttp://groups.google.com/group/algogeeks/msg/d90353c759125384?hl=en. Dave On Jul 10, 1:14 am, anurag anurag19aggar...@gmail.com wrote: You are given two integers n and k k signifies number of set bits i.e. if k = 3 then output should have 3 set bits. Output should be the nth smallest number having k set bits for example k=1 and n=3 output should be 4 (0100) -- 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] what would be the output of following code??
answer for first should be 2 22 23 and for second 2 222 2 correct me if i am wrong. On Sat, Jul 16, 2011 at 3:08 PM, Deoki Nandan deok...@gmail.com wrote: what about this printf(\n%d,printf(%d %d,2,2)printf(%d%d ,2,2)); On Sat, Jul 16, 2011 at 3:04 PM, swetha rahul swetharahu...@gmail.comwrote: 2 On Sat, Jul 16, 2011 at 2:51 PM, shiv narayan narayan.shiv...@gmail.comwrote: Printf(“%d”,printf(“%d %d”,2,2) printf(“%d %d ”, 2, 2)); -- 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. -- **With Regards Deoki Nandan Vishwakarma * * -- 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: Printf ...
according to me it processing is done from righ to left .first right most a would be incremented and then from righ to left for first question answer should be 8+7+6=21 and for 2nd it should be (8)+(7)*10+(6)*100=678 On Jul 15, 1:15 pm, Antony Kotre antonyko...@gmail.com wrote: can any tell and explain the output of following code #includestdio.h main() { int a =5, b=5; int res1=(++a)+(++a)+(++a); int res2=(++b)+(++b)*10+(++b)*100; printf(%d\n%d\n,res1,res2); } -- 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: Printf ...
I am using MinGW compiler (codeblocks , out put is 788 and not 678 . Its compiler dependent so , let us leave it that way only. On Sat, Jul 16, 2011 at 3:27 PM, shiv narayan narayan.shiv...@gmail.comwrote: according to me it processing is done from righ to left .first right most a would be incremented and then from righ to left for first question answer should be 8+7+6=21 and for 2nd it should be (8)+(7)*10+(6)*100=678 On Jul 15, 1:15 pm, Antony Kotre antonyko...@gmail.com wrote: can any tell and explain the output of following code #includestdio.h main() { int a =5, b=5; int res1=(++a)+(++a)+(++a); int res2=(++b)+(++b)*10+(++b)*100; printf(%d\n%d\n,res1,res2); } -- 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] Merge unsorted arrays
Use divide and conquer. take 2 array at a time and .so you are merging two array at a time. num_of_list=m; length of list=n; while(num_of_list 1) { while( (num of list where length = length_of_list) 2) { merge two lists of length (length_of_list); } if(num_of_list %2==0) num_of_list/=2; else num_of_list/=2+1; length of list=n; } (it is just a general idea , you have to take care of the left over list every time , the check for that i havent posted) so time complexity is 2*n* (m/2) + 2* 2n* (m/4) .. log(m) times. so complexity is n*m*log(m) On Sat, Jul 16, 2011 at 2:43 PM, aseem garg ase.as...@gmail.com wrote: Q2. Given m arrays of n size each, give an algorithm to combine these arrays into a single array with sorted elements. Also tell the time complexity of your solution. Aseem -- 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: Image based Problem (Google)
Divide the image into 1000x1000 grid. Compute and store hash of each individual cell. Now, compare hashes of cells instead. Assuming each hash is 16 bytes, it takes additional ~ 16 MB of memory, but the time required to localize the point of change is reduced by a factor of 10^6. To reduce the this time further, we can maintain a hierarchy of hash- tables, where each hierarchy divides the original section into 10x10 grids. Keep we can keep as many hashes as the disk space permits and each level will redirect us to a new level. On Jul 12, 6:11 pm, Navneet Gupta navneetn...@gmail.com wrote: Given 1000 million x 1000 million image, What information of this image to be stored such that you can find the locations when the given image has modi cations -- Regards, Navneet -- 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] MS:Linked list
i have solution with no extra space complexity but time complexity is O(n) traverse the list with a pointer ptr if odd no encounter then traverse the remaining list with tmp pointer with start point ptr-next and match the numbers with iti hope it works :) On Sat, Jul 16, 2011 at 10:10 AM, shady sinv...@gmail.com wrote: if hashing is allowed then it can be done in O(n)... space complexity in this case again will be O(n) this won't work for large numbers... On Sat, Jul 16, 2011 at 1:58 AM, Nishant Mittal mittal.nishan...@gmail.com wrote: @sagar... I know this solution but it was strictly asked to do in O(n) time and O(1) space complexity and what if range of numbers is very large On Sat, Jul 16, 2011 at 1:09 AM, sagar pareek sagarpar...@gmail.comwrote: You just need to maintain the array for the odd words which encountered during traversing the list and using hashing this can be done :) but of course not in O(n) :( On Sat, Jul 16, 2011 at 12:51 AM, aseem garg ase.as...@gmail.comwrote: Use a Hash Table. Aseem On Sat, Jul 16, 2011 at 12:28 AM, shady sinv...@gmail.com wrote: i don't think it is possible to do it in O(n)... rather not even in O(nlogn) without modifying the list On Fri, Jul 15, 2011 at 11:23 PM, Nishant Mittal mittal.nishan...@gmail.com wrote: How will you delete duplicate odd numbers from a linked list in O(n) time -- 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. -- **Regards SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT 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. -- 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. -- **Regards SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT 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.
[algogeeks] Microsoft Interview Qn
Given a Parent -Child binary tree ,build the child -sibling version of it? Minimize the space requirements wherever possible. -- 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] MS:Linked list
yup :) On Sat, Jul 16, 2011 at 4:17 PM, Nishant Mittal mittal.nishan...@gmail.comwrote: @sagar it will take O(n2) if all the elements of linked list are odd and distinct.. On Sat, Jul 16, 2011 at 4:06 PM, sagar pareek sagarpar...@gmail.comwrote: i have solution with no extra space complexity but time complexity is O(n) traverse the list with a pointer ptr if odd no encounter then traverse the remaining list with tmp pointer with start point ptr-next and match the numbers with iti hope it works :) On Sat, Jul 16, 2011 at 10:10 AM, shady sinv...@gmail.com wrote: if hashing is allowed then it can be done in O(n)... space complexity in this case again will be O(n) this won't work for large numbers... On Sat, Jul 16, 2011 at 1:58 AM, Nishant Mittal mittal.nishan...@gmail.com wrote: @sagar... I know this solution but it was strictly asked to do in O(n) time and O(1) space complexity and what if range of numbers is very large On Sat, Jul 16, 2011 at 1:09 AM, sagar pareek sagarpar...@gmail.comwrote: You just need to maintain the array for the odd words which encountered during traversing the list and using hashing this can be done :) but of course not in O(n) :( On Sat, Jul 16, 2011 at 12:51 AM, aseem garg ase.as...@gmail.comwrote: Use a Hash Table. Aseem On Sat, Jul 16, 2011 at 12:28 AM, shady sinv...@gmail.com wrote: i don't think it is possible to do it in O(n)... rather not even in O(nlogn) without modifying the list On Fri, Jul 15, 2011 at 11:23 PM, Nishant Mittal mittal.nishan...@gmail.com wrote: How will you delete duplicate odd numbers from a linked list in O(n) time -- 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. -- **Regards SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT 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. -- 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. -- **Regards SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT 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. -- 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 SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT 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
Re: [algogeeks] MS:Linked list
@sagar it will take O(n2) if all the elements of linked list are odd and distinct.. On Sat, Jul 16, 2011 at 4:06 PM, sagar pareek sagarpar...@gmail.com wrote: i have solution with no extra space complexity but time complexity is O(n) traverse the list with a pointer ptr if odd no encounter then traverse the remaining list with tmp pointer with start point ptr-next and match the numbers with iti hope it works :) On Sat, Jul 16, 2011 at 10:10 AM, shady sinv...@gmail.com wrote: if hashing is allowed then it can be done in O(n)... space complexity in this case again will be O(n) this won't work for large numbers... On Sat, Jul 16, 2011 at 1:58 AM, Nishant Mittal mittal.nishan...@gmail.com wrote: @sagar... I know this solution but it was strictly asked to do in O(n) time and O(1) space complexity and what if range of numbers is very large On Sat, Jul 16, 2011 at 1:09 AM, sagar pareek sagarpar...@gmail.comwrote: You just need to maintain the array for the odd words which encountered during traversing the list and using hashing this can be done :) but of course not in O(n) :( On Sat, Jul 16, 2011 at 12:51 AM, aseem garg ase.as...@gmail.comwrote: Use a Hash Table. Aseem On Sat, Jul 16, 2011 at 12:28 AM, shady sinv...@gmail.com wrote: i don't think it is possible to do it in O(n)... rather not even in O(nlogn) without modifying the list On Fri, Jul 15, 2011 at 11:23 PM, Nishant Mittal mittal.nishan...@gmail.com wrote: How will you delete duplicate odd numbers from a linked list in O(n) time -- 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. -- **Regards SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT 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. -- 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. -- **Regards SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT 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. -- 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] Merge unsorted arrays
sort all the arrays first O(nlogn) then use merge sort On Sat, Jul 16, 2011 at 3:43 PM, Ankur Khurana ankur.kkhur...@gmail.comwrote: Use divide and conquer. take 2 array at a time and .so you are merging two array at a time. num_of_list=m; length of list=n; while(num_of_list 1) { while( (num of list where length = length_of_list) 2) { merge two lists of length (length_of_list); } if(num_of_list %2==0) num_of_list/=2; else num_of_list/=2+1; length of list=n; } (it is just a general idea , you have to take care of the left over list every time , the check for that i havent posted) so time complexity is 2*n* (m/2) + 2* 2n* (m/4) .. log(m) times. so complexity is n*m*log(m) On Sat, Jul 16, 2011 at 2:43 PM, aseem garg ase.as...@gmail.com wrote: Q2. Given m arrays of n size each, give an algorithm to combine these arrays into a single array with sorted elements. Also tell the time complexity of your solution. Aseem -- 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. -- **Regards SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT 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.
Re: [algogeeks] Merge unsorted arrays
oops , didnt see the unsorted thing. complexity is mnlog(n) + mn log(m) On Sat, Jul 16, 2011 at 4:23 PM, sagar pareek sagarpar...@gmail.com wrote: sort all the arrays first O(nlogn) then use merge sort On Sat, Jul 16, 2011 at 3:43 PM, Ankur Khurana ankur.kkhur...@gmail.comwrote: Use divide and conquer. take 2 array at a time and .so you are merging two array at a time. num_of_list=m; length of list=n; while(num_of_list 1) { while( (num of list where length = length_of_list) 2) { merge two lists of length (length_of_list); } if(num_of_list %2==0) num_of_list/=2; else num_of_list/=2+1; length of list=n; } (it is just a general idea , you have to take care of the left over list every time , the check for that i havent posted) so time complexity is 2*n* (m/2) + 2* 2n* (m/4) .. log(m) times. so complexity is n*m*log(m) On Sat, Jul 16, 2011 at 2:43 PM, aseem garg ase.as...@gmail.com wrote: Q2. Given m arrays of n size each, give an algorithm to combine these arrays into a single array with sorted elements. Also tell the time complexity of your solution. Aseem -- 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. -- **Regards SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT 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. -- 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] MS:Linked list
@sagar ya this is brute force On Sat, Jul 16, 2011 at 4:19 PM, sagar pareek sagarpar...@gmail.com wrote: yup :) On Sat, Jul 16, 2011 at 4:17 PM, Nishant Mittal mittal.nishan...@gmail.com wrote: @sagar it will take O(n2) if all the elements of linked list are odd and distinct.. On Sat, Jul 16, 2011 at 4:06 PM, sagar pareek sagarpar...@gmail.comwrote: i have solution with no extra space complexity but time complexity is O(n) traverse the list with a pointer ptr if odd no encounter then traverse the remaining list with tmp pointer with start point ptr-next and match the numbers with iti hope it works :) On Sat, Jul 16, 2011 at 10:10 AM, shady sinv...@gmail.com wrote: if hashing is allowed then it can be done in O(n)... space complexity in this case again will be O(n) this won't work for large numbers... On Sat, Jul 16, 2011 at 1:58 AM, Nishant Mittal mittal.nishan...@gmail.com wrote: @sagar... I know this solution but it was strictly asked to do in O(n) time and O(1) space complexity and what if range of numbers is very large On Sat, Jul 16, 2011 at 1:09 AM, sagar pareek sagarpar...@gmail.comwrote: You just need to maintain the array for the odd words which encountered during traversing the list and using hashing this can be done :) but of course not in O(n) :( On Sat, Jul 16, 2011 at 12:51 AM, aseem garg ase.as...@gmail.comwrote: Use a Hash Table. Aseem On Sat, Jul 16, 2011 at 12:28 AM, shady sinv...@gmail.com wrote: i don't think it is possible to do it in O(n)... rather not even in O(nlogn) without modifying the list On Fri, Jul 15, 2011 at 11:23 PM, Nishant Mittal mittal.nishan...@gmail.com wrote: How will you delete duplicate odd numbers from a linked list in O(n) time -- 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. -- **Regards SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT 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. -- 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. -- **Regards SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT 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. -- 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 SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT 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
Re: [algogeeks] Microsoft Interview Qn
always state one input output while asking questions sample input-output ? On Sat, Jul 16, 2011 at 4:16 PM, Reynald reynaldsus...@gmail.com wrote: Given a Parent -Child binary tree ,build the child -sibling version of it? Minimize the space requirements wherever possible. -- 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] what would be the output of following code??
@ankur that's right :) On Sat, Jul 16, 2011 at 3:25 PM, Ankur Khurana ankur.kkhur...@gmail.comwrote: answer for first should be 2 22 23 and for second 2 222 2 correct me if i am wrong. On Sat, Jul 16, 2011 at 3:08 PM, Deoki Nandan deok...@gmail.com wrote: what about this printf(\n%d,printf(%d %d,2,2)printf(%d%d ,2,2)); On Sat, Jul 16, 2011 at 3:04 PM, swetha rahul swetharahu...@gmail.comwrote: 2 On Sat, Jul 16, 2011 at 2:51 PM, shiv narayan narayan.shiv...@gmail.com wrote: Printf(“%d”,printf(“%d %d”,2,2) printf(“%d %d ”, 2, 2)); -- 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. -- **With Regards Deoki Nandan Vishwakarma * * -- 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] what would be the output of following code??
the ans to first should be 2 2 2 2 0. and the and to second should be. 222 2 2 please correct me if i am wrong. On Sat, Jul 16, 2011 at 4:57 PM, shady sinv...@gmail.com wrote: @ankur that's right :) On Sat, Jul 16, 2011 at 3:25 PM, Ankur Khurana ankur.kkhur...@gmail.comwrote: answer for first should be 2 22 23 and for second 2 222 2 correct me if i am wrong. On Sat, Jul 16, 2011 at 3:08 PM, Deoki Nandan deok...@gmail.com wrote: what about this printf(\n%d,printf(%d %d,2,2)printf(%d%d ,2,2)); On Sat, Jul 16, 2011 at 3:04 PM, swetha rahul swetharahu...@gmail.comwrote: 2 On Sat, Jul 16, 2011 at 2:51 PM, shiv narayan narayan.shiv...@gmail.com wrote: Printf(“%d”,printf(“%d %d”,2,2) printf(“%d %d ”, 2, 2)); -- 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. -- **With Regards Deoki Nandan Vishwakarma * * -- 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. -- Varun Pahwa B.Tech (IT) 7th Sem. Indian Institute of Information Technology Allahabad. Ph : 09793899112 Official Email :: rit2008...@iiita.ac.in Another Email :: varunpahwa.ii...@gmail.com People who fail to plan are those who plan to fail. -- 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] what would be the output of following code??
please ignore my previous post. On Sat, Jul 16, 2011 at 5:38 PM, varun pahwa varunpahwa2...@gmail.comwrote: the ans to first should be 2 2 2 2 0. and the and to second should be. 222 2 2 please correct me if i am wrong. On Sat, Jul 16, 2011 at 4:57 PM, shady sinv...@gmail.com wrote: @ankur that's right :) On Sat, Jul 16, 2011 at 3:25 PM, Ankur Khurana ankur.kkhur...@gmail.comwrote: answer for first should be 2 22 23 and for second 2 222 2 correct me if i am wrong. On Sat, Jul 16, 2011 at 3:08 PM, Deoki Nandan deok...@gmail.com wrote: what about this printf(\n%d,printf(%d %d,2,2)printf(%d%d ,2,2)); On Sat, Jul 16, 2011 at 3:04 PM, swetha rahul swetharahu...@gmail.comwrote: 2 On Sat, Jul 16, 2011 at 2:51 PM, shiv narayan narayan.shiv...@gmail.com wrote: Printf(“%d”,printf(“%d %d”,2,2) printf(“%d %d ”, 2, 2)); -- 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. -- **With Regards Deoki Nandan Vishwakarma * * -- 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. -- Varun Pahwa B.Tech (IT) 7th Sem. Indian Institute of Information Technology Allahabad. Ph : 09793899112 Official Email :: rit2008...@iiita.ac.in Another Email :: varunpahwa.ii...@gmail.com People who fail to plan are those who plan to fail. -- Varun Pahwa B.Tech (IT) 7th Sem. Indian Institute of Information Technology Allahabad. Ph : 09793899112 Official Email :: rit2008...@iiita.ac.in Another Email :: varunpahwa.ii...@gmail.com People who fail to plan are those who plan to fail. -- 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] what would be the output of following code??
ignore my previous result. the ans to first should be 2 22 2 0. and the ans to second should be. 2 222 2 please correct me if i am wrong. On Sat, Jul 16, 2011 at 5:38 PM, varun pahwa varunpahwa2...@gmail.comwrote: the ans to first should be 2 2 2 2 0. and the and to second should be. 222 2 2 please correct me if i am wrong. On Sat, Jul 16, 2011 at 4:57 PM, shady sinv...@gmail.com wrote: @ankur that's right :) On Sat, Jul 16, 2011 at 3:25 PM, Ankur Khurana ankur.kkhur...@gmail.comwrote: answer for first should be 2 22 23 and for second 2 222 2 correct me if i am wrong. On Sat, Jul 16, 2011 at 3:08 PM, Deoki Nandan deok...@gmail.com wrote: what about this printf(\n%d,printf(%d %d,2,2)printf(%d%d ,2,2)); On Sat, Jul 16, 2011 at 3:04 PM, swetha rahul swetharahu...@gmail.comwrote: 2 On Sat, Jul 16, 2011 at 2:51 PM, shiv narayan narayan.shiv...@gmail.com wrote: Printf(“%d”,printf(“%d %d”,2,2) printf(“%d %d ”, 2, 2)); -- 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. -- **With Regards Deoki Nandan Vishwakarma * * -- 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. -- Varun Pahwa B.Tech (IT) 7th Sem. Indian Institute of Information Technology Allahabad. Ph : 09793899112 Official Email :: rit2008...@iiita.ac.in Another Email :: varunpahwa.ii...@gmail.com People who fail to plan are those who plan to fail. -- Varun Pahwa B.Tech (IT) 7th Sem. Indian Institute of Information Technology Allahabad. Ph : 09793899112 Official Email :: rit2008...@iiita.ac.in Another Email :: varunpahwa.ii...@gmail.com People who fail to plan are those who plan to fail. -- 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: Google interview question
how about using voters algorithm? TC O(n) and SC O(1) On Jul 16, 6:28 am, Anand Shastri anand.shastr...@gmail.com wrote: Given a file containing 4,300,000,000 integers, how can you *find **one* that *appears* at *least **twice* -- 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: Google interview question
If the there are problems with hashing method, What about simply sorting the numbers then comparing the adjacent numbers ! Time complexity O(nlogn)+O(n)=O(nlogn) Cheers! -- 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/-/b2Z_3lJHz9wJ. 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: Merge unsorted arrays
how does ur algo produce sorted elements in final array? On Jul 16, 3:55 pm, Ankur Khurana ankur.kkhur...@gmail.com wrote: oops , didnt see the unsorted thing. complexity is mnlog(n) + mn log(m) On Sat, Jul 16, 2011 at 4:23 PM, sagar pareek sagarpar...@gmail.com wrote: sort all the arrays first O(nlogn) then use merge sort On Sat, Jul 16, 2011 at 3:43 PM, Ankur Khurana ankur.kkhur...@gmail.comwrote: Use divide and conquer. take 2 array at a time and .so you are merging two array at a time. num_of_list=m; length of list=n; while(num_of_list 1) { while( (num of list where length = length_of_list) 2) { merge two lists of length (length_of_list); } if(num_of_list %2==0) num_of_list/=2; else num_of_list/=2+1; length of list=n; } (it is just a general idea , you have to take care of the left over list every time , the check for that i havent posted) so time complexity is 2*n* (m/2) + 2* 2n* (m/4) .. log(m) times. so complexity is n*m*log(m) On Sat, Jul 16, 2011 at 2:43 PM, aseem garg ase.as...@gmail.com wrote: Q2. Given m arrays of n size each, give an algorithm to combine these arrays into a single array with sorted elements. Also tell the time complexity of your solution. Aseem -- 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. -- **Regards SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT 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. -- 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 Qn: Algo to find the border of a binary tree
Algo to find the border of a given binary tree. Optimized for space and time. Input: 10 / \ 50 50 / \ / \ 25 75 20020 / \ / /\ 15 35 120155 250 Output:50 25 15 35 120 155 250 20 150 10 -- 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: Google interview question
@Anand: Assuming that the file contains unsigned 32-bit integers. Set an integer array a[65536] to zero, read through the file and tally the numbers based on their low-order 16 bits: a[j0x]++. Since 4.3 billion exceeds 2^32, by the pigeonhole principle, there will be at least one tally, say a[k], that has a value greater than 65536. Set the array to zero again. Read through the file again. Ignore all of the numbers whose low-order 16 bits are not k, and tally numbers based on their upper 16 bits: a[(j16)0x]++. Again by the pigeonhole principle, there will be at least one number that exceeds 1. Now you know the high-order 16 bits and the low-order 16 bits of a number that occurs at least twice. You can quit the second pass as soon as you have your first tally equalling 2. Dave On Jul 15, 8:28 pm, Anand Shastri anand.shastr...@gmail.com wrote: Given a file containing 4,300,000,000 integers, how can you *find **one* that *appears* at *least **twice* -- 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] Given a BST containing integers, and a value K. You have to find two nodes that give sum = K.
Given a BST containing integers, and a value K. You have to find two nodes that give sum = K. -- 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] Given a BST containing integers, and a value K. You have to find two nodes that give sum = K.
Given a BST containing integers, and a value K. You have to find two nodes that give sum = K. -- 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] Given a BST containing integers, and a value K. You have to find two nodes that give sum = K.
Check https://groups.google.com/group/algogeeks/browse_thread/thread/e8735bcdbf4c956/c49018d0eac8070b?hl=enlnk=gstq=saurabh8c#c49018d0eac8070b On Sat, Jul 16, 2011 at 7:50 PM, noobcoder ase.as...@gmail.com wrote: Given a BST containing integers, and a value K. You have to find two nodes that give sum = K. -- 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. -- Saurabh Singh B.Tech (Computer Science) MNNIT 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.
Re: [algogeeks] Given a BST containing integers, and a value K. You have to find two nodes that give sum = K.
convert into doubly linked list and than apply simple algo of finding two element with a sum On Sat, Jul 16, 2011 at 7:54 PM, saurabh singh saurab...@gmail.com wrote: Check https://groups.google.com/group/algogeeks/browse_thread/thread/e8735bcdbf4c956/c49018d0eac8070b?hl=enlnk=gstq=saurabh8c#c49018d0eac8070b On Sat, Jul 16, 2011 at 7:50 PM, noobcoder ase.as...@gmail.com wrote: Given a BST containing integers, and a value K. You have to find two nodes that give sum = K. -- 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. -- Saurabh Singh B.Tech (Computer Science) MNNIT 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. -- SOURABH JAKHAR,(CSE)(3 year) ROOM NO 167 , TILAK,HOSTEL 'MNNIT ALLAHABAD The Law of Win says, Let's not do it your way or my way; let's do it the best way. -- 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: Merge unsorted arrays
you sort array before merging. and then use merge sort On Sat, Jul 16, 2011 at 6:53 PM, noobcoder ase.as...@gmail.com wrote: how does ur algo produce sorted elements in final array? On Jul 16, 3:55 pm, Ankur Khurana ankur.kkhur...@gmail.com wrote: oops , didnt see the unsorted thing. complexity is mnlog(n) + mn log(m) On Sat, Jul 16, 2011 at 4:23 PM, sagar pareek sagarpar...@gmail.com wrote: sort all the arrays first O(nlogn) then use merge sort On Sat, Jul 16, 2011 at 3:43 PM, Ankur Khurana ankur.kkhur...@gmail.comwrote: Use divide and conquer. take 2 array at a time and .so you are merging two array at a time. num_of_list=m; length of list=n; while(num_of_list 1) { while( (num of list where length = length_of_list) 2) { merge two lists of length (length_of_list); } if(num_of_list %2==0) num_of_list/=2; else num_of_list/=2+1; length of list=n; } (it is just a general idea , you have to take care of the left over list every time , the check for that i havent posted) so time complexity is 2*n* (m/2) + 2* 2n* (m/4) .. log(m) times. so complexity is n*m*log(m) On Sat, Jul 16, 2011 at 2:43 PM, aseem garg ase.as...@gmail.com wrote: Q2. Given m arrays of n size each, give an algorithm to combine these arrays into a single array with sorted elements. Also tell the time complexity of your solution. Aseem -- 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. -- **Regards SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT 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. -- 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. -- Ankur Khurana Computer Science , 4th year Netaji Subhas Institute Of Technology Delhi. -- 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] Given a BST containing integers, and a value K. You have to find two nodes that give sum = K.
can be done in NlogN take a node, say 'a' check if k-a exists in the tree(logN) On Sat, Jul 16, 2011 at 7:58 PM, sourabh jakhar sourabhjak...@gmail.comwrote: convert into doubly linked list and than apply simple algo of finding two element with a sum On Sat, Jul 16, 2011 at 7:54 PM, saurabh singh saurab...@gmail.comwrote: Check https://groups.google.com/group/algogeeks/browse_thread/thread/e8735bcdbf4c956/c49018d0eac8070b?hl=enlnk=gstq=saurabh8c#c49018d0eac8070b On Sat, Jul 16, 2011 at 7:50 PM, noobcoder ase.as...@gmail.com wrote: Given a BST containing integers, and a value K. You have to find two nodes that give sum = K. -- 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. -- Saurabh Singh B.Tech (Computer Science) MNNIT 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. -- SOURABH JAKHAR,(CSE)(3 year) ROOM NO 167 , TILAK,HOSTEL 'MNNIT ALLAHABAD The Law of Win says, Let's not do it your way or my way; let's do it the best way. -- 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: Given a BST containing integers, and a value K. You have to find two nodes that give sum = K.
@Noobcoder: To do it in O(n) without destroying the BST, do two inorder traversals simultaneously, one in the normal forward (left subtree first) direction and one in the reverse direction (right subtree first). Let the two current nodes have value F and R respectively. If F + R = K, return success. If F = R, return failure. If F + R K, advance the forward traversal. Otherwise (F + R K), advance the reverse traversal. To do the traversals simultaneously, you will have to use explicit stacks instead of recursion. Dave On Jul 16, 9:01 am, noobcoder ase.as...@gmail.com wrote: Given a BST containing integers, and a value K. You have to find two nodes that give sum = K. -- 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: Merge unsorted arrays
@Aseem: Combine the arrays and sort the result. O(mn log mn). Dave On Jul 16, 4:13 am, aseem garg ase.as...@gmail.com wrote: Q2. Given m arrays of n size each, give an algorithm to combine these arrays into a single array with sorted elements. Also tell the time complexity of your solution. Aseem -- 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: Given a BST containing integers, and a value K. You have to find two nodes that give sum = K.
@dave what if the k= root-left + right most leaf ? how ur algo works on it? On Sat, Jul 16, 2011 at 9:28 PM, Dave dave_and_da...@juno.com wrote: @Noobcoder: To do it in O(n) without destroying the BST, do two inorder traversals simultaneously, one in the normal forward (left subtree first) direction and one in the reverse direction (right subtree first). Let the two current nodes have value F and R respectively. If F + R = K, return success. If F = R, return failure. If F + R K, advance the forward traversal. Otherwise (F + R K), advance the reverse traversal. To do the traversals simultaneously, you will have to use explicit stacks instead of recursion. Dave On Jul 16, 9:01 am, noobcoder ase.as...@gmail.com wrote: Given a BST containing integers, and a value K. You have to find two nodes that give sum = K. -- 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 SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT 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.
[algogeeks] Re: Given a BST containing integers, and a value K. You have to find two nodes that give sum = K.
@Sagar: No problem. The algorithm would do only forward traversal steps until it got to root_left, whereupon F + R = K. Dave On Jul 16, 11:40 am, sagar pareek sagarpar...@gmail.com wrote: @dave what if the k= root-left + right most leaf ? how ur algo works on it? On Sat, Jul 16, 2011 at 9:28 PM, Dave dave_and_da...@juno.com wrote: @Noobcoder: To do it in O(n) without destroying the BST, do two inorder traversals simultaneously, one in the normal forward (left subtree first) direction and one in the reverse direction (right subtree first). Let the two current nodes have value F and R respectively. If F + R = K, return success. If F = R, return failure. If F + R K, advance the forward traversal. Otherwise (F + R K), advance the reverse traversal. To do the traversals simultaneously, you will have to use explicit stacks instead of recursion. Dave On Jul 16, 9:01 am, noobcoder ase.as...@gmail.com wrote: Given a BST containing integers, and a value K. You have to find two nodes that give sum = K. -- 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 SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT ALLAHABAD- Hide quoted text - - Show quoted text - -- 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] c++ probs
Q.1 what is the output of following program? #include iostream using namespace std; class A { public: A() { coutConstructing Aendl; } ~A() { coutDestructing Aendl; } }; class B : public A { public: B() { coutConstructing Bendl; } ~B() {coutDestructing Bendl; } }; int main() { A *b=new B; delete b; } how is its output as: constructing A constructing B destructing B ?? Q2. Determine output. class A { int a; public: virtual void f() { } }; class B : private A { int b; public: void f() { } }; int main() { coutsizeof(A)endl; coutsizeof(B)endl; } its output is: 812 virtual functions do occupy 4 bytes ?? how?? -- 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: Given a BST containing integers, and a value K. You have to find two nodes that give sum = K.
ok i got it actually u written wrong that f/w and reverse traversal are running parallel u must wrote that f/w traversal inside reverse or vice versa On Sat, Jul 16, 2011 at 10:35 PM, Dave dave_and_da...@juno.com wrote: @Sagar: No problem. The algorithm would do only forward traversal steps until it got to root_left, whereupon F + R = K. Dave On Jul 16, 11:40 am, sagar pareek sagarpar...@gmail.com wrote: @dave what if the k= root-left + right most leaf ? how ur algo works on it? On Sat, Jul 16, 2011 at 9:28 PM, Dave dave_and_da...@juno.com wrote: @Noobcoder: To do it in O(n) without destroying the BST, do two inorder traversals simultaneously, one in the normal forward (left subtree first) direction and one in the reverse direction (right subtree first). Let the two current nodes have value F and R respectively. If F + R = K, return success. If F = R, return failure. If F + R K, advance the forward traversal. Otherwise (F + R K), advance the reverse traversal. To do the traversals simultaneously, you will have to use explicit stacks instead of recursion. Dave On Jul 16, 9:01 am, noobcoder ase.as...@gmail.com wrote: Given a BST containing integers, and a value K. You have to find two nodes that give sum = K. -- 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 SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT ALLAHABAD- Hide quoted text - - Show quoted text - -- 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 SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT 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.
Re: [algogeeks] c++ probs
Output of 1st is constructing A constructing B destructing *A* * * as destructor is not virtual only the base class destructor is called and during object creation first base class constructor is called then derived class during the derived class object creation. output of 2nd : the object of classes having virtual function has 1 extra pointer which points to the virtual table hence sizeof class A is 8 and sizeof class B is 12 (sizeof(int) + sizeof(pointer) + sizeof(int)). On Sat, Jul 16, 2011 at 10:51 PM, Anika Jain anika.jai...@gmail.com wrote: Q.1 what is the output of following program? #include iostream using namespace std; class A { public: A() { coutConstructing Aendl; } ~A() { coutDestructing Aendl; } }; class B : public A { public: B() { coutConstructing Bendl; } ~B() {coutDestructing Bendl; } }; int main() { A *b=new B; delete b; } how is its output as: constructing A constructing B destructing B ?? Q2. Determine output. class A { int a; public: virtual void f() { } }; class B : private A { int b; public: void f() { } }; int main() { coutsizeof(A)endl; coutsizeof(B)endl; } its output is: 812 virtual functions do occupy 4 bytes ?? how?? -- 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] c++ probs
HI, Q1: Destructor of B is not called because it doesn't have Run time type information as there is no virtual function. By have a declaration like A *b= new B(); Application only know that type of object b is A so when this object get destroyed, only Class A destructor is called. Q2: Virtual Call have minimum size of Vbptr ( virtual pointer) and size of any pointer(address) on 32 bit architecture is 4 bytes. On Sat, Jul 16, 2011 at 10:51 PM, Anika Jain anika.jai...@gmail.com wrote: Q.1 what is the output of following program? #include iostream using namespace std; class A { public: A() { coutConstructing Aendl; } ~A() { coutDestructing Aendl; } }; class B : public A { public: B() { coutConstructing Bendl; } ~B() {coutDestructing Bendl; } }; int main() { A *b=new B; delete b; } how is its output as: constructing A constructing B destructing B ?? Q2. Determine output. class A { int a; public: virtual void f() { } }; class B : private A { int b; public: void f() { } }; int main() { coutsizeof(A)endl; coutsizeof(B)endl; } its output is: 812 virtual functions do occupy 4 bytes ?? how?? -- 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: Given a BST containing integers, and a value K. You have to find two nodes that give sum = K.
@Sagar: No. I didn't say that they were in parallel or that one was inside the other. Go back and read it again and you will see that I said that they were being performed simultaneously, with each one being advanced in certain circumstances, and that in order to do that you would have to use explicit stacks instead of recursion. Perhaps, instead, you misread or misunderstood it. Dave On Jul 16, 12:24 pm, sagar pareek sagarpar...@gmail.com wrote: ok i got it actually u written wrong that f/w and reverse traversal are running parallel u must wrote that f/w traversal inside reverse or vice versa On Sat, Jul 16, 2011 at 10:35 PM, Dave dave_and_da...@juno.com wrote: @Sagar: No problem. The algorithm would do only forward traversal steps until it got to root_left, whereupon F + R = K. Dave On Jul 16, 11:40 am, sagar pareek sagarpar...@gmail.com wrote: @dave what if the k= root-left + right most leaf ? how ur algo works on it? On Sat, Jul 16, 2011 at 9:28 PM, Dave dave_and_da...@juno.com wrote: @Noobcoder: To do it in O(n) without destroying the BST, do two inorder traversals simultaneously, one in the normal forward (left subtree first) direction and one in the reverse direction (right subtree first). Let the two current nodes have value F and R respectively. If F + R = K, return success. If F = R, return failure. If F + R K, advance the forward traversal. Otherwise (F + R K), advance the reverse traversal. To do the traversals simultaneously, you will have to use explicit stacks instead of recursion. Dave On Jul 16, 9:01 am, noobcoder ase.as...@gmail.com wrote: Given a BST containing integers, and a value K. You have to find two nodes that give sum = K. -- 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 SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT ALLAHABAD- Hide quoted text - - Show quoted text - -- 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 SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT ALLAHABAD- Hide quoted text - - Show quoted text - -- 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: Given a BST containing integers, and a value K. You have to find two nodes that give sum = K.
and so it must not be O(n) On Sat, Jul 16, 2011 at 10:54 PM, sagar pareek sagarpar...@gmail.comwrote: ok i got it actually u written wrong that f/w and reverse traversal are running parallel u must wrote that f/w traversal inside reverse or vice versa On Sat, Jul 16, 2011 at 10:35 PM, Dave dave_and_da...@juno.com wrote: @Sagar: No problem. The algorithm would do only forward traversal steps until it got to root_left, whereupon F + R = K. Dave On Jul 16, 11:40 am, sagar pareek sagarpar...@gmail.com wrote: @dave what if the k= root-left + right most leaf ? how ur algo works on it? On Sat, Jul 16, 2011 at 9:28 PM, Dave dave_and_da...@juno.com wrote: @Noobcoder: To do it in O(n) without destroying the BST, do two inorder traversals simultaneously, one in the normal forward (left subtree first) direction and one in the reverse direction (right subtree first). Let the two current nodes have value F and R respectively. If F + R = K, return success. If F = R, return failure. If F + R K, advance the forward traversal. Otherwise (F + R K), advance the reverse traversal. To do the traversals simultaneously, you will have to use explicit stacks instead of recursion. Dave On Jul 16, 9:01 am, noobcoder ase.as...@gmail.com wrote: Given a BST containing integers, and a value K. You have to find two nodes that give sum = K. -- 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 SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT ALLAHABAD- Hide quoted text - - Show quoted text - -- 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 SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT ALLAHABAD -- **Regards SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT 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.
Re: [algogeeks] Re: Given a BST containing integers, and a value K. You have to find two nodes that give sum = K.
Ok may be i m not getting ur logic... On Sat, Jul 16, 2011 at 11:03 PM, Dave dave_and_da...@juno.com wrote: @Sagar: No. I didn't say that they were in parallel or that one was inside the other. Go back and read it again and you will see that I said that they were being performed simultaneously, with each one being advanced in certain circumstances, and that in order to do that you would have to use explicit stacks instead of recursion. Perhaps, instead, you misread or misunderstood it. Dave On Jul 16, 12:24 pm, sagar pareek sagarpar...@gmail.com wrote: ok i got it actually u written wrong that f/w and reverse traversal are running parallel u must wrote that f/w traversal inside reverse or vice versa On Sat, Jul 16, 2011 at 10:35 PM, Dave dave_and_da...@juno.com wrote: @Sagar: No problem. The algorithm would do only forward traversal steps until it got to root_left, whereupon F + R = K. Dave On Jul 16, 11:40 am, sagar pareek sagarpar...@gmail.com wrote: @dave what if the k= root-left + right most leaf ? how ur algo works on it? On Sat, Jul 16, 2011 at 9:28 PM, Dave dave_and_da...@juno.com wrote: @Noobcoder: To do it in O(n) without destroying the BST, do two inorder traversals simultaneously, one in the normal forward (left subtree first) direction and one in the reverse direction (right subtree first). Let the two current nodes have value F and R respectively. If F + R = K, return success. If F = R, return failure. If F + R K, advance the forward traversal. Otherwise (F + R K), advance the reverse traversal. To do the traversals simultaneously, you will have to use explicit stacks instead of recursion. Dave On Jul 16, 9:01 am, noobcoder ase.as...@gmail.com wrote: Given a BST containing integers, and a value K. You have to find two nodes that give sum = K. -- 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 SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT ALLAHABAD- Hide quoted text - - Show quoted text - -- 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 SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT ALLAHABAD- Hide quoted text - - Show quoted text - -- 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 SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT 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.
[algogeeks] Re: Given a BST containing integers, and a value K. You have to find two nodes that give sum = K.
@Sagar: The algorithm visits each node at most 3 times: Once when descending from its parent, once when ascending from its left child, and once when ascending from its right child. Furthermore, one node is eliminated from contention with every three comparisons of F with R. Thus, there are no more than 3n traversal steps and no more than 3n comparisons.Thus, it is O(n). Dave On Jul 16, 12:34 pm, sagar pareek sagarpar...@gmail.com wrote: and so it must not be O(n) On Sat, Jul 16, 2011 at 10:54 PM, sagar pareek sagarpar...@gmail.comwrote: ok i got it actually u written wrong that f/w and reverse traversal are running parallel u must wrote that f/w traversal inside reverse or vice versa On Sat, Jul 16, 2011 at 10:35 PM, Dave dave_and_da...@juno.com wrote: @Sagar: No problem. The algorithm would do only forward traversal steps until it got to root_left, whereupon F + R = K. Dave On Jul 16, 11:40 am, sagar pareek sagarpar...@gmail.com wrote: @dave what if the k= root-left + right most leaf ? how ur algo works on it? On Sat, Jul 16, 2011 at 9:28 PM, Dave dave_and_da...@juno.com wrote: @Noobcoder: To do it in O(n) without destroying the BST, do two inorder traversals simultaneously, one in the normal forward (left subtree first) direction and one in the reverse direction (right subtree first). Let the two current nodes have value F and R respectively. If F + R = K, return success. If F = R, return failure. If F + R K, advance the forward traversal. Otherwise (F + R K), advance the reverse traversal. To do the traversals simultaneously, you will have to use explicit stacks instead of recursion. Dave On Jul 16, 9:01 am, noobcoder ase.as...@gmail.com wrote: Given a BST containing integers, and a value K. You have to find two nodes that give sum = K. -- 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 SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT ALLAHABAD- Hide quoted text - - Show quoted text - -- 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 SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT ALLAHABAD -- **Regards SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT ALLAHABAD- Hide quoted text - - Show quoted text - -- 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: Given a BST containing integers, and a value K. You have to find two nodes that give sum = K.
@Sagar: If you are not getting my logic, ask a question. Dave On Jul 16, 12:35 pm, sagar pareek sagarpar...@gmail.com wrote: Ok may be i m not getting ur logic... On Sat, Jul 16, 2011 at 11:03 PM, Dave dave_and_da...@juno.com wrote: @Sagar: No. I didn't say that they were in parallel or that one was inside the other. Go back and read it again and you will see that I said that they were being performed simultaneously, with each one being advanced in certain circumstances, and that in order to do that you would have to use explicit stacks instead of recursion. Perhaps, instead, you misread or misunderstood it. Dave On Jul 16, 12:24 pm, sagar pareek sagarpar...@gmail.com wrote: ok i got it actually u written wrong that f/w and reverse traversal are running parallel u must wrote that f/w traversal inside reverse or vice versa On Sat, Jul 16, 2011 at 10:35 PM, Dave dave_and_da...@juno.com wrote: @Sagar: No problem. The algorithm would do only forward traversal steps until it got to root_left, whereupon F + R = K. Dave On Jul 16, 11:40 am, sagar pareek sagarpar...@gmail.com wrote: @dave what if the k= root-left + right most leaf ? how ur algo works on it? On Sat, Jul 16, 2011 at 9:28 PM, Dave dave_and_da...@juno.com wrote: @Noobcoder: To do it in O(n) without destroying the BST, do two inorder traversals simultaneously, one in the normal forward (left subtree first) direction and one in the reverse direction (right subtree first). Let the two current nodes have value F and R respectively. If F + R = K, return success. If F = R, return failure. If F + R K, advance the forward traversal. Otherwise (F + R K), advance the reverse traversal. To do the traversals simultaneously, you will have to use explicit stacks instead of recursion. Dave On Jul 16, 9:01 am, noobcoder ase.as...@gmail.com wrote: Given a BST containing integers, and a value K. You have to find two nodes that give sum = K. -- 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 SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT ALLAHABAD- Hide quoted text - - Show quoted text - -- 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 SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT ALLAHABAD- Hide quoted text - - Show quoted text - -- 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 SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT ALLAHABAD- Hide quoted text - - Show quoted text - -- 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: Given a BST containing integers, and a value K. You have to find two nodes that give sum = K.
You must take an example and then explain On Sat, Jul 16, 2011 at 11:59 PM, Dave dave_and_da...@juno.com wrote: @Sagar: If you are not getting my logic, ask a question. Dave On Jul 16, 12:35 pm, sagar pareek sagarpar...@gmail.com wrote: Ok may be i m not getting ur logic... On Sat, Jul 16, 2011 at 11:03 PM, Dave dave_and_da...@juno.com wrote: @Sagar: No. I didn't say that they were in parallel or that one was inside the other. Go back and read it again and you will see that I said that they were being performed simultaneously, with each one being advanced in certain circumstances, and that in order to do that you would have to use explicit stacks instead of recursion. Perhaps, instead, you misread or misunderstood it. Dave On Jul 16, 12:24 pm, sagar pareek sagarpar...@gmail.com wrote: ok i got it actually u written wrong that f/w and reverse traversal are running parallel u must wrote that f/w traversal inside reverse or vice versa On Sat, Jul 16, 2011 at 10:35 PM, Dave dave_and_da...@juno.com wrote: @Sagar: No problem. The algorithm would do only forward traversal steps until it got to root_left, whereupon F + R = K. Dave On Jul 16, 11:40 am, sagar pareek sagarpar...@gmail.com wrote: @dave what if the k= root-left + right most leaf ? how ur algo works on it? On Sat, Jul 16, 2011 at 9:28 PM, Dave dave_and_da...@juno.com wrote: @Noobcoder: To do it in O(n) without destroying the BST, do two inorder traversals simultaneously, one in the normal forward (left subtree first) direction and one in the reverse direction (right subtree first). Let the two current nodes have value F and R respectively. If F + R = K, return success. If F = R, return failure. If F + R K, advance the forward traversal. Otherwise (F + R K), advance the reverse traversal. To do the traversals simultaneously, you will have to use explicit stacks instead of recursion. Dave On Jul 16, 9:01 am, noobcoder ase.as...@gmail.com wrote: Given a BST containing integers, and a value K. You have to find two nodes that give sum = K. -- 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 SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT ALLAHABAD- Hide quoted text - - Show quoted text - -- 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 SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT ALLAHABAD- Hide quoted text - - Show quoted text - -- 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 SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT ALLAHABAD- Hide quoted text - - Show quoted text - -- 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 SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT 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.
Re: [algogeeks] Re: Printf ...
@sagain:in dev c it is #s Zi On Sat, Jul 16, 2011 at 3:35 PM, Ankur Khurana ankur.kkhur...@gmail.comwrote: I am using MinGW compiler (codeblocks , out put is 788 and not 678 . Its compiler dependent so , let us leave it that way only. On Sat, Jul 16, 2011 at 3:27 PM, shiv narayan narayan.shiv...@gmail.comwrote: according to me it processing is done from righ to left .first right most a would be incremented and then from righ to left for first question answer should be 8+7+6=21 and for 2nd it should be (8)+(7)*10+(6)*100=678 On Jul 15, 1:15 pm, Antony Kotre antonyko...@gmail.com wrote: can any tell and explain the output of following code #includestdio.h main() { int a =5, b=5; int res1=(++a)+(++a)+(++a); int res2=(++b)+(++b)*10+(++b)*100; printf(%d\n%d\n,res1,res2); } -- 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. -- Regards, Kamakshi kamakshi...@gmail.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.
Re: [algogeeks] what would be the output of following code??
answer to the first should be 2 22 23 On Sat, Jul 16, 2011 at 5:44 PM, varun pahwa varunpahwa2...@gmail.comwrote: ignore my previous result. the ans to first should be 2 22 2 0. and the ans to second should be. 2 222 2 please correct me if i am wrong. On Sat, Jul 16, 2011 at 5:38 PM, varun pahwa varunpahwa2...@gmail.comwrote: the ans to first should be 2 2 2 2 0. and the and to second should be. 222 2 2 please correct me if i am wrong. On Sat, Jul 16, 2011 at 4:57 PM, shady sinv...@gmail.com wrote: @ankur that's right :) On Sat, Jul 16, 2011 at 3:25 PM, Ankur Khurana ankur.kkhur...@gmail.com wrote: answer for first should be 2 22 23 and for second 2 222 2 correct me if i am wrong. On Sat, Jul 16, 2011 at 3:08 PM, Deoki Nandan deok...@gmail.comwrote: what about this printf(\n%d,printf(%d %d,2,2)printf(%d%d ,2,2)); On Sat, Jul 16, 2011 at 3:04 PM, swetha rahul swetharahu...@gmail.com wrote: 2 On Sat, Jul 16, 2011 at 2:51 PM, shiv narayan narayan.shiv...@gmail.com wrote: Printf(“%d”,printf(“%d %d”,2,2) printf(“%d %d ”, 2, 2)); -- 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. -- **With Regards Deoki Nandan Vishwakarma * * -- 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. -- Varun Pahwa B.Tech (IT) 7th Sem. Indian Institute of Information Technology Allahabad. Ph : 09793899112 Official Email :: rit2008...@iiita.ac.in Another Email :: varunpahwa.ii...@gmail.com People who fail to plan are those who plan to fail. -- Varun Pahwa B.Tech (IT) 7th Sem. Indian Institute of Information Technology Allahabad. Ph : 09793899112 Official Email :: rit2008...@iiita.ac.in Another Email :: varunpahwa.ii...@gmail.com People who fail to plan are those who plan to fail. -- 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, Kamakshi kamakshi...@gmail.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.
Re: [algogeeks] what would be the output of following code??
Give reason not answer . Answer can be found by compiler On Sun, Jul 17, 2011 at 12:38 AM, Kamakshii Aggarwal kamakshi...@gmail.comwrote: answer to the first should be 2 22 23 On Sat, Jul 16, 2011 at 5:44 PM, varun pahwa varunpahwa2...@gmail.comwrote: ignore my previous result. the ans to first should be 2 22 2 0. and the ans to second should be. 2 222 2 please correct me if i am wrong. On Sat, Jul 16, 2011 at 5:38 PM, varun pahwa varunpahwa2...@gmail.comwrote: the ans to first should be 2 2 2 2 0. and the and to second should be. 222 2 2 please correct me if i am wrong. On Sat, Jul 16, 2011 at 4:57 PM, shady sinv...@gmail.com wrote: @ankur that's right :) On Sat, Jul 16, 2011 at 3:25 PM, Ankur Khurana ankur.kkhur...@gmail.com wrote: answer for first should be 2 22 23 and for second 2 222 2 correct me if i am wrong. On Sat, Jul 16, 2011 at 3:08 PM, Deoki Nandan deok...@gmail.comwrote: what about this printf(\n%d,printf(%d %d,2,2)printf(%d%d ,2,2)); On Sat, Jul 16, 2011 at 3:04 PM, swetha rahul swetharahu...@gmail.com wrote: 2 On Sat, Jul 16, 2011 at 2:51 PM, shiv narayan narayan.shiv...@gmail.com wrote: Printf(“%d”,printf(“%d %d”,2,2) printf(“%d %d ”, 2, 2)); -- 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. -- **With Regards Deoki Nandan Vishwakarma * * -- 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. -- Varun Pahwa B.Tech (IT) 7th Sem. Indian Institute of Information Technology Allahabad. Ph : 09793899112 Official Email :: rit2008...@iiita.ac.in Another Email :: varunpahwa.ii...@gmail.com People who fail to plan are those who plan to fail. -- Varun Pahwa B.Tech (IT) 7th Sem. Indian Institute of Information Technology Allahabad. Ph : 09793899112 Official Email :: rit2008...@iiita.ac.in Another Email :: varunpahwa.ii...@gmail.com People who fail to plan are those who plan to fail. -- 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, Kamakshi kamakshi...@gmail.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. -- **With Regards Deoki Nandan Vishwakarma * * -- 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 Qn: Algo to find the border of a binary tree
here is the code void border(node*); void recur(node*); void border(node *ptr) { node* tmp; int stack[20],top=0; if(tmp=ptr-left) { while(tmp-left) { printf(%d ,tmp-data); tmp=tmp-left; } } recur(ptr); if(tmp=ptr-right) { while(tmp-right) { stack[top++]=tmp-data; tmp=tmp-right; } } while(top--) printf(%d ,stack[top]); printf(%d\n,ptr-data); } void recur(node* ptr) { if(ptr-left) recur(ptr-left); if(!ptr-left!ptr-right) printf(%d ,ptr-data); if(ptr-right) recur(ptr-right); } On Sat, Jul 16, 2011 at 7:07 PM, Reynald reynaldsus...@gmail.com wrote: Algo to find the border of a given binary tree. Optimized for space and time. Input: 10 / \ 50 50 / \ / \ 25 75 20020 / \ / /\ 15 35 120155 250 Output:50 25 15 35 120 155 250 20 150 10 -- 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 SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT 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.
Re: [algogeeks] C OUTPUT AGAIN
@gaurav :y it is -2?y not +2? On Sat, Jul 16, 2011 at 2:13 PM, sukhmeet singh sukhmeet2...@gmail.comwrote: for problem1 you can use %hi or %hd .. while scanning .. On Thu, Jul 14, 2011 at 12:03 PM, Gaurav Jain gjainroor...@gmail.comwrote: @Nicks *Problem 1* %d is used to take a signed integer as input. To take a short integer as input, use %hi. That way, you would get the correct answer as 2. *Problem 2:* a:1 means that variable a is of width *1 bit* Similarly, b:2 means that b is of width *2 bits* b = 6 sets the two bits as 10, (last two bits of 110 considered), which is equal to -2 a = 2 sets the only bit as 0, (last bit of 10 considered), which is nothing but zero. Bit-fields like these however tend to be implementation-dependent and in the interest of portability should be avoided. t.b = 6 sets the last two bits of b as 10, which is -2 in 2's complement t.a = 2 sets the On Thu, Jul 14, 2011 at 1:18 AM, nicks crazy.logic.k...@gmail.comwrote: Hey Guys, plz help me in getting these 2 C output problems *PROBLEM 1.* * * *#*includestdio.h int main() { short int a,b,c; scanf(%d%d,a,b); c=a+b; printf(%d,c); return 0; } INPUT- 1 1 OUTPUT 1 i am not getting why 1 is coming in the output.what difference is using short making in the code ??? *PROBLEM 2.* * * * * #includestdio.h main() { struct { int a:1; int b:2; }t; t.b=6; t.a=2; printf(%d %d,t.a,t.b); } OUTPUT 0 -2 What does the statement a:1 and b:1 mean and what are they doing.i am seeing them first time ever...hence not able to get the outputif someone has any idea plz help !! -- 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. -- Gaurav Jain Associate Software Engineer VxVM Escalations Symantec Software India Pvt. Ltd. -- 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. -- Regards, Kamakshi kamakshi...@gmail.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.
Re: [algogeeks] Microsoft Qn: Algo to find the border of a binary tree
@Reynald Will 75 not be included in the tree that u have given..?? On Sun, Jul 17, 2011 at 12:49 AM, sagar pareek sagarpar...@gmail.comwrote: here is the code void border(node*); void recur(node*); void border(node *ptr) { node* tmp; int stack[20],top=0; if(tmp=ptr-left) { while(tmp-left) { printf(%d ,tmp-data); tmp=tmp-left; } } recur(ptr); if(tmp=ptr-right) { while(tmp-right) { stack[top++]=tmp-data; tmp=tmp-right; } } while(top--) printf(%d ,stack[top]); printf(%d\n,ptr-data); } void recur(node* ptr) { if(ptr-left) recur(ptr-left); if(!ptr-left!ptr-right) printf(%d ,ptr-data); if(ptr-right) recur(ptr-right); } On Sat, Jul 16, 2011 at 7:07 PM, Reynald reynaldsus...@gmail.com wrote: Algo to find the border of a given binary tree. Optimized for space and time. Input: 10 / \ 50 50 / \ / \ 25 75 20020 / \ / /\ 15 35 120155 250 Output:50 25 15 35 120 155 250 20 150 10 -- 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 SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT 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. -- 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 Qn: Algo to find the border of a binary tree
according to saagar's algo, it'll be printed ... On Sun, Jul 17, 2011 at 1:02 AM, swetha rahul swetharahu...@gmail.comwrote: @Reynald Will 75 not be included in the tree that u have given..?? On Sun, Jul 17, 2011 at 12:49 AM, sagar pareek sagarpar...@gmail.comwrote: here is the code void border(node*); void recur(node*); void border(node *ptr) { node* tmp; int stack[20],top=0; if(tmp=ptr-left) { while(tmp-left) { printf(%d ,tmp-data); tmp=tmp-left; } } recur(ptr); if(tmp=ptr-right) { while(tmp-right) { stack[top++]=tmp-data; tmp=tmp-right; } } while(top--) printf(%d ,stack[top]); printf(%d\n,ptr-data); } void recur(node* ptr) { if(ptr-left) recur(ptr-left); if(!ptr-left!ptr-right) printf(%d ,ptr-data); if(ptr-right) recur(ptr-right); } On Sat, Jul 16, 2011 at 7:07 PM, Reynald reynaldsus...@gmail.com wrote: Algo to find the border of a given binary tree. Optimized for space and time. Input: 10 / \ 50 50 / \ / \ 25 75 20020 / \ / /\ 15 35 120155 250 Output:50 25 15 35 120 155 250 20 150 10 -- 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 SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT 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. -- 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. -- Shubham Maheshwari ShubZz O.o o.O enJoY ...!!! -- 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 Qn: Algo to find the border of a binary tree
yup :) On Sun, Jul 17, 2011 at 1:03 AM, Shubham Maheshwari shubham.veloc...@gmail.com wrote: according to saagar's algo, it'll be printed ... On Sun, Jul 17, 2011 at 1:02 AM, swetha rahul swetharahu...@gmail.comwrote: @Reynald Will 75 not be included in the tree that u have given..?? On Sun, Jul 17, 2011 at 12:49 AM, sagar pareek sagarpar...@gmail.comwrote: here is the code void border(node*); void recur(node*); void border(node *ptr) { node* tmp; int stack[20],top=0; if(tmp=ptr-left) { while(tmp-left) { printf(%d ,tmp-data); tmp=tmp-left; } } recur(ptr); if(tmp=ptr-right) { while(tmp-right) { stack[top++]=tmp-data; tmp=tmp-right; } } while(top--) printf(%d ,stack[top]); printf(%d\n,ptr-data); } void recur(node* ptr) { if(ptr-left) recur(ptr-left); if(!ptr-left!ptr-right) printf(%d ,ptr-data); if(ptr-right) recur(ptr-right); } On Sat, Jul 16, 2011 at 7:07 PM, Reynald reynaldsus...@gmail.comwrote: Algo to find the border of a given binary tree. Optimized for space and time. Input: 10 / \ 50 50 / \ / \ 25 75 20020 / \ / /\ 15 35 120155 250 Output:50 25 15 35 120 155 250 20 150 10 -- 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 SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT 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. -- 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. -- Shubham Maheshwari ShubZz O.o o.O enJoY ...!!! -- 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 SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT 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.
Re: [algogeeks] what would be the output of following code??
printf returns no of characters printed..first of all the rightmost printf will print 2 2 .and since it is printing 3 characters(two 2's and 1 space) thereby its returning 3.same is with the other printf..now the outer most printf will print the value of(3 3) which is 3..and hence the answer. On Sun, Jul 17, 2011 at 12:46 AM, Deoki Nandan deok...@gmail.com wrote: Give reason not answer . Answer can be found by compiler On Sun, Jul 17, 2011 at 12:38 AM, Kamakshii Aggarwal kamakshi...@gmail.com wrote: answer to the first should be 2 22 23 On Sat, Jul 16, 2011 at 5:44 PM, varun pahwa varunpahwa2...@gmail.comwrote: ignore my previous result. the ans to first should be 2 22 2 0. and the ans to second should be. 2 222 2 please correct me if i am wrong. On Sat, Jul 16, 2011 at 5:38 PM, varun pahwa varunpahwa2...@gmail.comwrote: the ans to first should be 2 2 2 2 0. and the and to second should be. 222 2 2 please correct me if i am wrong. On Sat, Jul 16, 2011 at 4:57 PM, shady sinv...@gmail.com wrote: @ankur that's right :) On Sat, Jul 16, 2011 at 3:25 PM, Ankur Khurana ankur.kkhur...@gmail.com wrote: answer for first should be 2 22 23 and for second 2 222 2 correct me if i am wrong. On Sat, Jul 16, 2011 at 3:08 PM, Deoki Nandan deok...@gmail.comwrote: what about this printf(\n%d,printf(%d %d,2,2)printf(%d%d ,2,2)); On Sat, Jul 16, 2011 at 3:04 PM, swetha rahul swetharahu...@gmail.com wrote: 2 On Sat, Jul 16, 2011 at 2:51 PM, shiv narayan narayan.shiv...@gmail.com wrote: Printf(“%d”,printf(“%d %d”,2,2) printf(“%d %d ”, 2, 2)); -- 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. -- **With Regards Deoki Nandan Vishwakarma * * -- 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. -- Varun Pahwa B.Tech (IT) 7th Sem. Indian Institute of Information Technology Allahabad. Ph : 09793899112 Official Email :: rit2008...@iiita.ac.in Another Email :: varunpahwa.ii...@gmail.com People who fail to plan are those who plan to fail. -- Varun Pahwa B.Tech (IT) 7th Sem. Indian Institute of Information Technology Allahabad. Ph : 09793899112 Official Email :: rit2008...@iiita.ac.in Another Email :: varunpahwa.ii...@gmail.com People who fail to plan are those who plan to fail. -- 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, Kamakshi kamakshi...@gmail.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. -- **With Regards Deoki Nandan Vishwakarma * * -- 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.
Re: [algogeeks] Microsoft Qn: Algo to find the border of a binary tree
Sagar , Shubam Maheshwari Thanks!! On Sun, Jul 17, 2011 at 1:11 AM, sagar pareek sagarpar...@gmail.com wrote: yup :) On Sun, Jul 17, 2011 at 1:03 AM, Shubham Maheshwari shubham.veloc...@gmail.com wrote: according to saagar's algo, it'll be printed ... On Sun, Jul 17, 2011 at 1:02 AM, swetha rahul swetharahu...@gmail.comwrote: @Reynald Will 75 not be included in the tree that u have given..?? On Sun, Jul 17, 2011 at 12:49 AM, sagar pareek sagarpar...@gmail.comwrote: here is the code void border(node*); void recur(node*); void border(node *ptr) { node* tmp; int stack[20],top=0; if(tmp=ptr-left) { while(tmp-left) { printf(%d ,tmp-data); tmp=tmp-left; } } recur(ptr); if(tmp=ptr-right) { while(tmp-right) { stack[top++]=tmp-data; tmp=tmp-right; } } while(top--) printf(%d ,stack[top]); printf(%d\n,ptr-data); } void recur(node* ptr) { if(ptr-left) recur(ptr-left); if(!ptr-left!ptr-right) printf(%d ,ptr-data); if(ptr-right) recur(ptr-right); } On Sat, Jul 16, 2011 at 7:07 PM, Reynald reynaldsus...@gmail.comwrote: Algo to find the border of a given binary tree. Optimized for space and time. Input: 10 / \ 50 50 / \ / \ 25 75 20020 / \ / /\ 15 35 120155 250 Output:50 25 15 35 120 155 250 20 150 10 -- 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 SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT 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. -- 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. -- Shubham Maheshwari ShubZz O.o o.O enJoY ...!!! -- 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 SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT 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. -- 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: Microsoft Interview Qn
void convert(Node * root, Node* sibling) { if(root == NULL) return; convert(root-left, root-right); convert(root-right, NULL); root-right = sibling; } convert(root, NULL); -- DK http://twitter.com/divyekapoor http://www.divye.in -- 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/-/UTKqLB7fawgJ. 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] What is the output of the following program? Why?
union Data Type What is the output of the following program? Why? #include main() { typedef union { int a; char b[10]; float c; } Union; Union x,y = {100}; x.a = 50; strcpy(x.b,hello); x.c = 21.50; printf(Union x : %d %s %f n,x.a,x.b,x.c); printf(Union y : %d %s %f n,y.a,y.b,y.c); } -- Shubham Maheshwari ShubZz O.o o.O enJoY ...!!! -- 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] What is the output of the following program? Why?
I think you must first read about unions and the differences between union and structures :) On Sun, Jul 17, 2011 at 1:48 AM, Shubham Maheshwari shubham.veloc...@gmail.com wrote: union Data Type What is the output of the following program? Why? #include main() { typedef union { int a; char b[10]; float c; } Union; Union x,y = {100}; x.a = 50; strcpy(x.b,hello); x.c = 21.50; printf(Union x : %d %s %f n,x.a,x.b,x.c); printf(Union y : %d %s %f n,y.a,y.b,y.c); } -- Shubham Maheshwari ShubZz O.o o.O enJoY ...!!! -- 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 SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT 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.
Re: [algogeeks] What is the output of the following program? Why?
you mean to say .. the ques is wrong ... or what ...!! On Sun, Jul 17, 2011 at 1:54 AM, sagar pareek sagarpar...@gmail.com wrote: I think you must first read about unions and the differences between union and structures :) On Sun, Jul 17, 2011 at 1:48 AM, Shubham Maheshwari shubham.veloc...@gmail.com wrote: union Data Type What is the output of the following program? Why? #include main() { typedef union { int a; char b[10]; float c; } Union; Union x,y = {100}; x.a = 50; strcpy(x.b,hello); x.c = 21.50; printf(Union x : %d %s %f n,x.a,x.b,x.c); printf(Union y : %d %s %f n,y.a,y.b,y.c); } -- Shubham Maheshwari ShubZz O.o o.O enJoY ...!!! -- 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 SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT 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. -- Shubham Maheshwari ShubZz O.o o.O enJoY ...!!! -- 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] What is the output of the following program? Why?
u can always retrieve that value from the union that has been assigned last.therefore u get correct answer only for x.c in the case of union y y.a=100 and so the output but am not sure why y.b is printing character equivalent of 100. On Sun, Jul 17, 2011 at 1:58 AM, Shubham Maheshwari shubham.veloc...@gmail.com wrote: you mean to say .. the ques is wrong ... or what ...!! On Sun, Jul 17, 2011 at 1:54 AM, sagar pareek sagarpar...@gmail.comwrote: I think you must first read about unions and the differences between union and structures :) On Sun, Jul 17, 2011 at 1:48 AM, Shubham Maheshwari shubham.veloc...@gmail.com wrote: union Data Type What is the output of the following program? Why? #include main() { typedef union { int a; char b[10]; float c; } Union; Union x,y = {100}; x.a = 50; strcpy(x.b,hello); x.c = 21.50; printf(Union x : %d %s %f n,x.a,x.b,x.c); printf(Union y : %d %s %f n,y.a,y.b,y.c); } -- Shubham Maheshwari ShubZz O.o o.O enJoY ...!!! -- 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 SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT 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. -- Shubham Maheshwari ShubZz O.o o.O enJoY ...!!! -- 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, Kamakshi kamakshi...@gmail.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.
Re: [algogeeks] What is the output of the following program? Why?
@Kamakshii: thats probably becuz a union has a common memory location, accessed by all its members. so, the value '100' is treated as an int by 'a', as a char array by 'b' and as a float by 'c'. I thnk i read this read tis somewhere sometime back. ... so aint completely sure abt it. On Sun, Jul 17, 2011 at 2:08 AM, Kamakshii Aggarwal kamakshi...@gmail.comwrote: u can always retrieve that value from the union that has been assigned last.therefore u get correct answer only for x.c in the case of union y y.a=100 and so the output but am not sure why y.b is printing character equivalent of 100. On Sun, Jul 17, 2011 at 1:58 AM, Shubham Maheshwari shubham.veloc...@gmail.com wrote: you mean to say .. the ques is wrong ... or what ...!! On Sun, Jul 17, 2011 at 1:54 AM, sagar pareek sagarpar...@gmail.comwrote: I think you must first read about unions and the differences between union and structures :) On Sun, Jul 17, 2011 at 1:48 AM, Shubham Maheshwari shubham.veloc...@gmail.com wrote: union Data Type What is the output of the following program? Why? #include main() { typedef union { int a; char b[10]; float c; } Union; Union x,y = {100}; x.a = 50; strcpy(x.b,hello); x.c = 21.50; printf(Union x : %d %s %f n,x.a,x.b,x.c); printf(Union y : %d %s %f n,y.a,y.b,y.c); } -- Shubham Maheshwari ShubZz O.o o.O enJoY ...!!! -- 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 SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT 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. -- Shubham Maheshwari ShubZz O.o o.O enJoY ...!!! -- 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, Kamakshi kamakshi...@gmail.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. -- Shubham Maheshwari ShubZz O.o o.O enJoY ...!!! -- 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] What is the output of the following program? Why?
@shubham:yes u r right.thanks :) On Sun, Jul 17, 2011 at 2:12 AM, Shubham Maheshwari shubham.veloc...@gmail.com wrote: @Kamakshii: thats probably becuz a union has a common memory location, accessed by all its members. so, the value '100' is treated as an int by 'a', as a char array by 'b' and as a float by 'c'. I thnk i read this read tis somewhere sometime back. ... so aint completely sure abt it. On Sun, Jul 17, 2011 at 2:08 AM, Kamakshii Aggarwal kamakshi...@gmail.com wrote: u can always retrieve that value from the union that has been assigned last.therefore u get correct answer only for x.c in the case of union y y.a=100 and so the output but am not sure why y.b is printing character equivalent of 100. On Sun, Jul 17, 2011 at 1:58 AM, Shubham Maheshwari shubham.veloc...@gmail.com wrote: you mean to say .. the ques is wrong ... or what ...!! On Sun, Jul 17, 2011 at 1:54 AM, sagar pareek sagarpar...@gmail.comwrote: I think you must first read about unions and the differences between union and structures :) On Sun, Jul 17, 2011 at 1:48 AM, Shubham Maheshwari shubham.veloc...@gmail.com wrote: union Data Type What is the output of the following program? Why? #include main() { typedef union { int a; char b[10]; float c; } Union; Union x,y = {100}; x.a = 50; strcpy(x.b,hello); x.c = 21.50; printf(Union x : %d %s %f n,x.a,x.b,x.c); printf(Union y : %d %s %f n,y.a,y.b,y.c); } -- Shubham Maheshwari ShubZz O.o o.O enJoY ...!!! -- 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 SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT 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. -- Shubham Maheshwari ShubZz O.o o.O enJoY ...!!! -- 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, Kamakshi kamakshi...@gmail.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. -- Shubham Maheshwari ShubZz O.o o.O enJoY ...!!! -- 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, Kamakshi kamakshi...@gmail.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.
Re: [algogeeks] What is the output of the following program? Why?
Well shubham if you know about the unions very well then why u asked this question? On Sun, Jul 17, 2011 at 2:27 AM, Shubham Maheshwari shubham.veloc...@gmail.com wrote: :D On Sun, Jul 17, 2011 at 2:24 AM, Kamakshii Aggarwal kamakshi...@gmail.com wrote: @shubham:yes u r right.thanks :) On Sun, Jul 17, 2011 at 2:12 AM, Shubham Maheshwari shubham.veloc...@gmail.com wrote: @Kamakshii: thats probably becuz a union has a common memory location, accessed by all its members. so, the value '100' is treated as an int by 'a', as a char array by 'b' and as a float by 'c'. I thnk i read this read tis somewhere sometime back. ... so aint completely sure abt it. On Sun, Jul 17, 2011 at 2:08 AM, Kamakshii Aggarwal kamakshi...@gmail.com wrote: u can always retrieve that value from the union that has been assigned last.therefore u get correct answer only for x.c in the case of union y y.a=100 and so the output but am not sure why y.b is printing character equivalent of 100. On Sun, Jul 17, 2011 at 1:58 AM, Shubham Maheshwari shubham.veloc...@gmail.com wrote: you mean to say .. the ques is wrong ... or what ...!! On Sun, Jul 17, 2011 at 1:54 AM, sagar pareek sagarpar...@gmail.comwrote: I think you must first read about unions and the differences between union and structures :) On Sun, Jul 17, 2011 at 1:48 AM, Shubham Maheshwari shubham.veloc...@gmail.com wrote: union Data Type What is the output of the following program? Why? #include main() { typedef union { int a; char b[10]; float c; } Union; Union x,y = {100}; x.a = 50; strcpy(x.b,hello); x.c = 21.50; printf(Union x : %d %s %f n,x.a,x.b,x.c); printf(Union y : %d %s %f n,y.a,y.b,y.c); } -- Shubham Maheshwari ShubZz O.o o.O enJoY ...!!! -- 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 SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT 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. -- Shubham Maheshwari ShubZz O.o o.O enJoY ...!!! -- 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, Kamakshi kamakshi...@gmail.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. -- Shubham Maheshwari ShubZz O.o o.O enJoY ...!!! -- 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, Kamakshi kamakshi...@gmail.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. -- Shubham Maheshwari ShubZz O.o o.O enJoY ...!!! -- 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 SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT 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.
Re: [algogeeks] Microsoft Qn: Algo to find the border of a binary tree
A pre-order traversal which is used to index the (min,max) pair value at each level except the bottom-most level where all the entries are to be printed. O(n) time O(log n) memory. On 7/17/11, swetha rahul swetharahu...@gmail.com wrote: Sagar , Shubam Maheshwari Thanks!! On Sun, Jul 17, 2011 at 1:11 AM, sagar pareek sagarpar...@gmail.com wrote: yup :) On Sun, Jul 17, 2011 at 1:03 AM, Shubham Maheshwari shubham.veloc...@gmail.com wrote: according to saagar's algo, it'll be printed ... On Sun, Jul 17, 2011 at 1:02 AM, swetha rahul swetharahu...@gmail.comwrote: @Reynald Will 75 not be included in the tree that u have given..?? On Sun, Jul 17, 2011 at 12:49 AM, sagar pareek sagarpar...@gmail.comwrote: here is the code void border(node*); void recur(node*); void border(node *ptr) { node* tmp; int stack[20],top=0; if(tmp=ptr-left) { while(tmp-left) { printf(%d ,tmp-data); tmp=tmp-left; } } recur(ptr); if(tmp=ptr-right) { while(tmp-right) { stack[top++]=tmp-data; tmp=tmp-right; } } while(top--) printf(%d ,stack[top]); printf(%d\n,ptr-data); } void recur(node* ptr) { if(ptr-left) recur(ptr-left); if(!ptr-left!ptr-right) printf(%d ,ptr-data); if(ptr-right) recur(ptr-right); } On Sat, Jul 16, 2011 at 7:07 PM, Reynald reynaldsus...@gmail.comwrote: Algo to find the border of a given binary tree. Optimized for space and time. Input: 10 / \ 50 50 / \ / \ 25 75 20020 / \ / /\ 15 35 120155 250 Output:50 25 15 35 120 155 250 20 150 10 -- 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 SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT 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. -- 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. -- Shubham Maheshwari ShubZz O.o o.O enJoY ...!!! -- 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 SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT 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. -- 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: Given a BST containing integers, and a value K. You have to find two nodes that give sum = K.
Use O(2n) memory , list the in-order traversal of BST say A[0..n]. and K-A[0...n] say B . Now apply standard merge function(Merge sort) on A and B. keeping track of equal found elements during comparison to get the ans. On 7/17/11, sagar pareek sagarpar...@gmail.com wrote: You must take an example and then explain On Sat, Jul 16, 2011 at 11:59 PM, Dave dave_and_da...@juno.com wrote: @Sagar: If you are not getting my logic, ask a question. Dave On Jul 16, 12:35 pm, sagar pareek sagarpar...@gmail.com wrote: Ok may be i m not getting ur logic... On Sat, Jul 16, 2011 at 11:03 PM, Dave dave_and_da...@juno.com wrote: @Sagar: No. I didn't say that they were in parallel or that one was inside the other. Go back and read it again and you will see that I said that they were being performed simultaneously, with each one being advanced in certain circumstances, and that in order to do that you would have to use explicit stacks instead of recursion. Perhaps, instead, you misread or misunderstood it. Dave On Jul 16, 12:24 pm, sagar pareek sagarpar...@gmail.com wrote: ok i got it actually u written wrong that f/w and reverse traversal are running parallel u must wrote that f/w traversal inside reverse or vice versa On Sat, Jul 16, 2011 at 10:35 PM, Dave dave_and_da...@juno.com wrote: @Sagar: No problem. The algorithm would do only forward traversal steps until it got to root_left, whereupon F + R = K. Dave On Jul 16, 11:40 am, sagar pareek sagarpar...@gmail.com wrote: @dave what if the k= root-left + right most leaf ? how ur algo works on it? On Sat, Jul 16, 2011 at 9:28 PM, Dave dave_and_da...@juno.com wrote: @Noobcoder: To do it in O(n) without destroying the BST, do two inorder traversals simultaneously, one in the normal forward (left subtree first) direction and one in the reverse direction (right subtree first). Let the two current nodes have value F and R respectively. If F + R = K, return success. If F = R, return failure. If F + R K, advance the forward traversal. Otherwise (F + R K), advance the reverse traversal. To do the traversals simultaneously, you will have to use explicit stacks instead of recursion. Dave On Jul 16, 9:01 am, noobcoder ase.as...@gmail.com wrote: Given a BST containing integers, and a value K. You have to find two nodes that give sum = K. -- 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 SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT ALLAHABAD- Hide quoted text - - Show quoted text - -- 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 SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT ALLAHABAD- Hide quoted text - - Show quoted text - -- 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 SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT ALLAHABAD- Hide quoted text - - Show quoted text - -- 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 SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT 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. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group.
Re: [algogeeks] Re: Given a BST containing integers, and a value K. You have to find two nodes that give sum = K.
@sagar This is what Dave is suggesting in a more pseudocode way:- 1-Traverse a pointer right down to the leftmost element,i.e.the shortest,say small 2-traverse a pointer left down to the rightmost element i.e.the largest.say large while(small!=large) 3-Compare their sum.If sumk set large to its successor in reverse inorder.(I am not sure if u meant the same but I am assuming rev inorder to be right-node-left) else set small to its inorder successor. break when u get the desired k. print :) return if u get out of the loop without getting the number then such number does not exist.print :( Amortized complexity order n. -- Saurabh Singh B.Tech (Computer Science) 5h sem MNNIT 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.
Re: [algogeeks] Microsoft Qn: Algo to find the border of a binary tree
Sagar;s Algo works, thank you so much guys. On Sun, Jul 17, 2011 at 3:41 AM, SkRiPt KiDdIe anuragmsi...@gmail.comwrote: A pre-order traversal which is used to index the (min,max) pair value at each level except the bottom-most level where all the entries are to be printed. O(n) time O(log n) memory. On 7/17/11, swetha rahul swetharahu...@gmail.com wrote: Sagar , Shubam Maheshwari Thanks!! On Sun, Jul 17, 2011 at 1:11 AM, sagar pareek sagarpar...@gmail.com wrote: yup :) On Sun, Jul 17, 2011 at 1:03 AM, Shubham Maheshwari shubham.veloc...@gmail.com wrote: according to saagar's algo, it'll be printed ... On Sun, Jul 17, 2011 at 1:02 AM, swetha rahul swetharahu...@gmail.comwrote: @Reynald Will 75 not be included in the tree that u have given..?? On Sun, Jul 17, 2011 at 12:49 AM, sagar pareek sagarpar...@gmail.comwrote: here is the code void border(node*); void recur(node*); void border(node *ptr) { node* tmp; int stack[20],top=0; if(tmp=ptr-left) { while(tmp-left) { printf(%d ,tmp-data); tmp=tmp-left; } } recur(ptr); if(tmp=ptr-right) { while(tmp-right) { stack[top++]=tmp-data; tmp=tmp-right; } } while(top--) printf(%d ,stack[top]); printf(%d\n,ptr-data); } void recur(node* ptr) { if(ptr-left) recur(ptr-left); if(!ptr-left!ptr-right) printf(%d ,ptr-data); if(ptr-right) recur(ptr-right); } On Sat, Jul 16, 2011 at 7:07 PM, Reynald reynaldsus...@gmail.comwrote: Algo to find the border of a given binary tree. Optimized for space and time. Input: 10 / \ 50 50 / \ / \ 25 75 20020 / \ / /\ 15 35 120155 250 Output:50 25 15 35 120 155 250 20 150 10 -- 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 SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT 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. -- 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. -- Shubham Maheshwari ShubZz O.o o.O enJoY ...!!! -- 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 SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT 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. -- 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. -- Regards Reynald Reni Masters in Software Engineering CIT - India -- 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.
Re: [algogeeks] Microsoft Qn: Algo to find the border of a binary tree
Yep! On Sun, Jul 17, 2011 at 1:02 AM, swetha rahul swetharahu...@gmail.comwrote: @Reynald Will 75 not be included in the tree that u have given..?? On Sun, Jul 17, 2011 at 12:49 AM, sagar pareek sagarpar...@gmail.comwrote: here is the code void border(node*); void recur(node*); void border(node *ptr) { node* tmp; int stack[20],top=0; if(tmp=ptr-left) { while(tmp-left) { printf(%d ,tmp-data); tmp=tmp-left; } } recur(ptr); if(tmp=ptr-right) { while(tmp-right) { stack[top++]=tmp-data; tmp=tmp-right; } } while(top--) printf(%d ,stack[top]); printf(%d\n,ptr-data); } void recur(node* ptr) { if(ptr-left) recur(ptr-left); if(!ptr-left!ptr-right) printf(%d ,ptr-data); if(ptr-right) recur(ptr-right); } On Sat, Jul 16, 2011 at 7:07 PM, Reynald reynaldsus...@gmail.com wrote: Algo to find the border of a given binary tree. Optimized for space and time. Input: 10 / \ 50 50 / \ / \ 25 75 20020 / \ / /\ 15 35 120155 250 Output:50 25 15 35 120 155 250 20 150 10 -- 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 SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT 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. -- 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 Reynald Reni Masters in Software Engineering CIT - India -- 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 Qn: Algo to find the border of a binary tree
please explain the code a bit more.. unable to understand it..an example will be better.. On Sun, Jul 17, 2011 at 7:10 AM, Reynald Suz reynaldsus...@gmail.comwrote: Yep! On Sun, Jul 17, 2011 at 1:02 AM, swetha rahul swetharahu...@gmail.comwrote: @Reynald Will 75 not be included in the tree that u have given..?? On Sun, Jul 17, 2011 at 12:49 AM, sagar pareek sagarpar...@gmail.comwrote: here is the code void border(node*); void recur(node*); void border(node *ptr) { node* tmp; int stack[20],top=0; if(tmp=ptr-left) { while(tmp-left) { printf(%d ,tmp-data); tmp=tmp-left; } } recur(ptr); if(tmp=ptr-right) { while(tmp-right) { stack[top++]=tmp-data; tmp=tmp-right; } } while(top--) printf(%d ,stack[top]); printf(%d\n,ptr-data); } void recur(node* ptr) { if(ptr-left) recur(ptr-left); if(!ptr-left!ptr-right) printf(%d ,ptr-data); if(ptr-right) recur(ptr-right); } On Sat, Jul 16, 2011 at 7:07 PM, Reynald reynaldsus...@gmail.comwrote: Algo to find the border of a given binary tree. Optimized for space and time. Input: 10 / \ 50 50 / \ / \ 25 75 20020 / \ / /\ 15 35 120155 250 Output:50 25 15 35 120 155 250 20 150 10 -- 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 SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT 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. -- 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 Reynald Reni Masters in Software Engineering CIT - India -- 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] C OUTPUT AGAIN
value of b = 10 (in binary) and since b is a signed integer and also MSB is 1 so final value of b is 2's complement of 10 i.e. -2 On Sun, Jul 17, 2011 at 12:55 AM, Kamakshii Aggarwal kamakshi...@gmail.comwrote: @gaurav :y it is -2?y not +2? On Sat, Jul 16, 2011 at 2:13 PM, sukhmeet singh sukhmeet2...@gmail.comwrote: for problem1 you can use %hi or %hd .. while scanning .. On Thu, Jul 14, 2011 at 12:03 PM, Gaurav Jain gjainroor...@gmail.comwrote: @Nicks *Problem 1* %d is used to take a signed integer as input. To take a short integer as input, use %hi. That way, you would get the correct answer as 2. *Problem 2:* a:1 means that variable a is of width *1 bit* Similarly, b:2 means that b is of width *2 bits* b = 6 sets the two bits as 10, (last two bits of 110 considered), which is equal to -2 a = 2 sets the only bit as 0, (last bit of 10 considered), which is nothing but zero. Bit-fields like these however tend to be implementation-dependent and in the interest of portability should be avoided. t.b = 6 sets the last two bits of b as 10, which is -2 in 2's complement t.a = 2 sets the On Thu, Jul 14, 2011 at 1:18 AM, nicks crazy.logic.k...@gmail.comwrote: Hey Guys, plz help me in getting these 2 C output problems *PROBLEM 1.* * * *#*includestdio.h int main() { short int a,b,c; scanf(%d%d,a,b); c=a+b; printf(%d,c); return 0; } INPUT- 1 1 OUTPUT 1 i am not getting why 1 is coming in the output.what difference is using short making in the code ??? *PROBLEM 2.* * * * * #includestdio.h main() { struct { int a:1; int b:2; }t; t.b=6; t.a=2; printf(%d %d,t.a,t.b); } OUTPUT 0 -2 What does the statement a:1 and b:1 mean and what are they doing.i am seeing them first time ever...hence not able to get the outputif someone has any idea plz help !! -- 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. -- Gaurav Jain Associate Software Engineer VxVM Escalations Symantec Software India Pvt. Ltd. -- 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. -- Regards, Kamakshi kamakshi...@gmail.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, 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: Merge unsorted arrays
It depends upon problem if n m, apply insertion sort for sorting m arrays because for smaller sublists insertion sort perform better then merge sort and then merge them all in mnlog(m) otherwise simply combine and apply merge sort or any other standard sorting algorithm On Sat, Jul 16, 2011 at 9:30 PM, Dave dave_and_da...@juno.com wrote: @Aseem: Combine the arrays and sort the result. O(mn log mn). Dave On Jul 16, 4:13 am, aseem garg ase.as...@gmail.com wrote: Q2. Given m arrays of n size each, give an algorithm to combine these arrays into a single array with sorted elements. Also tell the time complexity of your solution. Aseem -- 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. -- Sanjay Ahuja, Analyst, Financing Prime Brokerage Nomura Securities India Pvt. Ltd -- 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 Qn: Algo to find the border of a binary tree
@sagar: There is one flaw in the code. Trace ur code 15 and 250 get printed twice. otherwise it is fine. On Sat, Jul 16, 2011 at 7:59 PM, sukhmeet singh sukhmeet2...@gmail.comwrote: please explain the code a bit more.. unable to understand it..an example will be better.. On Sun, Jul 17, 2011 at 7:10 AM, Reynald Suz reynaldsus...@gmail.comwrote: Yep! On Sun, Jul 17, 2011 at 1:02 AM, swetha rahul swetharahu...@gmail.comwrote: @Reynald Will 75 not be included in the tree that u have given..?? On Sun, Jul 17, 2011 at 12:49 AM, sagar pareek sagarpar...@gmail.comwrote: here is the code void border(node*); void recur(node*); void border(node *ptr) { node* tmp; int stack[20],top=0; if(tmp=ptr-left) { while(tmp-left) { printf(%d ,tmp-data); tmp=tmp-left; } } recur(ptr); if(tmp=ptr-right) { while(tmp-right) { stack[top++]=tmp-data; tmp=tmp-right; } } while(top--) printf(%d ,stack[top]); printf(%d\n,ptr-data); } void recur(node* ptr) { if(ptr-left) recur(ptr-left); if(!ptr-left!ptr-right) printf(%d ,ptr-data); if(ptr-right) recur(ptr-right); } On Sat, Jul 16, 2011 at 7:07 PM, Reynald reynaldsus...@gmail.comwrote: Algo to find the border of a given binary tree. Optimized for space and time. Input: 10 / \ 50 50 / \ / \ 25 75 20020 / \ / /\ 15 35 120155 250 Output:50 25 15 35 120 155 250 20 150 10 -- 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 SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT 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. -- 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 Reynald Reni Masters in Software Engineering CIT - India -- 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] Re: Microsoft Interview Qn
im a bit confused with child-sibling term, this expects output for A /\ B C / \ / \ DE F G 1 A / B C / / DE FG 2 A / B-- C / DEFG is output expected 1 or 2 surender On Sun, Jul 17, 2011 at 1:32 AM, DK divyekap...@gmail.com wrote: void convert(Node * root, Node* sibling) { if(root == NULL) return; convert(root-left, root-right); convert(root-right, NULL); root-right = sibling; } convert(root, NULL); -- DK http://twitter.com/divyekapoor http://www.divye.in -- 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/-/UTKqLB7fawgJ. 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: Microsoft Interview Qn
in this recursive code...the right link node will point to its sibling to the right (if it has) or else it will be null. the left link of the node will point to its child(if it has) or else it will be null. regards, Naveen CSE R.V.C.E, Bangalore. -- 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.