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
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
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
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())
@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();
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
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
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
@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,
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,
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:
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
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,
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
@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
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
@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
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)
@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
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.
@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
@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
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?
@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
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
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
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
/|
--
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
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
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
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
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
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
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 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
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
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,
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.
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
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
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
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
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
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
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
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
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 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
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
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
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
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
@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,
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
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
@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
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 = 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
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
@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
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
@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
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
--
*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
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
@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
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
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;
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
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
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
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;
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
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);
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
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
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
@ 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
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];
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';
#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;
}
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--;
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
@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
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
#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
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--;
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
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
@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
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 ?
@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
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
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
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)
{
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,
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
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
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)
{
@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 - 100 of 112 matches
Mail list logo