Re: [algogeeks] Circular Left shift

2011-09-11 Thread vamshi vijay
reverse(s);  // reverse string S
reverse(1,n-k); // reverse first n-k characters
reverse(n-k+1,n) // reverse remaining
Time complexity :O(n),space : O(1)


On 10 September 2011 21:53, praveen raj  wrote:

> Whatever changes have been made in array in first step 1 will be  continue
> to 2nd step(reverse the n-k elements)
>
> With regards,
>
> Praveen Raj
> DCE-IT 3rd yr
> 735993
> praveen0...@gmail.com
>
>
>
>
> On Sun, Sep 11, 2011 at 9:51 AM, bharatkumar bagana <
> bagana.bharatku...@gmail.com> wrote:
>
>> @praveen:
>> will u pls explain the second step ... i didn't understand ..
>>
>> On Sat, Sep 10, 2011 at 8:09 PM, praveen raj wrote:
>>
>>> @amrit... +1 ..
>>>
>>>
>>> With regards,
>>>
>>> Praveen Raj
>>> DCE-IT 3rd yr
>>>
>>>  --
>>> You received this message because you are subscribed to the Google Groups
>>> "Algorithm Geeks" group.
>>> To post to this group, send email to algogeeks@googlegroups.com.
>>> To unsubscribe from this group, send email to
>>> algogeeks+unsubscr...@googlegroups.com.
>>> For more options, visit this group at
>>> http://groups.google.com/group/algogeeks?hl=en.
>>>
>>
>>
>>
>> --
>>
>> **Please do not print this e-mail until urgent requirement. Go Green!!
>> Save Papers <=> Save Trees
>>
>> *BharatKumar Bagana*
>> **http://www.google.com/profiles/bagana.bharatkumar
>> *
>> Mobile +91 8056127652*
>> 
>>
>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>



-- 
With Regards,
N.Vamshi Vijay,
Mtech,CSE
IIT Kharagpur
Mobile:-07501541110

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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] Circular Left shift

2011-09-10 Thread praveen raj
Whatever changes have been made in array in first step 1 will be  continue
to 2nd step(reverse the n-k elements)

With regards,

Praveen Raj
DCE-IT 3rd yr
735993
praveen0...@gmail.com



On Sun, Sep 11, 2011 at 9:51 AM, bharatkumar bagana <
bagana.bharatku...@gmail.com> wrote:

> @praveen:
> will u pls explain the second step ... i didn't understand ..
>
> On Sat, Sep 10, 2011 at 8:09 PM, praveen raj wrote:
>
>> @amrit... +1 ..
>>
>>
>> With regards,
>>
>> Praveen Raj
>> DCE-IT 3rd yr
>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>
>
> --
>
> **Please do not print this e-mail until urgent requirement. Go Green!!
> Save Papers <=> Save Trees
>
> *BharatKumar Bagana*
> **http://www.google.com/profiles/bagana.bharatkumar
> *
> Mobile +91 8056127652*
> 
>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from 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] Circular Left shift

2011-09-10 Thread rahul sharma
first do swap like this
if k=3
do 3 tym swap
let start: 1 element from front...its index
let end: 3rd last elemtn index...k lement from last
swap first wiht 3rd last
2nd with second last
3 wiht last
now we have list as:-14 2 4 5 3 23 9 7 6
now set ;4th element from last i.e k+1 from front
swap these now with first 3 elemtns
i.e 5 nad 14
3and 2
23 and 4

so we have:
5 3 23 14 2 4 9 7 6

space complexity is 1;;;
time is also nbut confrm it..plz comment if m wrong

On Sat, Sep 10, 2011 at 2:09 PM, kumar raja wrote:

> Given an array of 'n' values you need to circular shift it 'k' times
> towards left.
>
> Input : 9 7 6 5 3 23 14  2  4
> output : 5 3 23 14 2  4 9 7  6
>
> n=9 , k= 3
>
> constraints : Time complexity O(n)
> Space complexity O(1)
>
> The solutions with O(kn) time complexity and
> O(n) complexity with O(k) space complexity are already available.
>
> I want the O(n) solution with constant space..
> --
> Regards
> Kumar Raja
> M.Tech(SIT)
> IIT Kharagpur,
> 10it60...@iitkgp.ac.in
> 7797137043.
> 09491690115.
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from 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] Circular Left shift

2011-09-10 Thread bharatkumar bagana
@praveen:
will u pls explain the second step ... i didn't understand ..

On Sat, Sep 10, 2011 at 8:09 PM, praveen raj  wrote:

> @amrit... +1 ..
>
>
> With regards,
>
> Praveen Raj
> DCE-IT 3rd yr
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>



-- 

**Please do not print this e-mail until urgent requirement. Go Green!!
Save Papers <=> Save Trees
*BharatKumar Bagana*
**http://www.google.com/profiles/bagana.bharatkumar
*
Mobile +91 8056127652*


-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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] Circular Left shift

2011-09-10 Thread praveen raj
@amrit... +1 ..

With regards,

Praveen Raj
DCE-IT 3rd yr

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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] Circular Left shift

2011-09-10 Thread amrit harry
use circular link list put element into array and shift start point k nodes
leftwards...

On Sat, Sep 10, 2011 at 7:57 PM, praveen raj  wrote:

