Re: [algogeeks] reverse a string efficiently

2012-11-27 Thread Pralay Biswas
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

Re: [algogeeks] reverse a string efficiently

2012-11-27 Thread Pralay Biswas
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

Re: [algogeeks] reverse a string efficiently

2012-11-26 Thread atul anand
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

Re: [algogeeks] Reverse Queue

2012-06-23 Thread rajesh pandey
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())

Re: [algogeeks] Reverse Queue

2012-06-22 Thread Sourabh Singh
@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();

Re: [algogeeks] Reverse Queue

2012-06-21 Thread sanjay pandey
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] Reverse Queue

2012-06-20 Thread Navin Kumar
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

Re: [algogeeks] Reverse Queue

2012-06-20 Thread saurabh singh
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

Re: [algogeeks] Reverse Queue

2012-06-20 Thread Navin Kumar
@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,

Re: [algogeeks] Reverse Queue

2012-06-20 Thread Navin Kumar
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,

Re: [algogeeks] Reverse Queue

2012-06-20 Thread saurabh singh
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:

Re: [algogeeks] Reverse Queue

2012-06-20 Thread amrit harry
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

Re: [algogeeks] Reverse Queue

2012-06-20 Thread Navin Kumar
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,

Re: [algogeeks] Reverse Queue

2012-06-20 Thread Kirubakaran D
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

Re: [algogeeks] Reverse Queue

2012-06-20 Thread Navin Kumar
@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

Re: [algogeeks] Reverse Queue

2012-06-20 Thread saurabh singh
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

Re: [algogeeks] Reverse Queue

2012-06-20 Thread Navin Kumar
@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

Re: [algogeeks] Reverse Queue

2012-06-20 Thread saurabh singh
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)

Re: [algogeeks] Reverse Queue

2012-06-20 Thread Navin Kumar
@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

Re: [algogeeks] Reverse Queue

2012-06-20 Thread saurabh singh
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.

Re: [algogeeks] Reverse Queue

2012-06-20 Thread Rishabh Agarwal
@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

Re: [algogeeks] Reverse Queue

2012-06-20 Thread Navin Kumar
@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

Re: [algogeeks] Reverse Queue

2012-06-20 Thread amrit harry
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?

Re: [algogeeks] Reverse Queue

2012-06-20 Thread atul anand
@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

[algogeeks] Reverse Engg.

2012-01-30 Thread Karthikeyan V.B
hi, can anyone tell me how i can convert exe back to c source? -- You received this message because you are subscribed to the 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 Engg.

2012-01-30 Thread Ravi Ranjan
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] Reverse n-Ary Tree and Return List of Leaf Nodes as Output - FYI Google MV

2011-12-20 Thread WgpShashank
Hey Guys , whats do u think the to solve the problem ? my thinking to use recursion or stack , i tried but i think its not correct has lot of bugs ,, let me know some modification or your pseudo code ? Tree will be like 1 /|

[algogeeks] Reverse a XOR linked list in O(1) time ?

2011-11-30 Thread Rajeev Kumar
-- 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

Re: [algogeeks] Reverse a XOR linked list in O(1) time ?

2011-11-30 Thread atul anand
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

Re: [algogeeks] Reverse a XOR linked list in O(1) time ?

2011-11-30 Thread atul anand
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

Re: [algogeeks] Reverse dutch flag problem

2011-11-03 Thread ravindra patel
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

Re: [algogeeks] Reverse dutch flag problem

2011-11-03 Thread ravindra patel
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

Re: [algogeeks] Reverse dutch flag problem

2011-11-02 Thread shady
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

Re: [algogeeks] Reverse the string word by word . Can someone tell what is wrong in my code ?

2011-09-25 Thread avinesh saini
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);

[algogeeks] Reverse the string word by word . Can someone tell what is wrong in my code ?

2011-09-24 Thread Deoki Nandan
//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

Re: [algogeeks] Reverse the string word by word . Can someone tell what is wrong in my code ?

2011-09-24 Thread Dheeraj Sharma
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

Re: [algogeeks] Reverse dutch flag problem

2011-08-25 Thread sachin sabbarwal
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,

Re: [algogeeks] reverse

2011-08-24 Thread aditya kumar
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.

Re: [algogeeks] reverse

2011-08-24 Thread aditi garg
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

Re: [algogeeks] reverse

2011-08-24 Thread Sanjay Rajpal
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

[algogeeks] Reverse dutch flag problem

2011-08-20 Thread Sanjay Rajpal
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

Re: [algogeeks] Reverse dutch flag problem

2011-08-20 Thread sukran dhawan
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

[algogeeks] Reverse of dutch national flag

2011-08-15 Thread saurabh agrawal
In a given array of elements like [a1, a2, a3, a4, . an, b1, b2, b3, b4, ... bn, c1, c2, c3, c4, cn] without taking a extra memory how to merge like [a1, b1, c1, a2, b2, c2, a3, b3, c3, an, bn, cn] ..??? Time complexity should be o(n). you can not use stack or any

Re: [algogeeks] reverse

2011-08-12 Thread Rahul
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

Re: [algogeeks] reverse

