Re: [algogeeks] reverse a string efficiently
Technically linear! On Mon, Nov 26, 2012 at 9:47 PM, shady sinv...@gmail.com wrote: what is the time complexity of this? str_reverse(str){ if(isempty(str)) return str; else if(length(str) = even) then split str into str_1 and str_2; (of equal length) (Calculate mid =O(1), then extract(0,mid) , extract(mid+1,end) return str_reverse(str_2)+str_reverse(str_1); Reversals again have linear dependence on length. else split str into str_1, str_2, str_3; //if str is odd length, e.g. len = 7, split by 1-3 | 4 | 5-7 return str_reverse(str_3)+str_2+str_reverse(str_1); } Similar argument for the odd length stuff. So the net complexity is in fact linear. --
Re: [algogeeks] reverse a string efficiently
Yes, my bad. I din notice the recursion at all! Thot it to be a flat mid-split followed by a reverse followed by a concat. Thanks. On Mon, Nov 26, 2012 at 11:18 PM, atul anand atul.87fri...@gmail.comwrote: considering '+' , here will take Cn time . Here '+' is for concatenate , now this concatenation taking place in constant time?? , i dont think so..internally it will be adding elements to new m/m space and for that it need to traverse each character...so it will take cn time. so T(n) =T(n/2) + cn = nlogn On Tue, Nov 27, 2012 at 11:17 AM, shady sinv...@gmail.com wrote: what is the time complexity of this? str_reverse(str){ if(isempty(str)) return str; else if(length(str) = even) then split str into str_1 and str_2; (of equal length) return str_reverse(str_2)+str_reverse(str_1); else split str into str_1, str_2, str_3; //if str is odd length, e.g. len = 7, split by 1-3 | 4 | 5-7 return str_reverse(str_3)+str_2+str_reverse(str_1); } -- -- --
Re: [algogeeks] reverse a string efficiently
considering '+' , here will take Cn time . Here '+' is for concatenate , now this concatenation taking place in constant time?? , i dont think so..internally it will be adding elements to new m/m space and for that it need to traverse each character...so it will take cn time. so T(n) =T(n/2) + cn = nlogn On Tue, Nov 27, 2012 at 11:17 AM, shady sinv...@gmail.com wrote: what is the time complexity of this? str_reverse(str){ if(isempty(str)) return str; else if(length(str) = even) then split str into str_1 and str_2; (of equal length) return str_reverse(str_2)+str_reverse(str_1); else split str into str_1, str_2, str_3; //if str is odd length, e.g. len = 7, split by 1-3 | 4 | 5-7 return str_reverse(str_3)+str_2+str_reverse(str_1); } -- --
Re: [algogeeks] Reverse Queue
recursion internally uses one stack for maintaining the return addresses.which all we need... :-) On Friday, June 22, 2012 11:38:39 AM UTC+5:30, joker wrote: @ALL this shud work :-) #includeiostream #includequeue using namespace std; queueint Q; void rev() { if(!Q.empty()) { int x=Q.front(); Q.pop(); rev(); Q.push(x); } } main() { for(int i=1;i12;i++) Q.push(i); rev(); while(!Q.empty()) { int x=Q.front(); Q.pop(); printf(%d ,x); } system(pause); } On Thu, Jun 21, 2012 at 12:14 PM, sanjay pandey sanjaypandey...@gmail.com wrote: it seems @hassan sol is correctcan nybody knw d flaw in it??? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. On Friday, June 22, 2012 11:38:39 AM UTC+5:30, joker wrote: @ALL this shud work :-) #includeiostream #includequeue using namespace std; queueint Q; void rev() { if(!Q.empty()) { int x=Q.front(); Q.pop(); rev(); Q.push(x); } } main() { for(int i=1;i12;i++) Q.push(i); rev(); while(!Q.empty()) { int x=Q.front(); Q.pop(); printf(%d ,x); } system(pause); } On Thu, Jun 21, 2012 at 12:14 PM, sanjay pandey sanjaypandey...@gmail.com wrote: it seems @hassan sol is correctcan nybody knw d flaw in it??? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. On Friday, June 22, 2012 11:38:39 AM UTC+5:30, joker wrote: @ALL this shud work :-) #includeiostream #includequeue using namespace std; queueint Q; void rev() { if(!Q.empty()) { int x=Q.front(); Q.pop(); rev(); Q.push(x); } } main() { for(int i=1;i12;i++) Q.push(i); rev(); while(!Q.empty()) { int x=Q.front(); Q.pop(); printf(%d ,x); } system(pause); } On Thu, Jun 21, 2012 at 12:14 PM, sanjay pandey sanjaypandey...@gmail.com wrote: it seems @hassan sol is correctcan nybody knw d flaw in it??? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. On Friday, June 22, 2012 11:38:39 AM UTC+5:30, joker wrote: @ALL this shud work :-) #includeiostream #includequeue using namespace std; queueint Q; void rev() { if(!Q.empty()) { int x=Q.front(); Q.pop(); rev(); Q.push(x); } } main() { for(int i=1;i12;i++) Q.push(i); rev(); while(!Q.empty()) { int x=Q.front(); Q.pop(); printf(%d ,x); } system(pause); } On Thu, Jun 21, 2012 at 12:14 PM, sanjay pandey sanjaypandey...@gmail.com wrote: it seems @hassan sol is correctcan nybody knw d flaw in it??? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To view this discussion on the web visit https://groups.google.com/d/msg/algogeeks/-/rKd4pNXXxLoJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] Reverse Queue
@ALL this shud work :-) #includeiostream #includequeue using namespace std; queueint Q; void rev() { if(!Q.empty()) { int x=Q.front(); Q.pop(); rev(); Q.push(x); } } main() { for(int i=1;i12;i++) Q.push(i); rev(); while(!Q.empty()) { int x=Q.front(); Q.pop(); printf(%d ,x); } system(pause); } On Thu, Jun 21, 2012 at 12:14 PM, sanjay pandey sanjaypandey...@gmail.com wrote: it seems @hassan sol is correctcan nybody knw d flaw in it??? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Reverse Queue
it seems @hassan sol is correctcan nybody knw d flaw in it??? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Reverse Queue
count the size of queue : O(n) loop for n and do remove and add in queue : O(n) Total : O(n) On Wed, Jun 20, 2012 at 6:34 PM, Navin Kumar algorithm.i...@gmail.comwrote: How to reverse a Queue . Constraints: Time complexity O(n). space complexity: O(1) -- 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/-/kepls-8qRwgJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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, Saurabh -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] Reverse Queue
@Saurabh: queue will be remain unchanged according to your algorithm. Because if you will delete an element from front and add at rear no change will be there. After n iteration front will be pointing to same element and rear will also point to same element. Correct me if i am wrong. :) On Wed, Jun 20, 2012 at 6:39 PM, saurabh singh saurabh.n...@gmail.comwrote: count the size of queue : O(n) loop for n and do remove and add in queue : O(n) Total : O(n) On Wed, Jun 20, 2012 at 6:34 PM, Navin Kumar algorithm.i...@gmail.comwrote: How to reverse a Queue . Constraints: Time complexity O(n). space complexity: O(1) -- 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/-/kepls-8qRwgJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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, Saurabh -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] Reverse Queue
For ex: let only two element are in queue: 1 2 (1 at front and rear is at 2). looping two times: first time: delete from front and adding to rear: queue will be: 2 1(front at 2 , rear at 1) second iteration: deleting 2 and adding to queue :result will be: 1 2 (front 1, rear 2) On Wed, Jun 20, 2012 at 6:46 PM, Navin Kumar algorithm.i...@gmail.comwrote: @Saurabh: queue will be remain unchanged according to your algorithm. Because if you will delete an element from front and add at rear no change will be there. After n iteration front will be pointing to same element and rear will also point to same element. Correct me if i am wrong. :) On Wed, Jun 20, 2012 at 6:39 PM, saurabh singh saurabh.n...@gmail.comwrote: count the size of queue : O(n) loop for n and do remove and add in queue : O(n) Total : O(n) On Wed, Jun 20, 2012 at 6:34 PM, Navin Kumar algorithm.i...@gmail.comwrote: How to reverse a Queue . Constraints: Time complexity O(n). space complexity: O(1) -- 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/-/kepls-8qRwgJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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, Saurabh -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] Reverse Queue
I meant do it for n-1 times (my focus was on time complexity).Try with more examples and you will know :) On Wed, Jun 20, 2012 at 6:50 PM, Navin Kumar algorithm.i...@gmail.comwrote: For ex: let only two element are in queue: 1 2 (1 at front and rear is at 2). looping two times: first time: delete from front and adding to rear: queue will be: 2 1(front at 2 , rear at 1) second iteration: deleting 2 and adding to queue :result will be: 1 2 (front 1, rear 2) On Wed, Jun 20, 2012 at 6:46 PM, Navin Kumar algorithm.i...@gmail.comwrote: @Saurabh: queue will be remain unchanged according to your algorithm. Because if you will delete an element from front and add at rear no change will be there. After n iteration front will be pointing to same element and rear will also point to same element. Correct me if i am wrong. :) On Wed, Jun 20, 2012 at 6:39 PM, saurabh singh saurabh.n...@gmail.comwrote: count the size of queue : O(n) loop for n and do remove and add in queue : O(n) Total : O(n) On Wed, Jun 20, 2012 at 6:34 PM, Navin Kumar algorithm.i...@gmail.comwrote: How to reverse a Queue . Constraints: Time complexity O(n). space complexity: O(1) -- 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/-/kepls-8qRwgJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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, Saurabh -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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. -- Thanks Regards, Saurabh -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] Reverse Queue
can we create other methods or we have to use only enqueue and dequeue...? if yes then simply for(i=0;i=n/2;i++) swap(i,n-i); On Wed, Jun 20, 2012 at 6:46 PM, Navin Kumar algorithm.i...@gmail.comwrote: @Saurabh: queue will be remain unchanged according to your algorithm. Because if you will delete an element from front and add at rear no change will be there. After n iteration front will be pointing to same element and rear will also point to same element. Correct me if i am wrong. :) On Wed, Jun 20, 2012 at 6:39 PM, saurabh singh saurabh.n...@gmail.comwrote: count the size of queue : O(n) loop for n and do remove and add in queue : O(n) Total : O(n) On Wed, Jun 20, 2012 at 6:34 PM, Navin Kumar algorithm.i...@gmail.comwrote: How to reverse a Queue . Constraints: Time complexity O(n). space complexity: O(1) -- 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/-/kepls-8qRwgJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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, Saurabh -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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. -- 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] Reverse Queue
Use only standard operation of Queue like: EnQueue, DeQueue, IsEmptyQueue etc On Wed, Jun 20, 2012 at 6:50 PM, amrit harry dabbcomput...@gmail.comwrote: can we create other methods or we have to use only enqueue and dequeue...? if yes then simply for(i=0;i=n/2;i++) swap(i,n-i); On Wed, Jun 20, 2012 at 6:46 PM, Navin Kumar algorithm.i...@gmail.comwrote: @Saurabh: queue will be remain unchanged according to your algorithm. Because if you will delete an element from front and add at rear no change will be there. After n iteration front will be pointing to same element and rear will also point to same element. Correct me if i am wrong. :) On Wed, Jun 20, 2012 at 6:39 PM, saurabh singh saurabh.n...@gmail.comwrote: count the size of queue : O(n) loop for n and do remove and add in queue : O(n) Total : O(n) On Wed, Jun 20, 2012 at 6:34 PM, Navin Kumar algorithm.i...@gmail.comwrote: How to reverse a Queue . Constraints: Time complexity O(n). space complexity: O(1) -- 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/-/kepls-8qRwgJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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, Saurabh -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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. -- 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] Reverse Queue
You could use recursion. def reverse_Q q if !q.isEmpty? el = q.dequeue nQ = reverse_Q(q) nQ.enqueue el return nQ end return q end On Wednesday, June 20, 2012 6:57:23 PM UTC+5:30, Navin Kumar wrote: Use only standard operation of Queue like: EnQueue, DeQueue, IsEmptyQueue etc On Wed, Jun 20, 2012 at 6:50 PM, amrit harry dabbcomput...@gmail.comwrote: can we create other methods or we have to use only enqueue and dequeue...? if yes then simply for(i=0;i=n/2;i++) swap(i,n-i); On Wed, Jun 20, 2012 at 6:46 PM, Navin Kumar algorithm.i...@gmail.comwrote: @Saurabh: queue will be remain unchanged according to your algorithm. Because if you will delete an element from front and add at rear no change will be there. After n iteration front will be pointing to same element and rear will also point to same element. Correct me if i am wrong. :) On Wed, Jun 20, 2012 at 6:39 PM, saurabh singh saurabh.n...@gmail.comwrote: count the size of queue : O(n) loop for n and do remove and add in queue : O(n) Total : O(n) On Wed, Jun 20, 2012 at 6:34 PM, Navin Kumar algorithm.i...@gmail.comwrote: How to reverse a Queue . Constraints: Time complexity O(n). space complexity: O(1) -- 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/-/kepls-8qRwgJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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, Saurabh -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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. -- 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 view this discussion on the web visit https://groups.google.com/d/msg/algogeeks/-/qmLUaTNJns8J. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] Reverse Queue
@Kirubakaran : still space complexity is O(n) due to stack.Can it be solved in space complexity O(1). On Wed, Jun 20, 2012 at 8:00 PM, Kirubakaran D kirubakara...@gmail.comwrote: You could use recursion. def reverse_Q q if !q.isEmpty? el = q.dequeue nQ = reverse_Q(q) nQ.enqueue el return nQ end return q end On Wednesday, June 20, 2012 6:57:23 PM UTC+5:30, Navin Kumar wrote: Use only standard operation of Queue like: EnQueue, DeQueue, IsEmptyQueue etc On Wed, Jun 20, 2012 at 6:50 PM, amrit harry dabbcomput...@gmail.comwrote: can we create other methods or we have to use only enqueue and dequeue...? if yes then simply for(i=0;i=n/2;i++) swap(i,n-i); On Wed, Jun 20, 2012 at 6:46 PM, Navin Kumar algorithm.i...@gmail.comwrote: @Saurabh: queue will be remain unchanged according to your algorithm. Because if you will delete an element from front and add at rear no change will be there. After n iteration front will be pointing to same element and rear will also point to same element. Correct me if i am wrong. :) On Wed, Jun 20, 2012 at 6:39 PM, saurabh singh saurabh.n...@gmail.comwrote: count the size of queue : O(n) loop for n and do remove and add in queue : O(n) Total : O(n) On Wed, Jun 20, 2012 at 6:34 PM, Navin Kumar algorithm.i...@gmail.com wrote: How to reverse a Queue . Constraints: Time complexity O(n). space complexity: O(1) -- 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/-/kepls-8qRwgJhttps://groups.google.com/d/msg/algogeeks/-/kepls-8qRwgJ . To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscribe@* *googlegroups.com algogeeks%2bunsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/** group/algogeeks?hl=enhttp://groups.google.com/group/algogeeks?hl=en . -- Thanks Regards, Saurabh -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscribe@** googlegroups.com algogeeks%2bunsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/** group/algogeeks?hl=en 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+unsubscribe@** googlegroups.com algogeeks%2bunsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/** group/algogeeks?hl=en 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+unsubscribe@** googlegroups.com algogeeks%2bunsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/** group/algogeeks?hl=en http://groups.google.com/group/algogeeks?hl=en. -- 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/-/qmLUaTNJns8J. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] Reverse Queue
Why will my proposed solution not work for you ??? On Wed, Jun 20, 2012 at 8:19 PM, Navin Kumar algorithm.i...@gmail.comwrote: @Kirubakaran : still space complexity is O(n) due to stack.Can it be solved in space complexity O(1). On Wed, Jun 20, 2012 at 8:00 PM, Kirubakaran D kirubakara...@gmail.comwrote: You could use recursion. def reverse_Q q if !q.isEmpty? el = q.dequeue nQ = reverse_Q(q) nQ.enqueue el return nQ end return q end On Wednesday, June 20, 2012 6:57:23 PM UTC+5:30, Navin Kumar wrote: Use only standard operation of Queue like: EnQueue, DeQueue, IsEmptyQueue etc On Wed, Jun 20, 2012 at 6:50 PM, amrit harry dabbcomput...@gmail.comwrote: can we create other methods or we have to use only enqueue and dequeue...? if yes then simply for(i=0;i=n/2;i++) swap(i,n-i); On Wed, Jun 20, 2012 at 6:46 PM, Navin Kumar algorithm.i...@gmail.comwrote: @Saurabh: queue will be remain unchanged according to your algorithm. Because if you will delete an element from front and add at rear no change will be there. After n iteration front will be pointing to same element and rear will also point to same element. Correct me if i am wrong. :) On Wed, Jun 20, 2012 at 6:39 PM, saurabh singh saurabh.n...@gmail.com wrote: count the size of queue : O(n) loop for n and do remove and add in queue : O(n) Total : O(n) On Wed, Jun 20, 2012 at 6:34 PM, Navin Kumar algorithm.i...@gmail.com wrote: How to reverse a Queue . Constraints: Time complexity O(n). space complexity: O(1) -- 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/-/kepls-8qRwgJhttps://groups.google.com/d/msg/algogeeks/-/kepls-8qRwgJ . To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscribe@ **googlegroups.com algogeeks%2bunsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/** group/algogeeks?hl=enhttp://groups.google.com/group/algogeeks?hl=en . -- Thanks Regards, Saurabh -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscribe@* *googlegroups.com algogeeks%2bunsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/** group/algogeeks?hl=enhttp://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+unsubscribe@** googlegroups.com algogeeks%2bunsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/** group/algogeeks?hl=en 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+unsubscribe@** googlegroups.com algogeeks%2bunsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/** group/algogeeks?hl=en http://groups.google.com/group/algogeeks?hl=en. -- 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/-/qmLUaTNJns8J. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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. -- Thanks Regards, Saurabh -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] Reverse Queue
@saurabh : i want solution with space complexity of O(1) . your solution is right but it takes O(n) space. On Wed, Jun 20, 2012 at 8:28 PM, saurabh singh saurabh.n...@gmail.comwrote: Why will my proposed solution not work for you ??? On Wed, Jun 20, 2012 at 8:19 PM, Navin Kumar algorithm.i...@gmail.comwrote: @Kirubakaran : still space complexity is O(n) due to stack.Can it be solved in space complexity O(1). On Wed, Jun 20, 2012 at 8:00 PM, Kirubakaran D kirubakara...@gmail.comwrote: You could use recursion. def reverse_Q q if !q.isEmpty? el = q.dequeue nQ = reverse_Q(q) nQ.enqueue el return nQ end return q end On Wednesday, June 20, 2012 6:57:23 PM UTC+5:30, Navin Kumar wrote: Use only standard operation of Queue like: EnQueue, DeQueue, IsEmptyQueue etc On Wed, Jun 20, 2012 at 6:50 PM, amrit harry dabbcomput...@gmail.comwrote: can we create other methods or we have to use only enqueue and dequeue...? if yes then simply for(i=0;i=n/2;i++) swap(i,n-i); On Wed, Jun 20, 2012 at 6:46 PM, Navin Kumar algorithm.i...@gmail.com wrote: @Saurabh: queue will be remain unchanged according to your algorithm. Because if you will delete an element from front and add at rear no change will be there. After n iteration front will be pointing to same element and rear will also point to same element. Correct me if i am wrong. :) On Wed, Jun 20, 2012 at 6:39 PM, saurabh singh saurabh.n...@gmail.com wrote: count the size of queue : O(n) loop for n and do remove and add in queue : O(n) Total : O(n) On Wed, Jun 20, 2012 at 6:34 PM, Navin Kumar algorithm.i...@gmail.com wrote: How to reverse a Queue . Constraints: Time complexity O(n). space complexity: O(1) -- 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/-/kepls-8qRwgJhttps://groups.google.com/d/msg/algogeeks/-/kepls-8qRwgJ . To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscribe@**googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/** group/algogeeks?hl=enhttp://groups.google.com/group/algogeeks?hl=en . -- Thanks Regards, Saurabh -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscribe@ **googlegroups.com algogeeks%2bunsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/** group/algogeeks?hl=enhttp://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+unsubscribe@* *googlegroups.com algogeeks%2bunsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/** group/algogeeks?hl=enhttp://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+unsubscribe@** googlegroups.com algogeeks%2bunsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/** group/algogeeks?hl=en http://groups.google.com/group/algogeeks?hl=en . -- 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/-/qmLUaTNJns8J. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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. -- Thanks Regards, Saurabh -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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
Re: [algogeeks] Reverse Queue
How ?? I am asking to manipulate the same queue. Dequeue n-1 elements and enqueue them in order to you take out to the same queue..Where is extra space involved ? On Wed, Jun 20, 2012 at 8:36 PM, Navin Kumar algorithm.i...@gmail.comwrote: @saurabh : i want solution with space complexity of O(1) . your solution is right but it takes O(n) space. On Wed, Jun 20, 2012 at 8:28 PM, saurabh singh saurabh.n...@gmail.comwrote: Why will my proposed solution not work for you ??? On Wed, Jun 20, 2012 at 8:19 PM, Navin Kumar algorithm.i...@gmail.comwrote: @Kirubakaran : still space complexity is O(n) due to stack.Can it be solved in space complexity O(1). On Wed, Jun 20, 2012 at 8:00 PM, Kirubakaran D kirubakara...@gmail.comwrote: You could use recursion. def reverse_Q q if !q.isEmpty? el = q.dequeue nQ = reverse_Q(q) nQ.enqueue el return nQ end return q end On Wednesday, June 20, 2012 6:57:23 PM UTC+5:30, Navin Kumar wrote: Use only standard operation of Queue like: EnQueue, DeQueue, IsEmptyQueue etc On Wed, Jun 20, 2012 at 6:50 PM, amrit harry dabbcomput...@gmail.comwrote: can we create other methods or we have to use only enqueue and dequeue...? if yes then simply for(i=0;i=n/2;i++) swap(i,n-i); On Wed, Jun 20, 2012 at 6:46 PM, Navin Kumar algorithm.i...@gmail.com wrote: @Saurabh: queue will be remain unchanged according to your algorithm. Because if you will delete an element from front and add at rear no change will be there. After n iteration front will be pointing to same element and rear will also point to same element. Correct me if i am wrong. :) On Wed, Jun 20, 2012 at 6:39 PM, saurabh singh saurabh.n...@gmail.com wrote: count the size of queue : O(n) loop for n and do remove and add in queue : O(n) Total : O(n) On Wed, Jun 20, 2012 at 6:34 PM, Navin Kumar algorithm.i...@gmail.com wrote: How to reverse a Queue . Constraints: Time complexity O(n). space complexity: O(1) -- 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/-/kepls-8qRwgJhttps://groups.google.com/d/msg/algogeeks/-/kepls-8qRwgJ . To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscribe@**googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/** group/algogeeks?hl=enhttp://groups.google.com/group/algogeeks?hl=en . -- Thanks Regards, Saurabh -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscribe@**googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/** group/algogeeks?hl=enhttp://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+unsubscribe@ **googlegroups.com algogeeks%2bunsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/** group/algogeeks?hl=enhttp://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+unsubscribe@* *googlegroups.com algogeeks%2bunsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/** group/algogeeks?hl=enhttp://groups.google.com/group/algogeeks?hl=en . -- 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/-/qmLUaTNJns8J. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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. -- Thanks Regards, Saurabh -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to
Re: [algogeeks] Reverse Queue
@Saurabh:i was wrong in deciding space complexity. Yes, your algo will take O(1) time but you have to enqueue elements in reverse order.Not in the order you fetched. Think about it :). Then you have to take stack or some other data structure. On Wed, Jun 20, 2012 at 8:40 PM, saurabh singh saurabh.n...@gmail.comwrote: How ?? I am asking to manipulate the same queue. Dequeue n-1 elements and enqueue them in order to you take out to the same queue..Where is extra space involved ? On Wed, Jun 20, 2012 at 8:36 PM, Navin Kumar algorithm.i...@gmail.comwrote: @saurabh : i want solution with space complexity of O(1) . your solution is right but it takes O(n) space. On Wed, Jun 20, 2012 at 8:28 PM, saurabh singh saurabh.n...@gmail.comwrote: Why will my proposed solution not work for you ??? On Wed, Jun 20, 2012 at 8:19 PM, Navin Kumar algorithm.i...@gmail.comwrote: @Kirubakaran : still space complexity is O(n) due to stack.Can it be solved in space complexity O(1). On Wed, Jun 20, 2012 at 8:00 PM, Kirubakaran D kirubakara...@gmail.com wrote: You could use recursion. def reverse_Q q if !q.isEmpty? el = q.dequeue nQ = reverse_Q(q) nQ.enqueue el return nQ end return q end On Wednesday, June 20, 2012 6:57:23 PM UTC+5:30, Navin Kumar wrote: Use only standard operation of Queue like: EnQueue, DeQueue, IsEmptyQueue etc On Wed, Jun 20, 2012 at 6:50 PM, amrit harry dabbcomput...@gmail.com wrote: can we create other methods or we have to use only enqueue and dequeue...? if yes then simply for(i=0;i=n/2;i++) swap(i,n-i); On Wed, Jun 20, 2012 at 6:46 PM, Navin Kumar algorithm.i...@gmail.com wrote: @Saurabh: queue will be remain unchanged according to your algorithm. Because if you will delete an element from front and add at rear no change will be there. After n iteration front will be pointing to same element and rear will also point to same element. Correct me if i am wrong. :) On Wed, Jun 20, 2012 at 6:39 PM, saurabh singh saurabh.n...@gmail.com wrote: count the size of queue : O(n) loop for n and do remove and add in queue : O(n) Total : O(n) On Wed, Jun 20, 2012 at 6:34 PM, Navin Kumar algorithm.i...@gmail.com wrote: How to reverse a Queue . Constraints: Time complexity O(n). space complexity: O(1) -- 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/-/kepls-8qRwgJhttps://groups.google.com/d/msg/algogeeks/-/kepls-8qRwgJ . To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscribe@**googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/** group/algogeeks?hl=enhttp://groups.google.com/group/algogeeks?hl=en . -- Thanks Regards, Saurabh -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscribe@**googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/** group/algogeeks?hl=enhttp://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+unsubscribe@**googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/** group/algogeeks?hl=enhttp://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+unsubscribe@ **googlegroups.com algogeeks%2bunsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/** group/algogeeks?hl=enhttp://groups.google.com/group/algogeeks?hl=en . -- 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/-/qmLUaTNJns8J. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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
Re: [algogeeks] Reverse Queue
My bad...Sorry :(..Yes it certainly was not right On Wed, Jun 20, 2012 at 8:56 PM, Navin Kumar algorithm.i...@gmail.comwrote: @Saurabh:i was wrong in deciding space complexity. Yes, your algo will take O(1) time but you have to enqueue elements in reverse order.Not in the order you fetched. Think about it :). Then you have to take stack or some other data structure. On Wed, Jun 20, 2012 at 8:40 PM, saurabh singh saurabh.n...@gmail.comwrote: How ?? I am asking to manipulate the same queue. Dequeue n-1 elements and enqueue them in order to you take out to the same queue..Where is extra space involved ? On Wed, Jun 20, 2012 at 8:36 PM, Navin Kumar algorithm.i...@gmail.comwrote: @saurabh : i want solution with space complexity of O(1) . your solution is right but it takes O(n) space. On Wed, Jun 20, 2012 at 8:28 PM, saurabh singh saurabh.n...@gmail.comwrote: Why will my proposed solution not work for you ??? On Wed, Jun 20, 2012 at 8:19 PM, Navin Kumar algorithm.i...@gmail.comwrote: @Kirubakaran : still space complexity is O(n) due to stack.Can it be solved in space complexity O(1). On Wed, Jun 20, 2012 at 8:00 PM, Kirubakaran D kirubakara...@gmail.com wrote: You could use recursion. def reverse_Q q if !q.isEmpty? el = q.dequeue nQ = reverse_Q(q) nQ.enqueue el return nQ end return q end On Wednesday, June 20, 2012 6:57:23 PM UTC+5:30, Navin Kumar wrote: Use only standard operation of Queue like: EnQueue, DeQueue, IsEmptyQueue etc On Wed, Jun 20, 2012 at 6:50 PM, amrit harry dabbcomput...@gmail.com wrote: can we create other methods or we have to use only enqueue and dequeue...? if yes then simply for(i=0;i=n/2;i++) swap(i,n-i); On Wed, Jun 20, 2012 at 6:46 PM, Navin Kumar algorithm.i...@gmail.com wrote: @Saurabh: queue will be remain unchanged according to your algorithm. Because if you will delete an element from front and add at rear no change will be there. After n iteration front will be pointing to same element and rear will also point to same element. Correct me if i am wrong. :) On Wed, Jun 20, 2012 at 6:39 PM, saurabh singh saurabh.n...@gmail.com wrote: count the size of queue : O(n) loop for n and do remove and add in queue : O(n) Total : O(n) On Wed, Jun 20, 2012 at 6:34 PM, Navin Kumar algorithm.i...@gmail.com wrote: How to reverse a Queue . Constraints: Time complexity O(n). space complexity: O(1) -- 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/-/kepls-8qRwgJhttps://groups.google.com/d/msg/algogeeks/-/kepls-8qRwgJ . To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscribe@**googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/* *group/algogeeks?hl=enhttp://groups.google.com/group/algogeeks?hl=en . -- Thanks Regards, Saurabh -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscribe@**googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/** group/algogeeks?hl=enhttp://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+unsubscribe@**googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/** group/algogeeks?hl=enhttp://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+unsubscribe@**googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/** group/algogeeks?hl=enhttp://groups.google.com/group/algogeeks?hl=en . -- 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/-/qmLUaTNJns8J. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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
Re: [algogeeks] Reverse Queue
@Navin: as you say you have to take stack or some other data structure then it will definately not be donw in O(1) space complexity i think the recursive solution is best because we are not explicitly using any extra space its internal stack is using this space. -- 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/-/oKM6PICuD6oJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] Reverse Queue
@Rishabh: i know using stack or recursion it can be done easily with O(n) space. I want to know whether there exist more space efficient algo for this problem or not? On Wed, Jun 20, 2012 at 9:20 PM, Rishabh Agarwal rishabh...@gmail.comwrote: @Navin: as you say you have to take stack or some other data structure then it will definately not be donw in O(1) space complexity i think the recursive solution is best because we are not explicitly using any extra space its internal stack is using this space. -- 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/-/oKM6PICuD6oJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] Reverse Queue
i doesn't seem possible without using stack... On Wed, Jun 20, 2012 at 10:13 PM, Navin Kumar algorithm.i...@gmail.comwrote: @Rishabh: i know using stack or recursion it can be done easily with O(n) space. I want to know whether there exist more space efficient algo for this problem or not? On Wed, Jun 20, 2012 at 9:20 PM, Rishabh Agarwal rishabh...@gmail.comwrote: @Navin: as you say you have to take stack or some other data structure then it will definately not be donw in O(1) space complexity i think the recursive solution is best because we are not explicitly using any extra space its internal stack is using this space. -- 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/-/oKM6PICuD6oJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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. -- 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] Reverse Queue
@saurabh : your solution require O(n) space. On Wed, Jun 20, 2012 at 8:40 PM, saurabh singh saurabh.n...@gmail.comwrote: How ?? I am asking to manipulate the same queue. Dequeue n-1 elements and enqueue them in order to you take out to the same queue..Where is extra space involved ? On Wed, Jun 20, 2012 at 8:36 PM, Navin Kumar algorithm.i...@gmail.comwrote: @saurabh : i want solution with space complexity of O(1) . your solution is right but it takes O(n) space. On Wed, Jun 20, 2012 at 8:28 PM, saurabh singh saurabh.n...@gmail.comwrote: Why will my proposed solution not work for you ??? On Wed, Jun 20, 2012 at 8:19 PM, Navin Kumar algorithm.i...@gmail.comwrote: @Kirubakaran : still space complexity is O(n) due to stack.Can it be solved in space complexity O(1). On Wed, Jun 20, 2012 at 8:00 PM, Kirubakaran D kirubakara...@gmail.com wrote: You could use recursion. def reverse_Q q if !q.isEmpty? el = q.dequeue nQ = reverse_Q(q) nQ.enqueue el return nQ end return q end On Wednesday, June 20, 2012 6:57:23 PM UTC+5:30, Navin Kumar wrote: Use only standard operation of Queue like: EnQueue, DeQueue, IsEmptyQueue etc On Wed, Jun 20, 2012 at 6:50 PM, amrit harry dabbcomput...@gmail.com wrote: can we create other methods or we have to use only enqueue and dequeue...? if yes then simply for(i=0;i=n/2;i++) swap(i,n-i); On Wed, Jun 20, 2012 at 6:46 PM, Navin Kumar algorithm.i...@gmail.com wrote: @Saurabh: queue will be remain unchanged according to your algorithm. Because if you will delete an element from front and add at rear no change will be there. After n iteration front will be pointing to same element and rear will also point to same element. Correct me if i am wrong. :) On Wed, Jun 20, 2012 at 6:39 PM, saurabh singh saurabh.n...@gmail.com wrote: count the size of queue : O(n) loop for n and do remove and add in queue : O(n) Total : O(n) On Wed, Jun 20, 2012 at 6:34 PM, Navin Kumar algorithm.i...@gmail.com wrote: How to reverse a Queue . Constraints: Time complexity O(n). space complexity: O(1) -- 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/-/kepls-8qRwgJhttps://groups.google.com/d/msg/algogeeks/-/kepls-8qRwgJ . To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscribe@**googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/** group/algogeeks?hl=enhttp://groups.google.com/group/algogeeks?hl=en . -- Thanks Regards, Saurabh -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscribe@**googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/** group/algogeeks?hl=enhttp://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+unsubscribe@**googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/** group/algogeeks?hl=enhttp://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+unsubscribe@ **googlegroups.com algogeeks%2bunsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/** group/algogeeks?hl=enhttp://groups.google.com/group/algogeeks?hl=en . -- 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/-/qmLUaTNJns8J. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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. -- Thanks Regards, Saurabh -- You received this message
Re: [algogeeks] Reverse Engg.
its not possible to convert exe back to C. u can get the assembly code of that only. for that u can use the tool IDA or olly debugger -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] Reverse a XOR linked list in O(1) time ?
well to make it work in O(1) , i guess just make head=last node. now just by XORing next ptr of current element with the previous element , we will get second last node similarly keep traversing . On Thu, Dec 1, 2011 at 7:02 AM, Rajeev Kumar rajeevprasa...@gmail.comwrote: -- Thank You Rajeev Kumar -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] Reverse a XOR linked list in O(1) time ?
we can also do it by making next_ptr of head = 0 XOR address of last node. for both this and above method we must save the address of last node in temp while creating a XOR link list. On Thu, Dec 1, 2011 at 9:21 AM, atul anand atul.87fri...@gmail.com wrote: well to make it work in O(1) , i guess just make head=last node. now just by XORing next ptr of current element with the previous element , we will get second last node similarly keep traversing . On Thu, Dec 1, 2011 at 7:02 AM, Rajeev Kumar rajeevprasa...@gmail.comwrote: -- Thank You Rajeev Kumar -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] Reverse dutch flag problem
This is a special case of shuffling problem. In shuffling problem we have to merge k (here k = 3) parts of array such that each kth element is from the same sub-array and in same order. For eg - a1 a2 a3 a4 b1 b2 b3 b4 c1 c2 c3 c4 should become = a1 b1 c1 a2 b2 c2 a3 b3 c3 a4 b4 c4. Usually shuffling problem can be solved only in O(n*logn) time without additional space, but here you have an added advantage. You know what the sequence should look like exactly. So here goes the O(n) solution with constant space. 1- Take 2 pointers p1 and p2 initialize both of them to index 1 (second element) 2- now for each element at p2 find the right index where it should go and put it thr. The right index is - (k*p2 -1) % (n-1); // k=3 here 3- Keep doing it until p2 becomes same as p1 again. 4- Now advance p1 till the elements are in order 0 1 2 0 5- if p1 is less than n-1 than set p2 = p1. Repeat thru step 2-5 again. Here is a primitive C code to do the same. int p1 = p2 = 1; int preVal, next, temp; while (p1 n) { preVal = a[p1]; p2 = p1; do{ next = (k*p2 -1) % (n-1); // k=3 here temp = a[next]; a[next] = preVal; preVal = temp; p2 = next; } while (p2 != p1) while(p1 n) { if( ((a[p1] - a[p1-1]) == 1) || (a[p1] - a[p1-1]) == -2)) // elements are in sequence 0 1 2 0 p1++; else break; } } Feedback welcome :-). - Ravindra On Wed, Nov 2, 2011 at 6:43 PM, shady sinv...@gmail.com wrote: any solutions for this ? dutch national flag problem could be done in O(n) time and O(1) space by considering two pointers, but how to do this (reverse dutch national flag problem) ? On Sat, Aug 20, 2011 at 3:27 PM, Sanjay Rajpal srn...@gmail.com wrote: Suppose we are given a string . Make it 012012012012 in O(n) time and O(1) space. Sanju :) -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] Reverse dutch flag problem
Sorry, small mistake in designated index calculation. It should be k*p2 % (n-1) instead of (k*p2 -1) % (n - 1). Thanks, - Ravindra On Thu, Nov 3, 2011 at 11:37 PM, ravindra patel ravindra.it...@gmail.comwrote: This is a special case of shuffling problem. In shuffling problem we have to merge k (here k = 3) parts of array such that each kth element is from the same sub-array and in same order. For eg - a1 a2 a3 a4 b1 b2 b3 b4 c1 c2 c3 c4 should become = a1 b1 c1 a2 b2 c2 a3 b3 c3 a4 b4 c4. Usually shuffling problem can be solved only in O(n*logn) time without additional space, but here you have an added advantage. You know what the sequence should look like exactly. So here goes the O(n) solution with constant space. 1- Take 2 pointers p1 and p2 initialize both of them to index 1 (second element) 2- now for each element at p2 find the right index where it should go and put it thr. The right index is - (k*p2 -1) % (n-1); // k=3 here 3- Keep doing it until p2 becomes same as p1 again. 4- Now advance p1 till the elements are in order 0 1 2 0 5- if p1 is less than n-1 than set p2 = p1. Repeat thru step 2-5 again. Here is a primitive C code to do the same. int p1 = p2 = 1; int preVal, next, temp; while (p1 n) { preVal = a[p1]; p2 = p1; do{ next = (k*p2 -1) % (n-1); // k=3 here temp = a[next]; a[next] = preVal; preVal = temp; p2 = next; } while (p2 != p1) while(p1 n) { if( ((a[p1] - a[p1-1]) == 1) || (a[p1] - a[p1-1]) == -2)) // elements are in sequence 0 1 2 0 p1++; else break; } } Feedback welcome :-). - Ravindra On Wed, Nov 2, 2011 at 6:43 PM, shady sinv...@gmail.com wrote: any solutions for this ? dutch national flag problem could be done in O(n) time and O(1) space by considering two pointers, but how to do this (reverse dutch national flag problem) ? On Sat, Aug 20, 2011 at 3:27 PM, Sanjay Rajpal srn...@gmail.com wrote: Suppose we are given a string . Make it 012012012012 in O(n) time and O(1) space. Sanju :) -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] Reverse dutch flag problem
any solutions for this ? dutch national flag problem could be done in O(n) time and O(1) space by considering two pointers, but how to do this (reverse dutch national flag problem) ? On Sat, Aug 20, 2011 at 3:27 PM, Sanjay Rajpal srn...@gmail.com wrote: Suppose we are given a string . Make it 012012012012 in O(n) time and O(1) space. Sanju :) -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] Reverse the string word by word . Can someone tell what is wrong in my code ?
Try this one... #includestdio.h #includestring.h void reverse(char *p,char*q) { char c; while(pq) { c=*p;*p=*q;*q=c; p++; q--; } } int main() { char A[50]; printf(\n Enter a String:\n\n); gets(A); int len=strlen(A); reverse(A,A[len-1]); printf(%s\n,A); return 0; } On Sun, Sep 25, 2011 at 10:51 AM, Dheeraj Sharma dheerajsharma1...@gmail.com wrote: u shud do TWO things in..your reverseword function.. first is str[i]=='\0' and not str[i]='\0' second is while(i=len) and not while(ilen) On Sun, Sep 25, 2011 at 6:49 AM, Deoki Nandan deok...@gmail.com wrote: //Reverse String word by word // if string is :- I am a good boy //output string should be :- boy good a am I #includestdio.h #includestring.h void reverse(char *p,char*q) { int i;char c; while(pq) { c=*p;*p=*q;*q=c; p++; q--; } } void reverseWordByWord(char str[],int len) { int i=0,j=0; while(ilen) { if((str[i]==' ')||(str[i]=='\t')||(str[i]='\0')) { reverse(str[j],str[i-1]); j=i+1; } i++; } } int main() { char A[]=Ram is a good person; int i; int len=strlen(A); reverse(A[0],A[len-1]); printf(%s\n,A); reverseWordByWord(A,len); printf(%s\n,A); return 0; } -- **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. -- *Dheeraj Sharma* Comp Engg. NIT Kurukshetra -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- *Avinesh Kumar, MCA NIT Calicut. * -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] Reverse the string word by word . Can someone tell what is wrong in my code ?
u shud do TWO things in..your reverseword function.. first is str[i]=='\0' and not str[i]='\0' second is while(i=len) and not while(ilen) On Sun, Sep 25, 2011 at 6:49 AM, Deoki Nandan deok...@gmail.com wrote: //Reverse String word by word // if string is :- I am a good boy //output string should be :- boy good a am I #includestdio.h #includestring.h void reverse(char *p,char*q) { int i;char c; while(pq) { c=*p;*p=*q;*q=c; p++; q--; } } void reverseWordByWord(char str[],int len) { int i=0,j=0; while(ilen) { if((str[i]==' ')||(str[i]=='\t')||(str[i]='\0')) { reverse(str[j],str[i-1]); j=i+1; } i++; } } int main() { char A[]=Ram is a good person; int i; int len=strlen(A); reverse(A[0],A[len-1]); printf(%s\n,A); reverseWordByWord(A,len); printf(%s\n,A); return 0; } -- **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. -- *Dheeraj Sharma* Comp Engg. NIT Kurukshetra -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] Reverse dutch flag problem
one solution might be: to traverse whole list counting no of zeros and 1's. and then make another string(or overwrite the same) with the required pattern,append any other characters(suppose all 0's exhausted and some 1's and 2's were left) left at the end. is there any better solution?? On Sat, Aug 20, 2011 at 4:20 PM, sukran dhawan sukrandha...@gmail.comwrote: i that .ink the soln for this problem is given in geeksforgeeks.com On Sat, Aug 20, 2011 at 3:27 PM, Sanjay Rajpal srn...@gmail.com wrote: Suppose we are given a string . Make it 012012012012 in O(n) time and O(1) space. Sanju :) -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] reverse
does anyone know the correct solution this problem ?? problem : i/p :: 39 o/p:: 93 (using bitwise operator) On Fri, Aug 12, 2011 at 1:41 PM, Prakash D cegprak...@gmail.com wrote: how does the above code work? On Fri, Aug 12, 2011 at 1:14 PM, Rahul raikra...@gmail.com wrote: I understand. where I find some more tricks like these , I mean I really. find. bit thinking hacks. difficult to understand. On 8/12/11, Tarun Arya tarun@gmail.com wrote: RAHUL@ d question was to reverse d 2 numbers...it can b done by wat i hav said... if u want 2 extract numbers then a0x0f //this wil giv number in units place... a0xf0 a4//this wil give number in tens place correct me if i m wrong Tarun -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Rahul -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] reverse
though im very unsure abt this,but how abt converting the number to BCD and then normal swapping of the two nibbles?? Bt i guess this would work only for 2 digit numbers... On Wed, Aug 24, 2011 at 8:20 PM, aditya kumar aditya.kumar130...@gmail.comwrote: does anyone know the correct solution this problem ?? problem : i/p :: 39 o/p:: 93 (using bitwise operator) On Fri, Aug 12, 2011 at 1:41 PM, Prakash D cegprak...@gmail.com wrote: how does the above code work? On Fri, Aug 12, 2011 at 1:14 PM, Rahul raikra...@gmail.com wrote: I understand. where I find some more tricks like these , I mean I really. find. bit thinking hacks. difficult to understand. On 8/12/11, Tarun Arya tarun@gmail.com wrote: RAHUL@ d question was to reverse d 2 numbers...it can b done by wat i hav said... if u want 2 extract numbers then a0x0f //this wil giv number in units place... a0xf0 a4//this wil give number in tens place correct me if i m wrong Tarun -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Rahul -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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. -- Aditi Garg Undergraduate Student Electronics Communication Divison NETAJI SUBHAS INSTITUTE OF TECHNOLOGY Sector 3, Dwarka New 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] reverse
assuming unsigned integers and 8-bit size,and n to be the number, logic is : n 4 | n 4. Correct me if m wrong. Sanju :) On Wed, Aug 24, 2011 at 8:51 AM, aditi garg aditi.garg.6...@gmail.comwrote: though im very unsure abt this,but how abt converting the number to BCD and then normal swapping of the two nibbles?? Bt i guess this would work only for 2 digit numbers... On Wed, Aug 24, 2011 at 8:20 PM, aditya kumar aditya.kumar130...@gmail.com wrote: does anyone know the correct solution this problem ?? problem : i/p :: 39 o/p:: 93 (using bitwise operator) On Fri, Aug 12, 2011 at 1:41 PM, Prakash D cegprak...@gmail.com wrote: how does the above code work? On Fri, Aug 12, 2011 at 1:14 PM, Rahul raikra...@gmail.com wrote: I understand. where I find some more tricks like these , I mean I really. find. bit thinking hacks. difficult to understand. On 8/12/11, Tarun Arya tarun@gmail.com wrote: RAHUL@ d question was to reverse d 2 numbers...it can b done by wat i hav said... if u want 2 extract numbers then a0x0f //this wil giv number in units place... a0xf0 a4//this wil give number in tens place correct me if i m wrong Tarun -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Rahul -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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. -- Aditi Garg Undergraduate Student Electronics Communication Divison NETAJI SUBHAS INSTITUTE OF TECHNOLOGY Sector 3, Dwarka New 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. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] Reverse dutch flag problem
i think the soln for this problem is given in geeksforgeeks.com On Sat, Aug 20, 2011 at 3:27 PM, Sanjay Rajpal srn...@gmail.com wrote: Suppose we are given a string . Make it 012012012012 in O(n) time and O(1) space. Sanju :) -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] reverse
I understand , impact I find some more trials like these , I mean I really about bit thinking hacks On 8/12/11, Tarun Arya tarun@gmail.com wrote: RAHUL@ d question was to reverse d 2 numbers...it can b done by wat i hav said... if u want 2 extract numbers then a0x0f //this wil giv number in units place... a0xf0 a4//this wil give number in tens place correct me if i m wrong Tarun -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Rahul -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] reverse
I understand. where I find some more tricks like these , I mean I really. find. bit thinking hacks. difficult to understand. On 8/12/11, Tarun Arya tarun@gmail.com wrote: RAHUL@ d question was to reverse d 2 numbers...it can b done by wat i hav said... if u want 2 extract numbers then a0x0f //this wil giv number in units place... a0xf0 a4//this wil give number in tens place correct me if i m wrong Tarun -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Rahul -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] reverse
please tell me about the pattern of writen test for DE shaw .. and also tell me on which thing they focus more.. please help me.. i really need .. thnk u .. On Thu, Aug 11, 2011 at 11:01 PM, Naren s sweetna...@gmail.com wrote: not 100% sure if this is what you are asking for but here it goes. you have a number (binary) and you want (binary)? you want to use the xor operator ^ value = 0xf0; // binary printf(before %d\n); value ^= 0xff; // binary printf(after%d\n); output: before 240 after 15 240 in binary is 15 in binary is http://wiki.answers.com/Q/How_do_you_reverse_a_number_using_bitwise_operator#ixzz1Uk5fUjai On Thu, Aug 11, 2011 at 10:43 PM, Rajeshwar Patra rajeshwarpa...@gmail.com wrote: how can we reverse a number using bitwise operators? -- *Rajeshwar Patra,* *MCA final year,* *Nit Durgapur* -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- *Narayanan S,* B.E., C.S.E., (final year), College Of Engineering Guindy, Anna University, Chennai-25. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] reverse
You are trying to reverse the bits. not the number. This will not work for bits also! If given input is 1101 0011 you will get 0010 1100 On Thu, Aug 11, 2011 at 11:01 PM, Naren s sweetna...@gmail.com wrote: not 100% sure if this is what you are asking for but here it goes. you have a number (binary) and you want (binary)? you want to use the xor operator ^ value = 0xf0; // binary printf(before %d\n); value ^= 0xff; // binary printf(after%d\n); output: before 240 after 15 240 in binary is 15 in binary is http://wiki.answers.com/Q/How_do_you_reverse_a_number_using_bitwise_operator#ixzz1Uk5fUjai On Thu, Aug 11, 2011 at 10:43 PM, Rajeshwar Patra rajeshwarpa...@gmail.com wrote: how can we reverse a number using bitwise operators? -- *Rajeshwar Patra,* *MCA final year,* *Nit Durgapur* -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- *Narayanan S,* B.E., C.S.E., (final year), College Of Engineering Guindy, Anna University, Chennai-25. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] reverse
this is bit wise complement na? -- 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/-/MuwFaGq41X0J. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] reverse
please tell me abt the pattern of de shaw company.. please On Thu, Aug 11, 2011 at 11:06 PM, paul suganthan paul.sugant...@gmail.comwrote: You are trying to reverse the bits. not the number. This will not work for bits also! If given input is 1101 0011 you will get 0010 1100 On Thu, Aug 11, 2011 at 11:01 PM, Naren s sweetna...@gmail.com wrote: not 100% sure if this is what you are asking for but here it goes. you have a number (binary) and you want (binary)? you want to use the xor operator ^ value = 0xf0; // binary printf(before %d\n); value ^= 0xff; // binary printf(after%d\n); output: before 240 after 15 240 in binary is 15 in binary is http://wiki.answers.com/Q/How_do_you_reverse_a_number_using_bitwise_operator#ixzz1Uk5fUjai On Thu, Aug 11, 2011 at 10:43 PM, Rajeshwar Patra rajeshwarpa...@gmail.com wrote: how can we reverse a number using bitwise operators? -- *Rajeshwar Patra,* *MCA final year,* *Nit Durgapur* -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- *Narayanan S,* B.E., C.S.E., (final year), College Of Engineering Guindy, Anna University, Chennai-25. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] reverse
thats wat i wanna know is it possible to reverse a number using bitwise operators -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] reverse
a^=b^=a^=b; a and b are integer inputs Tarun -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] reverse
@Tarun Rahul @Tarun , How Do You Extract the digits of the two digit numbers using bit wise operators @Tarun , How Do You Extract the digits of the two digit numbers using bit wise operators ; And btw , the expression in the way it is written does not works for all langugaes On Thu, Aug 11, 2011 at 11:50 PM, Tarun Arya tarun@gmail.com wrote: a^=b^=a^=b; a and b are integer inputs Tarun -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] reverse
yaa..this is bitwise complement ! On Thu, Aug 11, 2011 at 11:11 PM, Mani Bharathi manibharat...@gmail.comwrote: this is bit wise complement na? -- 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/-/MuwFaGq41X0J. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] reverse
RAHUL@ d question was to reverse d 2 numbers...it can b done by wat i hav said... if u want 2 extract numbers then a0x0f //this wil giv number in units place... a0xf0 a4//this wil give number in tens place correct me if i m wrong Tarun -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] reverse
@tarun no it wont gv u the 2 digits dat way...the numbers are stored in binary format not BCD...ur jst extracting the two nibbles like dat not the tens and unit's digit of the number... On Fri, Aug 12, 2011 at 12:17 AM, Tarun Arya tarun@gmail.com wrote: RAHUL@ d question was to reverse d 2 numbers...it can b done by wat i hav said... if u want 2 extract numbers then a0x0f //this wil giv number in units place... a0xf0 a4//this wil give number in tens place correct me if i m wrong Tarun -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Aditi Garg Undergraduate Student Electronics Communication Divison NETAJI SUBHAS INSTITUTE OF TECHNOLOGY Sector 3, Dwarka New 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] Reverse Bits
x = x16 | (0xx)16 this line exchanges ls 16bits with ms 16bits, i.e. 1 pair of 16bit this logic of exchanging bits is the used for 2 pairs of 8bits each, then for 4 pairs of 4bit, then for 8 pairs of 2 bit and finally 16 pairs of 1bit. On Fri, Aug 5, 2011 at 6:04 PM, rShetty rajeevr...@gmail.com wrote: This is the code to reverse the bits in an unsigned integer . Could anyone please explain the logic of this approach ? Thank You !! #define reverse(x) \ (x=x16|(0xx)16, \ x=(0xff00ff00x)8|(0x00ff00ffx)8, \ x=(0xf0f0f0f0x)4|(0x0f0f0f0fx)4, \ x=(0xx)2|(0xx)2, \ x=(0xx)1|(0xx)1) -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] Reverse Bits
Hi Rajeev, I follow similar approach. The basic logic is swap bits of a pair, then swap nibbles(2 bits) and then swap (4bits), 8bits and go on. So for ex. 0110 1101 1100 0101 In first step, I swap bits of each pair. So this becomes, Input - 0110 1101 1100 0101 output- 1001 1110 1100 1010 In second step, I swap 2bits Input - 1001 1110 1100 1010 output-0110 1011 0011 1010 I swap 4 bits now Input - 0110 1011 0011 1010 output-1011 0110 1010 0011 Now I swap 8bits Input - 1011 0110 1010 0011 output-1010 0011 1011 0110 So, now we have the bits in reverse order. First step I do this way x = ((x | 0x) 2) | (x2) | 0x; Next step similarly x = ((x | 0x) 4) | (x4) | 0x; This is the logic. Your code does the reverse way. Regards, Mithun On Fri, Aug 5, 2011 at 6:04 PM, rShetty rajeevr...@gmail.com wrote: This is the code to reverse the bits in an unsigned integer . Could anyone please explain the logic of this approach ? Thank You !! #define reverse(x) \ (x=x16|(0xx)16, \ x=(0xff00ff00x)8|(0x00ff00ffx)8, \ x=(0xf0f0f0f0x)4|(0x0f0f0f0fx)4, \ x=(0xx)2|(0xx)2, \ x=(0xx)1|(0xx)1) -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Mithun.B.S M:9916775380 -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] Reverse Bits
@mithun : Thanks On Fri, Aug 5, 2011 at 6:37 PM, mithun bs mithun...@gmail.com wrote: Hi Rajeev, I follow similar approach. The basic logic is swap bits of a pair, then swap nibbles(2 bits) and then swap (4bits), 8bits and go on. So for ex. 0110 1101 1100 0101 In first step, I swap bits of each pair. So this becomes, Input - 0110 1101 1100 0101 output- 1001 1110 1100 1010 In second step, I swap 2bits Input - 1001 1110 1100 1010 output-0110 1011 0011 1010 I swap 4 bits now Input - 0110 1011 0011 1010 output-1011 0110 1010 0011 Now I swap 8bits Input - 1011 0110 1010 0011 output-1010 0011 1011 0110 So, now we have the bits in reverse order. First step I do this way x = ((x | 0x) 2) | (x2) | 0x; Next step similarly x = ((x | 0x) 4) | (x4) | 0x; This is the logic. Your code does the reverse way. Regards, Mithun On Fri, Aug 5, 2011 at 6:04 PM, rShetty rajeevr...@gmail.com wrote: This is the code to reverse the bits in an unsigned integer . Could anyone please explain the logic of this approach ? Thank You !! #define reverse(x) \ (x=x16|(0xx)16, \ x=(0xff00ff00x)8|(0x00ff00ffx)8, \ x=(0xf0f0f0f0x)4|(0x0f0f0f0fx)4, \ x=(0xx)2|(0xx)2, \ x=(0xx)1|(0xx)1) -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Mithun.B.S M:9916775380 -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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 Rajeev N B http://www.opensourcemania.co.cc *Winners Don't do Different things , they do things Differently* -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] reverse a line.
Push each word into the stack and pop it out at the end of the line. Sent from BlackBerry® on Airtel -Original Message- From: Saurabh saurabh24...@gmail.com Sender: algogeeks@googlegroups.com Date: Thu, 21 Jul 2011 17:15:29 To: algogeeks@googlegroups.com Reply-To: algogeeks@googlegroups.com Subject: [algogeeks] reverse a line. what is the best way to reverse a line word by word in c or c++??? ex - my name is john Then after reversing it will be like - john is name my Regards Saurabh -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] reverse a line.
1st reverse each word in place.then reverse the whole sentenceit will give the required *answer* -- Tushar Kanta Rath, Master In Computer Application 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] reverse a line.
ya it will work but if i dont want any extra space,I have to reverse it with in that char buffer then how can i it be done.. On Thu, Jul 21, 2011 at 5:17 PM, mageshthegr...@gmail.com wrote: ** Push each word into the stack and pop it out at the end of the line. Sent from BlackBerry® on Airtel -- *From: * Saurabh saurabh24...@gmail.com *Sender: * algogeeks@googlegroups.com *Date: *Thu, 21 Jul 2011 17:15:29 +0530 *To: *algogeeks@googlegroups.com *ReplyTo: * algogeeks@googlegroups.com *Subject: *[algogeeks] reverse a line. what is the best way to reverse a line word by word in c or c++??? ex - my name is john Then after reversing it will be like - john is name my Regards Saurabh -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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 n Luv Saurabh Badhai -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] reverse a line.
Then is need to be done at the cost of performance. 1. First scan the input string till midway and swap the first character with last and second character with second last and so on. 2. Second scan, swap the word within string the same way. On Thu, Jul 21, 2011 at 5:36 PM, Saurabh saurabh24...@gmail.com wrote: ya it will work but if i dont want any extra space,I have to reverse it with in that char buffer then how can i it be done.. On Thu, Jul 21, 2011 at 5:17 PM, mageshthegr...@gmail.com wrote: **Push each word into the stack and pop it out at the end of the line. Sent from BlackBerry® on Airtel -- *From: *Saurabh saurabh24...@gmail.com *Sender: *algogeeks@googlegroups.com *Date: *Thu, 21 Jul 2011 17:15:29 +0530 *To: *algogeeks@googlegroups.com *ReplyTo: *algogeeks@googlegroups.com *Subject: *[algogeeks] reverse a line. what is the best way to reverse a line word by word in c or c++??? ex - my name is john Then after reversing it will be like - john is name my Regards Saurabh -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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 n Luv Saurabh Badhai -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Dinesh Bansal 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] reverse a line.
great answer thanks.. On Thu, Jul 21, 2011 at 5:49 PM, dinesh bansal bansal...@gmail.com wrote: Then is need to be done at the cost of performance. 1. First scan the input string till midway and swap the first character with last and second character with second last and so on. 2. Second scan, swap the word within string the same way. On Thu, Jul 21, 2011 at 5:36 PM, Saurabh saurabh24...@gmail.com wrote: ya it will work but if i dont want any extra space,I have to reverse it with in that char buffer then how can i it be done.. On Thu, Jul 21, 2011 at 5:17 PM, mageshthegr...@gmail.com wrote: **Push each word into the stack and pop it out at the end of the line. Sent from BlackBerry® on Airtel -- *From: *Saurabh saurabh24...@gmail.com *Sender: *algogeeks@googlegroups.com *Date: *Thu, 21 Jul 2011 17:15:29 +0530 *To: *algogeeks@googlegroups.com *ReplyTo: *algogeeks@googlegroups.com *Subject: *[algogeeks] reverse a line. what is the best way to reverse a line word by word in c or c++??? ex - my name is john Then after reversing it will be like - john is name my Regards Saurabh -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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 n Luv Saurabh Badhai -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Dinesh Bansal 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. -- Regards n Luv Saurabh Badhai -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] Reverse a List with Recursion
int reverse(node * tmp) { static int i; // couti ; i++; if(tmp==NULL) { return 0; } if((tmp-next)==NULL) { head=tmp; i--; return 0; } if((tmp-next)!=NULL) { reverse(tmp-next); (tmp-next)-next=tmp; i--; if(i==0) { tmp-next=NULL; tail=tmp;} return 0; } return 0; } On Sun, Jul 17, 2011 at 2:42 PM, Navneet Gupta navneetn...@gmail.comwrote: Hi, I was trying to accomplish this task with the following call , header = ReverseList(header) I don't want to pass tail pointer or anything and just want that i get a reversed list with new header properly assigned after this call. I am getting issues in corner conditions like returning the correct node to be assigned to header. Can anyone give an elegant solution with above requirement? Since it is with recursion, please test for multiple scenarios (empty list, one node list, twe nodes list etc) before posting your solution. In case of empty list, the procedure should report that. -- 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. -- 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] Reverse a List with Recursion
struct node *reverse_recurse(struct node *start) { if(start-next) { reverse_recurse(start-next); start-next-next=start; return(start); } else { head=start; } } in main if(head) { temp = reverse_recurse(head); temp-next =NULL; } head and temp are global On Sun, Jul 17, 2011 at 2:42 PM, Navneet Gupta navneetn...@gmail.comwrote: Hi, I was trying to accomplish this task with the following call , header = ReverseList(header) I don't want to pass tail pointer or anything and just want that i get a reversed list with new header properly assigned after this call. I am getting issues in corner conditions like returning the correct node to be assigned to header. Can anyone give an elegant solution with above requirement? Since it is with recursion, please test for multiple scenarios (empty list, one node list, twe nodes list etc) before posting your solution. In case of empty list, the procedure should report that. -- 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. -- best wishes!! Vaibhav Shukla DU-MCA -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] Reverse a List with Recursion
void rev_recursion(NODE **head) { if(*head==NULL) return; NODE *first, *rest; first=*head; rest=first-next; if(!rest) return; rev_recursion(rest); first-next-next=first; first-next=NULL; *head=rest; } On Sun, Jul 17, 2011 at 2:53 PM, vaibhav shukla vaibhav200...@gmail.comwrote: struct node *reverse_recurse(struct node *start) { if(start-next) { reverse_recurse(start-next); start-next-next=start; return(start); } else { head=start; } } in main if(head) { temp = reverse_recurse(head); temp-next =NULL; } head and temp are global On Sun, Jul 17, 2011 at 2:42 PM, Navneet Gupta navneetn...@gmail.comwrote: Hi, I was trying to accomplish this task with the following call , header = ReverseList(header) I don't want to pass tail pointer or anything and just want that i get a reversed list with new header properly assigned after this call. I am getting issues in corner conditions like returning the correct node to be assigned to header. Can anyone give an elegant solution with above requirement? Since it is with recursion, please test for multiple scenarios (empty list, one node list, twe nodes list etc) before posting your solution. In case of empty list, the procedure should report that. -- 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. -- best wishes!! Vaibhav Shukla DU-MCA -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] Reverse a List with Recursion
node *listing::rev(node *p) { if(p-next==NULL) { head=p; return p; } else { node *t=rev(p-next); t-next=p; p-next=NULL; tail=p; return p; } } On Sun, Jul 17, 2011 at 3:21 PM, Nishant Mittal mittal.nishan...@gmail.comwrote: void rev_recursion(NODE **head) { if(*head==NULL) return; NODE *first, *rest; first=*head; rest=first-next; if(!rest) return; rev_recursion(rest); first-next-next=first; first-next=NULL; *head=rest; } On Sun, Jul 17, 2011 at 2:53 PM, vaibhav shukla vaibhav200...@gmail.comwrote: struct node *reverse_recurse(struct node *start) { if(start-next) { reverse_recurse(start-next); start-next-next=start; return(start); } else { head=start; } } in main if(head) { temp = reverse_recurse(head); temp-next =NULL; } head and temp are global On Sun, Jul 17, 2011 at 2:42 PM, Navneet Gupta navneetn...@gmail.comwrote: Hi, I was trying to accomplish this task with the following call , header = ReverseList(header) I don't want to pass tail pointer or anything and just want that i get a reversed list with new header properly assigned after this call. I am getting issues in corner conditions like returning the correct node to be assigned to header. Can anyone give an elegant solution with above requirement? Since it is with recursion, please test for multiple scenarios (empty list, one node list, twe nodes list etc) before posting your solution. In case of empty list, the procedure should report that. -- 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. -- best wishes!! Vaibhav Shukla DU-MCA -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] Reverse a List with Recursion
initial call to this will be rev(head); On Sun, Jul 17, 2011 at 4:28 PM, Anika Jain anika.jai...@gmail.com wrote: node *listing::rev(node *p) { if(p-next==NULL) { head=p; return p; } else { node *t=rev(p-next); t-next=p; p-next=NULL; tail=p; return p; } } On Sun, Jul 17, 2011 at 3:21 PM, Nishant Mittal mittal.nishan...@gmail.com wrote: void rev_recursion(NODE **head) { if(*head==NULL) return; NODE *first, *rest; first=*head; rest=first-next; if(!rest) return; rev_recursion(rest); first-next-next=first; first-next=NULL; *head=rest; } On Sun, Jul 17, 2011 at 2:53 PM, vaibhav shukla vaibhav200...@gmail.comwrote: struct node *reverse_recurse(struct node *start) { if(start-next) { reverse_recurse(start-next); start-next-next=start; return(start); } else { head=start; } } in main if(head) { temp = reverse_recurse(head); temp-next =NULL; } head and temp are global On Sun, Jul 17, 2011 at 2:42 PM, Navneet Gupta navneetn...@gmail.comwrote: Hi, I was trying to accomplish this task with the following call , header = ReverseList(header) I don't want to pass tail pointer or anything and just want that i get a reversed list with new header properly assigned after this call. I am getting issues in corner conditions like returning the correct node to be assigned to header. Can anyone give an elegant solution with above requirement? Since it is with recursion, please test for multiple scenarios (empty list, one node list, twe nodes list etc) before posting your solution. In case of empty list, the procedure should report that. -- 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. -- best wishes!! Vaibhav Shukla DU-MCA -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] Reverse a List with Recursion
node * reverse(node *head) { if(head-next) { node * temp=reverse(head-next); head-next-next=head; head-next=NULL; return temp; } return head; } On Sun, Jul 17, 2011 at 4:57 PM, Piyush Sinha ecstasy.piy...@gmail.comwrote: *node *reverse(node *head) { if(head==NULL) return head; if(head-next==NULL) return head; node *temp = reverse(head-next); head-next-next = head; head-next = NULL; return (temp); }* On Sun, Jul 17, 2011 at 4:30 PM, Anika Jain anika.jai...@gmail.comwrote: initial call to this will be rev(head); On Sun, Jul 17, 2011 at 4:28 PM, Anika Jain anika.jai...@gmail.comwrote: node *listing::rev(node *p) { if(p-next==NULL) { head=p; return p; } else { node *t=rev(p-next); t-next=p; p-next=NULL; tail=p; return p; } } On Sun, Jul 17, 2011 at 3:21 PM, Nishant Mittal mittal.nishan...@gmail.com wrote: void rev_recursion(NODE **head) { if(*head==NULL) return; NODE *first, *rest; first=*head; rest=first-next; if(!rest) return; rev_recursion(rest); first-next-next=first; first-next=NULL; *head=rest; } On Sun, Jul 17, 2011 at 2:53 PM, vaibhav shukla vaibhav200...@gmail.com wrote: struct node *reverse_recurse(struct node *start) { if(start-next) { reverse_recurse(start-next); start-next-next=start; return(start); } else { head=start; } } in main if(head) { temp = reverse_recurse(head); temp-next =NULL; } head and temp are global On Sun, Jul 17, 2011 at 2:42 PM, Navneet Gupta navneetn...@gmail.comwrote: Hi, I was trying to accomplish this task with the following call , header = ReverseList(header) I don't want to pass tail pointer or anything and just want that i get a reversed list with new header properly assigned after this call. I am getting issues in corner conditions like returning the correct node to be assigned to header. Can anyone give an elegant solution with above requirement? Since it is with recursion, please test for multiple scenarios (empty list, one node list, twe nodes list etc) before posting your solution. In case of empty list, the procedure should report that. -- 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. -- best wishes!! Vaibhav Shukla DU-MCA -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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. -- *Piyush Sinha* *IIIT, Allahabad* *+91-7483122727* * https://www.facebook.com/profile.php?id=10655377926 NEVER SAY NEVER * -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] Reverse
OK On Thu, Jun 30, 2011 at 3:14 PM, Anders Ma xuejiao...@gmail.com wrote: On Tue, Jun 28, 2011 at 3:04 PM, sagar pareek sagarpar...@gmail.com wrote: I have 1 more solution :- #includestdio.h #includestring.h main() { int i,j,l; char arr[100]; printf(Enter the string\n); fgets(arr,100,stdin); for(i=0,l=strlen(arr),j=l;i=l/2;i++) { arr[j--]=arr[i]; arr[i]=arr[j]; } for(i--;il;i++) arr[i]=arr[i+1]; arr[i]='\0'; printf(%s\n,arr); } I hope it will work perfect :) it works, but it does need extra space to swap variables, it uses '\0' space. personally speaking, I prefer to use XOR, it is so cool. :-) -- Regards Anders -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] Reverse
Thanks On Wed, Jun 29, 2011 at 2:45 AM, aditya kumar aditya.kumar130...@gmail.comwrote: @sagar : it works perfectly fine. On Tue, Jun 28, 2011 at 3:29 PM, sagar pareek sagarpar...@gmail.comwrote: Check out my solution above :) Its reversing the string On Tue, Jun 28, 2011 at 1:56 PM, shady sinv...@gmail.com wrote: no, you arent actually reversing anything, you are just printing. On Tue, Jun 28, 2011 at 11:40 AM, Kamakshii Aggarwal kamakshi...@gmail.com wrote: #include stdio.h #include stdlib.h void revers(char *s) { if(*s) { revers(++s); s--; printf(%c ,*s); } } int main(int argc, char *argv[]) { char arr[]=string; revers(arr); system(PAUSE); return 0; } acording to above given definition of temporary variable will the above code also work for this question??? On Mon, Jun 27, 2011 at 11:56 PM, Swathi chukka.swa...@gmail.comwrote: it works perfectly On Mon, Jun 27, 2011 at 11:53 PM, hary rathor harry.rat...@gmail.comwrote: this solution according to sameer statement solution if there is any problem then pls tell me . here string or char is not being store anywhere char * reverse(char *str,int i ,int j) { while(ij) { str[i]=str[i]^str[j]; str[j]=str[i]^str[j]; str[i]=str[i]^str[j]; i++;j--; } return str; } int main () { char str[]=harish; printf(%s,reverse(str,0,sizeof(str)-2)); return 0; } -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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. -- **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 http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Reverse
guy can anybody reverse without taking 0 extra variables ? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] Reverse
We need at least one variable - loop counter. All other can be done via XOR. -- 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/-/AzSS4tMoDlYJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] Reverse
@ juver++ : that i have already done. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] Reverse
On Tue, Jun 28, 2011 at 3:04 PM, sagar pareek sagarpar...@gmail.com wrote: I have 1 more solution :- #includestdio.h #includestring.h main() { int i,j,l; char arr[100]; printf(Enter the string\n); fgets(arr,100,stdin); for(i=0,l=strlen(arr),j=l;i=l/2;i++) { arr[j--]=arr[i]; arr[i]=arr[j]; } for(i--;il;i++) arr[i]=arr[i+1]; arr[i]='\0'; printf(%s\n,arr); } I hope it will work perfect :) it works, but it does need extra space to swap variables, it uses '\0' space. personally speaking, I prefer to use XOR, it is so cool. :-) -- Regards Anders -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] Reverse
I have 1 more solution :- #includestdio.h #includestring.h main() { int i,j,l; char arr[100]; printf(Enter the string\n); fgets(arr,100,stdin); for(i=0,l=strlen(arr),j=l;i=l/2;i++) { arr[j--]=arr[i]; arr[i]=arr[j]; } for(i--;il;i++) arr[i]=arr[i+1]; arr[i]='\0'; printf(%s\n,arr); } I hope it will work perfect :) On Mon, Jun 27, 2011 at 11:56 PM, Swathi chukka.swa...@gmail.com wrote: it works perfectly On Mon, Jun 27, 2011 at 11:53 PM, hary rathor harry.rat...@gmail.comwrote: this solution according to sameer statement solution if there is any problem then pls tell me . here string or char is not being store anywhere char * reverse(char *str,int i ,int j) { while(ij) { str[i]=str[i]^str[j]; str[j]=str[i]^str[j]; str[i]=str[i]^str[j]; i++;j--; } return str; } int main () { char str[]=harish; printf(%s,reverse(str,0,sizeof(str)-2)); return 0; } -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] Reverse
#include stdio.h #include stdlib.h void revers(char *s) { if(*s) { revers(++s); s--; printf(%c ,*s); } } int main(int argc, char *argv[]) { char arr[]=string; revers(arr); system(PAUSE); return 0; } acording to above given definition of temporary variable will the above code also work for this question??? On Mon, Jun 27, 2011 at 11:56 PM, Swathi chukka.swa...@gmail.com wrote: it works perfectly On Mon, Jun 27, 2011 at 11:53 PM, hary rathor harry.rat...@gmail.comwrote: this solution according to sameer statement solution if there is any problem then pls tell me . here string or char is not being store anywhere char * reverse(char *str,int i ,int j) { while(ij) { str[i]=str[i]^str[j]; str[j]=str[i]^str[j]; str[i]=str[i]^str[j]; i++;j--; } return str; } int main () { char str[]=harish; printf(%s,reverse(str,0,sizeof(str)-2)); return 0; } -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] Reverse
no, you arent actually reversing anything, you are just printing. On Tue, Jun 28, 2011 at 11:40 AM, Kamakshii Aggarwal kamakshi...@gmail.comwrote: #include stdio.h #include stdlib.h void revers(char *s) { if(*s) { revers(++s); s--; printf(%c ,*s); } } int main(int argc, char *argv[]) { char arr[]=string; revers(arr); system(PAUSE); return 0; } acording to above given definition of temporary variable will the above code also work for this question??? On Mon, Jun 27, 2011 at 11:56 PM, Swathi chukka.swa...@gmail.com wrote: it works perfectly On Mon, Jun 27, 2011 at 11:53 PM, hary rathor harry.rat...@gmail.comwrote: this solution according to sameer statement solution if there is any problem then pls tell me . here string or char is not being store anywhere char * reverse(char *str,int i ,int j) { while(ij) { str[i]=str[i]^str[j]; str[j]=str[i]^str[j]; str[i]=str[i]^str[j]; i++;j--; } return str; } int main () { char str[]=harish; printf(%s,reverse(str,0,sizeof(str)-2)); return 0; } -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] Reverse
Check out my solution above :) Its reversing the string On Tue, Jun 28, 2011 at 1:56 PM, shady sinv...@gmail.com wrote: no, you arent actually reversing anything, you are just printing. On Tue, Jun 28, 2011 at 11:40 AM, Kamakshii Aggarwal kamakshi...@gmail.com wrote: #include stdio.h #include stdlib.h void revers(char *s) { if(*s) { revers(++s); s--; printf(%c ,*s); } } int main(int argc, char *argv[]) { char arr[]=string; revers(arr); system(PAUSE); return 0; } acording to above given definition of temporary variable will the above code also work for this question??? On Mon, Jun 27, 2011 at 11:56 PM, Swathi chukka.swa...@gmail.com wrote: it works perfectly On Mon, Jun 27, 2011 at 11:53 PM, hary rathor harry.rat...@gmail.comwrote: this solution according to sameer statement solution if there is any problem then pls tell me . here string or char is not being store anywhere char * reverse(char *str,int i ,int j) { while(ij) { str[i]=str[i]^str[j]; str[j]=str[i]^str[j]; str[i]=str[i]^str[j]; i++;j--; } return str; } int main () { char str[]=harish; printf(%s,reverse(str,0,sizeof(str)-2)); return 0; } -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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. -- **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] Reverse
@sagar : it works perfectly fine. On Tue, Jun 28, 2011 at 3:29 PM, sagar pareek sagarpar...@gmail.com wrote: Check out my solution above :) Its reversing the string On Tue, Jun 28, 2011 at 1:56 PM, shady sinv...@gmail.com wrote: no, you arent actually reversing anything, you are just printing. On Tue, Jun 28, 2011 at 11:40 AM, Kamakshii Aggarwal kamakshi...@gmail.com wrote: #include stdio.h #include stdlib.h void revers(char *s) { if(*s) { revers(++s); s--; printf(%c ,*s); } } int main(int argc, char *argv[]) { char arr[]=string; revers(arr); system(PAUSE); return 0; } acording to above given definition of temporary variable will the above code also work for this question??? On Mon, Jun 27, 2011 at 11:56 PM, Swathi chukka.swa...@gmail.comwrote: it works perfectly On Mon, Jun 27, 2011 at 11:53 PM, hary rathor harry.rat...@gmail.comwrote: this solution according to sameer statement solution if there is any problem then pls tell me . here string or char is not being store anywhere char * reverse(char *str,int i ,int j) { while(ij) { str[i]=str[i]^str[j]; str[j]=str[i]^str[j]; str[i]=str[i]^str[j]; i++;j--; } return str; } int main () { char str[]=harish; printf(%s,reverse(str,0,sizeof(str)-2)); return 0; } -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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. -- **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] Reverse
#include stdio.h #include stdlib.h void revers(char *s) { if(*s) { revers(++s); s--; printf(%c ,*s); } } int main(int argc, char *argv[]) { char arr[]=string; revers(arr); system(PAUSE); return 0; } will s be counted as temporary variable in this? On Mon, Jun 27, 2011 at 8:57 PM, rShetty rajeevr...@gmail.com wrote: Reversing a String without using a temporary variable ? Rajeev N B -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] Reverse
this code will only print, it will not store the reverse string. On Mon, Jun 27, 2011 at 9:53 PM, Kamakshii Aggarwal kamakshi...@gmail.com wrote: #include stdio.h #include stdlib.h void revers(char *s) { if(*s) { revers(++s); s--; printf(%c ,*s); } } int main(int argc, char *argv[]) { char arr[]=string; revers(arr); system(PAUSE); return 0; } will s be counted as temporary variable in this? On Mon, Jun 27, 2011 at 8:57 PM, rShetty rajeevr...@gmail.com wrote: Reversing a String without using a temporary variable ? Rajeev N B -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] Reverse
and yes, s will be stored in stack everytime you call the function, so its a temp variable.. string reverse is a simple logic, just iterate i through 1 to n/2 and swap the i to n-i On Mon, Jun 27, 2011 at 10:06 PM, Vishal Thanki vishaltha...@gmail.com wrote: this code will only print, it will not store the reverse string. On Mon, Jun 27, 2011 at 9:53 PM, Kamakshii Aggarwal kamakshi...@gmail.com wrote: #include stdio.h #include stdlib.h void revers(char *s) { if(*s) { revers(++s); s--; printf(%c ,*s); } } int main(int argc, char *argv[]) { char arr[]=string; revers(arr); system(PAUSE); return 0; } will s be counted as temporary variable in this? On Mon, Jun 27, 2011 at 8:57 PM, rShetty rajeevr...@gmail.com wrote: Reversing a String without using a temporary variable ? Rajeev N B -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] Reverse
and how will swap without using temp variable ? On Mon, Jun 27, 2011 at 10:07 PM, Vishal Thanki vishaltha...@gmail.comwrote: and yes, s will be stored in stack everytime you call the function, so its a temp variable.. string reverse is a simple logic, just iterate i through 1 to n/2 and swap the i to n-i On Mon, Jun 27, 2011 at 10:06 PM, Vishal Thanki vishaltha...@gmail.com wrote: this code will only print, it will not store the reverse string. On Mon, Jun 27, 2011 at 9:53 PM, Kamakshii Aggarwal kamakshi...@gmail.com wrote: #include stdio.h #include stdlib.h void revers(char *s) { if(*s) { revers(++s); s--; printf(%c ,*s); } } int main(int argc, char *argv[]) { char arr[]=string; revers(arr); system(PAUSE); return 0; } will s be counted as temporary variable in this? On Mon, Jun 27, 2011 at 8:57 PM, rShetty rajeevr...@gmail.com wrote: Reversing a String without using a temporary variable ? Rajeev N B -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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. -- best wishes!! Vaibhav Shukla DU-MCA -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] Reverse
@vaibhav just like u swap two int variable without using 3rd On Mon, Jun 27, 2011 at 10:17 PM, vaibhav shukla vaibhav200...@gmail.comwrote: and how will swap without using temp variable ? On Mon, Jun 27, 2011 at 10:07 PM, Vishal Thanki vishaltha...@gmail.comwrote: and yes, s will be stored in stack everytime you call the function, so its a temp variable.. string reverse is a simple logic, just iterate i through 1 to n/2 and swap the i to n-i On Mon, Jun 27, 2011 at 10:06 PM, Vishal Thanki vishaltha...@gmail.com wrote: this code will only print, it will not store the reverse string. On Mon, Jun 27, 2011 at 9:53 PM, Kamakshii Aggarwal kamakshi...@gmail.com wrote: #include stdio.h #include stdlib.h void revers(char *s) { if(*s) { revers(++s); s--; printf(%c ,*s); } } int main(int argc, char *argv[]) { char arr[]=string; revers(arr); system(PAUSE); return 0; } will s be counted as temporary variable in this? On Mon, Jun 27, 2011 at 8:57 PM, rShetty rajeevr...@gmail.com wrote: Reversing a String without using a temporary variable ? Rajeev N B -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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. -- best wishes!! Vaibhav Shukla DU-MCA -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] Reverse
h.yup On Mon, Jun 27, 2011 at 10:18 PM, vaibhav agarwal vibhu.bitspil...@gmail.com wrote: @vaibhav just like u swap two int variable without using 3rd On Mon, Jun 27, 2011 at 10:17 PM, vaibhav shukla vaibhav200...@gmail.comwrote: and how will swap without using temp variable ? On Mon, Jun 27, 2011 at 10:07 PM, Vishal Thanki vishaltha...@gmail.comwrote: and yes, s will be stored in stack everytime you call the function, so its a temp variable.. string reverse is a simple logic, just iterate i through 1 to n/2 and swap the i to n-i On Mon, Jun 27, 2011 at 10:06 PM, Vishal Thanki vishaltha...@gmail.com wrote: this code will only print, it will not store the reverse string. On Mon, Jun 27, 2011 at 9:53 PM, Kamakshii Aggarwal kamakshi...@gmail.com wrote: #include stdio.h #include stdlib.h void revers(char *s) { if(*s) { revers(++s); s--; printf(%c ,*s); } } int main(int argc, char *argv[]) { char arr[]=string; revers(arr); system(PAUSE); return 0; } will s be counted as temporary variable in this? On Mon, Jun 27, 2011 at 8:57 PM, rShetty rajeevr...@gmail.com wrote: Reversing a String without using a temporary variable ? Rajeev N B -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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. -- best wishes!! Vaibhav Shukla DU-MCA -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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. -- best wishes!! Vaibhav Shukla DU-MCA -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] Reverse
@vishal : dont you think that , i is also a variable? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] Reverse
guys temporary variable means not to store string in another variable. On Mon, Jun 27, 2011 at 10:37 PM, hary rathor harry.rat...@gmail.comwrote: @vishal : dont you think that , i is also a variable? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] Reverse
this solution according to sameer statement solution if there is any problem then pls tell me . here string or char is not being store anywhere char * reverse(char *str,int i ,int j) { while(ij) { str[i]=str[i]^str[j]; str[j]=str[i]^str[j]; str[i]=str[i]^str[j]; i++;j--; } return str; } int main () { char str[]=harish; printf(%s,reverse(str,0,sizeof(str)-2)); return 0; } -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] Reverse
it works perfectly On Mon, Jun 27, 2011 at 11:53 PM, hary rathor harry.rat...@gmail.comwrote: this solution according to sameer statement solution if there is any problem then pls tell me . here string or char is not being store anywhere char * reverse(char *str,int i ,int j) { while(ij) { str[i]=str[i]^str[j]; str[j]=str[i]^str[j]; str[i]=str[i]^str[j]; i++;j--; } return str; } int main () { char str[]=harish; printf(%s,reverse(str,0,sizeof(str)-2)); return 0; } -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] Reverse the bits.
Thanks Guys I got it. @balaji... you are right.. it will work just fine. -Dinesh Bansal On Fri, Jun 10, 2011 at 10:22 PM, Vetri Balaji vetribal...@gmail.com wrote: int flip(int j,int k,int n) { int t1=(1j)-1; int t2=(1k)-1; t1=t2^t1; return n^t1; } correct me if im wrong On Fri, Jun 10, 2011 at 10:09 PM, Kunal Patil kp101...@gmail.com wrote: How about this??? unsigned int flip_j_to_k_bits (unsigned int n,unsigned int j,unsigned int k) { unsigned int temp; int num_of_on_bits = k-j+1; temp = (1num_of_on_bits)-1; temp = j; return (n^temp); } I dont know whether shift operation is O(1) or not ! But i think this is the best possible that can be done !!! On Fri, Jun 10, 2011 at 8:40 PM, dinesh bansal bansal...@gmail.com wrote: How do you reverse the bits between j to k in a 32 bit integer. For e.g.: n = 11100011; j = 2 and k = 5 output: 1101 (bits from 2 to 5 are reversed.) n = 11010110; j = 1 and k = 5 output: 11101000 O(1) method is preferred. Thanks, -- Dinesh Bansal 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. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Dinesh Bansal 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] Reverse the bits.
How about this??? * unsigned int flip_j_to_k_bits (unsigned int n,unsigned int j,unsigned int k) { unsigned int temp; int num_of_on_bits = k-j+1; temp = (1num_of_on_bits)-1; temp = j; return (n^temp); }* I dont know whether shift operation is O(1) or not ! But i think this is the best possible that can be done !!! On Fri, Jun 10, 2011 at 8:40 PM, dinesh bansal bansal...@gmail.com wrote: How do you reverse the bits between j to k in a 32 bit integer. For e.g.: n = 11100011; j = 2 and k = 5 output: 1101 (bits from 2 to 5 are reversed.) n = 11010110; j = 1 and k = 5 output: 11101000 O(1) method is preferred. Thanks, -- Dinesh Bansal 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.
Re: [algogeeks] Reverse the bits.
int flip(int j,int k,int n) { int t1=(1j)-1; int t2=(1k)-1; t1=t2^t1; return n^t1; } correct me if im wrong On Fri, Jun 10, 2011 at 10:09 PM, Kunal Patil kp101...@gmail.com wrote: How about this??? * unsigned int flip_j_to_k_bits (unsigned int n,unsigned int j,unsigned int k) { unsigned int temp; int num_of_on_bits = k-j+1; temp = (1num_of_on_bits)-1; temp = j; return (n^temp); }* I dont know whether shift operation is O(1) or not ! But i think this is the best possible that can be done !!! On Fri, Jun 10, 2011 at 8:40 PM, dinesh bansal bansal...@gmail.comwrote: How do you reverse the bits between j to k in a 32 bit integer. For e.g.: n = 11100011; j = 2 and k = 5 output: 1101 (bits from 2 to 5 are reversed.) n = 11010110; j = 1 and k = 5 output: 11101000 O(1) method is preferred. Thanks, -- Dinesh Bansal 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. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] Reverse the bits.
@balaji: right , just one change required i think so coz in question they are asking for change of one more bit i.e. for j=2,k=5.. bits 2,3,4,5 are modified..ur code is doing i guess only 2,3,4.. i think just one change needed int t2=(1(k+1))-1; On Fri, Jun 10, 2011 at 10:22 PM, Vetri Balaji vetribal...@gmail.comwrote: int flip(int j,int k,int n) { int t1=(1j)-1; int t2=(1k)-1; t1=t2^t1; return n^t1; } correct me if im wrong On Fri, Jun 10, 2011 at 10:09 PM, Kunal Patil kp101...@gmail.com wrote: How about this??? * unsigned int flip_j_to_k_bits (unsigned int n,unsigned int j,unsigned int k) { unsigned int temp; int num_of_on_bits = k-j+1; temp = (1num_of_on_bits)-1; temp = j; return (n^temp); }* I dont know whether shift operation is O(1) or not ! But i think this is the best possible that can be done !!! On Fri, Jun 10, 2011 at 8:40 PM, dinesh bansal bansal...@gmail.comwrote: How do you reverse the bits between j to k in a 32 bit integer. For e.g.: n = 11100011; j = 2 and k = 5 output: 1101 (bits from 2 to 5 are reversed.) n = 11010110; j = 1 and k = 5 output: 11101000 O(1) method is preferred. Thanks, -- Dinesh Bansal 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. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] Reverse the bits.
no..it will work just fine On Sat, Jun 11, 2011 at 3:31 AM, Anika Jain anika.jai...@gmail.com wrote: @balaji: right , just one change required i think so coz in question they are asking for change of one more bit i.e. for j=2,k=5.. bits 2,3,4,5 are modified..ur code is doing i guess only 2,3,4.. i think just one change needed int t2=(1(k+1))-1; On Fri, Jun 10, 2011 at 10:22 PM, Vetri Balaji vetribal...@gmail.comwrote: int flip(int j,int k,int n) { int t1=(1j)-1; int t2=(1k)-1; t1=t2^t1; return n^t1; } correct me if im wrong On Fri, Jun 10, 2011 at 10:09 PM, Kunal Patil kp101...@gmail.com wrote: How about this??? * unsigned int flip_j_to_k_bits (unsigned int n,unsigned int j,unsigned int k) { unsigned int temp; int num_of_on_bits = k-j+1; temp = (1num_of_on_bits)-1; temp = j; return (n^temp); }* I dont know whether shift operation is O(1) or not ! But i think this is the best possible that can be done !!! On Fri, Jun 10, 2011 at 8:40 PM, dinesh bansal bansal...@gmail.comwrote: How do you reverse the bits between j to k in a 32 bit integer. For e.g.: n = 11100011; j = 2 and k = 5 output: 1101 (bits from 2 to 5 are reversed.) n = 11010110; j = 1 and k = 5 output: 11101000 O(1) method is preferred. Thanks, -- Dinesh Bansal 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. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] ReVerse a string using recursion
char* temp, temp2; char* s=Nitin; for(temp2=s;*temp2='\0';temp2++ );/*just to calculate the length of s*/ void strrev(char * s,char* temp2) { if (s==temp2 ||stemp2) {return;} *temp = *s; *s=* temp2; *temp2=*temp; temp2++; s++; strrev(*s,*temp2) } But it is using two extra char pointer... is that allowed.?? On Thu, Sep 23, 2010 at 12:59 PM, Albert alberttheb...@gmail.com wrote: How to reverse a String using recursion in C without using any extra memory? the question seems to be simple. char* strrev(char *) { ... ... ... } Try to give all the answers for this prototype. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@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 algoge...@googlegroups.com. To unsubscribe from 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] ReVerse a string using recursion
Sorry ...correction we have to bring temp2 to last char again... so char* temp, temp2; char* s=Nitin; for(temp2=s;*temp2='\0';temp2++ );/*just to calculate the length of s*/ --temp2; *===* void strrev(char * s,char* temp2) { if (s==temp2 ||stemp2) {return;} *temp = *s; *s=* temp2; *temp2=*temp; temp2++; s++; strrev(*s,*temp2) } On Thu, Sep 23, 2010 at 1:15 PM, coolfrog$ dixit.coolfrog.div...@gmail.comwrote: char* temp, temp2; char* s=Nitin; for(temp2=s;*temp2='\0';temp2++ );/*just to calculate the length of s*/ void strrev(char * s,char* temp2) { if (s==temp2 ||stemp2) {return;} *temp = *s; *s=* temp2; *temp2=*temp; temp2++; s++; strrev(*s,*temp2) } But it is using two extra char pointer... is that allowed.?? On Thu, Sep 23, 2010 at 12:59 PM, Albert alberttheb...@gmail.com wrote: How to reverse a String using recursion in C without using any extra memory? the question seems to be simple. char* strrev(char *) { ... ... ... } Try to give all the answers for this prototype. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@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 algoge...@googlegroups.com. To unsubscribe from 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] ReVerse a string using recursion
void xstrrev(char *s , int i , int j) { char t; if(ij) { t=s[i]; s[i]=s[j]; s[j]=t; xstrrev(s,i+1,j-1); } } On Thu, Sep 23, 2010 at 11:29 PM, Albert alberttheb...@gmail.com wrote: How to reverse a String using recursion in C without using any extra memory? the question seems to be simple. char* strrev(char *) { ... ... ... } Try to give all the answers for this prototype. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- :-) * Nishant Agarwal 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 algoge...@googlegroups.com. To unsubscribe from 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] ReVerse a string using recursion
Ur function prototype is not similar to one i posted before check it out -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from 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] ReVerse a string using recursion
@nishant: what is i and j..??? @ On Thu, Sep 23, 2010 at 1:20 PM, Nishant Agarwal nishant.agarwa...@gmail.com wrote: void xstrrev(char *s , int i , int j) { char t; if(ij) { t=s[i]; s[i]=s[j]; s[j]=t; xstrrev(s,i+1,j-1); } } On Thu, Sep 23, 2010 at 11:29 PM, Albert alberttheb...@gmail.com wrote: How to reverse a String using recursion in C without using any extra memory? the question seems to be simple. char* strrev(char *) { ... ... ... } Try to give all the answers for this prototype. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- :-) * Nishant Agarwal 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 algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@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 algoge...@googlegroups.com. To unsubscribe from 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] ReVerse a string using recursion
i am giving the full code #includestdio.h #includestdlib.h #includestring.h void xstrrev(char *s , int i , int j) { char t; if(ij) { t=s[i]; s[i]=s[j]; s[j]=t; xstrrev(s,i+1,j-1); } } int main() { char *s; s=(char *)malloc(sizeof(s)); gets(s); xstrrev(s,0,strlen(s)-1); puts(s); return 0; } On Fri, Sep 24, 2010 at 12:15 AM, coolfrog$ dixit.coolfrog.div...@gmail.com wrote: @nishant: what is i and j..??? @ On Thu, Sep 23, 2010 at 1:20 PM, Nishant Agarwal nishant.agarwa...@gmail.com wrote: void xstrrev(char *s , int i , int j) { char t; if(ij) { t=s[i]; s[i]=s[j]; s[j]=t; xstrrev(s,i+1,j-1); } } On Thu, Sep 23, 2010 at 11:29 PM, Albert alberttheb...@gmail.com wrote: How to reverse a String using recursion in C without using any extra memory? the question seems to be simple. char* strrev(char *) { ... ... ... } Try to give all the answers for this prototype. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- :-) * Nishant Agarwal 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 algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@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 algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- :-) * Nishant Agarwal 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 algoge...@googlegroups.com. To unsubscribe from 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] ReVerse a string using recursion
*...@nisanth : help me plz... to solve this finding largest and second largest elements from a set of n elements by means of Minimum comparison of n+celling(log n) +2* On Thu, Sep 23, 2010 at 1:50 PM, Nishant Agarwal nishant.agarwa...@gmail.com wrote: i am giving the full code #includestdio.h #includestdlib.h #includestring.h void xstrrev(char *s , int i , int j) { char t; if(ij) { t=s[i]; s[i]=s[j]; s[j]=t; xstrrev(s,i+1,j-1); } } int main() { char *s; s=(char *)malloc(sizeof(s)); gets(s); xstrrev(s,0,strlen(s)-1); puts(s); return 0; } On Fri, Sep 24, 2010 at 12:15 AM, coolfrog$ dixit.coolfrog.div...@gmail.com wrote: @nishant: what is i and j..??? @ On Thu, Sep 23, 2010 at 1:20 PM, Nishant Agarwal nishant.agarwa...@gmail.com wrote: void xstrrev(char *s , int i , int j) { char t; if(ij) { t=s[i]; s[i]=s[j]; s[j]=t; xstrrev(s,i+1,j-1); } } On Thu, Sep 23, 2010 at 11:29 PM, Albert alberttheb...@gmail.comwrote: How to reverse a String using recursion in C without using any extra memory? the question seems to be simple. char* strrev(char *) { ... ... ... } Try to give all the answers for this prototype. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- :-) * Nishant Agarwal 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 algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@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 algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- :-) * Nishant Agarwal 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 algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@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 algoge...@googlegroups.com. To unsubscribe from 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] ReVerse a string using recursion
@Albert i think this should be right static int i=0; int j; void xstrrev(char *s) { char t; if(i==0) j=strlen(s)-1; if(ij) { t=s[i]; s[i++]=s[j]; s[j--]=t; xstrrev(s); } } On Fri, Sep 24, 2010 at 12:05 AM, albert theboss alberttheb...@gmail.comwrote: Ur function prototype is not similar to one i posted before check it out -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- :-) * Nishant Agarwal 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 algoge...@googlegroups.com. To unsubscribe from 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] ReVerse a string using recursion
void RevStr (char *str){ char ch = '\0'; if (*str){ ch = *str; RevStr (++str); } printf (%c, ch); } On Fri, Sep 24, 2010 at 12:37 AM, Nishant Agarwal nishant.agarwa...@gmail.com wrote: @Albert i think this should be right static int i=0; int j; void xstrrev(char *s) { char t; if(i==0) j=strlen(s)-1; if(ij) { t=s[i]; s[i++]=s[j]; s[j--]=t; xstrrev(s); } } On Fri, Sep 24, 2010 at 12:05 AM, albert theboss alberttheb...@gmail.comwrote: Ur function prototype is not similar to one i posted before check it out -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- :-) * Nishant Agarwal 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 algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@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 algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.