[algogeeks] Re: Question asked in Amazon online test
Hi, This one is quite easy. You have to calculate the number of one's before every zero and add them up. That's it. public class Test1 { public void printArray(int[] tmpArr) { for (int i : tmpArr) { System.out.println(i); } } public int calculateMinSwaps(int[] tmpArr) { int minSwaps = 0; int numberOfOne = 0; for (int i : tmpArr) { if (i == 1) { numberOfOne++; } else { minSwaps += numberOfOne; } } return minSwaps; } /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Test1 test1 = new Test1(); int[] minSwaps = { 1,1,1,0,0,0,1,0 }; // test1.printArray(minSwaps); int minswap = test1.calculateMinSwaps(minSwaps); System.out.println(minswap); } } On Saturday, June 23, 2012 11:34:55 AM UTC+5:30, zerocool142 wrote: Given an array containing sequence of bits (0 or 1), you have to sort this array in the ascending order i.e. all 0' in first part of array followed by all 1's. The constraints is that you can swap only the adjacent elements in the array. Find the minimum number of swaps required to sort the given input array. Example: Given the array (0,0,1,0,1,0,1,1) the minimum number of swaps is 3. -- 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/-/XDJ5a5YfykEJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] A programming competition question
http://stackoverflow.com/q/11240022/1081340 -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] MS Question: Segregrate positive and negative nos in array without changing order
Hi Question as in subject *No extra space (can use one extra space)-O(1) max *No order change allowed example: input : 1,-5,2,10,-100,-2 output: -5,-10,-100,1,2 input : -1,-5,10,11,15,-500,200,-10 output : -1,-5,-10,-500,-10,10,11,15 Thanks Raghavn -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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 Question :implement read write lock class
This link should help http://stackoverflow.com/questions/5667793/how-does-a-read-write-mutex-lock-work?rq=1 -mithun On Fri, Jun 29, 2012 at 7:30 AM, bharat b bagana.bharatku...@gmail.comwrote: class lock { enum{read, write,free}status; }; By default, make status value as free. Based on the request, status value will be changed... Based on the value of the status, we should decide whether another read/write lock can be given. Any suggestions ? On Thu, Jun 28, 2012 at 4:46 PM, Ashish Goel ashg...@gmail.com wrote: Best Regards Ashish Goel Think positive and find fuel in failure +919985813081 +919966006652 -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] trie display
first search for node where abc ends i.e say func Search() will return node whose node-ch='c';(last character of input abc) then pass this node to following algo :- this is just a code sketchso you can add boundary conditions to it..(if i miss it) print(node *root,int j) { if(!root) return; if(root-end) { output[j]=root-data; output[j+1]='\0'; printf(\n%s\n,output); } for(i=0;i26;i++) { if(root-childre[i]) { if(root[i]-data==('a'+i) ) { output[ j ] = root-data } print(root-child[i],j+1) } else { print(root-child[i], j ); } } } On Thu, Jun 28, 2012 at 12:23 PM, deepikaanand swinyanand...@gmail.comwrote: If there is a trie of following strings(say URLs) abcde,abcegh,abcpqr,abcxyz,xyz if input = abc then output should be = de,egh,pqr,xyz How can I code for this ??? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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 Question: Segregrate positive and negative nos in array without changing order
duplicate of a previous post.Kindly refer to that post. Saurabh Singh B.Tech (Computer Science) MNNIT blog:geekinessthecoolway.blogspot.com On Fri, Jun 29, 2012 at 10:41 AM, raghavan M peacelover1987...@yahoo.co.inwrote: Hi Question as in subject *No extra space (can use one extra space)-O(1) max *No order change allowed example: input : 1,-5,2,10,-100,-2 output: -5,-10,-100,1,2 input : -1,-5,10,11,15,-500,200,-10 output : -1,-5,-10,-500,-10,10,11,15 Thanks Raghavn -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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 Question: Segregrate positive and negative nos in array without changing order
one can modify dutch national flag algo for two colors(2 types positive n negative) -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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 Question: Segregrate positive and negative nos in array without changing order
Quick sort partition routine variation. On Fri, Jun 29, 2012 at 3:06 PM, Ravi Ranjan ravi.cool2...@gmail.comwrote: one can modify dutch national flag algo for two colors(2 types positive n negative) -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] Switch doubt in C
Doubt, very trivial though: #includestdio.h int main() { int x=3; switch(x) { case 1: x=1; break; case 2: x=2; break; case 3: x=3; break; default: x=0; break; case 4: x=4; break; } printf(%d,x) return 0; } gives an output of 3. But, #includestdio.h using namespace std; int main() { int x=3; switch(x) { case 1: x=1; case 2: x=2; case 3: x=3; default: x=0; case 4: x=4; } printf(%d,x); getch(); return 0; } gives an output of 4. My doubt is, in spite of the missing break statements in the second case, how will it enter case 4, as it should check if x=4 before doing that, which is not true. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] Switch doubt in C
the cases are simple lables they have nothing to do with the flow of program. Saurabh Singh B.Tech (Computer Science) MNNIT blog:geekinessthecoolway.blogspot.com On Fri, Jun 29, 2012 at 3:14 PM, adarsh kumar algog...@gmail.com wrote: Doubt, very trivial though: #includestdio.h int main() { int x=3; switch(x) { case 1: x=1; break; case 2: x=2; break; case 3: x=3; break; default: x=0; break; case 4: x=4; break; } printf(%d,x) return 0; } gives an output of 3. But, #includestdio.h using namespace std; int main() { int x=3; switch(x) { case 1: x=1; case 2: x=2; case 3: x=3; default: x=0; case 4: x=4; } printf(%d,x); getch(); return 0; } gives an output of 4. My doubt is, in spite of the missing break statements in the second case, how will it enter case 4, as it should check if x=4 before doing that, which is not true. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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 Question: Segregrate positive and negative nos in array without changing order
The main idea of this question is *not to change order of occurrence.Dutch National flag other swapping like quick sort will change the order of occurrence of number try yourself with simple example for proof. From: Ravi Ranjan ravi.cool2...@gmail.com To: algogeeks@googlegroups.com Sent: Friday, 29 June 2012 3:06 PM Subject: Re: [algogeeks] MS Question: Segregrate positive and negative nos in array without changing order one can modify dutch national flag algo for two colors(2 types positive n negative) -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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 Question: Segregrate positive and negative nos in array without changing order
This is a variant of that one From: saurabh singh saurab...@gmail.com To: algogeeks@googlegroups.com Sent: Friday, 29 June 2012 3:05 PM Subject: Re: [algogeeks] MS Question: Segregrate positive and negative nos in array without changing order duplicate of a previous post.Kindly refer to that post. Saurabh Singh B.Tech (Computer Science) MNNIT blog:geekinessthecoolway.blogspot.com On Fri, Jun 29, 2012 at 10:41 AM, raghavan M peacelover1987...@yahoo.co.in wrote: Hi Question as in subject *No extra space (can use one extra space)-O(1) max *No order change allowed example: input : 1,-5,2,10,-100,-2 output: -5,-10,-100,1,2 input : -1,-5,10,11,15,-500,200,-10 output : -1,-5,-10,-500,-10,10,11,15 Thanks Raghavn -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] Switch doubt in C
your program enter at case 3: after that it kept falling in next cases as well hence x was assigned values x=0, x=0, and x=4 at the end.. and then exit the switch case... use print after every assignment u'll see that... On Fri, Jun 29, 2012 at 3:16 PM, saurabh singh saurab...@gmail.com wrote: the cases are simple lables they have nothing to do with the flow of program. Saurabh Singh B.Tech (Computer Science) MNNIT blog:geekinessthecoolway.blogspot.com On Fri, Jun 29, 2012 at 3:14 PM, adarsh kumar algog...@gmail.com wrote: Doubt, very trivial though: #includestdio.h int main() { int x=3; switch(x) { case 1: x=1; break; case 2: x=2; break; case 3: x=3; break; default: x=0; break; case 4: x=4; break; } printf(%d,x) return 0; } gives an output of 3. But, #includestdio.h using namespace std; int main() { int x=3; switch(x) { case 1: x=1; case 2: x=2; case 3: x=3; default: x=0; case 4: x=4; } printf(%d,x); getch(); return 0; } gives an output of 4. My doubt is, in spite of the missing break statements in the second case, how will it enter case 4, as it should check if x=4 before doing that, which is not true. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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. -- Praveen Sonare +91-7838908235 -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] Switch doubt in C
case 1: , case 2 : , case 3 , case 4 ...etc etc are just labels... so switch(x) just jumps to that case x and then move downward. so if you dont use break..it will keep checking following cases. On Fri, Jun 29, 2012 at 3:14 PM, adarsh kumar algog...@gmail.com wrote: Doubt, very trivial though: #includestdio.h int main() { int x=3; switch(x) { case 1: x=1; break; case 2: x=2; break; case 3: x=3; break; default: x=0; break; case 4: x=4; break; } printf(%d,x) return 0; } gives an output of 3. But, #includestdio.h using namespace std; int main() { int x=3; switch(x) { case 1: x=1; case 2: x=2; case 3: x=3; default: x=0; case 4: x=4; } printf(%d,x); getch(); return 0; } gives an output of 4. My doubt is, in spite of the missing break statements in the second case, how will it enter case 4, as it should check if x=4 before doing that, which is not true. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] Switch doubt in C
+1 atul If a matching label is found, execution proceeds from there. Control then passes down through all remaining labels within the switch statement. On Fri, Jun 29, 2012 at 3:28 PM, atul anand atul.87fri...@gmail.com wrote: case 1: , case 2 : , case 3 , case 4 ...etc etc are just labels... so switch(x) just jumps to that case x and then move downward. so if you dont use break..it will keep checking following cases. On Fri, Jun 29, 2012 at 3:14 PM, adarsh kumar algog...@gmail.com wrote: Doubt, very trivial though: #includestdio.h int main() { int x=3; switch(x) { case 1: x=1; break; case 2: x=2; break; case 3: x=3; break; default: x=0; break; case 4: x=4; break; } printf(%d,x) return 0; } gives an output of 3. But, #includestdio.h using namespace std; int main() { int x=3; switch(x) { case 1: x=1; case 2: x=2; case 3: x=3; default: x=0; case 4: x=4; } printf(%d,x); getch(); return 0; } gives an output of 4. My doubt is, in spite of the missing break statements in the second case, how will it enter case 4, as it should check if x=4 before doing that, which is not true. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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. -- Sharad Dixit -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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]
please someone explain lvalue and rvalue with example... for llvalue..please explain ++x++ also.. thanks. -- Vindhya Chhabra -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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]
l-values(left, literal meaning) appear on the lhs of a statement, and r-values vice versa. Essentially, l-values are identifiers. The memory location that will be thereby allocated can vary for r-values. Put in short, all l-values are r-values but not all r-values are l-values. And ++x++, will cause a compiler error saying non-lvalue in increment, if x is predefined. This means lvalues cannot be modified as such, like const ones. On Fri, Jun 29, 2012 at 4:28 PM, vindhya chhabra vindhyachha...@gmail.comwrote: please someone explain lvalue and rvalue with example... for llvalue..please explain ++x++ also.. thanks. -- Vindhya Chhabra -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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]
R-value - Contents of memory location ( ie value stored in that memory location ) L-Value - Name of that memory location suppose , int i=9; than here* r-value is 9* and* l-value is i* . Taking *++x++ ..* As Postfix ( ++ ) is having higher precendence over Prefix( ++ ) so Postfix will be evaluated first. then ++x++here *x++ *generates a temporary and you cant apply *prefix ++ *on a temporay ( generated as a result of an r-value expresiion ). Prefix increment operator requires its operand to be an lvalue ,, and x++ isnt an l-value ...that's why it would give error, . - ATul Singh | Computer Science Engineering| 2008-12 Batch | NIT Jalandhar | 9530739855 -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] Fixing Up The Binary Search Tree
calculate the balance factor for all nodes and find any node with factor 1 or factor -1 and perform AVL rotation from that node -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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]
l value - address r value - content of variable(value) ex- x=2 x has value and address but 2 has only value cout++x++ I think this will result into l error . PRAVEEN RAJ DELHI COLLEGE OF ENGINEERING -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] adobe
2 malloc(): int **a=(int **)malloc(sizeof(int *)*nrows); for(i=0;inrows;i++) a[i]=(int *)malloc(sizeof(int)*ncols); using only 1 malloc: int **a=(int **)malloc(sizeof(int *)*nrows+(nrows*ncols)*(sizeof(int))); for(i=0;inrows;i++) { a[i]=(int*)(a+nrows+i*ncols); } On Fri, Jun 29, 2012 at 4:46 PM, rahul r. srivastava rahul.ranjan...@gmail.com wrote: implement a 2d matrix using only 2 mallocs. -- 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/-/s4vvxtO2yVsJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] Question asked in Amazon Online Test
Given an integer expression in a prefix format (i.e. the operator precedes the number it is operating on) , print the expression in the post fix format . Example: If the integer expression is in the prefix format is *+56-78, the postfix format expression is 56+78-*. Both of these correspond to the expression (5+6)*(7-8). -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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]
@all thanks On Fri, Jun 29, 2012 at 6:33 PM, Atul Singh atulsingh7...@gmail.com wrote: R-value - Contents of memory location ( ie value stored in that memory location ) L-Value - Name of that memory location suppose , int i=9; than here* r-value is 9* and* l-value is i* . Taking *++x++ ..* As Postfix ( ++ ) is having higher precendence over Prefix( ++ ) so Postfix will be evaluated first. then ++x++here *x++ *generates a temporary and you cant apply *prefix ++ *on a temporay ( generated as a result of an r-value expresiion ). Prefix increment operator requires its operand to be an lvalue ,, and x++ isnt an l-value ...that's why it would give error, . - ATul Singh | Computer Science Engineering| 2008-12 Batch | NIT Jalandhar | 9530739855 -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Vindhya Chhabra -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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 Question: Segregrate positive and negative nos in array without changing order
If the order is important then I think we can use any stable sorting algorithm with the following comparison function int compare (int a ,int b) { if((a0b0)||(a0b0)) return 0; else return ab; } On Fri, Jun 29, 2012 at 3:37 PM, raghavan M peacelover1987...@yahoo.co.inwrote: This is a variant of that one -- *From:* saurabh singh saurab...@gmail.com *To:* algogeeks@googlegroups.com *Sent:* Friday, 29 June 2012 3:05 PM *Subject:* Re: [algogeeks] MS Question: Segregrate positive and negative nos in array without changing order duplicate of a previous post.Kindly refer to that post. Saurabh Singh B.Tech (Computer Science) MNNIT blog:geekinessthecoolway.blogspot.com On Fri, Jun 29, 2012 at 10:41 AM, raghavan M peacelover1987...@yahoo.co.in wrote: Hi Question as in subject *No extra space (can use one extra space)-O(1) max *No order change allowed example: input : 1,-5,2,10,-100,-2 output: -5,-10,-100,1,2 input : -1,-5,10,11,15,-500,200,-10 output : -1,-5,-10,-500,-10,10,11,15 Thanks Raghavn -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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, Bhaskar Kushwaha Student Final year CSE M.N.N.I.T. 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] MS Question: Segregrate positive and negative nos in array without changing order
@saurabh please provide the link to the post you are mentioning On Fri, Jun 29, 2012 at 8:38 PM, Bhaskar Kushwaha bhaskar.kushwaha2...@gmail.com wrote: If the order is important then I think we can use any stable sorting algorithm with the following comparison function int compare (int a ,int b) { if((a0b0)||(a0b0)) return 0; else return ab; } On Fri, Jun 29, 2012 at 3:37 PM, raghavan M peacelover1987...@yahoo.co.in wrote: This is a variant of that one -- *From:* saurabh singh saurab...@gmail.com *To:* algogeeks@googlegroups.com *Sent:* Friday, 29 June 2012 3:05 PM *Subject:* Re: [algogeeks] MS Question: Segregrate positive and negative nos in array without changing order duplicate of a previous post.Kindly refer to that post. Saurabh Singh B.Tech (Computer Science) MNNIT blog:geekinessthecoolway.blogspot.com On Fri, Jun 29, 2012 at 10:41 AM, raghavan M peacelover1987...@yahoo.co.in wrote: Hi Question as in subject *No extra space (can use one extra space)-O(1) max *No order change allowed example: input : 1,-5,2,10,-100,-2 output: -5,-10,-100,1,2 input : -1,-5,10,11,15,-500,200,-10 output : -1,-5,-10,-500,-10,10,11,15 Thanks Raghavn -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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, Bhaskar Kushwaha Student Final year CSE M.N.N.I.T. Allahabad -- regards, Bhaskar Kushwaha Student Final year CSE M.N.N.I.T. 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] MS Question: Segregrate positive and negative nos in array without changing order
@bhaskar:- please explain stable sorting algorithm you would use(as mainly all of them require extra space) @sourabh:- that previous post discussion does't lead to any correct soln On Fri, Jun 29, 2012 at 8:39 PM, Bhaskar Kushwaha bhaskar.kushwaha2...@gmail.com wrote: @saurabh please provide the link to the post you are mentioning On Fri, Jun 29, 2012 at 8:38 PM, Bhaskar Kushwaha bhaskar.kushwaha2...@gmail.com wrote: If the order is important then I think we can use any stable sorting algorithm with the following comparison function int compare (int a ,int b) { if((a0b0)||(a0b0)) return 0; else return ab; } On Fri, Jun 29, 2012 at 3:37 PM, raghavan M peacelover1987...@yahoo.co.in wrote: This is a variant of that one -- *From:* saurabh singh saurab...@gmail.com *To:* algogeeks@googlegroups.com *Sent:* Friday, 29 June 2012 3:05 PM *Subject:* Re: [algogeeks] MS Question: Segregrate positive and negative nos in array without changing order duplicate of a previous post.Kindly refer to that post. Saurabh Singh B.Tech (Computer Science) MNNIT blog:geekinessthecoolway.blogspot.com On Fri, Jun 29, 2012 at 10:41 AM, raghavan M peacelover1987...@yahoo.co.in wrote: Hi Question as in subject *No extra space (can use one extra space)-O(1) max *No order change allowed example: input : 1,-5,2,10,-100,-2 output: -5,-10,-100,1,2 input : -1,-5,10,11,15,-500,200,-10 output : -1,-5,-10,-500,-10,10,11,15 Thanks Raghavn -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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, Bhaskar Kushwaha Student Final year CSE M.N.N.I.T. Allahabad -- regards, Bhaskar Kushwaha Student Final year CSE M.N.N.I.T. 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. -- Utsav Sharma, 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: Microsoft Interview Question
+1 naveen On Thursday, June 28, 2012 8:29:26 PM UTC+5:30, Navin Gupta wrote: Keep two pointers - one at start of the array and other at end of the array Now current points to start of the array If current is negative , increment current If current is positive , swap it with the element at end and decrement current and end both If current = end , then break. Navin Kumar Gupta Final Year, B.Tech (Hons.) Computer Science Engg. National Institute of Technology,Jamshedpur Mobile - 8285303045 -- 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/-/hTWp_UkuDc8J. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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 Question: Segregrate positive and negative nos in array without changing order
Hi, this can be done by simple modification in bubble sort : void inplace_pos_neg(int pdata[],int sz) { bool changed=false; do { changed=false; for(int i=1;isz;i++) if(pdata[i-1]0 pdata[i]0) { swap(pdata[i-1], pdata[i]); changed=true; } }while(changed); } void test_inplace_pos_neg() { int a[]={-1,-5,10,11,15,-500,200,-10}; copy(a,a+sizeof(a)/sizeof(int),ostream_iteratorint(cout,,));coutendl; inplace_pos_neg(a,sizeof(a)/sizeof(int)); copy(a,a+sizeof(a)/sizeof(int),ostream_iteratorint(cout,,));coutendl; } Regards On Fri, Jun 29, 2012 at 7:52 PM, utsav sharma utsav.sharm...@gmail.comwrote: @bhaskar:- please explain stable sorting algorithm you would use(as mainly all of them require extra space) @sourabh:- that previous post discussion does't lead to any correct soln On Fri, Jun 29, 2012 at 8:39 PM, Bhaskar Kushwaha bhaskar.kushwaha2...@gmail.com wrote: @saurabh please provide the link to the post you are mentioning On Fri, Jun 29, 2012 at 8:38 PM, Bhaskar Kushwaha bhaskar.kushwaha2...@gmail.com wrote: If the order is important then I think we can use any stable sorting algorithm with the following comparison function int compare (int a ,int b) { if((a0b0)||(a0b0)) return 0; else return ab; } On Fri, Jun 29, 2012 at 3:37 PM, raghavan M peacelover1987...@yahoo.co.in wrote: This is a variant of that one -- *From:* saurabh singh saurab...@gmail.com *To:* algogeeks@googlegroups.com *Sent:* Friday, 29 June 2012 3:05 PM *Subject:* Re: [algogeeks] MS Question: Segregrate positive and negative nos in array without changing order duplicate of a previous post.Kindly refer to that post. Saurabh Singh B.Tech (Computer Science) MNNIT blog:geekinessthecoolway.blogspot.com On Fri, Jun 29, 2012 at 10:41 AM, raghavan M peacelover1987...@yahoo.co.in wrote: Hi Question as in subject *No extra space (can use one extra space)-O(1) max *No order change allowed example: input : 1,-5,2,10,-100,-2 output: -5,-10,-100,1,2 input : -1,-5,10,11,15,-500,200,-10 output : -1,-5,-10,-500,-10,10,11,15 Thanks Raghavn -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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, Bhaskar Kushwaha Student Final year CSE M.N.N.I.T. Allahabad -- regards, Bhaskar Kushwaha Student Final year CSE M.N.N.I.T. 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. -- Utsav Sharma, 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] Question asked in Amazon Online Test
I think just reversing the prefix notation converts it to postfix notation On Fri, Jun 29, 2012 at 7:46 PM, Gobind Kumar Hembram gobind@gmail.comwrote: Given an integer expression in a prefix format (i.e. the operator precedes the number it is operating on) , print the expression in the post fix format . Example: If the integer expression is in the prefix format is *+56-78, the postfix format expression is 56+78-*. Both of these correspond to the expression (5+6)*(7-8). -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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, Bhaskar Kushwaha Student Final year CSE M.N.N.I.T. 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] MS Question: Segregrate positive and negative nos in array without changing order
@Hassan I think your algo will take time O(n^2) in worst case which occurs when all elements are negative except the last one @everyone Can we solve this problem in linear time? On Fri, Jun 29, 2012 at 9:10 PM, Hassan Monfared hmonfa...@gmail.comwrote: Hi, this can be done by simple modification in bubble sort : void inplace_pos_neg(int pdata[],int sz) { bool changed=false; do { changed=false; for(int i=1;isz;i++) if(pdata[i-1]0 pdata[i]0) { swap(pdata[i-1], pdata[i]); changed=true; } }while(changed); } void test_inplace_pos_neg() { int a[]={-1,-5,10,11,15,-500,200,-10}; copy(a,a+sizeof(a)/sizeof(int),ostream_iteratorint(cout,,));coutendl; inplace_pos_neg(a,sizeof(a)/sizeof(int)); copy(a,a+sizeof(a)/sizeof(int),ostream_iteratorint(cout,,));coutendl; } Regards On Fri, Jun 29, 2012 at 7:52 PM, utsav sharma utsav.sharm...@gmail.comwrote: @bhaskar:- please explain stable sorting algorithm you would use(as mainly all of them require extra space) @sourabh:- that previous post discussion does't lead to any correct soln On Fri, Jun 29, 2012 at 8:39 PM, Bhaskar Kushwaha bhaskar.kushwaha2...@gmail.com wrote: @saurabh please provide the link to the post you are mentioning On Fri, Jun 29, 2012 at 8:38 PM, Bhaskar Kushwaha bhaskar.kushwaha2...@gmail.com wrote: If the order is important then I think we can use any stable sorting algorithm with the following comparison function int compare (int a ,int b) { if((a0b0)||(a0b0)) return 0; else return ab; } On Fri, Jun 29, 2012 at 3:37 PM, raghavan M peacelover1987...@yahoo.co.in wrote: This is a variant of that one -- *From:* saurabh singh saurab...@gmail.com *To:* algogeeks@googlegroups.com *Sent:* Friday, 29 June 2012 3:05 PM *Subject:* Re: [algogeeks] MS Question: Segregrate positive and negative nos in array without changing order duplicate of a previous post.Kindly refer to that post. Saurabh Singh B.Tech (Computer Science) MNNIT blog:geekinessthecoolway.blogspot.com On Fri, Jun 29, 2012 at 10:41 AM, raghavan M peacelover1987...@yahoo.co.in wrote: Hi Question as in subject *No extra space (can use one extra space)-O(1) max *No order change allowed example: input : 1,-5,2,10,-100,-2 output: -5,-10,-100,1,2 input : -1,-5,10,11,15,-500,200,-10 output : -1,-5,-10,-500,-10,10,11,15 Thanks Raghavn -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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, Bhaskar Kushwaha Student Final year CSE M.N.N.I.T. Allahabad -- regards, Bhaskar Kushwaha Student Final year CSE M.N.N.I.T. 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. -- Utsav Sharma, 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, Bhaskar Kushwaha Student Final year CSE M.N.N.I.T. 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] Re: Microsoft Interview Question
@Navin: Try this with {1,-1,2}. current points to the 1 and end points to the 2. Since 1 is positive, the algorithm swaps the 1 and the 2, giving {2,-1,1}. Then it decrements current to point outside the array and end to point to the -1. How can this be right? Dave On Thursday, June 28, 2012 9:59:26 AM UTC-5, Navin Gupta wrote: Keep two pointers - one at start of the array and other at end of the array Now current points to start of the array If current is negative , increment current If current is positive , swap it with the element at end and decrement current and end both If current = end , then break. Navin Kumar Gupta Final Year, B.Tech (Hons.) Computer Science Engg. National Institute of Technology,Jamshedpur Mobile - 8285303045 -- 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/-/JW4NPf7xBTkJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] Question asked in Amazon Online Test
@bhaskar ur algo fails on this case (5+3)-(2+(3/6)) -+53+2/36 63/2+35-+ showing that 6/3 but actually it is 3/6 so i think it could be done by folowing algo make a binary tree of given expression in O(n) then do postorder traversal take O(n) so problem can be solved in O(n). and take O(2*n+1) space On Fri, Jun 29, 2012 at 9:13 PM, Bhaskar Kushwaha bhaskar.kushwaha2...@gmail.com wrote: I think just reversing the prefix notation converts it to postfix notation On Fri, Jun 29, 2012 at 7:46 PM, Gobind Kumar Hembram gobind@gmail.com wrote: Given an integer expression in a prefix format (i.e. the operator precedes the number it is operating on) , print the expression in the post fix format . Example: If the integer expression is in the prefix format is *+56-78, the postfix format expression is 56+78-*. Both of these correspond to the expression (5+6)*(7-8). -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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, Bhaskar Kushwaha Student Final year CSE M.N.N.I.T. 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. -- Thanks Regards Amritpal singh -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] Question asked in Amazon Online Test
oh bhai mere. kewal preorder use karke kaise tree bana dega??? On Fri, Jun 29, 2012 at 11:23 PM, amrit harry dabbcomput...@gmail.comwrote: @bhaskar ur algo fails on this case (5+3)-(2+(3/6)) -+53+2/36 63/2+35-+ showing that 6/3 but actually it is 3/6 so i think it could be done by folowing algo make a binary tree of given expression in O(n) then do postorder traversal take O(n) so problem can be solved in O(n). and take O(2*n+1) space On Fri, Jun 29, 2012 at 9:13 PM, Bhaskar Kushwaha bhaskar.kushwaha2...@gmail.com wrote: I think just reversing the prefix notation converts it to postfix notation On Fri, Jun 29, 2012 at 7:46 PM, Gobind Kumar Hembram gobind@gmail.com wrote: Given an integer expression in a prefix format (i.e. the operator precedes the number it is operating on) , print the expression in the post fix format . Example: If the integer expression is in the prefix format is *+56-78, the postfix format expression is 56+78-*. Both of these correspond to the expression (5+6)*(7-8). -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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, Bhaskar Kushwaha Student Final year CSE M.N.N.I.T. 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. -- Thanks Regards Amritpal singh -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] Question asked in Amazon Online Test
convert prefix to infix,then convert infix to postfix.Now, to convert prefix to infix, push numbers in one stack and operators in other.Then use thishttp://www.velocityreviews.com/forums/t445633-prefix-to-infix-conversion.html algo to perform this.Then do the same for infix to postfix.It works with simple operators,but difficult to implement with parenthesis. On Sat, Jun 30, 2012 at 12:21 AM, rahul ranjan rahul.ranjan...@gmail.comwrote: oh bhai mere. kewal preorder use karke kaise tree bana dega??? On Fri, Jun 29, 2012 at 11:23 PM, amrit harry dabbcomput...@gmail.comwrote: @bhaskar ur algo fails on this case (5+3)-(2+(3/6)) -+53+2/36 63/2+35-+ showing that 6/3 but actually it is 3/6 so i think it could be done by folowing algo make a binary tree of given expression in O(n) then do postorder traversal take O(n) so problem can be solved in O(n). and take O(2*n+1) space On Fri, Jun 29, 2012 at 9:13 PM, Bhaskar Kushwaha bhaskar.kushwaha2...@gmail.com wrote: I think just reversing the prefix notation converts it to postfix notation On Fri, Jun 29, 2012 at 7:46 PM, Gobind Kumar Hembram gobind@gmail.com wrote: Given an integer expression in a prefix format (i.e. the operator precedes the number it is operating on) , print the expression in the post fix format . Example: If the integer expression is in the prefix format is *+56-78, the postfix format expression is 56+78-*. Both of these correspond to the expression (5+6)*(7-8). -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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, Bhaskar Kushwaha Student Final year CSE M.N.N.I.T. 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. -- Thanks Regards Amritpal singh -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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. -- Abhishek Sharma Under-Graduate Student, PEC University of Technology -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] Question asked in Amazon Online Test
reverse the prefix notation and then reverse each continuous occurence of operands On Sat, Jun 30, 2012 at 12:50 AM, Abhishek Sharma abhi120...@gmail.comwrote: convert prefix to infix,then convert infix to postfix.Now, to convert prefix to infix, push numbers in one stack and operators in other.Then use thishttp://www.velocityreviews.com/forums/t445633-prefix-to-infix-conversion.html algo to perform this.Then do the same for infix to postfix.It works with simple operators,but difficult to implement with parenthesis. On Sat, Jun 30, 2012 at 12:21 AM, rahul ranjan rahul.ranjan...@gmail.comwrote: oh bhai mere. kewal preorder use karke kaise tree bana dega??? On Fri, Jun 29, 2012 at 11:23 PM, amrit harry dabbcomput...@gmail.comwrote: @bhaskar ur algo fails on this case (5+3)-(2+(3/6)) -+53+2/36 63/2+35-+ showing that 6/3 but actually it is 3/6 so i think it could be done by folowing algo make a binary tree of given expression in O(n) then do postorder traversal take O(n) so problem can be solved in O(n). and take O(2*n+1) space On Fri, Jun 29, 2012 at 9:13 PM, Bhaskar Kushwaha bhaskar.kushwaha2...@gmail.com wrote: I think just reversing the prefix notation converts it to postfix notation On Fri, Jun 29, 2012 at 7:46 PM, Gobind Kumar Hembram gobind@gmail.com wrote: Given an integer expression in a prefix format (i.e. the operator precedes the number it is operating on) , print the expression in the post fix format . Example: If the integer expression is in the prefix format is *+56-78, the postfix format expression is 56+78-*. Both of these correspond to the expression (5+6)*(7-8). -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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, Bhaskar Kushwaha Student Final year CSE M.N.N.I.T. 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. -- Thanks Regards Amritpal singh -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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. -- Abhishek Sharma Under-Graduate Student, PEC University of Technology -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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, Bhaskar Kushwaha Student Final year CSE M.N.N.I.T. 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] Question asked in Amazon Online Test
example -+53+2/36 step 1: 63/2+35+- step 2: 36/2+53+- On Sat, Jun 30, 2012 at 1:55 AM, Bhaskar Kushwaha bhaskar.kushwaha2...@gmail.com wrote: reverse the prefix notation and then reverse each continuous occurence of operands On Sat, Jun 30, 2012 at 12:50 AM, Abhishek Sharma abhi120...@gmail.comwrote: convert prefix to infix,then convert infix to postfix.Now, to convert prefix to infix, push numbers in one stack and operators in other.Then use thishttp://www.velocityreviews.com/forums/t445633-prefix-to-infix-conversion.html algo to perform this.Then do the same for infix to postfix.It works with simple operators,but difficult to implement with parenthesis. On Sat, Jun 30, 2012 at 12:21 AM, rahul ranjan rahul.ranjan...@gmail.com wrote: oh bhai mere. kewal preorder use karke kaise tree bana dega??? On Fri, Jun 29, 2012 at 11:23 PM, amrit harry dabbcomput...@gmail.comwrote: @bhaskar ur algo fails on this case (5+3)-(2+(3/6)) -+53+2/36 63/2+35-+ showing that 6/3 but actually it is 3/6 so i think it could be done by folowing algo make a binary tree of given expression in O(n) then do postorder traversal take O(n) so problem can be solved in O(n). and take O(2*n+1) space On Fri, Jun 29, 2012 at 9:13 PM, Bhaskar Kushwaha bhaskar.kushwaha2...@gmail.com wrote: I think just reversing the prefix notation converts it to postfix notation On Fri, Jun 29, 2012 at 7:46 PM, Gobind Kumar Hembram gobind@gmail.com wrote: Given an integer expression in a prefix format (i.e. the operator precedes the number it is operating on) , print the expression in the post fix format . Example: If the integer expression is in the prefix format is *+56-78, the postfix format expression is 56+78-*. Both of these correspond to the expression (5+6)*(7-8). -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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, Bhaskar Kushwaha Student Final year CSE M.N.N.I.T. 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. -- Thanks Regards Amritpal singh -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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. -- Abhishek Sharma Under-Graduate Student, PEC University of Technology -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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, Bhaskar Kushwaha Student Final year CSE M.N.N.I.T. Allahabad -- regards, Bhaskar Kushwaha Student Final year CSE M.N.N.I.T. 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.