2011-08-12 Thread Rahul
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

[algogeeks] reverse

2011-08-11 Thread Rajeshwar Patra
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

Re: [algogeeks] reverse

2011-08-11 Thread manvir siyo
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.

Re: [algogeeks] reverse

2011-08-11 Thread paul suganthan
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

Re: [algogeeks] reverse

2011-08-11 Thread Mani Bharathi
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

Re: [algogeeks] reverse

2011-08-11 Thread manvir siyo
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

Re: [algogeeks] reverse

2011-08-11 Thread Rajeshwar Patra
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

Re: [algogeeks] reverse

2011-08-11 Thread Tarun Arya
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

Re: [algogeeks] reverse

2011-08-11 Thread Rahul
@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,

Re: [algogeeks] reverse

2011-08-11 Thread paul suganthan
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

Re: [algogeeks] reverse

2011-08-11 Thread Tarun Arya
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

Re: [algogeeks] reverse

2011-08-11 Thread aditi garg
@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

[algogeeks] Reverse Bits

2011-08-05 Thread rShetty
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, \

Re: [algogeeks] Reverse Bits

2011-08-05 Thread Nitin Nizhawan
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

Re: [algogeeks] Reverse Bits

2011-08-05 Thread mithun bs
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

Re: [algogeeks] Reverse Bits

2011-08-05 Thread rajeev bharshetty
@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

[algogeeks] reverse a line.

2011-07-21 Thread Saurabh
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

Re: [algogeeks] reverse a line.

2011-07-21 Thread mageshthegreat
@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

Re: [algogeeks] reverse a line.

2011-07-21 Thread Tushar Kanta Rath
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

Re: [algogeeks] reverse a line.

2011-07-21 Thread Saurabh
-- *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

Re: [algogeeks] reverse a line.

2011-07-21 Thread dinesh bansal
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

Re: [algogeeks] reverse a line.

2011-07-21 Thread Saurabh
@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

[algogeeks] Reverse a List with Recursion

2011-07-17 Thread Navneet Gupta
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

Re: [algogeeks] Reverse a List with Recursion

2011-07-17 Thread Ankur Khurana
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;

Re: [algogeeks] Reverse a List with Recursion

2011-07-17 Thread vaibhav shukla
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

Re: [algogeeks] Reverse a List with Recursion

2011-07-17 Thread Nishant Mittal
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

Re: [algogeeks] Reverse a List with Recursion

2011-07-17 Thread Anika Jain
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

Re: [algogeeks] Reverse a List with Recursion

2011-07-17 Thread Anika Jain
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;

Re: [algogeeks] Reverse a List with Recursion

2011-07-17 Thread bharath kannan
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

Re: [algogeeks] Reverse

2011-07-03 Thread sagar pareek
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);

Re: [algogeeks] Reverse

2011-06-30 Thread sagar pareek
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

Re: [algogeeks] Reverse

2011-06-30 Thread hary rathor
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

Re: [algogeeks] Reverse

2011-06-30 Thread juver++
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

Re: [algogeeks] Reverse

2011-06-30 Thread hary rathor
@ 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

Re: [algogeeks] Reverse

2011-06-30 Thread Anders Ma
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];

Re: [algogeeks] Reverse

2011-06-28 Thread sagar pareek
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';

Re: [algogeeks] Reverse

2011-06-28 Thread Kamakshii Aggarwal
#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; }

Re: [algogeeks] Reverse

2011-06-28 Thread shady
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--;

Re: [algogeeks] Reverse

2011-06-28 Thread sagar pareek
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

Re: [algogeeks] Reverse

2011-06-28 Thread aditya kumar
@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

[algogeeks] Reverse

2011-06-27 Thread rShetty
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

Re: [algogeeks] Reverse

2011-06-27 Thread Kamakshii Aggarwal
#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

Re: [algogeeks] Reverse

2011-06-27 Thread Vishal Thanki
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--;        

Re: [algogeeks] Reverse

2011-06-27 Thread Vishal Thanki
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

Re: [algogeeks] Reverse

2011-06-27 Thread vaibhav shukla
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

Re: [algogeeks] Reverse

2011-06-27 Thread vaibhav agarwal
@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

Re: [algogeeks] Reverse

2011-06-27 Thread vaibhav shukla
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 ?

Re: [algogeeks] Reverse

2011-06-27 Thread hary rathor
@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

Re: [algogeeks] Reverse

2011-06-27 Thread sameer.mut...@gmail.com
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

Re: [algogeeks] Reverse

2011-06-27 Thread hary rathor
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

Re: [algogeeks] Reverse

2011-06-27 Thread Swathi
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) {

Re: [algogeeks] Reverse the bits.

2011-06-11 Thread dinesh bansal
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,

[algogeeks] Reverse the bits.

2011-06-10 Thread dinesh bansal
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

Re: [algogeeks] Reverse the bits.

2011-06-10 Thread Kunal Patil
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

Re: [algogeeks] Reverse the bits.

2011-06-10 Thread Vetri Balaji
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) {

Re: [algogeeks] Reverse the bits.

2011-06-10 Thread Anika Jain
@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

  1   2   >