> @all...
> arr=[3,6,7,1,2,7,8,9]
> suppose: k=3 rotated three times..
> first step... reverse.. first k(3) elements... [7,6,3,1,2,7,8,9]
> second step...reverse last (n-k) elements... [7,6,3,9,8,7,2,1]
> third step reverse the whole array[1,2,7,8,9,3,6,7]
>
>
> thanx,
>
> With regards,
>
> Praveen Raj
> DCE-IT 3rd yr
>
>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>



-- 
AMRIT

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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] Circular Left shift

2011-09-10 Thread praveen raj
@all...
arr=[3,6,7,1,2,7,8,9]
suppose: k=3 rotated three times..
first step... reverse.. first k(3) elements... [7,6,3,1,2,7,8,9]
second step...reverse last (n-k) elements... [7,6,3,9,8,7,2,1]
third step reverse the whole array[1,2,7,8,9,3,6,7]


thanx,

With regards,

Praveen Raj
DCE-IT 3rd yr

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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] Circular Left shift

2011-09-10 Thread kumar raja
Ur idea does not work in the following case

array : 7 5 3 6 9 2 11

n=7 and k=3

as per your explanation the answer would come  9 2 11  6 7 5 3

correct me if i am wrong...

On 10 September 2011 04:54, bharatkumar bagana  wrote:

> swap k elements form 1 to k and n-k to n respectively...
> ex: k=3
>temp=k;
>
> int a[9]= {9,7,6,5,3,23,14,2,4} ; has become {14,2,4,5,3,23,9,7,6};
>
> now swap first k elements with k+1 to 2k elements ...now k=2k+1 , do this 
> step again up to (k at last {5,3,23,14,2,4,9,7,6,} ;
>
> Time :O(n) and space O(1).
>
>
>
> On Sat, Sep 10, 2011 at 7:15 AM, kumar raja wrote:
>
>> @sarath:
>> I did not get u .Could u please explain it with the example.
>>
>>
>> On 10 September 2011 03:39, sarath prasath wrote:
>>
>>> consider this approach..
>>> first reverse the entire array...
>>> so it will be.. 4,2,14,23,3,5,6,7,9
>>> and u want to shift k times right so
>>> u have to cut the array as n-k  and reverse both the sides u ll get it..
>>> so in ur scenario we are reversing upto the element 5 in array and
>>> reversing the remaining elements..
>>> hope the complexity is of o(n)..
>>>
>>>
>>>
>>> On Sat, Sep 10, 2011 at 3:17 PM, kumar raja wrote:
>>>
 U have used c[3] extra array.It is already known solution. so it is
 using O(k) space .i want the solution with constant space..


 On 10 September 2011 02:08, Ishan Aggarwal <
 ishan.aggarwal.1...@gmail.com> wrote:

> Solution :-
>
>
>
>
>
> void main(){int a[9]= {9,7,6,5,3,23,14,2,4} ;int n = 3;int c[3];int i;int 
> k =0;for ( i=0;i<3;i++)
> c[i]= a[i];for(i=3;i<9;i++)
> a[i-3] =a[i];for(i=9-3;i<9;i++)
> a[i] = c[k++];for(i=0;i<9;i++)printf 
> ("\n%d",a[i]);}
>
>
> On Sat, Sep 10, 2011 at 2:09 PM, kumar raja 
> wrote:
>
>> Given an array of 'n' values you need to circular shift it 'k' times
>> towards left.
>>
>> Input : 9 7 6 5 3 23 14  2  4
>> output : 5 3 23 14 2  4 9 7  6
>>
>> n=9 , k= 3
>>
>> constraints : Time complexity O(n)
>> Space complexity O(1)
>>
>> The solutions with O(kn) time complexity and
>> O(n) complexity with O(k) space complexity are already available.
>>
>> I want the O(n) solution with constant space..
>> --
>> Regards
>> Kumar Raja
>> M.Tech(SIT)
>> IIT Kharagpur,
>> 10it60...@iitkgp.ac.in
>> 7797137043.
>> 09491690115.
>>
>>  --
>> You received this message because you are subscribed to the Google
>> Groups "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>
>
> --
> Kind Regards
> Ishan Aggarwal
> [image: Aricent Group]
> Presidency Tower-A, M.G.Road,Sector-14
> Gurgaon,Haryana.122015 INDIA
> Phone : +91-9654602663
> ishan2.aggar...@aricent.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.
>



 --
 Regards
 Kumar Raja
 M.Tech(SIT)
 IIT Kharagpur,
 10it60...@iitkgp.ac.in
 7797137043.
 09491690115.

  --
 You received this message because you are subscribed to the Google
 Groups "Algorithm Geeks" group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from 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
>> Kumar Raja
>> M.Tech(SIT)
>> IIT Kharagpur,
>> 10it60...@iitkgp.ac.in
>> 7797137043.
>> 09491690115.
>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from 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] Circular Left shift

2011-09-10 Thread Rohit jalan
@BharathKumar: extremely sorry dude .. will not do this again .. Can you
forgive me ? :p
On Sep 10, 2011 12:09 PM, "bharatkumar bagana" 
wrote:
> @rohit : why don't u have a look at the older posts before replying some
> thing ...ok .. I'm sorry if u are hurt ..
> what is the time complexity and space complexity of u'r older post ..
>
> On Sat, Sep 10, 2011 at 8:03 AM, Rohit jalan  wrote:
>
>> This can also be done:
>>
>>
>> for( i=0; i> {
>> b[i]=a[i];
>> }
>>
>> for (;i> {
>> a[i-k]=a[i];
>> }
>> while((i-k)> {
>> a[i-k]=b[i];
>> }
>>
>> But extra array is used here.
>>
>>
>> On Sat, Sep 10, 2011 at 5:30 PM, Rohit jalan 
wrote:
>>
>>>
>>> How is this one ??
>>>
>>>
>>> int a[9]={9,7,6,5,3,23,14,2,4}
>>> n=9
>>> int *p,*q;
>>> p=a;
>>> for(q=a;i>> ReverseArray(p,q)
>>>
>>> p=&a[0];
>>> q=&a[n-1-k]
>>> ReverseArray(p,q)
>>>
>>> p=&a[n-k];
>>> q=&a[n-1]
>>> ReverseArray(p,q)
>>>
>>> void ReverseArray(int *l,int *r)
>>> {
>>> int temp;
>>> while(l>> {
>>> temp=*l;
>>> *l=*r;
>>> *r=temp
>>> l++;
>>> r--;
>>> }
>>> }
>>>
>>>
>>> Thanks & Regards,
>>> -Rohit
>>>
>>>
>>> On Sat, Sep 10, 2011 at 5:24 PM, bharatkumar bagana <
>>> bagana.bharatku...@gmail.com> wrote:
>>>
 swap k elements form 1 to k and n-k to n respectively...
 ex: k=3
 temp=k;

 int a[9]= {9,7,6,5,3,23,14,2,4} ; has become {14,2,4,5,3,23,9,7,6};



 now swap first k elements with k+1 to 2k elements ...now k=2k+1 , do
this step again up to (k>>> at last {5,3,23,14,2,4,9,7,6,} ;



 Time :O(n) and space O(1).



 On Sat, Sep 10, 2011 at 7:15 AM, kumar raja wrote:

> @sarath:
> I did not get u .Could u please explain it with the example.
>
>
> On 10 September 2011 03:39, sarath prasath wrote:
>
>> consider this approach..
>> first reverse the entire array...
>> so it will be.. 4,2,14,23,3,5,6,7,9
>> and u want to shift k times right so
>> u have to cut the array as n-k and reverse both the sides u ll get
>> it..
>> so in ur scenario we are reversing upto the element 5 in array and
>> reversing the remaining elements..
>> hope the complexity is of o(n)..
>>
>>
>>
>> On Sat, Sep 10, 2011 at 3:17 PM, kumar raja wrote:
>>
>>> U have used c[3] extra array.It is already known solution. so it is
>>> using O(k) space .i want the solution with constant space..
>>>
>>>
>>> On 10 September 2011 02:08, Ishan Aggarwal <
>>> ishan.aggarwal.1...@gmail.com> wrote:
>>>
 Solution :-







 void main(){int a[9]= {9,7,6,5,3,23,14,2,4} ;int n = 3;int c[3];int
i;int k =0;for ( i=0;i<3;i++)
 c[i]= a[i];for(i=3;i<9;i++)
 a[i-3] =a[i];for(i=9-3;i<9;i++)
 a[i] = c[k++];for(i=0;i<9;i++)printf <
http://www.opengroup.org/onlinepubs/009695399/functions/printf.html
>("\n%d",a[i]);}


 On Sat, Sep 10, 2011 at 2:09 PM, kumar raja <
 rajkumar.cs...@gmail.com> wrote:

> Given an array of 'n' values you need to circular shift it 'k'
times
> towards left.
>
> Input : 9 7 6 5 3 23 14 2 4
> output : 5 3 23 14 2 4 9 7 6
>
> n=9 , k= 3
>
> constraints : Time complexity O(n)
> Space complexity O(1)
>
> The solutions with O(kn) time complexity and
> O(n) complexity with O(k) space complexity are already available.
>
> I want the O(n) solution with constant space..
> --
> Regards
> Kumar Raja
> M.Tech(SIT)
> IIT Kharagpur,
> 10it60...@iitkgp.ac.in
> 7797137043.
> 09491690115.
>
> --
> You received this message because you are subscribed to the Google
> Groups "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>



 --
 Kind Regards
 Ishan Aggarwal
 [image: Aricent Group]
 Presidency Tower-A, M.G.Road,Sector-14
 Gurgaon,Haryana.122015 INDIA
 Phone : +91-9654602663
 ishan2.aggar...@aricent.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.

>>>
>>>
>>>
>>> --
>>> Regards
>>> Kumar Raja
>>> M.Tech(SIT)
>>> IIT Khara

Re: [algogeeks] Circular Left shift

2011-09-10 Thread bharatkumar bagana
@rohit : why don't u have a look at the older posts before replying some
thing ...ok .. I'm sorry if u are hurt ..
what is the time complexity and space complexity of u'r older post ..

On Sat, Sep 10, 2011 at 8:03 AM, Rohit jalan  wrote:

> This can also be done:
>
>
> for( i=0; i {
> b[i]=a[i];
> }
>
> for (;i {
> a[i-k]=a[i];
> }
> while((i-k) {
> a[i-k]=b[i];
> }
>
> But extra array is used here.
>
>
> On Sat, Sep 10, 2011 at 5:30 PM, Rohit jalan  wrote:
>
>>
>> How is this one ??
>>
>>
>> int a[9]={9,7,6,5,3,23,14,2,4}
>> n=9
>> int *p,*q;
>> p=a;
>> for(q=a;i> ReverseArray(p,q)
>>
>> p=&a[0];
>> q=&a[n-1-k]
>> ReverseArray(p,q)
>>
>> p=&a[n-k];
>> q=&a[n-1]
>> ReverseArray(p,q)
>>
>> void ReverseArray(int *l,int *r)
>> {
>> int temp;
>> while(l> {
>> temp=*l;
>> *l=*r;
>> *r=temp
>> l++;
>> r--;
>> }
>> }
>>
>>
>> Thanks & Regards,
>> -Rohit
>>
>>
>> On Sat, Sep 10, 2011 at 5:24 PM, bharatkumar bagana <
>> bagana.bharatku...@gmail.com> wrote:
>>
>>> swap k elements form 1 to k and n-k to n respectively...
>>> ex: k=3
>>>temp=k;
>>>
>>> int a[9]= {9,7,6,5,3,23,14,2,4} ; has become {14,2,4,5,3,23,9,7,6};
>>>
>>>
>>>
>>> now swap first k elements with k+1 to 2k elements ...now k=2k+1 , do this 
>>> step again up to (k>> at last {5,3,23,14,2,4,9,7,6,} ;
>>>
>>>
>>>
>>> Time :O(n) and space O(1).
>>>
>>>
>>>
>>> On Sat, Sep 10, 2011 at 7:15 AM, kumar raja wrote:
>>>
 @sarath:
 I did not get u .Could u please explain it with the example.


 On 10 September 2011 03:39, sarath prasath wrote:

> consider this approach..
> first reverse the entire array...
> so it will be.. 4,2,14,23,3,5,6,7,9
> and u want to shift k times right so
> u have to cut the array as n-k  and reverse both the sides u ll get
> it..
> so in ur scenario we are reversing upto the element 5 in array and
> reversing the remaining elements..
> hope the complexity is of o(n)..
>
>
>
> On Sat, Sep 10, 2011 at 3:17 PM, kumar raja 
> wrote:
>
>> U have used c[3] extra array.It is already known solution. so it is
>> using O(k) space .i want the solution with constant space..
>>
>>
>> On 10 September 2011 02:08, Ishan Aggarwal <
>> ishan.aggarwal.1...@gmail.com> wrote:
>>
>>> Solution :-
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> void main(){int a[9]= {9,7,6,5,3,23,14,2,4} ;int n = 3;int c[3];int 
>>> i;int k =0;for ( i=0;i<3;i++)
>>> c[i]= a[i];for(i=3;i<9;i++)
>>> a[i-3] =a[i];for(i=9-3;i<9;i++)
>>> a[i] = c[k++];for(i=0;i<9;i++)printf 
>>> ("\n%d",a[i]);}
>>>
>>>
>>> On Sat, Sep 10, 2011 at 2:09 PM, kumar raja <
>>> rajkumar.cs...@gmail.com> wrote:
>>>
 Given an array of 'n' values you need to circular shift it 'k' times
 towards left.

 Input : 9 7 6 5 3 23 14  2  4
 output : 5 3 23 14 2  4 9 7  6

 n=9 , k= 3

 constraints : Time complexity O(n)
 Space complexity O(1)

 The solutions with O(kn) time complexity and
 O(n) complexity with O(k) space complexity are already available.

 I want the O(n) solution with constant space..
 --
 Regards
 Kumar Raja
 M.Tech(SIT)
 IIT Kharagpur,
 10it60...@iitkgp.ac.in
 7797137043.
 09491690115.

  --
 You received this message because you are subscribed to the Google
 Groups "Algorithm Geeks" group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.

>>>
>>>
>>>
>>> --
>>> Kind Regards
>>> Ishan Aggarwal
>>> [image: Aricent Group]
>>> Presidency Tower-A, M.G.Road,Sector-14
>>> Gurgaon,Haryana.122015 INDIA
>>> Phone : +91-9654602663
>>> ishan2.aggar...@aricent.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.
>>>
>>
>>
>>
>> --
>> Regards
>> Kumar Raja
>> M.Tech(SIT)
>> IIT Kharagpur,
>> 10it60...@iitkgp.ac.in
>> 7797137043.
>> 09491690115.
>>
>>  --
>> You received this message because you are subscribed to the Google
>> Groups "Algorithm Geeks" group.
>> To post to this group,

Re: [algogeeks] Circular Left shift

2011-09-10 Thread Rohit jalan
This can also be done:


for( i=0; i wrote:

>
> How is this one ??
>
>
> int a[9]={9,7,6,5,3,23,14,2,4}
> n=9
> int *p,*q;
> p=a;
> for(q=a;i ReverseArray(p,q)
>
> p=&a[0];
> q=&a[n-1-k]
> ReverseArray(p,q)
>
> p=&a[n-k];
> q=&a[n-1]
> ReverseArray(p,q)
>
> void ReverseArray(int *l,int *r)
> {
> int temp;
> while(l {
> temp=*l;
> *l=*r;
> *r=temp
> l++;
> r--;
> }
> }
>
>
> Thanks & Regards,
> -Rohit
>
>
> On Sat, Sep 10, 2011 at 5:24 PM, bharatkumar bagana <
> bagana.bharatku...@gmail.com> wrote:
>
>> swap k elements form 1 to k and n-k to n respectively...
>> ex: k=3
>>temp=k;
>>
>> int a[9]= {9,7,6,5,3,23,14,2,4} ; has become {14,2,4,5,3,23,9,7,6};
>>
>>
>> now swap first k elements with k+1 to 2k elements ...now k=2k+1 , do this 
>> step again up to (k> at last {5,3,23,14,2,4,9,7,6,} ;
>>
>>
>> Time :O(n) and space O(1).
>>
>>
>>
>> On Sat, Sep 10, 2011 at 7:15 AM, kumar raja wrote:
>>
>>> @sarath:
>>> I did not get u .Could u please explain it with the example.
>>>
>>>
>>> On 10 September 2011 03:39, sarath prasath wrote:
>>>
 consider this approach..
 first reverse the entire array...
 so it will be.. 4,2,14,23,3,5,6,7,9
 and u want to shift k times right so
 u have to cut the array as n-k  and reverse both the sides u ll get it..
 so in ur scenario we are reversing upto the element 5 in array and
 reversing the remaining elements..
 hope the complexity is of o(n)..



 On Sat, Sep 10, 2011 at 3:17 PM, kumar raja 
 wrote:

> U have used c[3] extra array.It is already known solution. so it is
> using O(k) space .i want the solution with constant space..
>
>
> On 10 September 2011 02:08, Ishan Aggarwal <
> ishan.aggarwal.1...@gmail.com> wrote:
>
>> Solution :-
>>
>>
>>
>>
>>
>>
>> void main(){int a[9]= {9,7,6,5,3,23,14,2,4} ;int n = 3;int c[3];int 
>> i;int k =0;for ( i=0;i<3;i++)
>> c[i]= a[i];for(i=3;i<9;i++)
>> a[i-3] =a[i];for(i=9-3;i<9;i++)
>> a[i] = c[k++];for(i=0;i<9;i++)printf 
>> ("\n%d",a[i]);}
>>
>>
>> On Sat, Sep 10, 2011 at 2:09 PM, kumar raja > > wrote:
>>
>>> Given an array of 'n' values you need to circular shift it 'k' times
>>> towards left.
>>>
>>> Input : 9 7 6 5 3 23 14  2  4
>>> output : 5 3 23 14 2  4 9 7  6
>>>
>>> n=9 , k= 3
>>>
>>> constraints : Time complexity O(n)
>>> Space complexity O(1)
>>>
>>> The solutions with O(kn) time complexity and
>>> O(n) complexity with O(k) space complexity are already available.
>>>
>>> I want the O(n) solution with constant space..
>>> --
>>> Regards
>>> Kumar Raja
>>> M.Tech(SIT)
>>> IIT Kharagpur,
>>> 10it60...@iitkgp.ac.in
>>> 7797137043.
>>> 09491690115.
>>>
>>>  --
>>> You received this message because you are subscribed to the Google
>>> Groups "Algorithm Geeks" group.
>>> To post to this group, send email to algogeeks@googlegroups.com.
>>> To unsubscribe from this group, send email to
>>> algogeeks+unsubscr...@googlegroups.com.
>>> For more options, visit this group at
>>> http://groups.google.com/group/algogeeks?hl=en.
>>>
>>
>>
>>
>> --
>> Kind Regards
>> Ishan Aggarwal
>> [image: Aricent Group]
>> Presidency Tower-A, M.G.Road,Sector-14
>> Gurgaon,Haryana.122015 INDIA
>> Phone : +91-9654602663
>> ishan2.aggar...@aricent.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.
>>
>
>
>
> --
> Regards
> Kumar Raja
> M.Tech(SIT)
> IIT Kharagpur,
> 10it60...@iitkgp.ac.in
> 7797137043.
> 09491690115.
>
>  --
> You received this message because you are subscribed to the Google
> Groups "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from 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] Circular Left shift

2011-09-10 Thread Rohit jalan
How is this one ??

int a[9]={9,7,6,5,3,23,14,2,4}
n=9
int *p,*q;
p=a;
for(q=a;i wrote:

> swap k elements form 1 to k and n-k to n respectively...
> ex: k=3
>temp=k;
>
> int a[9]= {9,7,6,5,3,23,14,2,4} ; has become {14,2,4,5,3,23,9,7,6};
>
> now swap first k elements with k+1 to 2k elements ...now k=2k+1 , do this 
> step again up to (k at last {5,3,23,14,2,4,9,7,6,} ;
>
> Time :O(n) and space O(1).
>
>
>
> On Sat, Sep 10, 2011 at 7:15 AM, kumar raja wrote:
>
>> @sarath:
>> I did not get u .Could u please explain it with the example.
>>
>>
>> On 10 September 2011 03:39, sarath prasath wrote:
>>
>>> consider this approach..
>>> first reverse the entire array...
>>> so it will be.. 4,2,14,23,3,5,6,7,9
>>> and u want to shift k times right so
>>> u have to cut the array as n-k  and reverse both the sides u ll get it..
>>> so in ur scenario we are reversing upto the element 5 in array and
>>> reversing the remaining elements..
>>> hope the complexity is of o(n)..
>>>
>>>
>>>
>>> On Sat, Sep 10, 2011 at 3:17 PM, kumar raja wrote:
>>>
 U have used c[3] extra array.It is already known solution. so it is
 using O(k) space .i want the solution with constant space..


 On 10 September 2011 02:08, Ishan Aggarwal <
 ishan.aggarwal.1...@gmail.com> wrote:

> Solution :-
>
>
>
>
>
> void main(){int a[9]= {9,7,6,5,3,23,14,2,4} ;int n = 3;int c[3];int i;int 
> k =0;for ( i=0;i<3;i++)
> c[i]= a[i];for(i=3;i<9;i++)
> a[i-3] =a[i];for(i=9-3;i<9;i++)
> a[i] = c[k++];for(i=0;i<9;i++)printf 
> ("\n%d",a[i]);}
>
>
> On Sat, Sep 10, 2011 at 2:09 PM, kumar raja 
> wrote:
>
>> Given an array of 'n' values you need to circular shift it 'k' times
>> towards left.
>>
>> Input : 9 7 6 5 3 23 14  2  4
>> output : 5 3 23 14 2  4 9 7  6
>>
>> n=9 , k= 3
>>
>> constraints : Time complexity O(n)
>> Space complexity O(1)
>>
>> The solutions with O(kn) time complexity and
>> O(n) complexity with O(k) space complexity are already available.
>>
>> I want the O(n) solution with constant space..
>> --
>> Regards
>> Kumar Raja
>> M.Tech(SIT)
>> IIT Kharagpur,
>> 10it60...@iitkgp.ac.in
>> 7797137043.
>> 09491690115.
>>
>>  --
>> You received this message because you are subscribed to the Google
>> Groups "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>
>
> --
> Kind Regards
> Ishan Aggarwal
> [image: Aricent Group]
> Presidency Tower-A, M.G.Road,Sector-14
> Gurgaon,Haryana.122015 INDIA
> Phone : +91-9654602663
> ishan2.aggar...@aricent.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.
>



 --
 Regards
 Kumar Raja
 M.Tech(SIT)
 IIT Kharagpur,
 10it60...@iitkgp.ac.in
 7797137043.
 09491690115.

  --
 You received this message because you are subscribed to the Google
 Groups "Algorithm Geeks" group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from 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
>> Kumar Raja
>> M.Tech(SIT)
>> IIT Kharagpur,
>> 10it60...@iitkgp.ac.in
>> 7797137043.
>> 09491690115.
>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>
>
> --
>
> **Please do not print this e-mail until urgent requirement. Go Green!!
> Save Papers <=> Save Trees
> *BharatKumar Bagana*
> **http://www.go

Re: [algogeeks] Circular Left shift

2011-09-10 Thread bharatkumar bagana
swap k elements form 1 to k and n-k to n respectively...
ex: k=3
   temp=k;

int a[9]= {9,7,6,5,3,23,14,2,4} ; has become {14,2,4,5,3,23,9,7,6};
now swap first k elements with k+1 to 2k elements ...now k=2k+1 , do
this step again up to (kwrote:

> @sarath:
> I did not get u .Could u please explain it with the example.
>
>
> On 10 September 2011 03:39, sarath prasath wrote:
>
>> consider this approach..
>> first reverse the entire array...
>> so it will be.. 4,2,14,23,3,5,6,7,9
>> and u want to shift k times right so
>> u have to cut the array as n-k  and reverse both the sides u ll get it..
>> so in ur scenario we are reversing upto the element 5 in array and
>> reversing the remaining elements..
>> hope the complexity is of o(n)..
>>
>>
>>
>> On Sat, Sep 10, 2011 at 3:17 PM, kumar raja wrote:
>>
>>> U have used c[3] extra array.It is already known solution. so it is using
>>> O(k) space .i want the solution with constant space..
>>>
>>>
>>> On 10 September 2011 02:08, Ishan Aggarwal <
>>> ishan.aggarwal.1...@gmail.com> wrote:
>>>
 Solution :-




 void main(){int a[9]= {9,7,6,5,3,23,14,2,4} ;int n = 3;int c[3];int i;int 
 k =0;for ( i=0;i<3;i++)
 c[i]= a[i];for(i=3;i<9;i++)
 a[i-3] =a[i];for(i=9-3;i<9;i++)
 a[i] = c[k++];for(i=0;i<9;i++)printf 
 ("\n%d",a[i]);}


 On Sat, Sep 10, 2011 at 2:09 PM, kumar raja 
 wrote:

> Given an array of 'n' values you need to circular shift it 'k' times
> towards left.
>
> Input : 9 7 6 5 3 23 14  2  4
> output : 5 3 23 14 2  4 9 7  6
>
> n=9 , k= 3
>
> constraints : Time complexity O(n)
> Space complexity O(1)
>
> The solutions with O(kn) time complexity and
> O(n) complexity with O(k) space complexity are already available.
>
> I want the O(n) solution with constant space..
> --
> Regards
> Kumar Raja
> M.Tech(SIT)
> IIT Kharagpur,
> 10it60...@iitkgp.ac.in
> 7797137043.
> 09491690115.
>
>  --
> You received this message because you are subscribed to the Google
> Groups "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>



 --
 Kind Regards
 Ishan Aggarwal
 [image: Aricent Group]
 Presidency Tower-A, M.G.Road,Sector-14
 Gurgaon,Haryana.122015 INDIA
 Phone : +91-9654602663
 ishan2.aggar...@aricent.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.

>>>
>>>
>>>
>>> --
>>> Regards
>>> Kumar Raja
>>> M.Tech(SIT)
>>> IIT Kharagpur,
>>> 10it60...@iitkgp.ac.in
>>> 7797137043.
>>> 09491690115.
>>>
>>>  --
>>> You received this message because you are subscribed to the Google Groups
>>> "Algorithm Geeks" group.
>>> To post to this group, send email to algogeeks@googlegroups.com.
>>> To unsubscribe from 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
> Kumar Raja
> M.Tech(SIT)
> IIT Kharagpur,
> 10it60...@iitkgp.ac.in
> 7797137043.
> 09491690115.
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>



-- 

**Please do not print this e-mail until urgent requirement. Go Green!!
Save Papers <=> Save Trees
*BharatKumar Bagana*
**http://www.google.com/profiles/bagana.bharatkumar
*
Mobile +91 8056127652*


-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, v

Re: [algogeeks] Circular Left shift

2011-09-10 Thread kumar raja
@sarath:
I did not get u .Could u please explain it with the example.

On 10 September 2011 03:39, sarath prasath  wrote:

> consider this approach..
> first reverse the entire array...
> so it will be.. 4,2,14,23,3,5,6,7,9
> and u want to shift k times right so
> u have to cut the array as n-k  and reverse both the sides u ll get it..
> so in ur scenario we are reversing upto the element 5 in array and
> reversing the remaining elements..
> hope the complexity is of o(n)..
>
>
>
> On Sat, Sep 10, 2011 at 3:17 PM, kumar raja wrote:
>
>> U have used c[3] extra array.It is already known solution. so it is using
>> O(k) space .i want the solution with constant space..
>>
>>
>> On 10 September 2011 02:08, Ishan Aggarwal > > wrote:
>>
>>> Solution :-
>>>
>>>
>>>
>>> void main(){int a[9]= {9,7,6,5,3,23,14,2,4} ;int n = 3;int c[3];int i;int k 
>>> =0;for ( i=0;i<3;i++)
>>> c[i]= a[i];for(i=3;i<9;i++)
>>> a[i-3] =a[i];for(i=9-3;i<9;i++)
>>> a[i] = c[k++];for(i=0;i<9;i++)printf 
>>> ("\n%d",a[i]);}
>>>
>>>
>>> On Sat, Sep 10, 2011 at 2:09 PM, kumar raja wrote:
>>>
 Given an array of 'n' values you need to circular shift it 'k' times
 towards left.

 Input : 9 7 6 5 3 23 14  2  4
 output : 5 3 23 14 2  4 9 7  6

 n=9 , k= 3

 constraints : Time complexity O(n)
 Space complexity O(1)

 The solutions with O(kn) time complexity and
 O(n) complexity with O(k) space complexity are already available.

 I want the O(n) solution with constant space..
 --
 Regards
 Kumar Raja
 M.Tech(SIT)
 IIT Kharagpur,
 10it60...@iitkgp.ac.in
 7797137043.
 09491690115.

  --
 You received this message because you are subscribed to the Google
 Groups "Algorithm Geeks" group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.

>>>
>>>
>>>
>>> --
>>> Kind Regards
>>> Ishan Aggarwal
>>> [image: Aricent Group]
>>> Presidency Tower-A, M.G.Road,Sector-14
>>> Gurgaon,Haryana.122015 INDIA
>>> Phone : +91-9654602663
>>> ishan2.aggar...@aricent.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.
>>>
>>
>>
>>
>> --
>> Regards
>> Kumar Raja
>> M.Tech(SIT)
>> IIT Kharagpur,
>> 10it60...@iitkgp.ac.in
>> 7797137043.
>> 09491690115.
>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from 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
Kumar Raja
M.Tech(SIT)
IIT Kharagpur,
10it60...@iitkgp.ac.in
7797137043.
09491690115.

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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] Circular Left shift

2011-09-10 Thread sarath prasath
consider this approach..
first reverse the entire array...
so it will be.. 4,2,14,23,3,5,6,7,9
and u want to shift k times right so
u have to cut the array as n-k  and reverse both the sides u ll get it..
so in ur scenario we are reversing upto the element 5 in array and reversing
the remaining elements..
hope the complexity is of o(n)..


On Sat, Sep 10, 2011 at 3:17 PM, kumar raja wrote:

> U have used c[3] extra array.It is already known solution. so it is using
> O(k) space .i want the solution with constant space..
>
>
> On 10 September 2011 02:08, Ishan Aggarwal 
> wrote:
>
>> Solution :-
>>
>>
>> void main(){int a[9]= {9,7,6,5,3,23,14,2,4} ;int n = 3;int c[3];int i;int k 
>> =0;for ( i=0;i<3;i++)
>> c[i]= a[i];for(i=3;i<9;i++)
>> a[i-3] =a[i];for(i=9-3;i<9;i++)
>> a[i] = c[k++];for(i=0;i<9;i++)printf 
>> ("\n%d",a[i]);}
>>
>>
>> On Sat, Sep 10, 2011 at 2:09 PM, kumar raja wrote:
>>
>>> Given an array of 'n' values you need to circular shift it 'k' times
>>> towards left.
>>>
>>> Input : 9 7 6 5 3 23 14  2  4
>>> output : 5 3 23 14 2  4 9 7  6
>>>
>>> n=9 , k= 3
>>>
>>> constraints : Time complexity O(n)
>>> Space complexity O(1)
>>>
>>> The solutions with O(kn) time complexity and
>>> O(n) complexity with O(k) space complexity are already available.
>>>
>>> I want the O(n) solution with constant space..
>>> --
>>> Regards
>>> Kumar Raja
>>> M.Tech(SIT)
>>> IIT Kharagpur,
>>> 10it60...@iitkgp.ac.in
>>> 7797137043.
>>> 09491690115.
>>>
>>>  --
>>> You received this message because you are subscribed to the Google Groups
>>> "Algorithm Geeks" group.
>>> To post to this group, send email to algogeeks@googlegroups.com.
>>> To unsubscribe from this group, send email to
>>> algogeeks+unsubscr...@googlegroups.com.
>>> For more options, visit this group at
>>> http://groups.google.com/group/algogeeks?hl=en.
>>>
>>
>>
>>
>> --
>> Kind Regards
>> Ishan Aggarwal
>> [image: Aricent Group]
>> Presidency Tower-A, M.G.Road,Sector-14
>> Gurgaon,Haryana.122015 INDIA
>> Phone : +91-9654602663
>> ishan2.aggar...@aricent.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.
>>
>
>
>
> --
> Regards
> Kumar Raja
> M.Tech(SIT)
> IIT Kharagpur,
> 10it60...@iitkgp.ac.in
> 7797137043.
> 09491690115.
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from 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] Circular Left shift

2011-09-10 Thread kumar raja
U have used c[3] extra array.It is already known solution. so it is using
O(k) space .i want the solution with constant space..

On 10 September 2011 02:08, Ishan Aggarwal wrote:

> Solution :-
>
>
> void main(){int a[9]= {9,7,6,5,3,23,14,2,4} ;int n = 3;int c[3];int i;int k 
> =0;for ( i=0;i<3;i++)
> c[i]= a[i];for(i=3;i<9;i++)
> a[i-3] =a[i];for(i=9-3;i<9;i++)
> a[i] = c[k++];for(i=0;i<9;i++)printf 
> ("\n%d",a[i]);}
>
>
> On Sat, Sep 10, 2011 at 2:09 PM, kumar raja wrote:
>
>> Given an array of 'n' values you need to circular shift it 'k' times
>> towards left.
>>
>> Input : 9 7 6 5 3 23 14  2  4
>> output : 5 3 23 14 2  4 9 7  6
>>
>> n=9 , k= 3
>>
>> constraints : Time complexity O(n)
>> Space complexity O(1)
>>
>> The solutions with O(kn) time complexity and
>> O(n) complexity with O(k) space complexity are already available.
>>
>> I want the O(n) solution with constant space..
>> --
>> Regards
>> Kumar Raja
>> M.Tech(SIT)
>> IIT Kharagpur,
>> 10it60...@iitkgp.ac.in
>> 7797137043.
>> 09491690115.
>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>
>
> --
> Kind Regards
> Ishan Aggarwal
> [image: Aricent Group]
> Presidency Tower-A, M.G.Road,Sector-14
> Gurgaon,Haryana.122015 INDIA
> Phone : +91-9654602663
> ishan2.aggar...@aricent.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.
>



-- 
Regards
Kumar Raja
M.Tech(SIT)
IIT Kharagpur,
10it60...@iitkgp.ac.in
7797137043.
09491690115.

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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] Circular Left shift

2011-09-10 Thread Ishan Aggarwal
Solution :-


void main(){int a[9]= {9,7,6,5,3,23,14,2,4} ;int n = 3;int c[3];int
i;int k =0;for ( i=0;i<3;i++)
c[i]= a[i];for(i=3;i<9;i++)
a[i-3] =a[i];for(i=9-3;i<9;i++)
a[i] = c[k++];for(i=0;i<9;i++)printf
("\n%d",a[i]);}


On Sat, Sep 10, 2011 at 2:09 PM, kumar raja wrote:

> Given an array of 'n' values you need to circular shift it 'k' times
> towards left.
>
> Input : 9 7 6 5 3 23 14  2  4
> output : 5 3 23 14 2  4 9 7  6
>
> n=9 , k= 3
>
> constraints : Time complexity O(n)
> Space complexity O(1)
>
> The solutions with O(kn) time complexity and
> O(n) complexity with O(k) space complexity are already available.
>
> I want the O(n) solution with constant space..
> --
> Regards
> Kumar Raja
> M.Tech(SIT)
> IIT Kharagpur,
> 10it60...@iitkgp.ac.in
> 7797137043.
> 09491690115.
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>



-- 
Kind Regards
Ishan Aggarwal
[image: Aricent Group]
Presidency Tower-A, M.G.Road,Sector-14
Gurgaon,Haryana.122015 INDIA
Phone : +91-9654602663
ishan2.aggar...@aricent.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.



[algogeeks] Circular Left shift

2011-09-10 Thread kumar raja
Given an array of 'n' values you need to circular shift it 'k' times towards
left.

Input : 9 7 6 5 3 23 14  2  4
output : 5 3 23 14 2  4 9 7  6

n=9 , k= 3

constraints : Time complexity O(n)
Space complexity O(1)

The solutions with O(kn) time complexity and
O(n) complexity with O(k) space complexity are already available.

I want the O(n) solution with constant space..
-- 
Regards
Kumar Raja
M.Tech(SIT)
IIT Kharagpur,
10it60...@iitkgp.ac.in
7797137043.
09491690115.

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.