Re: [algogeeks] MS Question

2013-01-22 Thread Amitesh Singh
you can't implement in O(log n). It can be done in O(log n) in case of
Ranked BS Tree.


-- 
Amitesh



On Sun, Jan 20, 2013 at 6:23 PM, Praveen  wrote:

> If for all the nodes in BST we also store the size of subtree, then it is
> possible to find nth smallest element in O(logN).
>
> On Sun, Jan 20, 2013 at 4:57 PM, Guneesh Paul Singh 
> wrote:
>
>> not possible unless u use augmented bst..which itself takes o(n) to built
>>
>> --
>>
>>
>>
>
>
>
> --
> Praveen Sonare
> +91-7838908235
>
>
>
> --
>
>
>

-- 




Re: [algogeeks] MS Question

2013-01-20 Thread Praveen
If for all the nodes in BST we also store the size of subtree, then it is
possible to find nth smallest element in O(logN).

On Sun, Jan 20, 2013 at 4:57 PM, Guneesh Paul Singh wrote:

> not possible unless u use augmented bst..which itself takes o(n) to built
>
> --
>
>
>



-- 
Praveen Sonare
+91-7838908235

-- 




Re: [algogeeks] MS Question

2013-01-20 Thread Mohanabalan D B
http://stackoverflow.com/questions/2329171/find-kth-smallest-element-in-a-binary-search-tree-in-optimum-way


On Sun, Jan 20, 2013 at 4:57 PM, Guneesh Paul Singh wrote:

> not possible unless u use augmented bst..which itself takes o(n) to built
>
> --
>
>
>

-- 




Re: [algogeeks] MS Question

2013-01-20 Thread Guneesh Paul Singh
not possible unless u use augmented bst..which itself takes o(n) to built

-- 




[algogeeks] MS Question

2013-01-19 Thread Umer Farooq
Given a BST, how would you return the nth smallest element. The code had to
cover all the edge cases and was expected to write a logn solution.


-- 
Umer

-- 




Re: [algogeeks] MS QUESTION

2012-08-24 Thread Navin Kumar
Few more Test cases :

Check for 10 node.
Check for 1 million node
Check for even number of nodes
Check for odd number of nodes...

etc etc...

On Fri, Aug 24, 2012 at 6:25 PM, Navin Kumar wrote:

> Reversing a linked list if loop exists:
>
> 1. Find the node from which loop start by any loop finding algorithm in
> linked list and keep the position of that node.
>
> 2. Unroll the loop i.e. set the last node's(last unrepeating node) next
> pointer to NULL.
>
> 3. Reverse this singly linked list.
>
> 4. Change the last node's next pointer to the node corresponding to the
> position we found in step1.
>
>
> On Thu, Aug 23, 2012 at 8:02 PM, sulekha metta wrote:
>
>> Hi all,
>>  This was asked in microsoft, question is  write a program to
>> reverse a linked list.and write it's test cases.
>> i got very few test cases
>> 1) check if the node is null
>> 2) check if there is only one node
>> 3) check if there is any loop in the linked list.
>>  can any one tell how to reverse a linked list if loop exits? is it
>> possible?
>> and  can any one add few more test cases??
>>
>>
>> --
>> Regards
>> sulekha metta
>> B.E computer science
>> osmania university
>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>

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



Re: [algogeeks] MS QUESTION

2012-08-24 Thread Navin Kumar
Reversing a linked list if loop exists:

1. Find the node from which loop start by any loop finding algorithm in
linked list and keep the position of that node.

2. Unroll the loop i.e. set the last node's(last unrepeating node) next
pointer to NULL.

3. Reverse this singly linked list.

4. Change the last node's next pointer to the node corresponding to the
position we found in step1.

On Thu, Aug 23, 2012 at 8:02 PM, sulekha metta wrote:

> Hi all,
>  This was asked in microsoft, question is  write a program to
> reverse a linked list.and write it's test cases.
> i got very few test cases
> 1) check if the node is null
> 2) check if there is only one node
> 3) check if there is any loop in the linked list.
>  can any one tell how to reverse a linked list if loop exits? is it
> possible?
> and  can any one add few more test cases??
>
>
> --
> Regards
> sulekha metta
> B.E computer science
> osmania university
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

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



[algogeeks] MS QUESTION

2012-08-24 Thread sulekha metta
Hi all,
 This was asked in microsoft, question is  write a program to
reverse a linked list.and write it's test cases.
i got very few test cases
1) check if the node is null
2) check if there is only one node
3) check if there is any loop in the linked list.
 can any one tell how to reverse a linked list if loop exits? is it
possible?
and  can any one add few more test cases??


--
Regards
sulekha metta
B.E computer science
osmania university

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



Re: [algogeeks] MS Question: Segregrate positive and negative nos in array without changing order

2012-07-02 Thread atul anand
@amol : algo seems to work but will fail if size of arr increases.
int arr[]={21,2,7,9,20,15,3,5,0,17,11,12,13,14,1,8,10,4,19,6,18,16};
it will fail for above case.
if we u run outer loop one more time then it will work fine. So there
should be some relation b/w number of elements and minimum number number of
outer loop we need to run.

On Mon, Jul 2, 2012 at 4:08 PM, Amol Sharma  wrote:

> @atul:
> the logic for the O(n) counting is same as for the count sort.
>
> you haven't write the swap function correctly,
>
> here is correct code for swap function --
>
>
> temp=arr[i];
> arr[i]=arr[arr[i]];
> arr[temp]=temp;
>
> please replace this in your code and it works fine, hope now it's clear.
>
>
> --
>
>
> Amol Sharma
> Final Year Student
> Computer Science and Engineering
> MNNIT Allahabad
>
>  
> 
>
>
>
>
>
>
> On Mon, Jul 2, 2012 at 3:30 PM, atul anand wrote:
>
>> yes it is same and it not working . Apart for this you had provided code
>> for sorting O(n) time and not the idea/algo.
>> please explain the algorithm , how you are sorting it within O(n) time
>> and O(1) space complexity.
>>
>> On Mon, Jul 2, 2012 at 3:18 PM, Amol Sharma wrote:
>>
>>> i don't see any change in the code you posted...other than expanding
>>> swap function
>>>
>>> i believe in discussing the idea/algonot the code..
>>>
>>> --
>>>
>>>
>>> Amol Sharma
>>> Final Year Student
>>> Computer Science and Engineering
>>> MNNIT Allahabad
>>>
>>>  
>>> 
>>>
>>>
>>>
>>>
>>>
>>>
>>> On Mon, Jul 2, 2012 at 12:59 PM, atul anand wrote:
>>>
 @amol :

 #include

 int main()
 {

 int arr[]={5,0,1,2,6,7,8,3,4,9};
 int i,j,n,temp;
 n=sizeof(arr)/sizeof(arr[0]);

 for(j=0;j<=1;j++)
 {
 for(i=0;i>>> {
   if(arr[i]!=i){
 temp=arr[i];
 arr[i]=arr[arr[i]];
 arr[arr[i]]=temp;

 }

 }
 }

 for(i=0;i>>> printf("%d ",arr[i]);
 printf("\n");
 return 1;

 }



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

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

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



Re: [algogeeks] MS Question: Segregrate positive and negative nos in array without changing order

2012-07-02 Thread atul anand
opssyeah dat was the bug... now got it :)

On Mon, Jul 2, 2012 at 4:08 PM, Amol Sharma  wrote:

> @atul:
> the logic for the O(n) counting is same as for the count sort.
>
> you haven't write the swap function correctly,
>
> here is correct code for swap function --
>
>
> temp=arr[i];
> arr[i]=arr[arr[i]];
> arr[temp]=temp;
>
> please replace this in your code and it works fine, hope now it's clear.
>
>
> --
>
>
> Amol Sharma
> Final Year Student
> Computer Science and Engineering
> MNNIT Allahabad
>
>  
> 
>
>
>
>
>
>
> On Mon, Jul 2, 2012 at 3:30 PM, atul anand wrote:
>
>> yes it is same and it not working . Apart for this you had provided code
>> for sorting O(n) time and not the idea/algo.
>> please explain the algorithm , how you are sorting it within O(n) time
>> and O(1) space complexity.
>>
>> On Mon, Jul 2, 2012 at 3:18 PM, Amol Sharma wrote:
>>
>>> i don't see any change in the code you posted...other than expanding
>>> swap function
>>>
>>> i believe in discussing the idea/algonot the code..
>>>
>>> --
>>>
>>>
>>> Amol Sharma
>>> Final Year Student
>>> Computer Science and Engineering
>>> MNNIT Allahabad
>>>
>>>  
>>> 
>>>
>>>
>>>
>>>
>>>
>>>
>>> On Mon, Jul 2, 2012 at 12:59 PM, atul anand wrote:
>>>
 @amol :

 #include

 int main()
 {

 int arr[]={5,0,1,2,6,7,8,3,4,9};
 int i,j,n,temp;
 n=sizeof(arr)/sizeof(arr[0]);

 for(j=0;j<=1;j++)
 {
 for(i=0;i>>> {
   if(arr[i]!=i){
 temp=arr[i];
 arr[i]=arr[arr[i]];
 arr[arr[i]]=temp;

 }

 }
 }

 for(i=0;i>>> printf("%d ",arr[i]);
 printf("\n");
 return 1;

 }



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

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

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



Re: [algogeeks] MS Question: Segregrate positive and negative nos in array without changing order

2012-07-02 Thread atul anand
yes it is same and it not working . Apart for this you had provided code
for sorting O(n) time and not the idea/algo.
please explain the algorithm , how you are sorting it within O(n) time and
O(1) space complexity.

On Mon, Jul 2, 2012 at 3:18 PM, Amol Sharma  wrote:

> i don't see any change in the code you posted...other than expanding swap
> function
>
> i believe in discussing the idea/algonot the code..
>
> --
>
>
> Amol Sharma
> Final Year Student
> Computer Science and Engineering
> MNNIT Allahabad
>
>  
> 
>
>
>
>
>
>
> On Mon, Jul 2, 2012 at 12:59 PM, atul anand wrote:
>
>> @amol :
>>
>> #include
>>
>> int main()
>> {
>>
>> int arr[]={5,0,1,2,6,7,8,3,4,9};
>> int i,j,n,temp;
>> n=sizeof(arr)/sizeof(arr[0]);
>>
>> for(j=0;j<=1;j++)
>> {
>> for(i=0;i> {
>>   if(arr[i]!=i){
>> temp=arr[i];
>> arr[i]=arr[arr[i]];
>> arr[arr[i]]=temp;
>>
>> }
>>
>> }
>> }
>>
>> for(i=0;i> printf("%d ",arr[i]);
>> printf("\n");
>> return 1;
>>
>> }
>>
>>
>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

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



Re: [algogeeks] MS Question: Segregrate positive and negative nos in array without changing order

2012-07-02 Thread Amol Sharma
i don't see any change in the code you posted...other than expanding swap
function

i believe in discussing the idea/algonot the code..
--


Amol Sharma
Final Year Student
Computer Science and Engineering
MNNIT Allahabad









On Mon, Jul 2, 2012 at 12:59 PM, atul anand  wrote:

> @amol :
>
> #include
>
> int main()
> {
>
> int arr[]={5,0,1,2,6,7,8,3,4,9};
> int i,j,n,temp;
> n=sizeof(arr)/sizeof(arr[0]);
>
> for(j=0;j<=1;j++)
> {
> for(i=0;i {
>   if(arr[i]!=i){
> temp=arr[i];
> arr[i]=arr[arr[i]];
> arr[arr[i]]=temp;
>
> }
>
> }
> }
>
> for(i=0;i printf("%d ",arr[i]);
> printf("\n");
> return 1;
>
> }
>
>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

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



Re: [algogeeks] MS Question: Segregrate positive and negative nos in array without changing order

2012-07-02 Thread atul anand
@amol :

#include

int main()
{

int arr[]={5,0,1,2,6,7,8,3,4,9};
int i,j,n,temp;
n=sizeof(arr)/sizeof(arr[0]);
for(j=0;j<=1;j++)
{
for(i=0;ihttp://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] MS Question: Segregrate positive and negative nos in array without changing order

2012-07-02 Thread Amol Sharma
@atul... can u point out where sorting is not working ? any case ?

--


Amol Sharma
Final Year Student
Computer Science and Engineering
MNNIT Allahabad

<http://gplus.to/amolsharma99>
<http://twitter.com/amolsharma99><http://in.linkedin.com/pub/amol-sharma/21/79b/507><http://www.simplyamol.blogspot.com/><http://facebook.com/amolsharma99>






On Mon, Jul 2, 2012 at 12:12 PM, Hassan Monfared wrote:

> I think O(N) space or O(nlogn) [stable nlogn sort : like stable merge sort
> ) time is required.
> ( I provided O(n^2) time and O(1) space before )
>
>
>
> On Mon, Jul 2, 2012 at 10:24 AM, atul anand wrote:
>
>> @amol : even if your algo wont work for this...until and unless you use
>> extra space...
>> but your sorting algo is not working.
>>
>> On Sun, Jul 1, 2012 at 11:08 PM, Amol Sharma wrote:
>>
>>> i think it has been discussed beforenevertheless here is the
>>> required linear time solution.
>>>
>>> first, count the total number 0's and 1's in the array.
>>>
>>> let say, total elements are n and there are x zero's.
>>>
>>> take count1=0 and count2=x;
>>>
>>> traverse through the array :
>>> for(i=0;i>> if(arr[i]==0)
>>>   arr[i]=count1++;
>>> else
>>>   arr[i]=count2++;
>>>
>>> let's say array is {1,0,0,0,1,1,1,0,0,1}  n=10,x=5
>>> count1=0;count2=5
>>>
>>> after the traversal it becomes a[]={5,0,1,2,6,7,8,3,4,9}
>>>
>>> now sort this array in O(n) like this :
>>>
>>> for(j=0;j<=1;j++)
>>> {
>>> for(i=0;i>> {
>>>   if(arr[i]!=i)
>>>swap(arr[i],arr[arr[i]]);
>>> }
>>> }
>>>
>>> after the array is sorted again traverse the array and set the elements
>>> from index 0 to x-1 to '0' and rest '1'.
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> --
>>>
>>>
>>> Amol Sharma
>>> Final Year Student
>>> Computer Science and Engineering
>>> MNNIT Allahabad
>>>
>>> <http://gplus.to/amolsharma99> 
>>> <http://twitter.com/amolsharma99><http://in.linkedin.com/pub/amol-sharma/21/79b/507><http://www.simplyamol.blogspot.com/><http://facebook.com/amolsharma99>
>>>
>>>
>>>
>>>
>>>
>>>
>>> On Fri, Jun 29, 2012 at 9:20 PM, Bhaskar Kushwaha <
>>> bhaskar.kushwaha2...@gmail.com> wrote:
>>>
>>>> @Hassan I think your algo will take time O(n^2) in worst case which
>>>> occurs when all elements are negative except the last one
>>>> @everyone Can we solve this problem in linear time?
>>>>
>>>>
>>>> On Fri, Jun 29, 2012 at 9:10 PM, Hassan Monfared 
>>>> wrote:
>>>>
>>>>> Hi,
>>>>> this can be done by simple modification in bubble sort :
>>>>> void inplace_pos_neg(int pdata[],int sz)
>>>>> {
>>>>> bool changed=false;
>>>>>  do
>>>>> {
>>>>> changed=false;
>>>>>  for(int i=1;i>>>> if(pdata[i-1]>0 && pdata[i]<0)
>>>>> {
>>>>>  swap(pdata[i-1], pdata[i]);
>>>>> changed=true;
>>>>> }
>>>>>  }while(changed);
>>>>> }
>>>>>
>>>>> void test_inplace_pos_neg()
>>>>> {
>>>>> int a[]={-1,-5,10,11,15,-500,200,-10};
>>>>>
>>>>> copy(a,a+sizeof(a)/sizeof(int),ostream_iterator(cout,","));cout<>>>> inplace_pos_neg(a,sizeof(a)/sizeof(int));
>>>>>
>>>>> copy(a,a+sizeof(a)/sizeof(int),ostream_iterator(cout,","));cout<>>>>
>>>>> }
>>>>>
>>>>>
>>>>> Regards
>>>>>
>>>>> On Fri, Jun 29, 2012 at 7:52 PM, utsav sharma <
>>>>> utsav.sharm...@gmail.com> wrote:
>>>>>
>>>>>> @bhaskar:- please explain stable sorting algorithm you would use(as
>>>>>> mainly all of them require extra space)
>>>>>> @sourabh:- that previous post discussion does't lead to any correct
>>>>>> soln
>>>>>>
>>>>>> On Fri, Jun 29, 2012 at 8:39 P

Re: [algogeeks] MS Question: Segregrate positive and negative nos in array without changing order

2012-07-01 Thread Hassan Monfared
I think O(N) space or O(nlogn) [stable nlogn sort : like stable merge sort
) time is required.
( I provided O(n^2) time and O(1) space before )


On Mon, Jul 2, 2012 at 10:24 AM, atul anand  wrote:

> @amol : even if your algo wont work for this...until and unless you use
> extra space...
> but your sorting algo is not working.
>
> On Sun, Jul 1, 2012 at 11:08 PM, Amol Sharma wrote:
>
>> i think it has been discussed beforenevertheless here is the required
>> linear time solution.
>>
>> first, count the total number 0's and 1's in the array.
>>
>> let say, total elements are n and there are x zero's.
>>
>> take count1=0 and count2=x;
>>
>> traverse through the array :
>> for(i=0;i> if(arr[i]==0)
>>   arr[i]=count1++;
>> else
>>   arr[i]=count2++;
>>
>> let's say array is {1,0,0,0,1,1,1,0,0,1}  n=10,x=5
>> count1=0;count2=5
>>
>> after the traversal it becomes a[]={5,0,1,2,6,7,8,3,4,9}
>>
>> now sort this array in O(n) like this :
>>
>> for(j=0;j<=1;j++)
>> {
>> for(i=0;i> {
>>   if(arr[i]!=i)
>>swap(arr[i],arr[arr[i]]);
>> }
>> }
>>
>> after the array is sorted again traverse the array and set the elements
>> from index 0 to x-1 to '0' and rest '1'.
>>
>>
>>
>>
>>
>>
>>
>>
>> --
>>
>>
>> Amol Sharma
>> Final Year Student
>> Computer Science and Engineering
>> MNNIT Allahabad
>>
>> <http://gplus.to/amolsharma99> 
>> <http://twitter.com/amolsharma99><http://in.linkedin.com/pub/amol-sharma/21/79b/507><http://www.simplyamol.blogspot.com/><http://facebook.com/amolsharma99>
>>
>>
>>
>>
>>
>>
>> On Fri, Jun 29, 2012 at 9:20 PM, Bhaskar Kushwaha <
>> bhaskar.kushwaha2...@gmail.com> wrote:
>>
>>> @Hassan I think your algo will take time O(n^2) in worst case which
>>> occurs when all elements are negative except the last one
>>> @everyone Can we solve this problem in linear time?
>>>
>>>
>>> On Fri, Jun 29, 2012 at 9:10 PM, Hassan Monfared wrote:
>>>
>>>> Hi,
>>>> this can be done by simple modification in bubble sort :
>>>> void inplace_pos_neg(int pdata[],int sz)
>>>> {
>>>> bool changed=false;
>>>>  do
>>>> {
>>>> changed=false;
>>>>  for(int i=1;i>>> if(pdata[i-1]>0 && pdata[i]<0)
>>>> {
>>>>  swap(pdata[i-1], pdata[i]);
>>>> changed=true;
>>>> }
>>>>  }while(changed);
>>>> }
>>>>
>>>> void test_inplace_pos_neg()
>>>> {
>>>> int a[]={-1,-5,10,11,15,-500,200,-10};
>>>>
>>>> copy(a,a+sizeof(a)/sizeof(int),ostream_iterator(cout,","));cout<>>> inplace_pos_neg(a,sizeof(a)/sizeof(int));
>>>>
>>>> copy(a,a+sizeof(a)/sizeof(int),ostream_iterator(cout,","));cout<>>>
>>>> }
>>>>
>>>>
>>>> Regards
>>>>
>>>> On Fri, Jun 29, 2012 at 7:52 PM, utsav sharma >>> > wrote:
>>>>
>>>>> @bhaskar:- please explain stable sorting algorithm you would use(as
>>>>> mainly all of them require extra space)
>>>>> @sourabh:- that previous post discussion does't lead to any correct
>>>>> soln
>>>>>
>>>>> On Fri, Jun 29, 2012 at 8:39 PM, Bhaskar Kushwaha <
>>>>> bhaskar.kushwaha2...@gmail.com> wrote:
>>>>>
>>>>>> @saurabh please provide the link to the post you are mentioning
>>>>>>
>>>>>> On Fri, Jun 29, 2012 at 8:38 PM, Bhaskar Kushwaha <
>>>>>> bhaskar.kushwaha2...@gmail.com> wrote:
>>>>>>
>>>>>>>  If the order is important then I think we can use any stable
>>>>>>> sorting algorithm with the following comparison function
>>>>>>>
>>>>>>> int compare (int a ,int b)
>>>>>>> {
>>>>>>> if((a>0&&b>0)||(a<0&&b<0)) return 0;
>>>>>>> else return a>>>>>> }
>>>>>>> On Fri, Jun 29, 2012 at 3:37 PM, raghavan M <
>>>>>>> peacelover1987...@yahoo.co.

Re: [algogeeks] MS Question: Segregrate positive and negative nos in array without changing order

2012-07-01 Thread atul anand
@amol : even if your algo wont work for this...until and unless you use
extra space...
but your sorting algo is not working.

On Sun, Jul 1, 2012 at 11:08 PM, Amol Sharma  wrote:

> i think it has been discussed beforenevertheless here is the required
> linear time solution.
>
> first, count the total number 0's and 1's in the array.
>
> let say, total elements are n and there are x zero's.
>
> take count1=0 and count2=x;
>
> traverse through the array :
> for(i=0;i if(arr[i]==0)
>   arr[i]=count1++;
> else
>   arr[i]=count2++;
>
> let's say array is {1,0,0,0,1,1,1,0,0,1}  n=10,x=5
> count1=0;count2=5
>
> after the traversal it becomes a[]={5,0,1,2,6,7,8,3,4,9}
>
> now sort this array in O(n) like this :
>
> for(j=0;j<=1;j++)
> {
> for(i=0;i {
>   if(arr[i]!=i)
>swap(arr[i],arr[arr[i]]);
> }
> }
>
> after the array is sorted again traverse the array and set the elements
> from index 0 to x-1 to '0' and rest '1'.
>
>
>
>
>
>
>
>
> --
>
>
> Amol Sharma
> Final Year Student
> Computer Science and Engineering
> MNNIT Allahabad
>
> <http://gplus.to/amolsharma99> 
> <http://twitter.com/amolsharma99><http://in.linkedin.com/pub/amol-sharma/21/79b/507><http://www.simplyamol.blogspot.com/><http://facebook.com/amolsharma99>
>
>
>
>
>
>
> On Fri, Jun 29, 2012 at 9:20 PM, Bhaskar Kushwaha <
> bhaskar.kushwaha2...@gmail.com> wrote:
>
>> @Hassan I think your algo will take time O(n^2) in worst case which
>> occurs when all elements are negative except the last one
>> @everyone Can we solve this problem in linear time?
>>
>>
>> On Fri, Jun 29, 2012 at 9:10 PM, Hassan Monfared wrote:
>>
>>> Hi,
>>> this can be done by simple modification in bubble sort :
>>> void inplace_pos_neg(int pdata[],int sz)
>>> {
>>> bool changed=false;
>>>  do
>>> {
>>> changed=false;
>>>  for(int i=1;i>> if(pdata[i-1]>0 && pdata[i]<0)
>>> {
>>>  swap(pdata[i-1], pdata[i]);
>>> changed=true;
>>> }
>>>  }while(changed);
>>> }
>>>
>>> void test_inplace_pos_neg()
>>> {
>>> int a[]={-1,-5,10,11,15,-500,200,-10};
>>>
>>> copy(a,a+sizeof(a)/sizeof(int),ostream_iterator(cout,","));cout<>> inplace_pos_neg(a,sizeof(a)/sizeof(int));
>>>
>>> copy(a,a+sizeof(a)/sizeof(int),ostream_iterator(cout,","));cout<>>
>>> }
>>>
>>>
>>> Regards
>>>
>>> On Fri, Jun 29, 2012 at 7:52 PM, utsav sharma 
>>> wrote:
>>>
>>>> @bhaskar:- please explain stable sorting algorithm you would use(as
>>>> mainly all of them require extra space)
>>>> @sourabh:- that previous post discussion does't lead to any correct soln
>>>>
>>>> On Fri, Jun 29, 2012 at 8:39 PM, Bhaskar Kushwaha <
>>>> bhaskar.kushwaha2...@gmail.com> wrote:
>>>>
>>>>> @saurabh please provide the link to the post you are mentioning
>>>>>
>>>>> On Fri, Jun 29, 2012 at 8:38 PM, Bhaskar Kushwaha <
>>>>> bhaskar.kushwaha2...@gmail.com> wrote:
>>>>>
>>>>>>  If the order is important then I think we can use any stable sorting
>>>>>> algorithm with the following comparison function
>>>>>>
>>>>>> int compare (int a ,int b)
>>>>>> {
>>>>>> if((a>0&&b>0)||(a<0&&b<0)) return 0;
>>>>>> else return a>>>>> }
>>>>>> On Fri, Jun 29, 2012 at 3:37 PM, raghavan M <
>>>>>> peacelover1987...@yahoo.co.in> wrote:
>>>>>>
>>>>>>> This is a variant of that one
>>>>>>>
>>>>>>>   --
>>>>>>> *From:* saurabh singh 
>>>>>>> *To:* algogeeks@googlegroups.com
>>>>>>> *Sent:* Friday, 29 June 2012 3:05 PM
>>>>>>>
>>>>>>> *Subject:* Re: [algogeeks] MS Question: Segregrate positive and
>>>>>>> negative nos in array without changing order
>>>>>>>
>>>>>>> duplicate of a previous post.Kindly refer to that post.
>>>>>>> Saurabh Singh
>>>

Re: [algogeeks] MS Question: Segregrate positive and negative nos in array without changing order

2012-07-01 Thread Amol Sharma
negative except the last one
>>> >>> @everyone Can we solve this problem in linear time?
>>> >>>
>>> >>>
>>> >>> On Fri, Jun 29, 2012 at 9:10 PM, Hassan Monfared
>>> >>> wrote:
>>> >>>
>>> >>>> Hi,
>>> >>>> this can be done by simple modification in bubble sort :
>>> >>>> void inplace_pos_neg(int pdata[],int sz)
>>> >>>> {
>>> >>>> bool changed=false;
>>> >>>>  do
>>> >>>> {
>>> >>>> changed=false;
>>> >>>>  for(int i=1;i>> >>>> if(pdata[i-1]>0 && pdata[i]<0)
>>> >>>> {
>>> >>>>  swap(pdata[i-1], pdata[i]);
>>> >>>> changed=true;
>>> >>>> }
>>> >>>>  }while(changed);
>>> >>>> }
>>> >>>>
>>> >>>> void test_inplace_pos_neg()
>>> >>>> {
>>> >>>> int a[]={-1,-5,10,11,15,-500,200,-10};
>>> >>>>
>>> >>>>
>>> copy(a,a+sizeof(a)/sizeof(int),ostream_iterator(cout,","));cout<>> >>>> inplace_pos_neg(a,sizeof(a)/sizeof(int));
>>> >>>>
>>> >>>>
>>> copy(a,a+sizeof(a)/sizeof(int),ostream_iterator(cout,","));cout<>> >>>>
>>> >>>> }
>>> >>>>
>>> >>>>
>>> >>>> Regards
>>> >>>>
>>> >>>> On Fri, Jun 29, 2012 at 7:52 PM, utsav sharma
>>> >>>> wrote:
>>> >>>>
>>> >>>>> @bhaskar:- please explain stable sorting algorithm you would use(as
>>> >>>>> mainly all of them require extra space)
>>> >>>>> @sourabh:- that previous post discussion does't lead to any correct
>>> >>>>> soln
>>> >>>>>
>>> >>>>> On Fri, Jun 29, 2012 at 8:39 PM, Bhaskar Kushwaha <
>>> >>>>> bhaskar.kushwaha2...@gmail.com> wrote:
>>> >>>>>
>>> >>>>>> @saurabh please provide the link to the post you are mentioning
>>> >>>>>>
>>> >>>>>> On Fri, Jun 29, 2012 at 8:38 PM, Bhaskar Kushwaha <
>>> >>>>>> bhaskar.kushwaha2...@gmail.com> wrote:
>>> >>>>>>
>>> >>>>>>>  If the order is important then I think we can use any stable
>>> >>>>>>> sorting
>>> >>>>>>> algorithm with the following comparison function
>>> >>>>>>>
>>> >>>>>>> int compare (int a ,int b)
>>> >>>>>>> {
>>> >>>>>>> if((a>0&&b>0)||(a<0&&b<0)) return 0;
>>> >>>>>>> else return a>> >>>>>>> }
>>> >>>>>>> On Fri, Jun 29, 2012 at 3:37 PM, raghavan M <
>>> >>>>>>> peacelover1987...@yahoo.co.in> wrote:
>>> >>>>>>>
>>> >>>>>>>> This is a variant of that one
>>> >>>>>>>>
>>> >>>>>>>>   --
>>> >>>>>>>> *From:* saurabh singh 
>>> >>>>>>>> *To:* algogeeks@googlegroups.com
>>> >>>>>>>> *Sent:* Friday, 29 June 2012 3:05 PM
>>> >>>>>>>>
>>> >>>>>>>> *Subject:* Re: [algogeeks] MS Question: Segregrate positive and
>>> >>>>>>>> negative nos in array without changing order
>>> >>>>>>>>
>>> >>>>>>>> duplicate of a previous post.Kindly refer to that post.
>>> >>>>>>>> Saurabh Singh
>>> >>>>>>>> B.Tech (Computer Science)
>>> >>>>>>>> MNNIT
>>> >>>>>>>> blog:geekinessthecoolway.blogspot.com
>>> >>>>>>>>
>>> >>>>>>>>
>>> >>>>>>>>
>>> >>>>>>>> On Fri, Jun 29, 2012 at 10:41 AM, raghavan M <
>>> >>

Re: [algogeeks] MS Question: Segregrate positive and negative nos in array without changing order

2012-07-01 Thread shiva@Algo
>> >>>> int a[]={-1,-5,10,11,15,-500,200,-10};
>> >>>>
>> >>>>
>> copy(a,a+sizeof(a)/sizeof(int),ostream_iterator(cout,","));cout<> >>>> inplace_pos_neg(a,sizeof(a)/sizeof(int));
>> >>>>
>> >>>>
>> copy(a,a+sizeof(a)/sizeof(int),ostream_iterator(cout,","));cout<> >>>>
>> >>>> }
>> >>>>
>> >>>>
>> >>>> Regards
>> >>>>
>> >>>> On Fri, Jun 29, 2012 at 7:52 PM, utsav sharma
>> >>>> wrote:
>> >>>>
>> >>>>> @bhaskar:- please explain stable sorting algorithm you would use(as
>> >>>>> mainly all of them require extra space)
>> >>>>> @sourabh:- that previous post discussion does't lead to any correct
>> >>>>> soln
>> >>>>>
>> >>>>> On Fri, Jun 29, 2012 at 8:39 PM, Bhaskar Kushwaha <
>> >>>>> bhaskar.kushwaha2...@gmail.com> wrote:
>> >>>>>
>> >>>>>> @saurabh please provide the link to the post you are mentioning
>> >>>>>>
>> >>>>>> On Fri, Jun 29, 2012 at 8:38 PM, Bhaskar Kushwaha <
>> >>>>>> bhaskar.kushwaha2...@gmail.com> wrote:
>> >>>>>>
>> >>>>>>>  If the order is important then I think we can use any stable
>> >>>>>>> sorting
>> >>>>>>> algorithm with the following comparison function
>> >>>>>>>
>> >>>>>>> int compare (int a ,int b)
>> >>>>>>> {
>> >>>>>>> if((a>0&&b>0)||(a<0&&b<0)) return 0;
>> >>>>>>> else return a> >>>>>>> }
>> >>>>>>> On Fri, Jun 29, 2012 at 3:37 PM, raghavan M <
>> >>>>>>> peacelover1987...@yahoo.co.in> wrote:
>> >>>>>>>
>> >>>>>>>> This is a variant of that one
>> >>>>>>>>
>> >>>>>>>>   --
>> >>>>>>>> *From:* saurabh singh 
>> >>>>>>>> *To:* algogeeks@googlegroups.com
>> >>>>>>>> *Sent:* Friday, 29 June 2012 3:05 PM
>> >>>>>>>>
>> >>>>>>>> *Subject:* Re: [algogeeks] MS Question: Segregrate positive and
>> >>>>>>>> negative nos in array without changing order
>> >>>>>>>>
>> >>>>>>>> duplicate of a previous post.Kindly refer to that post.
>> >>>>>>>> Saurabh Singh
>> >>>>>>>> B.Tech (Computer Science)
>> >>>>>>>> MNNIT
>> >>>>>>>> blog:geekinessthecoolway.blogspot.com
>> >>>>>>>>
>> >>>>>>>>
>> >>>>>>>>
>> >>>>>>>> On Fri, Jun 29, 2012 at 10:41 AM, raghavan M <
>> >>>>>>>> peacelover1987...@yahoo.co.in> wrote:
>> >>>>>>>>
>> >>>>>>>> Hi
>> >>>>>>>> Question as in subject
>> >>>>>>>>
>> >>>>>>>> *No extra space (can use one extra space)-O(1) max
>> >>>>>>>> *No order change allowed
>> >>>>>>>> example:
>> >>>>>>>>
>> >>>>>>>> input : 1,-5,2,10,-100,-2
>> >>>>>>>> output: -5,-10,-100,1,2
>> >>>>>>>>
>> >>>>>>>> input : -1,-5,10,11,15,-500,200,-10
>> >>>>>>>> output : -1,-5,-10,-500,-10,10,11,15
>> >>>>>>>>
>> >>>>>>>>
>> >>>>>>>> Thanks
>> >>>>>>>> Raghavn
>> >>>>>>>>  --
>> >>>>>>>> You received this message because you are subscribed to the
>> Google
>> >>>>>>>> Groups "Algorithm Geeks" group.
>> >>>>>>>> To post to this group, send email to algogeeks@googlegroups.com.
>> >>>>>>

Re: [algogeeks] MS Question: Segregrate positive and negative nos in array without changing order

2012-07-01 Thread shiva@Algo
A simple Divide and Conquer strategy can work Well

Seg_pos_neg(A,beg,end) //A is the array
->
mid=beg+end/2
if(beg
  Running Time O(nlogn)
  O(1) space
   Correct me if I'm Wrong.


On Mon, Jul 2, 2012 at 7:53 AM, Bhaskar Kushwaha <
bhaskar.kushwaha2...@gmail.com> wrote:

> @amol u have used O(n) extra space!
> I think it's not possible without using extra space.
>
> On 7/2/12, Darpan Baweja  wrote:
> > @amol :- i don't think this algo would work here
> > after sorting how would you replace back the original no.s(as no.s are
> not
> > 0 and 1 in this case)
> >
> > On Sun, Jul 1, 2012 at 11:08 PM, Amol Sharma 
> > wrote:
> >
> >> i think it has been discussed beforenevertheless here is the
> required
> >> linear time solution.
> >>
> >> first, count the total number 0's and 1's in the array.
> >>
> >> let say, total elements are n and there are x zero's.
> >>
> >> take count1=0 and count2=x;
> >>
> >> traverse through the array :
> >> for(i=0;i >> if(arr[i]==0)
> >>   arr[i]=count1++;
> >> else
> >>   arr[i]=count2++;
> >>
> >> let's say array is {1,0,0,0,1,1,1,0,0,1}  n=10,x=5
> >> count1=0;count2=5
> >>
> >> after the traversal it becomes a[]={5,0,1,2,6,7,8,3,4,9}
> >>
> >> now sort this array in O(n) like this :
> >>
> >> for(j=0;j<=1;j++)
> >> {
> >> for(i=0;i >> {
> >>   if(arr[i]!=i)
> >>swap(arr[i],arr[arr[i]]);
> >> }
> >> }
> >>
> >> after the array is sorted again traverse the array and set the elements
> >> from index 0 to x-1 to '0' and rest '1'.
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >> --
> >>
> >>
> >> Amol Sharma
> >> Final Year Student
> >> Computer Science and Engineering
> >> MNNIT Allahabad
> >>
> >> <http://gplus.to/amolsharma99>
> >> <http://twitter.com/amolsharma99><
> http://in.linkedin.com/pub/amol-sharma/21/79b/507><
> http://www.simplyamol.blogspot.com/><http://facebook.com/amolsharma99>
> >>
> >>
> >>
> >>
> >>
> >>
> >> On Fri, Jun 29, 2012 at 9:20 PM, Bhaskar Kushwaha <
> >> bhaskar.kushwaha2...@gmail.com> wrote:
> >>
> >>> @Hassan I think your algo will take time O(n^2) in worst case which
> >>> occurs when all elements are negative except the last one
> >>> @everyone Can we solve this problem in linear time?
> >>>
> >>>
> >>> On Fri, Jun 29, 2012 at 9:10 PM, Hassan Monfared
> >>> wrote:
> >>>
> >>>> Hi,
> >>>> this can be done by simple modification in bubble sort :
> >>>> void inplace_pos_neg(int pdata[],int sz)
> >>>> {
> >>>> bool changed=false;
> >>>>  do
> >>>> {
> >>>> changed=false;
> >>>>  for(int i=1;i >>>> if(pdata[i-1]>0 && pdata[i]<0)
> >>>> {
> >>>>  swap(pdata[i-1], pdata[i]);
> >>>> changed=true;
> >>>> }
> >>>>  }while(changed);
> >>>> }
> >>>>
> >>>> void test_inplace_pos_neg()
> >>>> {
> >>>> int a[]={-1,-5,10,11,15,-500,200,-10};
> >>>>
> >>>>
> copy(a,a+sizeof(a)/sizeof(int),ostream_iterator(cout,","));cout< >>>> inplace_pos_neg(a,sizeof(a)/sizeof(int));
> >>>>
> >>>>
> copy(a,a+sizeof(a)/sizeof(int),ostream_iterator(cout,","));cout< >>>>
> >>>> }
> >>>>
> >>>>
> >>>> Regards
> >>>>
> >>>> On Fri, Jun 29, 2012 at 7:52 PM, utsav sharma
> >>>> wrote:
> >>>>
> >>>>> @bhaskar:- please explain stable sorting algorithm you would use(as
> >>>>> mainly all of them require extra space)
> >>>>> @sourabh:- that previous post discussion does't lead to any correct
> >>>>> soln
> >>>>>
> >>>>> On Fri, Jun 29, 2012 at 8:39 PM, Bhaskar Kushwaha <
> >>>>

Re: [algogeeks] MS Question: Segregrate positive and negative nos in array without changing order

2012-07-01 Thread Bhaskar Kushwaha
@amol u have used O(n) extra space!
I think it's not possible without using extra space.

On 7/2/12, Darpan Baweja  wrote:
> @amol :- i don't think this algo would work here
> after sorting how would you replace back the original no.s(as no.s are not
> 0 and 1 in this case)
>
> On Sun, Jul 1, 2012 at 11:08 PM, Amol Sharma 
> wrote:
>
>> i think it has been discussed beforenevertheless here is the required
>> linear time solution.
>>
>> first, count the total number 0's and 1's in the array.
>>
>> let say, total elements are n and there are x zero's.
>>
>> take count1=0 and count2=x;
>>
>> traverse through the array :
>> for(i=0;i> if(arr[i]==0)
>>   arr[i]=count1++;
>> else
>>   arr[i]=count2++;
>>
>> let's say array is {1,0,0,0,1,1,1,0,0,1}  n=10,x=5
>> count1=0;count2=5
>>
>> after the traversal it becomes a[]={5,0,1,2,6,7,8,3,4,9}
>>
>> now sort this array in O(n) like this :
>>
>> for(j=0;j<=1;j++)
>> {
>> for(i=0;i> {
>>   if(arr[i]!=i)
>>swap(arr[i],arr[arr[i]]);
>> }
>> }
>>
>> after the array is sorted again traverse the array and set the elements
>> from index 0 to x-1 to '0' and rest '1'.
>>
>>
>>
>>
>>
>>
>>
>>
>> --
>>
>>
>> Amol Sharma
>> Final Year Student
>> Computer Science and Engineering
>> MNNIT Allahabad
>>
>> <http://gplus.to/amolsharma99>
>> <http://twitter.com/amolsharma99><http://in.linkedin.com/pub/amol-sharma/21/79b/507><http://www.simplyamol.blogspot.com/><http://facebook.com/amolsharma99>
>>
>>
>>
>>
>>
>>
>> On Fri, Jun 29, 2012 at 9:20 PM, Bhaskar Kushwaha <
>> bhaskar.kushwaha2...@gmail.com> wrote:
>>
>>> @Hassan I think your algo will take time O(n^2) in worst case which
>>> occurs when all elements are negative except the last one
>>> @everyone Can we solve this problem in linear time?
>>>
>>>
>>> On Fri, Jun 29, 2012 at 9:10 PM, Hassan Monfared
>>> wrote:
>>>
>>>> Hi,
>>>> this can be done by simple modification in bubble sort :
>>>> void inplace_pos_neg(int pdata[],int sz)
>>>> {
>>>> bool changed=false;
>>>>  do
>>>> {
>>>> changed=false;
>>>>  for(int i=1;i>>> if(pdata[i-1]>0 && pdata[i]<0)
>>>> {
>>>>  swap(pdata[i-1], pdata[i]);
>>>> changed=true;
>>>> }
>>>>  }while(changed);
>>>> }
>>>>
>>>> void test_inplace_pos_neg()
>>>> {
>>>> int a[]={-1,-5,10,11,15,-500,200,-10};
>>>>
>>>> copy(a,a+sizeof(a)/sizeof(int),ostream_iterator(cout,","));cout<>>> inplace_pos_neg(a,sizeof(a)/sizeof(int));
>>>>
>>>> copy(a,a+sizeof(a)/sizeof(int),ostream_iterator(cout,","));cout<>>>
>>>> }
>>>>
>>>>
>>>> Regards
>>>>
>>>> On Fri, Jun 29, 2012 at 7:52 PM, utsav sharma
>>>> wrote:
>>>>
>>>>> @bhaskar:- please explain stable sorting algorithm you would use(as
>>>>> mainly all of them require extra space)
>>>>> @sourabh:- that previous post discussion does't lead to any correct
>>>>> soln
>>>>>
>>>>> On Fri, Jun 29, 2012 at 8:39 PM, Bhaskar Kushwaha <
>>>>> bhaskar.kushwaha2...@gmail.com> wrote:
>>>>>
>>>>>> @saurabh please provide the link to the post you are mentioning
>>>>>>
>>>>>> On Fri, Jun 29, 2012 at 8:38 PM, Bhaskar Kushwaha <
>>>>>> bhaskar.kushwaha2...@gmail.com> wrote:
>>>>>>
>>>>>>>  If the order is important then I think we can use any stable
>>>>>>> sorting
>>>>>>> algorithm with the following comparison function
>>>>>>>
>>>>>>> int compare (int a ,int b)
>>>>>>> {
>>>>>>> if((a>0&&b>0)||(a<0&&b<0)) return 0;
>>>>>>> else return a>>>>>> }
>>>>>>> On Fri, Jun 29, 2012 at 3:37 PM, raghavan M <
>>>>>>> peacelover1987...@y

Re: [algogeeks] MS Question: Segregrate positive and negative nos in array without changing order

2012-07-01 Thread Darpan Baweja
@amol :- i don't think this algo would work here
after sorting how would you replace back the original no.s(as no.s are not
0 and 1 in this case)

On Sun, Jul 1, 2012 at 11:08 PM, Amol Sharma  wrote:

> i think it has been discussed beforenevertheless here is the required
> linear time solution.
>
> first, count the total number 0's and 1's in the array.
>
> let say, total elements are n and there are x zero's.
>
> take count1=0 and count2=x;
>
> traverse through the array :
> for(i=0;i if(arr[i]==0)
>   arr[i]=count1++;
> else
>   arr[i]=count2++;
>
> let's say array is {1,0,0,0,1,1,1,0,0,1}  n=10,x=5
> count1=0;count2=5
>
> after the traversal it becomes a[]={5,0,1,2,6,7,8,3,4,9}
>
> now sort this array in O(n) like this :
>
> for(j=0;j<=1;j++)
> {
> for(i=0;i {
>   if(arr[i]!=i)
>swap(arr[i],arr[arr[i]]);
> }
> }
>
> after the array is sorted again traverse the array and set the elements
> from index 0 to x-1 to '0' and rest '1'.
>
>
>
>
>
>
>
>
> --
>
>
> Amol Sharma
> Final Year Student
> Computer Science and Engineering
> MNNIT Allahabad
>
> <http://gplus.to/amolsharma99> 
> <http://twitter.com/amolsharma99><http://in.linkedin.com/pub/amol-sharma/21/79b/507><http://www.simplyamol.blogspot.com/><http://facebook.com/amolsharma99>
>
>
>
>
>
>
> On Fri, Jun 29, 2012 at 9:20 PM, Bhaskar Kushwaha <
> bhaskar.kushwaha2...@gmail.com> wrote:
>
>> @Hassan I think your algo will take time O(n^2) in worst case which
>> occurs when all elements are negative except the last one
>> @everyone Can we solve this problem in linear time?
>>
>>
>> On Fri, Jun 29, 2012 at 9:10 PM, Hassan Monfared wrote:
>>
>>> Hi,
>>> this can be done by simple modification in bubble sort :
>>> void inplace_pos_neg(int pdata[],int sz)
>>> {
>>> bool changed=false;
>>>  do
>>> {
>>> changed=false;
>>>  for(int i=1;i>> if(pdata[i-1]>0 && pdata[i]<0)
>>> {
>>>  swap(pdata[i-1], pdata[i]);
>>> changed=true;
>>> }
>>>  }while(changed);
>>> }
>>>
>>> void test_inplace_pos_neg()
>>> {
>>> int a[]={-1,-5,10,11,15,-500,200,-10};
>>>
>>> copy(a,a+sizeof(a)/sizeof(int),ostream_iterator(cout,","));cout<>> inplace_pos_neg(a,sizeof(a)/sizeof(int));
>>>
>>> copy(a,a+sizeof(a)/sizeof(int),ostream_iterator(cout,","));cout<>>
>>> }
>>>
>>>
>>> Regards
>>>
>>> On Fri, Jun 29, 2012 at 7:52 PM, utsav sharma 
>>> wrote:
>>>
>>>> @bhaskar:- please explain stable sorting algorithm you would use(as
>>>> mainly all of them require extra space)
>>>> @sourabh:- that previous post discussion does't lead to any correct soln
>>>>
>>>> On Fri, Jun 29, 2012 at 8:39 PM, Bhaskar Kushwaha <
>>>> bhaskar.kushwaha2...@gmail.com> wrote:
>>>>
>>>>> @saurabh please provide the link to the post you are mentioning
>>>>>
>>>>> On Fri, Jun 29, 2012 at 8:38 PM, Bhaskar Kushwaha <
>>>>> bhaskar.kushwaha2...@gmail.com> wrote:
>>>>>
>>>>>>  If the order is important then I think we can use any stable sorting
>>>>>> algorithm with the following comparison function
>>>>>>
>>>>>> int compare (int a ,int b)
>>>>>> {
>>>>>> if((a>0&&b>0)||(a<0&&b<0)) return 0;
>>>>>> else return a>>>>> }
>>>>>> On Fri, Jun 29, 2012 at 3:37 PM, raghavan M <
>>>>>> peacelover1987...@yahoo.co.in> wrote:
>>>>>>
>>>>>>> This is a variant of that one
>>>>>>>
>>>>>>>   --
>>>>>>> *From:* saurabh singh 
>>>>>>> *To:* algogeeks@googlegroups.com
>>>>>>> *Sent:* Friday, 29 June 2012 3:05 PM
>>>>>>>
>>>>>>> *Subject:* Re: [algogeeks] MS Question: Segregrate positive and
>>>>>>> negative nos in array without changing order
>>>>>>>
>>>>>>> duplicate of a previous post.Kindly refer to that post.
>>>>>>> Saurabh Sing

Re: [algogeeks] MS Question: Segregrate positive and negative nos in array without changing order

2012-07-01 Thread Amol Sharma
i think it has been discussed beforenevertheless here is the required
linear time solution.

first, count the total number 0's and 1's in the array.

let say, total elements are n and there are x zero's.

take count1=0 and count2=x;

traverse through the array :
for(i=0;ihttp://gplus.to/amolsharma99>
<http://twitter.com/amolsharma99><http://in.linkedin.com/pub/amol-sharma/21/79b/507><http://www.simplyamol.blogspot.com/><http://facebook.com/amolsharma99>






On Fri, Jun 29, 2012 at 9:20 PM, Bhaskar Kushwaha <
bhaskar.kushwaha2...@gmail.com> wrote:

> @Hassan I think your algo will take time O(n^2) in worst case which occurs
> when all elements are negative except the last one
> @everyone Can we solve this problem in linear time?
>
>
> On Fri, Jun 29, 2012 at 9:10 PM, Hassan Monfared wrote:
>
>> Hi,
>> this can be done by simple modification in bubble sort :
>> void inplace_pos_neg(int pdata[],int sz)
>> {
>> bool changed=false;
>>  do
>> {
>> changed=false;
>>  for(int i=1;i> if(pdata[i-1]>0 && pdata[i]<0)
>> {
>>  swap(pdata[i-1], pdata[i]);
>> changed=true;
>> }
>>  }while(changed);
>> }
>>
>> void test_inplace_pos_neg()
>> {
>> int a[]={-1,-5,10,11,15,-500,200,-10};
>>
>> copy(a,a+sizeof(a)/sizeof(int),ostream_iterator(cout,","));cout<> inplace_pos_neg(a,sizeof(a)/sizeof(int));
>>
>> copy(a,a+sizeof(a)/sizeof(int),ostream_iterator(cout,","));cout<>
>> }
>>
>>
>> Regards
>>
>> On Fri, Jun 29, 2012 at 7:52 PM, utsav sharma 
>> wrote:
>>
>>> @bhaskar:- please explain stable sorting algorithm you would use(as
>>> mainly all of them require extra space)
>>> @sourabh:- that previous post discussion does't lead to any correct soln
>>>
>>> On Fri, Jun 29, 2012 at 8:39 PM, Bhaskar Kushwaha <
>>> bhaskar.kushwaha2...@gmail.com> wrote:
>>>
>>>> @saurabh please provide the link to the post you are mentioning
>>>>
>>>> On Fri, Jun 29, 2012 at 8:38 PM, Bhaskar Kushwaha <
>>>> bhaskar.kushwaha2...@gmail.com> wrote:
>>>>
>>>>>  If the order is important then I think we can use any stable sorting
>>>>> algorithm with the following comparison function
>>>>>
>>>>> int compare (int a ,int b)
>>>>> {
>>>>> if((a>0&&b>0)||(a<0&&b<0)) return 0;
>>>>> else return a>>>> }
>>>>> On Fri, Jun 29, 2012 at 3:37 PM, raghavan M <
>>>>> peacelover1987...@yahoo.co.in> wrote:
>>>>>
>>>>>> This is a variant of that one
>>>>>>
>>>>>>   --
>>>>>> *From:* saurabh singh 
>>>>>> *To:* algogeeks@googlegroups.com
>>>>>> *Sent:* Friday, 29 June 2012 3:05 PM
>>>>>>
>>>>>> *Subject:* Re: [algogeeks] MS Question: Segregrate positive and
>>>>>> negative nos in array without changing order
>>>>>>
>>>>>> duplicate of a previous post.Kindly refer to that post.
>>>>>> Saurabh Singh
>>>>>> B.Tech (Computer Science)
>>>>>> MNNIT
>>>>>> blog:geekinessthecoolway.blogspot.com
>>>>>>
>>>>>>
>>>>>>
>>>>>> On Fri, Jun 29, 2012 at 10:41 AM, raghavan M <
>>>>>> peacelover1987...@yahoo.co.in> wrote:
>>>>>>
>>>>>> Hi
>>>>>> Question as in subject
>>>>>>
>>>>>> *No extra space (can use one extra space)-O(1) max
>>>>>> *No order change allowed
>>>>>> example:
>>>>>>
>>>>>> input : 1,-5,2,10,-100,-2
>>>>>> output: -5,-10,-100,1,2
>>>>>>
>>>>>> input : -1,-5,10,11,15,-500,200,-10
>>>>>> output : -1,-5,-10,-500,-10,10,11,15
>>>>>>
>>>>>>
>>>>>> Thanks
>>>>>> Raghavn
>>>>>>  --
>>>>>> You received this message because you are subscribed to the Google
>>>>>> Groups "Algorithm Geeks" group.
>>>>>> To post to this group, send email to algogeeks@googlegroups.com.
>>>>>> To unsubscribe from this group, send email to
>>>>>> algogeeks+unsub

Re: [algogeeks] MS Question: Segregrate positive and negative nos in array without changing order

2012-06-29 Thread Bhaskar Kushwaha
@Hassan I think your algo will take time O(n^2) in worst case which occurs
when all elements are negative except the last one
@everyone Can we solve this problem in linear time?

On Fri, Jun 29, 2012 at 9:10 PM, Hassan Monfared wrote:

> Hi,
> this can be done by simple modification in bubble sort :
> void inplace_pos_neg(int pdata[],int sz)
> {
> bool changed=false;
>  do
> {
> changed=false;
>  for(int i=1;i if(pdata[i-1]>0 && pdata[i]<0)
> {
>  swap(pdata[i-1], pdata[i]);
> changed=true;
> }
>  }while(changed);
> }
>
> void test_inplace_pos_neg()
> {
> int a[]={-1,-5,10,11,15,-500,200,-10};
>
> copy(a,a+sizeof(a)/sizeof(int),ostream_iterator(cout,","));cout< inplace_pos_neg(a,sizeof(a)/sizeof(int));
>
> copy(a,a+sizeof(a)/sizeof(int),ostream_iterator(cout,","));cout<
> }
>
>
> Regards
>
> On Fri, Jun 29, 2012 at 7:52 PM, utsav sharma wrote:
>
>> @bhaskar:- please explain stable sorting algorithm you would use(as
>> mainly all of them require extra space)
>> @sourabh:- that previous post discussion does't lead to any correct soln
>>
>> On Fri, Jun 29, 2012 at 8:39 PM, Bhaskar Kushwaha <
>> bhaskar.kushwaha2...@gmail.com> wrote:
>>
>>> @saurabh please provide the link to the post you are mentioning
>>>
>>> On Fri, Jun 29, 2012 at 8:38 PM, Bhaskar Kushwaha <
>>> bhaskar.kushwaha2...@gmail.com> wrote:
>>>
>>>>  If the order is important then I think we can use any stable sorting
>>>> algorithm with the following comparison function
>>>>
>>>> int compare (int a ,int b)
>>>> {
>>>> if((a>0&&b>0)||(a<0&&b<0)) return 0;
>>>> else return a>>> }
>>>> On Fri, Jun 29, 2012 at 3:37 PM, raghavan M <
>>>> peacelover1987...@yahoo.co.in> wrote:
>>>>
>>>>> This is a variant of that one
>>>>>
>>>>>   --
>>>>> *From:* saurabh singh 
>>>>> *To:* algogeeks@googlegroups.com
>>>>> *Sent:* Friday, 29 June 2012 3:05 PM
>>>>>
>>>>> *Subject:* Re: [algogeeks] MS Question: Segregrate positive and
>>>>> negative nos in array without changing order
>>>>>
>>>>> duplicate of a previous post.Kindly refer to that post.
>>>>> Saurabh Singh
>>>>> B.Tech (Computer Science)
>>>>> MNNIT
>>>>> blog:geekinessthecoolway.blogspot.com
>>>>>
>>>>>
>>>>>
>>>>> On Fri, Jun 29, 2012 at 10:41 AM, raghavan M <
>>>>> peacelover1987...@yahoo.co.in> wrote:
>>>>>
>>>>> Hi
>>>>> Question as in subject
>>>>>
>>>>> *No extra space (can use one extra space)-O(1) max
>>>>> *No order change allowed
>>>>> example:
>>>>>
>>>>> input : 1,-5,2,10,-100,-2
>>>>> output: -5,-10,-100,1,2
>>>>>
>>>>> input : -1,-5,10,11,15,-500,200,-10
>>>>> output : -1,-5,-10,-500,-10,10,11,15
>>>>>
>>>>>
>>>>> Thanks
>>>>> Raghavn
>>>>>  --
>>>>> You received this message because you are subscribed to the Google
>>>>> Groups "Algorithm Geeks" group.
>>>>> To post to this group, send email to algogeeks@googlegroups.com.
>>>>> To unsubscribe from this group, send email to
>>>>> algogeeks+unsubscr...@googlegroups.com.
>>>>> For more options, visit this group at
>>>>> http://groups.google.com/group/algogeeks?hl=en.
>>>>>
>>>>>
>>>>>  --
>>>>> You received this message because you are subscribed to the Google
>>>>> Groups "Algorithm Geeks" group.
>>>>> To post to this group, send email to algogeeks@googlegroups.com.
>>>>> To unsubscribe from this group, send email to
>>>>> algogeeks+unsubscr...@googlegroups.com.
>>>>> For more options, visit this group at
>>>>> http://groups.google.com/group/algogeeks?hl=en.
>>>>>
>>>>>
>>>>>   --
>>>>> You received this message because you are subscribed to the Google
>>>>> Groups "Algorithm Geeks" group.
>>>>> To post to this group, send email to algogeeks@googlegroups.com.
>>>>> To unsubsc

Re: [algogeeks] MS Question: Segregrate positive and negative nos in array without changing order

2012-06-29 Thread Hassan Monfared
Hi,
this can be done by simple modification in bubble sort :
void inplace_pos_neg(int pdata[],int sz)
{
bool changed=false;
do
{
changed=false;
for(int i=1;i0 && pdata[i]<0)
{
swap(pdata[i-1], pdata[i]);
changed=true;
}
}while(changed);
}

void test_inplace_pos_neg()
{
int a[]={-1,-5,10,11,15,-500,200,-10};
copy(a,a+sizeof(a)/sizeof(int),ostream_iterator(cout,","));cout<(cout,","));cout<wrote:

> @bhaskar:- please explain stable sorting algorithm you would use(as mainly
> all of them require extra space)
> @sourabh:- that previous post discussion does't lead to any correct soln
>
> On Fri, Jun 29, 2012 at 8:39 PM, Bhaskar Kushwaha <
> bhaskar.kushwaha2...@gmail.com> wrote:
>
>> @saurabh please provide the link to the post you are mentioning
>>
>> On Fri, Jun 29, 2012 at 8:38 PM, Bhaskar Kushwaha <
>> bhaskar.kushwaha2...@gmail.com> wrote:
>>
>>>  If the order is important then I think we can use any stable sorting
>>> algorithm with the following comparison function
>>>
>>> int compare (int a ,int b)
>>> {
>>> if((a>0&&b>0)||(a<0&&b<0)) return 0;
>>> else return a>> }
>>> On Fri, Jun 29, 2012 at 3:37 PM, raghavan M <
>>> peacelover1987...@yahoo.co.in> wrote:
>>>
>>>> This is a variant of that one
>>>>
>>>>   --
>>>> *From:* saurabh singh 
>>>> *To:* algogeeks@googlegroups.com
>>>> *Sent:* Friday, 29 June 2012 3:05 PM
>>>>
>>>> *Subject:* Re: [algogeeks] MS Question: Segregrate positive and
>>>> negative nos in array without changing order
>>>>
>>>> duplicate of a previous post.Kindly refer to that post.
>>>> Saurabh Singh
>>>> B.Tech (Computer Science)
>>>> MNNIT
>>>> blog:geekinessthecoolway.blogspot.com
>>>>
>>>>
>>>>
>>>> On Fri, Jun 29, 2012 at 10:41 AM, raghavan M <
>>>> peacelover1987...@yahoo.co.in> wrote:
>>>>
>>>> Hi
>>>> Question as in subject
>>>>
>>>> *No extra space (can use one extra space)-O(1) max
>>>> *No order change allowed
>>>> example:
>>>>
>>>> input : 1,-5,2,10,-100,-2
>>>> output: -5,-10,-100,1,2
>>>>
>>>> input : -1,-5,10,11,15,-500,200,-10
>>>> output : -1,-5,-10,-500,-10,10,11,15
>>>>
>>>>
>>>> Thanks
>>>> Raghavn
>>>>  --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "Algorithm Geeks" group.
>>>> To post to this group, send email to algogeeks@googlegroups.com.
>>>> To unsubscribe from this group, send email to
>>>> algogeeks+unsubscr...@googlegroups.com.
>>>> For more options, visit this group at
>>>> http://groups.google.com/group/algogeeks?hl=en.
>>>>
>>>>
>>>>  --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "Algorithm Geeks" group.
>>>> To post to this group, send email to algogeeks@googlegroups.com.
>>>> To unsubscribe from this group, send email to
>>>> algogeeks+unsubscr...@googlegroups.com.
>>>> For more options, visit this group at
>>>> http://groups.google.com/group/algogeeks?hl=en.
>>>>
>>>>
>>>>   --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "Algorithm Geeks" group.
>>>> To post to this group, send email to algogeeks@googlegroups.com.
>>>> To unsubscribe from this group, send email to
>>>> algogeeks+unsubscr...@googlegroups.com.
>>>> For more options, visit this group at
>>>> http://groups.google.com/group/algogeeks?hl=en.
>>>>
>>>
>>>
>>>
>>> --
>>> regards,
>>> Bhaskar Kushwaha
>>> Student
>>> Final year
>>> CSE
>>> M.N.N.I.T.  Allahabad
>>>
>>>
>>
>>
>> --
>> regards,
>> Bhaskar Kushwaha
>> Student
>> Final year
>> CSE
>> M.N.N.I.T.  Allahabad
>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>
>
> --
> Utsav Sharma,
> NIT Allahabad
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

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



Re: [algogeeks] MS Question: Segregrate positive and negative nos in array without changing order

2012-06-29 Thread utsav sharma
@bhaskar:- please explain stable sorting algorithm you would use(as mainly
all of them require extra space)
@sourabh:- that previous post discussion does't lead to any correct soln
On Fri, Jun 29, 2012 at 8:39 PM, Bhaskar Kushwaha <
bhaskar.kushwaha2...@gmail.com> wrote:

> @saurabh please provide the link to the post you are mentioning
>
> On Fri, Jun 29, 2012 at 8:38 PM, Bhaskar Kushwaha <
> bhaskar.kushwaha2...@gmail.com> wrote:
>
>>  If the order is important then I think we can use any stable sorting
>> algorithm with the following comparison function
>>
>> int compare (int a ,int b)
>> {
>> if((a>0&&b>0)||(a<0&&b<0)) return 0;
>> else return a> }
>> On Fri, Jun 29, 2012 at 3:37 PM, raghavan M <
>> peacelover1987...@yahoo.co.in> wrote:
>>
>>> This is a variant of that one
>>>
>>>   ------
>>> *From:* saurabh singh 
>>> *To:* algogeeks@googlegroups.com
>>> *Sent:* Friday, 29 June 2012 3:05 PM
>>>
>>> *Subject:* Re: [algogeeks] MS Question: Segregrate positive and
>>> negative nos in array without changing order
>>>
>>> duplicate of a previous post.Kindly refer to that post.
>>> Saurabh Singh
>>> B.Tech (Computer Science)
>>> MNNIT
>>> blog:geekinessthecoolway.blogspot.com
>>>
>>>
>>>
>>> On Fri, Jun 29, 2012 at 10:41 AM, raghavan M <
>>> peacelover1987...@yahoo.co.in> wrote:
>>>
>>> Hi
>>> Question as in subject
>>>
>>> *No extra space (can use one extra space)-O(1) max
>>> *No order change allowed
>>> example:
>>>
>>> input : 1,-5,2,10,-100,-2
>>> output: -5,-10,-100,1,2
>>>
>>> input : -1,-5,10,11,15,-500,200,-10
>>> output : -1,-5,-10,-500,-10,10,11,15
>>>
>>>
>>> Thanks
>>> Raghavn
>>>  --
>>> You received this message because you are subscribed to the Google
>>> Groups "Algorithm Geeks" group.
>>> To post to this group, send email to algogeeks@googlegroups.com.
>>> To unsubscribe from this group, send email to
>>> algogeeks+unsubscr...@googlegroups.com.
>>> For more options, visit this group at
>>> http://groups.google.com/group/algogeeks?hl=en.
>>>
>>>
>>>  --
>>> You received this message because you are subscribed to the Google
>>> Groups "Algorithm Geeks" group.
>>> To post to this group, send email to algogeeks@googlegroups.com.
>>> To unsubscribe from this group, send email to
>>> algogeeks+unsubscr...@googlegroups.com.
>>> For more options, visit this group at
>>> http://groups.google.com/group/algogeeks?hl=en.
>>>
>>>
>>>   --
>>> You received this message because you are subscribed to the Google
>>> Groups "Algorithm Geeks" group.
>>> To post to this group, send email to algogeeks@googlegroups.com.
>>> To unsubscribe from this group, send email to
>>> algogeeks+unsubscr...@googlegroups.com.
>>> For more options, visit this group at
>>> http://groups.google.com/group/algogeeks?hl=en.
>>>
>>
>>
>>
>> --
>> regards,
>> Bhaskar Kushwaha
>> Student
>> Final year
>> CSE
>> M.N.N.I.T.  Allahabad
>>
>>
>
>
> --
> regards,
> Bhaskar Kushwaha
> Student
> Final year
> CSE
> M.N.N.I.T.  Allahabad
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>



-- 
Utsav Sharma,
NIT Allahabad

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



Re: [algogeeks] MS Question: Segregrate positive and negative nos in array without changing order

2012-06-29 Thread Bhaskar Kushwaha
@saurabh please provide the link to the post you are mentioning

On Fri, Jun 29, 2012 at 8:38 PM, Bhaskar Kushwaha <
bhaskar.kushwaha2...@gmail.com> wrote:

>  If the order is important then I think we can use any stable sorting
> algorithm with the following comparison function
>
> int compare (int a ,int b)
> {
> if((a>0&&b>0)||(a<0&&b<0)) return 0;
> else return a }
> On Fri, Jun 29, 2012 at 3:37 PM, raghavan M  > wrote:
>
>> This is a variant of that one
>>
>>   --
>> *From:* saurabh singh 
>> *To:* algogeeks@googlegroups.com
>> *Sent:* Friday, 29 June 2012 3:05 PM
>>
>> *Subject:* Re: [algogeeks] MS Question: Segregrate positive and negative
>> nos in array without changing order
>>
>> duplicate of a previous post.Kindly refer to that post.
>> Saurabh Singh
>> B.Tech (Computer Science)
>> MNNIT
>> blog:geekinessthecoolway.blogspot.com
>>
>>
>>
>> On Fri, Jun 29, 2012 at 10:41 AM, raghavan M <
>> peacelover1987...@yahoo.co.in> wrote:
>>
>> Hi
>> Question as in subject
>>
>> *No extra space (can use one extra space)-O(1) max
>> *No order change allowed
>> example:
>>
>> input : 1,-5,2,10,-100,-2
>> output: -5,-10,-100,1,2
>>
>> input : -1,-5,10,11,15,-500,200,-10
>> output : -1,-5,-10,-500,-10,10,11,15
>>
>>
>> Thanks
>> Raghavn
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>>
>>   --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>
>
> --
> regards,
> Bhaskar Kushwaha
> Student
> Final year
> CSE
> M.N.N.I.T.  Allahabad
>
>


-- 
regards,
Bhaskar Kushwaha
Student
Final year
CSE
M.N.N.I.T.  Allahabad

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



Re: [algogeeks] MS Question: Segregrate positive and negative nos in array without changing order

2012-06-29 Thread Bhaskar Kushwaha
 If the order is important then I think we can use any stable sorting
algorithm with the following comparison function

int compare (int a ,int b)
{
if((a>0&&b>0)||(a<0&&b<0)) return 0;
else return awrote:

> This is a variant of that one
>
>   --
> *From:* saurabh singh 
> *To:* algogeeks@googlegroups.com
> *Sent:* Friday, 29 June 2012 3:05 PM
>
> *Subject:* Re: [algogeeks] MS Question: Segregrate positive and negative
> nos in array without changing order
>
> duplicate of a previous post.Kindly refer to that post.
> Saurabh Singh
> B.Tech (Computer Science)
> MNNIT
> blog:geekinessthecoolway.blogspot.com
>
>
>
> On Fri, Jun 29, 2012 at 10:41 AM, raghavan M <
> peacelover1987...@yahoo.co.in> wrote:
>
> Hi
> Question as in subject
>
> *No extra space (can use one extra space)-O(1) max
> *No order change allowed
> example:
>
> input : 1,-5,2,10,-100,-2
> output: -5,-10,-100,1,2
>
> input : -1,-5,10,11,15,-500,200,-10
> output : -1,-5,-10,-500,-10,10,11,15
>
>
> Thanks
> Raghavn
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>
>   --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>



-- 
regards,
Bhaskar Kushwaha
Student
Final year
CSE
M.N.N.I.T.  Allahabad

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



Re: [algogeeks] MS Question: Segregrate positive and negative nos in array without changing order

2012-06-29 Thread raghavan M
This is a variant of that one



 From: saurabh singh 
To: algogeeks@googlegroups.com 
Sent: Friday, 29 June 2012 3:05 PM
Subject: Re: [algogeeks] MS Question: Segregrate positive and negative nos in 
array without changing order
 

duplicate of a previous post.Kindly refer to that post.
Saurabh Singh
B.Tech (Computer Science)
MNNIT 

blog:geekinessthecoolway.blogspot.com



On Fri, Jun 29, 2012 at 10:41 AM, raghavan M  
wrote:

Hi
>Question as in subject
>
>
>*No extra space (can use one extra space)-O(1) max
>
>*No order change allowed
>example:
>
>
>input : 1,-5,2,10,-100,-2
>output: -5,-10,-100,1,2
>
>
>input : -1,-5,10,11,15,-500,200,-10
>output : -1,-5,-10,-500,-10,10,11,15
>
>
>
>
>Thanks
>Raghavn
-- 
>You received this message because you are subscribed to the Google Groups 
>"Algorithm Geeks" group.
>To post to this group, send email to algogeeks@googlegroups.com.
>To unsubscribe from this group, send email to 
>algogeeks+unsubscr...@googlegroups.com.
>For more options, visit this group at 
>http://groups.google.com/group/algogeeks?hl=en.
>

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

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



Re: [algogeeks] MS Question: Segregrate positive and negative nos in array without changing order

2012-06-29 Thread raghavan M
The main idea of this question is *not to change order of occurrence".Dutch 
National flag & other swapping like quick sort will change the order of 
occurrence of number
try yourself with simple example for proof.



 From: Ravi Ranjan 
To: algogeeks@googlegroups.com 
Sent: Friday, 29 June 2012 3:06 PM
Subject: Re: [algogeeks] MS Question: Segregrate positive and negative nos in 
array without changing order
 

one can modify dutch national flag algo for two colors(2 types positive n 
negative)

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

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



Re: [algogeeks] MS Question: Segregrate positive and negative nos in array without changing order

2012-06-29 Thread adarsh kumar
Quick sort partition routine variation.

On Fri, Jun 29, 2012 at 3:06 PM, Ravi Ranjan wrote:

> one can modify dutch national flag algo for two colors(2 types positive n
> negative)
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

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



Re: [algogeeks] MS Question: Segregrate positive and negative nos in array without changing order

2012-06-29 Thread Ravi Ranjan
one can modify dutch national flag algo for two colors(2 types positive n
negative)

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



Re: [algogeeks] MS Question: Segregrate positive and negative nos in array without changing order

2012-06-29 Thread saurabh singh
duplicate of a previous post.Kindly refer to that post.
Saurabh Singh
B.Tech (Computer Science)
MNNIT
blog:geekinessthecoolway.blogspot.com



On Fri, Jun 29, 2012 at 10:41 AM, raghavan M
wrote:

> Hi
> Question as in subject
>
> *No extra space (can use one extra space)-O(1) max
> *No order change allowed
> example:
>
> input : 1,-5,2,10,-100,-2
> output: -5,-10,-100,1,2
>
> input : -1,-5,10,11,15,-500,200,-10
> output : -1,-5,-10,-500,-10,10,11,15
>
>
> Thanks
> Raghavn
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

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



[algogeeks] MS Question: Segregrate positive and negative nos in array without changing order

2012-06-29 Thread raghavan M
Hi
Question as in subject

*No extra space (can use one extra space)-O(1) max

*No order change allowed
example:

input : 1,-5,2,10,-100,-2
output: -5,-10,-100,1,2

input : -1,-5,10,11,15,-500,200,-10
output : -1,-5,-10,-500,-10,10,11,15


Thanks
Raghavn

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



Re: [algogeeks] MS Question :implement read write lock class

2012-06-29 Thread Mithun Kumar
This link should help

http://stackoverflow.com/questions/5667793/how-does-a-read-write-mutex-lock-work?rq=1

-mithun



On Fri, Jun 29, 2012 at 7:30 AM, bharat b wrote:

> class lock
> {
>  enum{"read", "write","free"}status;
> };
> By default, make status value as "free".
> Based on the request, status value will be changed...
> Based on the value of the status, we should decide whether another
> read/write lock can be given.
>
> Any suggestions ?
> On Thu, Jun 28, 2012 at 4:46 PM, Ashish Goel  wrote:
>
>>
>> Best Regards
>> Ashish Goel
>> "Think positive and find fuel in failure"
>> +919985813081
>> +919966006652
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

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



Re: [algogeeks] MS Question :implement read write lock class

2012-06-28 Thread bharat b
class lock
{
 enum{"read", "write","free"}status;
};
By default, make status value as "free".
Based on the request, status value will be changed...
Based on the value of the status, we should decide whether another
read/write lock can be given.

Any suggestions ?
On Thu, Jun 28, 2012 at 4:46 PM, Ashish Goel  wrote:

>
> Best Regards
> Ashish Goel
> "Think positive and find fuel in failure"
> +919985813081
> +919966006652
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

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



[algogeeks] MS Question :implement read write lock class

2012-06-28 Thread Ashish Goel
Best Regards
Ashish Goel
"Think positive and find fuel in failure"
+919985813081
+919966006652

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



Re: [algogeeks] MS Question: Add two large numbers where the numbers are stored in an array format

2012-06-27 Thread Lomash Goyal
we can create linked list for the number where each node will store some k
digits (say 5) in the reverse order.then we just perform a normal addition
of the data of the nodes with the help of carry.
note that if the numbers are not positive then we need to maintain a sign
bit node also.if any of the number is negative then we have to find the
greater number among the both considering their absolute values only.
in this case for comparing the two numbers use doubly linked list so as to
compare the digits.

On Tue, Jun 26, 2012 at 7:33 PM, Ashish Goel  wrote:

> the base is not given, so 10 can't be assumed
>
> Best Regards
> Ashish Goel
> "Think positive and find fuel in failure"
> +919985813081
> +919966006652
>
>
> On Tue, Jun 26, 2012 at 4:38 PM, amrit harry wrote:
>
>> make size of both array by adding '0' in front of smaller array
>> then
>> int carry=0;
>> for(i=array.size();i>=0;i--)
>> {
>> sum[i]=carry+arrayA[i]+arrayB[i];
>> carry=sum[i]/10;
>> sum[i]=sum[i]%10;
>> }
>> then reverse and print sum
>> On Tue, Jun 26, 2012 at 3:40 PM, Ashish Goel  wrote:
>>
>>>
>>> Best Regards
>>>
>>> Ashish Goel
>>> "Think positive and find fuel in failure"
>>> +919985813081
>>> +919966006652
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Algorithm Geeks" group.
>>> To post to this group, send email to algogeeks@googlegroups.com.
>>> To unsubscribe from this group, send email to
>>> algogeeks+unsubscr...@googlegroups.com.
>>> For more options, visit this group at
>>> http://groups.google.com/group/algogeeks?hl=en.
>>>
>>
>>
>>
>> --
>> Thanks & Regards
>> Amritpal singh
>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>



-- 
Regards

Lomash Goyal
*
*

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



Re: [algogeeks] MS Question: Add two large numbers where the numbers are stored in an array format

2012-06-26 Thread Ashish Goel
the base is not given, so 10 can't be assumed

Best Regards
Ashish Goel
"Think positive and find fuel in failure"
+919985813081
+919966006652


On Tue, Jun 26, 2012 at 4:38 PM, amrit harry wrote:

> make size of both array by adding '0' in front of smaller array
> then
> int carry=0;
> for(i=array.size();i>=0;i--)
> {
> sum[i]=carry+arrayA[i]+arrayB[i];
> carry=sum[i]/10;
> sum[i]=sum[i]%10;
> }
> then reverse and print sum
> On Tue, Jun 26, 2012 at 3:40 PM, Ashish Goel  wrote:
>
>>
>> Best Regards
>>
>> Ashish Goel
>> "Think positive and find fuel in failure"
>> +919985813081
>> +919966006652
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>
>
> --
> Thanks & Regards
> Amritpal singh
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

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



Re: [algogeeks] MS Question: Add two large numbers where the numbers are stored in an array format

2012-06-26 Thread Kumar Vishal
I mean 123 is store as 1,2,3 or   3,2,1

On Tue, Jun 26, 2012 at 6:01 PM, Kumar Vishal  wrote:

> MSB is at end or at the last of the array .. ??
>
> On Tue, Jun 26, 2012 at 5:43 PM, saurabh singh wrote:
>
>> ^ Does it make any difference?
>> Saurabh Singh
>> B.Tech (Computer Science)
>> MNNIT
>> blog:geekinessthecoolway.blogspot.com
>>
>>
>>
>> On Tue, Jun 26, 2012 at 5:32 PM, Navin Kumar wrote:
>>
>>> whether it is in character array or integer array??
>>>
>>>
>>> On Tue, Jun 26, 2   012 at 3:40 PM, Ashish Goel wrote:
>>>

 Best Regards
 Ashish Goel
 "Think positive and find fuel in failure"
 +919985813081
 +919966006652

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

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


-- 
Regards
Kumar Vishal
_
*http://wethecommonpeople.wordpress.com/   *
*h**ttp://kumartechnicalarticles.wordpress.com/
*
_

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



Re: [algogeeks] MS Question: Add two large numbers where the numbers are stored in an array format

2012-06-26 Thread Kumar Vishal
MSB is at end or at the last of the array .. ??

On Tue, Jun 26, 2012 at 5:43 PM, saurabh singh  wrote:

> ^ Does it make any difference?
> Saurabh Singh
> B.Tech (Computer Science)
> MNNIT
> blog:geekinessthecoolway.blogspot.com
>
>
>
> On Tue, Jun 26, 2012 at 5:32 PM, Navin Kumar wrote:
>
>> whether it is in character array or integer array??
>>
>>
>> On Tue, Jun 26, 2   012 at 3:40 PM, Ashish Goel wrote:
>>
>>>
>>> Best Regards
>>> Ashish Goel
>>> "Think positive and find fuel in failure"
>>> +919985813081
>>> +919966006652
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Algorithm Geeks" group.
>>> To post to this group, send email to algogeeks@googlegroups.com.
>>> To unsubscribe from this group, send email to
>>> algogeeks+unsubscr...@googlegroups.com.
>>> For more options, visit this group at
>>> http://groups.google.com/group/algogeeks?hl=en.
>>>
>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>



-- 
Regards
Kumar Vishal
_
*http://wethecommonpeople.wordpress.com/   *
*h**ttp://kumartechnicalarticles.wordpress.com/
*
_

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



Re: [algogeeks] MS Question: Add two large numbers where the numbers are stored in an array format

2012-06-26 Thread amrit harry
make size of both array by adding '0' in front of smaller array
then
int carry=0;
for(i=array.size();i>=0;i--)
{
sum[i]=carry+arrayA[i]+arrayB[i];
carry=sum[i]/10;
sum[i]=sum[i]%10;
}
then reverse and print sum
On Tue, Jun 26, 2012 at 3:40 PM, Ashish Goel  wrote:

>
> Best Regards
> Ashish Goel
> "Think positive and find fuel in failure"
> +919985813081
> +919966006652
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>



-- 
Thanks & Regards
Amritpal singh

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



Re: [algogeeks] MS Question: Add two large numbers where the numbers are stored in an array format

2012-06-26 Thread saurabh singh
^ Does it make any difference?
Saurabh Singh
B.Tech (Computer Science)
MNNIT
blog:geekinessthecoolway.blogspot.com



On Tue, Jun 26, 2012 at 5:32 PM, Navin Kumar wrote:

> whether it is in character array or integer array??
>
>
> On Tue, Jun 26, 2012 at 3:40 PM, Ashish Goel  wrote:
>
>>
>> Best Regards
>> Ashish Goel
>> "Think positive and find fuel in failure"
>> +919985813081
>> +919966006652
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

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



Re: [algogeeks] MS Question: Add two large numbers where the numbers are stored in an array format

2012-06-26 Thread Navin Kumar
whether it is in character array or integer array??

On Tue, Jun 26, 2012 at 3:40 PM, Ashish Goel  wrote:

>
> Best Regards
> Ashish Goel
> "Think positive and find fuel in failure"
> +919985813081
> +919966006652
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

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



[algogeeks] MS Question: Add two large numbers where the numbers are stored in an array format

2012-06-26 Thread Ashish Goel
Best Regards
Ashish Goel
"Think positive and find fuel in failure"
+919985813081
+919966006652

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



Re: [algogeeks] MS Question: Reverse stack using push, pop without any auxiliary data structure

2012-06-17 Thread algogeek
This solution works perfectly :)

On Friday, June 15, 2012 10:59:22 AM UTC+5:30, Navin Kumar wrote:
>
> I corrected in function InsertAtBottom :"In my code isntead of 
> (!IsEmptyStack) use IsEmptyStack"
>
> On Fri, Jun 15, 2012 at 10:49 AM, Navin Kumar wrote:
>
>> @all:
>>
>> In my code isntead of (!IsEmptyStack) use IsEmptyStack
>>
>> Logic :
>>
>> First pop the all element and then start putting element at bottom in 
>> reverse order i.e. the element which is fetched last is put at the bottom 
>> and so on.
>>
>> ex: let our stack is: 1 2 3 4 (1 is at bottom).
>>
>> function Call is will be:
>>
>> Reverse(S) -->Reverse(S)  -->Reverse(S)   
>> -->Reverse(S)  -->stack empty so return
>> InsertAtBottom(4)   InsertAtBottom(3)InsertAtBottom(2)  
>> InsertAtBottom(1)
>>
>> going back First 1 will be placed at bottom: stack content :1
>> now 2 will be placed at bottom: stack content will be: 2 1
>> now 3 will be placed at bottom: stack content will be: 3 2 1 
>> now 4 will be placed at bottom: stack content will be:4 3 2 1 
>>
>>
>>
>>
>>
>> On Thu, Jun 14, 2012 at 2:46 PM, Nishant Pandey <
>> nishant.bits.me...@gmail.com> wrote:
>>
>>> stack means inbuild stack we cant use any DS from our program explicitly.
>>>
>>> On Thu, Jun 14, 2012 at 2:44 PM, rahul patil <
>>> rahul.deshmukhpa...@gmail.com> wrote:
>>>
 to store items in stack you will need some DS. Do they mean you cant 
 use any auxillary DS than stack ? 


 On Thu, Jun 14, 2012 at 2:24 PM, Ashish Goel  wrote:

>
> Best Regards
> Ashish Goel
> "Think positive and find fuel in failure"
> +919985813081
> +919966006652
>
> -- 
> You received this message because you are subscribed to the Google 
> Groups "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to 
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/algogeeks?hl=en.
>



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

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

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



Re: [algogeeks] MS Question: Reverse stack using push, pop without any auxiliary data structure

2012-06-14 Thread Navin Kumar
I corrected in function InsertAtBottom :"In my code isntead of
(!IsEmptyStack) use IsEmptyStack"

On Fri, Jun 15, 2012 at 10:49 AM, Navin Kumar wrote:

> @all:
>
> In my code isntead of (!IsEmptyStack) use IsEmptyStack
>
> Logic :
>
> First pop the all element and then start putting element at bottom in
> reverse order i.e. the element which is fetched last is put at the bottom
> and so on.
>
> ex: let our stack is: 1 2 3 4 (1 is at bottom).
>
> function Call is will be:
>
> Reverse(S) -->Reverse(S)  -->Reverse(S)
> -->Reverse(S)  -->stack empty so return
> InsertAtBottom(4)   InsertAtBottom(3)InsertAtBottom(2)
> InsertAtBottom(1)
>
> going back First 1 will be placed at bottom: stack content :1
> now 2 will be placed at bottom: stack content will be: 2 1
> now 3 will be placed at bottom: stack content will be: 3 2 1
> now 4 will be placed at bottom: stack content will be:4 3 2 1
>
>
>
>
>
> On Thu, Jun 14, 2012 at 2:46 PM, Nishant Pandey <
> nishant.bits.me...@gmail.com> wrote:
>
>> stack means inbuild stack we cant use any DS from our program explicitly.
>>
>> On Thu, Jun 14, 2012 at 2:44 PM, rahul patil <
>> rahul.deshmukhpa...@gmail.com> wrote:
>>
>>> to store items in stack you will need some DS. Do they mean you cant use
>>> any auxillary DS than stack ?
>>>
>>>
>>> On Thu, Jun 14, 2012 at 2:24 PM, Ashish Goel  wrote:
>>>

 Best Regards
 Ashish Goel
 "Think positive and find fuel in failure"
 +919985813081
 +919966006652

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

>>>
>>>
>>>
>>> --
>>> Regards,
>>> Rahul Patil
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Algorithm Geeks" group.
>>> To post to this group, send email to algogeeks@googlegroups.com.
>>> To unsubscribe from this group, send email to
>>> algogeeks+unsubscr...@googlegroups.com.
>>> For more options, visit this group at
>>> http://groups.google.com/group/algogeeks?hl=en.
>>>
>>
>>
>>
>> --
>> Cheers,
>>
>> Nishant Pandey |Specialist Tools Development  |  
>> npan...@google.com |
>> +91-9911258345
>>
>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>

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



Re: [algogeeks] MS Question: Reverse stack using push, pop without any auxiliary data structure

2012-06-14 Thread Navin Kumar
@all:

In my code isntead of (!IsEmptyStack) use IsEmptyStack

Logic :

First pop the all element and then start putting element at bottom in
reverse order i.e. the element which is fetched last is put at the bottom
and so on.

ex: let our stack is: 1 2 3 4 (1 is at bottom).

function Call is will be:

Reverse(S) -->Reverse(S)  -->Reverse(S)
-->Reverse(S)  -->stack empty so return
InsertAtBottom(4)   InsertAtBottom(3)InsertAtBottom(2)
InsertAtBottom(1)

going back First 1 will be placed at bottom: stack content :1
now 2 will be placed at bottom: stack content will be: 2 1
now 3 will be placed at bottom: stack content will be: 3 2 1
now 4 will be placed at bottom: stack content will be:4 3 2 1





On Thu, Jun 14, 2012 at 2:46 PM, Nishant Pandey <
nishant.bits.me...@gmail.com> wrote:

> stack means inbuild stack we cant use any DS from our program explicitly.
>
> On Thu, Jun 14, 2012 at 2:44 PM, rahul patil <
> rahul.deshmukhpa...@gmail.com> wrote:
>
>> to store items in stack you will need some DS. Do they mean you cant use
>> any auxillary DS than stack ?
>>
>>
>> On Thu, Jun 14, 2012 at 2:24 PM, Ashish Goel  wrote:
>>
>>>
>>> Best Regards
>>> Ashish Goel
>>> "Think positive and find fuel in failure"
>>> +919985813081
>>> +919966006652
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Algorithm Geeks" group.
>>> To post to this group, send email to algogeeks@googlegroups.com.
>>> To unsubscribe from this group, send email to
>>> algogeeks+unsubscr...@googlegroups.com.
>>> For more options, visit this group at
>>> http://groups.google.com/group/algogeeks?hl=en.
>>>
>>
>>
>>
>> --
>> Regards,
>> Rahul Patil
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>
>
> --
> Cheers,
>
> Nishant Pandey |Specialist Tools Development  |  
> npan...@google.com |
> +91-9911258345
>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

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



Re: [algogeeks] MS Question: Reverse stack using push, pop without any auxiliary data structure

2012-06-14 Thread Nishant Pandey
i think i already explained the logic initially :)

On Thu, Jun 14, 2012 at 9:30 PM, Hassan Monfared wrote:

> how can you pop from empty stack ?
> "  temp=pop(S); "
>
> Regards,
> Hassan
>
> On Thu, Jun 14, 2012 at 8:25 PM, Ashish Goel  wrote:
>
>> Navin: copy pastes not encouraged till the logic is also clarified ;)
>>
>> Best Regards
>> Ashish Goel
>> "Think positive and find fuel in failure"
>> +919985813081
>> +919966006652
>>
>>
>> On Thu, Jun 14, 2012 at 7:25 PM, Sourabh Singh 
>> wrote:
>>
>>> @ Navin Kumar
>>>
>>> Nice . Solution.
>>> But
>>> your  function also make a stack only. so you are using a
>>> stack[internal] here.
>>> but may be this one is allowed:-)
>>>
>>>
>>> On Thu, Jun 14, 2012 at 5:23 AM, Navin Kumar 
>>> wrote:
>>>
 void Reverse(struct Stack *S) {
 int data;
 if(IsEmptyStack(S)) return;
 data=pop(s);
 ReverseStack(S);
 InsertAtBottom(S, data);
 }

 void InsertAtBottom(struct stack *S, int data)
 {
int temp;
if(!IsEmptyStack(S)){
push(S,data);
return;
 }
temp=pop(S);
InsertAtBottom(S,data);
 push(S, temp);

 }


 On Thu, Jun 14, 2012 at 2:44 PM, rahul patil <
 rahul.deshmukhpa...@gmail.com> wrote:

> to store items in stack you will need some DS. Do they mean you cant
> use any auxillary DS than stack ?
>
>
> On Thu, Jun 14, 2012 at 2:24 PM, Ashish Goel wrote:
>
>>
>> Best Regards
>> Ashish Goel
>> "Think positive and find fuel in failure"
>> +919985813081
>> +919966006652
>>
>> --
>> You received this message because you are subscribed to the Google
>> Groups "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>
>
> --
> Regards,
> Rahul Patil
>
> --
> You received this message because you are subscribed to the Google
> Groups "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

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

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



-- 
Cheers,

Nishant Pandey |Specialist Tools Development  |
npan...@google.com |
+91-9911258345

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



Re: [algogeeks] MS Question: Reverse stack using push, pop without any auxiliary data structure

2012-06-14 Thread Karthikeyan V.B
Hi all,

Generate combinations (taken k out of n) of a given string

Eg: Input : abcd
Output:
abc
acd
abd
bcd

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



Re: [algogeeks] MS Question: Reverse stack using push, pop without any auxiliary data structure

2012-06-14 Thread Nishant Pandey
the steps would be like this :
if i say stack is like this 1,2,3,4 then
1) pop each and every item from the stack till stack is empty
the nodes will be ther in function call stack stil  not pushed

2) now now take elements from function call stack like 4 and push it
3) when 3 comes next time first pop 4 and then push 3 again
4) repeat the step 3 again till the function call stack in not empty .

and uir done .

On Thu, Jun 14, 2012 at 2:24 PM, Ashish Goel  wrote:

>
> Best Regards
> Ashish Goel
> "Think positive and find fuel in failure"
> +919985813081
> +919966006652
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>



-- 
Cheers,

Nishant Pandey |Specialist Tools Development  |
npan...@google.com |
+91-9911258345

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



Re: [algogeeks] MS Question: Reverse stack using push, pop without any auxiliary data structure

2012-06-14 Thread Nishant Pandey
stack means inbuild stack we cant use any DS from our program explicitly.

On Thu, Jun 14, 2012 at 2:44 PM, rahul patil
wrote:

> to store items in stack you will need some DS. Do they mean you cant use
> any auxillary DS than stack ?
>
>
> On Thu, Jun 14, 2012 at 2:24 PM, Ashish Goel  wrote:
>
>>
>> Best Regards
>> Ashish Goel
>> "Think positive and find fuel in failure"
>> +919985813081
>> +919966006652
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>
>
> --
> Regards,
> Rahul Patil
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>



-- 
Cheers,

Nishant Pandey |Specialist Tools Development  |
npan...@google.com |
+91-9911258345

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



Re: [algogeeks] MS Question: Reverse stack using push, pop without any auxiliary data structure

2012-06-14 Thread Lomash Goyal
void pushreverse(int data)
{
int temp;
if(top==0)
{
push(data);
return;
}
else
temp=pop();
pushreverse(data);
push(temp);

}
int reversestack()
{
//static int arr[50];
 int top2=0;
int i;
if(top==0)
{ return top2;
}
 top2=pop();
reversestack();
pushreverse(top2);
 }


On Thu, Jun 14, 2012 at 2:44 PM, rahul patil
wrote:

> to store items in stack you will need some DS. Do they mean you cant use
> any auxillary DS than stack ?
>
>
> On Thu, Jun 14, 2012 at 2:24 PM, Ashish Goel  wrote:
>
>>
>> Best Regards
>> Ashish Goel
>> "Think positive and find fuel in failure"
>> +919985813081
>> +919966006652
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>
>
> --
> Regards,
> Rahul Patil
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from 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

Lomash Goyal
*
*

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



Re: [algogeeks] MS Question: Reverse stack using push, pop without any auxiliary data structure

2012-06-14 Thread Hassan Monfared
how can you pop from empty stack ?
"  temp=pop(S); "

Regards,
Hassan
On Thu, Jun 14, 2012 at 8:25 PM, Ashish Goel  wrote:

> Navin: copy pastes not encouraged till the logic is also clarified ;)
>
> Best Regards
> Ashish Goel
> "Think positive and find fuel in failure"
> +919985813081
> +919966006652
>
>
> On Thu, Jun 14, 2012 at 7:25 PM, Sourabh Singh 
> wrote:
>
>> @ Navin Kumar
>>
>> Nice . Solution.
>> But
>> your  function also make a stack only. so you are using a stack[internal]
>> here.
>> but may be this one is allowed:-)
>>
>>
>> On Thu, Jun 14, 2012 at 5:23 AM, Navin Kumar wrote:
>>
>>> void Reverse(struct Stack *S) {
>>> int data;
>>> if(IsEmptyStack(S)) return;
>>> data=pop(s);
>>> ReverseStack(S);
>>> InsertAtBottom(S, data);
>>> }
>>>
>>> void InsertAtBottom(struct stack *S, int data)
>>> {
>>>int temp;
>>>if(!IsEmptyStack(S)){
>>>push(S,data);
>>>return;
>>> }
>>>temp=pop(S);
>>>InsertAtBottom(S,data);
>>> push(S, temp);
>>>
>>> }
>>>
>>>
>>> On Thu, Jun 14, 2012 at 2:44 PM, rahul patil <
>>> rahul.deshmukhpa...@gmail.com> wrote:
>>>
 to store items in stack you will need some DS. Do they mean you cant
 use any auxillary DS than stack ?


 On Thu, Jun 14, 2012 at 2:24 PM, Ashish Goel  wrote:

>
> Best Regards
> Ashish Goel
> "Think positive and find fuel in failure"
> +919985813081
> +919966006652
>
> --
> You received this message because you are subscribed to the Google
> Groups "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>



 --
 Regards,
 Rahul Patil

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

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

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



Re: [algogeeks] MS Question: Reverse stack using push, pop without any auxiliary data structure

2012-06-14 Thread Ashish Goel
Navin: copy pastes not encouraged till the logic is also clarified ;)

Best Regards
Ashish Goel
"Think positive and find fuel in failure"
+919985813081
+919966006652


On Thu, Jun 14, 2012 at 7:25 PM, Sourabh Singh wrote:

> @ Navin Kumar
>
> Nice . Solution.
> But
> your  function also make a stack only. so you are using a stack[internal]
> here.
> but may be this one is allowed:-)
>
>
> On Thu, Jun 14, 2012 at 5:23 AM, Navin Kumar wrote:
>
>> void Reverse(struct Stack *S) {
>> int data;
>> if(IsEmptyStack(S)) return;
>> data=pop(s);
>> ReverseStack(S);
>> InsertAtBottom(S, data);
>> }
>>
>> void InsertAtBottom(struct stack *S, int data)
>> {
>>int temp;
>>if(!IsEmptyStack(S)){
>>push(S,data);
>>return;
>> }
>>temp=pop(S);
>>InsertAtBottom(S,data);
>> push(S, temp);
>>
>> }
>>
>>
>> On Thu, Jun 14, 2012 at 2:44 PM, rahul patil <
>> rahul.deshmukhpa...@gmail.com> wrote:
>>
>>> to store items in stack you will need some DS. Do they mean you cant use
>>> any auxillary DS than stack ?
>>>
>>>
>>> On Thu, Jun 14, 2012 at 2:24 PM, Ashish Goel  wrote:
>>>

 Best Regards
 Ashish Goel
 "Think positive and find fuel in failure"
 +919985813081
 +919966006652

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

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

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



Re: [algogeeks] MS Question: Reverse stack using push, pop without any auxiliary data structure

2012-06-14 Thread Sourabh Singh
@ Navin Kumar

Nice . Solution.
But
your  function also make a stack only. so you are using a stack[internal]
here.
but may be this one is allowed:-)

On Thu, Jun 14, 2012 at 5:23 AM, Navin Kumar wrote:

> void Reverse(struct Stack *S) {
> int data;
> if(IsEmptyStack(S)) return;
> data=pop(s);
> ReverseStack(S);
> InsertAtBottom(S, data);
> }
>
> void InsertAtBottom(struct stack *S, int data)
> {
>int temp;
>if(!IsEmptyStack(S)){
>push(S,data);
>return;
> }
>temp=pop(S);
>InsertAtBottom(S,data);
> push(S, temp);
>
> }
>
>
> On Thu, Jun 14, 2012 at 2:44 PM, rahul patil <
> rahul.deshmukhpa...@gmail.com> wrote:
>
>> to store items in stack you will need some DS. Do they mean you cant use
>> any auxillary DS than stack ?
>>
>>
>> On Thu, Jun 14, 2012 at 2:24 PM, Ashish Goel  wrote:
>>
>>>
>>> Best Regards
>>> Ashish Goel
>>> "Think positive and find fuel in failure"
>>> +919985813081
>>> +919966006652
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Algorithm Geeks" group.
>>> To post to this group, send email to algogeeks@googlegroups.com.
>>> To unsubscribe from this group, send email to
>>> algogeeks+unsubscr...@googlegroups.com.
>>> For more options, visit this group at
>>> http://groups.google.com/group/algogeeks?hl=en.
>>>
>>
>>
>>
>> --
>> Regards,
>> Rahul Patil
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

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



Re: [algogeeks] MS Question: Reverse stack using push, pop without any auxiliary data structure

2012-06-14 Thread Navin Kumar
void Reverse(struct Stack *S) {
int data;
if(IsEmptyStack(S)) return;
data=pop(s);
ReverseStack(S);
InsertAtBottom(S, data);
}

void InsertAtBottom(struct stack *S, int data)
{
   int temp;
   if(!IsEmptyStack(S)){
   push(S,data);
   return;
}
   temp=pop(S);
   InsertAtBottom(S,data);
push(S, temp);
}


On Thu, Jun 14, 2012 at 2:44 PM, rahul patil
wrote:

> to store items in stack you will need some DS. Do they mean you cant use
> any auxillary DS than stack ?
>
>
> On Thu, Jun 14, 2012 at 2:24 PM, Ashish Goel  wrote:
>
>>
>> Best Regards
>> Ashish Goel
>> "Think positive and find fuel in failure"
>> +919985813081
>> +919966006652
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>
>
> --
> Regards,
> Rahul Patil
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

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



Re: [algogeeks] MS Question: Reverse stack using push, pop without any auxiliary data structure

2012-06-14 Thread rahul patil
to store items in stack you will need some DS. Do they mean you cant use
any auxillary DS than stack ?


On Thu, Jun 14, 2012 at 2:24 PM, Ashish Goel  wrote:

>
> Best Regards
> Ashish Goel
> "Think positive and find fuel in failure"
> +919985813081
> +919966006652
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>



-- 
Regards,
Rahul Patil

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



[algogeeks] MS Question: Reverse stack using push, pop without any auxiliary data structure

2012-06-14 Thread Ashish Goel
Best Regards
Ashish Goel
"Think positive and find fuel in failure"
+919985813081
+919966006652

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



Re: [algogeeks] MS Question : find word in 2D array

2012-06-09 Thread Bhaskar Kushwaha
@utsav u haven't initialized match anywhere so ur algo fails


On Thu, Jun 7, 2012 at 2:50 AM, utsav sharma wrote:

> i think it can be solved using DP
> word="bcdf"  take hash of word h[b]=1 h[c]=2 h[d]=3 h[f]=4
> given 2d matrix m[][]=
> {b c b e f g h
>  b c d f p o u
>  d f  d f g k p  }
>
> take another matrix match[][]
> if( h[ m[i][j] ] > 0 )   //if this char is in word then
> {a=h[ m[i][j] ];
> if (match[i-1][j] ==a-1 || match[][]=a-1 || match[][]=a-1 )check
> prev element of row / diagonal /column
> match[i][j]=a;
> }
> else if char is not matched, then match[i][j] will contain longest prefix
> match(as in KMP).
> if at any instance we get match[i][j]==no. of chars in word then we will
> backtrack it to get the string.
> correct me if i'm wrong !!
>
> On Wed, Jun 6, 2012 at 10:39 PM, atul anand wrote:
>
>> i did this question long time back
>> well simple brute force check can be doneyou can keep one flag
>> matrix of same size to avoid necessary recursion.
>>
>>
>> On 6/6/12, Ashish Goel  wrote:
>> > WAP to find a word in a 2D array. The word can be formed on
>> > row/col/diagnal/reverse diagnal
>> >
>> > Best Regards
>> > Ashish Goel
>> > "Think positive and find fuel in failure"
>> > +919985813081
>> > +919966006652
>> >
>> > --
>> > You received this message because you are subscribed to the Google
>> Groups
>> > "Algorithm Geeks" group.
>> > To post to this group, send email to algogeeks@googlegroups.com.
>> > To unsubscribe from this group, send email to
>> > algogeeks+unsubscr...@googlegroups.com.
>> > For more options, visit this group at
>> > http://groups.google.com/group/algogeeks?hl=en.
>> >
>> >
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>>
>
>
> --
> Utsav Sharma,
> NIT Allahabad
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>



-- 
regards,
Bhaskar Kushwaha
Student
CSE
Third year
M.N.N.I.T.  Allahabad

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



Re: [algogeeks] MS Question : find word in 2D array

2012-06-06 Thread utsav sharma
i think it can be solved using DP
word="bcdf"  take hash of word h[b]=1 h[c]=2 h[d]=3 h[f]=4
given 2d matrix m[][]=
{b c b e f g h
 b c d f p o u
 d f  d f g k p  }

take another matrix match[][]
if( h[ m[i][j] ] > 0 )   //if this char is in word then
{a=h[ m[i][j] ];
if (match[i-1][j] ==a-1 || match[][]=a-1 || match[][]=a-1 )check
prev element of row / diagonal /column
match[i][j]=a;
}
else if char is not matched, then match[i][j] will contain longest prefix
match(as in KMP).
if at any instance we get match[i][j]==no. of chars in word then we will
backtrack it to get the string.
correct me if i'm wrong !!

On Wed, Jun 6, 2012 at 10:39 PM, atul anand  wrote:

> i did this question long time back
> well simple brute force check can be doneyou can keep one flag
> matrix of same size to avoid necessary recursion.
>
>
> On 6/6/12, Ashish Goel  wrote:
> > WAP to find a word in a 2D array. The word can be formed on
> > row/col/diagnal/reverse diagnal
> >
> > Best Regards
> > Ashish Goel
> > "Think positive and find fuel in failure"
> > +919985813081
> > +919966006652
> >
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Algorithm Geeks" group.
> > To post to this group, send email to algogeeks@googlegroups.com.
> > To unsubscribe from this group, send email to
> > algogeeks+unsubscr...@googlegroups.com.
> > For more options, visit this group at
> > http://groups.google.com/group/algogeeks?hl=en.
> >
> >
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>


-- 
Utsav Sharma,
NIT Allahabad

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



Re: [algogeeks] MS Question : find word in 2D array

2012-06-06 Thread atul anand
i did this question long time back
well simple brute force check can be doneyou can keep one flag
matrix of same size to avoid necessary recursion.


On 6/6/12, Ashish Goel  wrote:
> WAP to find a word in a 2D array. The word can be formed on
> row/col/diagnal/reverse diagnal
>
> Best Regards
> Ashish Goel
> "Think positive and find fuel in failure"
> +919985813081
> +919966006652
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>

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



[algogeeks] MS Question : find word in 2D array

2012-06-06 Thread Ashish Goel
WAP to find a word in a 2D array. The word can be formed on
row/col/diagnal/reverse diagnal

Best Regards
Ashish Goel
"Think positive and find fuel in failure"
+919985813081
+919966006652

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



Re: [algogeeks] MS Question: Delete a node in single linked list if it is less than any of the successor nodes

2012-06-04 Thread atul anand
whats problem with the approch provided by navin

http://k2code.blogspot.in/2011/09/deleting-node-in-singly-linked-list-if.html

it seems much simpler ...is there any test case for which it wont work ??

On Mon, Jun 4, 2012 at 3:25 PM, Amol Sharma  wrote:

> here is the question ans solution with proper explanation
>
> http://www.geeksforgeeks.org/archives/11604
>
> --
>
>
> Amol Sharma
> Third Year Student
> Computer Science and Engineering
> MNNIT Allahabad
>  
> 
>
>
>
>
>
>
> On Sat, Jun 2, 2012 at 1:21 AM, Hassan Monfared wrote:
>
>> 1- read all elements of list into stack
>> 2- max = stak.pop()
>> 3- if stack.empty() goto 7
>> 4- next=stack.pop()
>> 5- if next > max then max=next
>>  else delete next from list
>> 6- repeat from 3
>> 7- end!
>>
>> Regards,
>>
>> On Thu, May 31, 2012 at 9:45 PM, atul anand wrote:
>>
>>> @navin : +1
>>>
>>> On 5/31/12, Navin Kumar  wrote:
>>> > I think the easiest method to do this problem is this:
>>> >
>>> >
>>> http://k2code.blogspot.in/2011/09/deleting-node-in-singly-linked-list-if.html
>>> >
>>> > On Thu, May 31, 2012 at 5:58 PM, Ashish Goel 
>>> wrote:
>>> >
>>> >> that is what i have done by using recursion<=>stack.
>>> >>
>>> >> my code has problem, after  free(pCurr);, i should have return pRest;
>>> >>
>>> >> Best Regards
>>> >> Ashish Goel
>>> >> "Think positive and find fuel in failure"
>>> >> +919985813081
>>> >> +919966006652
>>> >>
>>> >>
>>> >> On Thu, May 31, 2012 at 4:37 PM, atul anand
>>> >> wrote:
>>> >>
>>> >>> then i guess ...it can be done using stack..with O(n) complexity..
>>> >>> it is similar to finding next greater element 
>>> >>>
>>> >>> http://www.geeksforgeeks.org/archives/8405
>>> >>>
>>> >>> element in the stack at the end of the algo...are the element which
>>> will
>>> >>> remain in the linked list . if stack is not empty then keep poping
>>> >>> elements
>>> >>> and create a SLL.
>>> >>>
>>> >>>
>>> >>> On Thu, May 31, 2012 at 4:29 PM, Ashish Goel 
>>> wrote:
>>> >>>
>>>  yes
>>> 
>>>  Best Regards
>>>  Ashish Goel
>>>  "Think positive and find fuel in failure"
>>>  +919985813081
>>>  +919966006652
>>> 
>>> 
>>>  On Thu, May 31, 2012 at 2:34 PM, atul anand
>>>  wrote:
>>> 
>>> > @Ashish :  please clarify this ques...
>>> >
>>> > delete a node in SLL if it is less than *any* of the succesor node
>>> ..
>>> >
>>> > 1 2 8 10 3 4 7 12
>>> >
>>> > delete 1,2,8,10,3,4,7
>>> >
>>> > ouput will be single node i.e 12
>>> >
>>> > dats what question asks?
>>> >
>>> > On Thu, May 31, 2012 at 2:16 PM, Ashish Goel 
>>> > wrote:
>>> >
>>> >> the LL is unsorted, is there any better solution that this?
>>> >>
>>> >> struct node* deleteNodes(struct node *pHead, struct node *pPrev)
>>> >> {
>>> >>   struct  node *pLL = *pHead;
>>> >>   if (!pLL) return NULL;
>>> >>   struct node *pCurr = pLL;
>>> >>
>>> >>   struct node *pRest = deleteNodes(pCurr->next, pCurr);
>>> >>   if (!pRest) return pCurr;
>>> >>   if (pCurr->data data)
>>> >>   {
>>> >> if (pPrev) { pPrev->next = pRest; };
>>> >> free(pCurr);
>>> >>   }
>>> >>  else
>>> >>  {
>>> >>pCurr->next = pRest;
>>> >>  }
>>> >>return pCurr;
>>> >> }
>>> >>
>>> >>
>>> >> Best Regards
>>> >> Ashish Goel
>>> >> "Think positive and find fuel in failure"
>>> >> +919985813081
>>> >> +919966006652
>>> >>
>>> >> --
>>> >> You received this message because you are subscribed to the Google
>>> >> Groups "Algorithm Geeks" group.
>>> >> To post to this group, send email to algogeeks@googlegroups.com.
>>> >> To unsubscribe from this group, send email to
>>> >> algogeeks+unsubscr...@googlegroups.com.
>>> >> For more options, visit this group at
>>> >> http://groups.google.com/group/algogeeks?hl=en.
>>> >>
>>> >
>>> >  --
>>> > You received this message because you are subscribed to the Google
>>> > Groups "Algorithm Geeks" group.
>>> > To post to this group, send email to algogeeks@googlegroups.com.
>>> > To unsubscribe from this group, send email to
>>> > algogeeks+unsubscr...@googlegroups.com.
>>> > For more options, visit this group at
>>> > http://groups.google.com/group/algogeeks?hl=en.
>>> >
>>> 
>>>   --
>>>  You received this message because you are subscribed to the Google
>>>  Groups "Algorithm Geeks" group.
>>>  To post to this group, send email to algogeeks@googlegroups.com.
>>>  To unsubscribe from this group, send email to
>>>  algogeeks+unsubscr...@googlegroups.com.
>>>  For more options, visit this group at
>>>  http://groups.google.com/group/algogeeks?hl=en.
>>> 
>>> >>>
>>> >>>  --
>>> >>> You r

Re: [algogeeks] MS Question: Delete a node in single linked list if it is less than any of the successor nodes

2012-06-04 Thread Amol Sharma
here is the question ans solution with proper explanation

http://www.geeksforgeeks.org/archives/11604

--


Amol Sharma
Third Year Student
Computer Science and Engineering
MNNIT Allahabad








On Sat, Jun 2, 2012 at 1:21 AM, Hassan Monfared  wrote:

> 1- read all elements of list into stack
> 2- max = stak.pop()
> 3- if stack.empty() goto 7
> 4- next=stack.pop()
> 5- if next > max then max=next
>  else delete next from list
> 6- repeat from 3
> 7- end!
>
> Regards,
>
> On Thu, May 31, 2012 at 9:45 PM, atul anand wrote:
>
>> @navin : +1
>>
>> On 5/31/12, Navin Kumar  wrote:
>> > I think the easiest method to do this problem is this:
>> >
>> >
>> http://k2code.blogspot.in/2011/09/deleting-node-in-singly-linked-list-if.html
>> >
>> > On Thu, May 31, 2012 at 5:58 PM, Ashish Goel  wrote:
>> >
>> >> that is what i have done by using recursion<=>stack.
>> >>
>> >> my code has problem, after  free(pCurr);, i should have return pRest;
>> >>
>> >> Best Regards
>> >> Ashish Goel
>> >> "Think positive and find fuel in failure"
>> >> +919985813081
>> >> +919966006652
>> >>
>> >>
>> >> On Thu, May 31, 2012 at 4:37 PM, atul anand
>> >> wrote:
>> >>
>> >>> then i guess ...it can be done using stack..with O(n) complexity..
>> >>> it is similar to finding next greater element 
>> >>>
>> >>> http://www.geeksforgeeks.org/archives/8405
>> >>>
>> >>> element in the stack at the end of the algo...are the element which
>> will
>> >>> remain in the linked list . if stack is not empty then keep poping
>> >>> elements
>> >>> and create a SLL.
>> >>>
>> >>>
>> >>> On Thu, May 31, 2012 at 4:29 PM, Ashish Goel 
>> wrote:
>> >>>
>>  yes
>> 
>>  Best Regards
>>  Ashish Goel
>>  "Think positive and find fuel in failure"
>>  +919985813081
>>  +919966006652
>> 
>> 
>>  On Thu, May 31, 2012 at 2:34 PM, atul anand
>>  wrote:
>> 
>> > @Ashish :  please clarify this ques...
>> >
>> > delete a node in SLL if it is less than *any* of the succesor node
>> ..
>> >
>> > 1 2 8 10 3 4 7 12
>> >
>> > delete 1,2,8,10,3,4,7
>> >
>> > ouput will be single node i.e 12
>> >
>> > dats what question asks?
>> >
>> > On Thu, May 31, 2012 at 2:16 PM, Ashish Goel 
>> > wrote:
>> >
>> >> the LL is unsorted, is there any better solution that this?
>> >>
>> >> struct node* deleteNodes(struct node *pHead, struct node *pPrev)
>> >> {
>> >>   struct  node *pLL = *pHead;
>> >>   if (!pLL) return NULL;
>> >>   struct node *pCurr = pLL;
>> >>
>> >>   struct node *pRest = deleteNodes(pCurr->next, pCurr);
>> >>   if (!pRest) return pCurr;
>> >>   if (pCurr->data data)
>> >>   {
>> >> if (pPrev) { pPrev->next = pRest; };
>> >> free(pCurr);
>> >>   }
>> >>  else
>> >>  {
>> >>pCurr->next = pRest;
>> >>  }
>> >>return pCurr;
>> >> }
>> >>
>> >>
>> >> Best Regards
>> >> Ashish Goel
>> >> "Think positive and find fuel in failure"
>> >> +919985813081
>> >> +919966006652
>> >>
>> >> --
>> >> You received this message because you are subscribed to the Google
>> >> Groups "Algorithm Geeks" group.
>> >> To post to this group, send email to algogeeks@googlegroups.com.
>> >> To unsubscribe from this group, send email to
>> >> algogeeks+unsubscr...@googlegroups.com.
>> >> For more options, visit this group at
>> >> http://groups.google.com/group/algogeeks?hl=en.
>> >>
>> >
>> >  --
>> > You received this message because you are subscribed to the Google
>> > Groups "Algorithm Geeks" group.
>> > To post to this group, send email to algogeeks@googlegroups.com.
>> > To unsubscribe from this group, send email to
>> > algogeeks+unsubscr...@googlegroups.com.
>> > For more options, visit this group at
>> > http://groups.google.com/group/algogeeks?hl=en.
>> >
>> 
>>   --
>>  You received this message because you are subscribed to the Google
>>  Groups "Algorithm Geeks" group.
>>  To post to this group, send email to algogeeks@googlegroups.com.
>>  To unsubscribe from this group, send email to
>>  algogeeks+unsubscr...@googlegroups.com.
>>  For more options, visit this group at
>>  http://groups.google.com/group/algogeeks?hl=en.
>> 
>> >>>
>> >>>  --
>> >>> You received this message because you are subscribed to the Google
>> >>> Groups
>> >>> "Algorithm Geeks" group.
>> >>> To post to this group, send email to algogeeks@googlegroups.com.
>> >>> To unsubscribe from 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 messag

RE: [algogeeks] MS Question: WAP to find files in a

2012-06-02 Thread Ashish Goel
 directory/subdirectories
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit

The question is to implement without use of any library

Sent from my Windows Phone
From: atul anand
Sent: 03-06-2012 11:19
To: algogeeks@googlegroups.com
Subject: Re: [algogeeks] MS Question: WAP to find files in a
directory/subdirectories
i wrote this program in college labbut used shell script to
simulate ls -r functionality.
now to do in c or java .. we only need to knw about the libraries to use.

On 6/3/12, Ashish Goel  wrote:
> ls-r implementation needed...
>
>
> Best Regards
> Ashish Goel
> "Think positive and find fuel in failure"
> +919985813081
> +919966006652
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>

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

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



Re: [algogeeks] MS Question: WAP to find files in a directory/subdirectories

2012-06-02 Thread Navin Kumar
you can set your directory path in this line

char *home="/home/navin/temp/";

On Sun, Jun 3, 2012 at 11:26 AM, Navin Kumar wrote:

>
>
> #include 
> #include 
> #include 
> #include 
> #include 
> #include 
> #include 
>
> void dirfun(char *);
>
>
> int main()
> {
>
> char *home="/home/navin/temp/";
> dirfun(home);
> return 0;
> }
>
>
> void dirfun(char *path)
> {
> struct dirent *dir;
> DIR *dp= opendir(path);
>
> if(dp!=NULL)
> {
> while((dir = readdir(dp)))
> {
> if(dir->d_type == DT_DIR)
> {
> if(strcmp(dir->d_name,".") &&
> strcmp(dir->d_name,".."))
>
>  printf("%s\n",dir->d_name);
>
>
>
> }
> else
>
> printf("%s\n",dir->d_name);
>
>
>
>
> }
>   }
>  }
>
>
>
> On Sun, Jun 3, 2012 at 8:14 AM, Ashish Goel  wrote:
>
>> ls-r implementation needed...
>>
>>
>> Best Regards
>> Ashish Goel
>> "Think positive and find fuel in failure"
>> +919985813081
>> +919966006652
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>

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



Re: [algogeeks] MS Question: WAP to find files in a directory/subdirectories

2012-06-02 Thread Navin Kumar
#include 
#include 
#include 
#include 
#include 
#include 
#include 

void dirfun(char *);


int main()
{

char *home="/home/navin/temp/";
dirfun(home);
return 0;
}


void dirfun(char *path)
{
struct dirent *dir;
DIR *dp= opendir(path);

if(dp!=NULL)
{
while((dir = readdir(dp)))
{
if(dir->d_type == DT_DIR)
{
if(strcmp(dir->d_name,".") &&
strcmp(dir->d_name,".."))

 printf("%s\n",dir->d_name);



}
else

printf("%s\n",dir->d_name);



}
  }
 }



On Sun, Jun 3, 2012 at 8:14 AM, Ashish Goel  wrote:

> ls-r implementation needed...
>
>
> Best Regards
> Ashish Goel
> "Think positive and find fuel in failure"
> +919985813081
> +919966006652
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

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



Re: [algogeeks] MS Question: WAP to find files in a directory/subdirectories

2012-06-02 Thread atul anand
i wrote this program in college labbut used shell script to
simulate ls -r functionality.
now to do in c or java .. we only need to knw about the libraries to use.

On 6/3/12, Ashish Goel  wrote:
> ls-r implementation needed...
>
>
> Best Regards
> Ashish Goel
> "Think positive and find fuel in failure"
> +919985813081
> +919966006652
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>

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



[algogeeks] MS Question: WAP to find files in a directory/subdirectories

2012-06-02 Thread Ashish Goel
ls-r implementation needed...


Best Regards
Ashish Goel
"Think positive and find fuel in failure"
+919985813081
+919966006652

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



Re: [algogeeks] MS Question: Delete a node in single linked list if it is less than any of the successor nodes

2012-06-01 Thread Hassan Monfared
1- read all elements of list into stack
2- max = stak.pop()
3- if stack.empty() goto 7
4- next=stack.pop()
5- if next > max then max=next
 else delete next from list
6- repeat from 3
7- end!

Regards,

On Thu, May 31, 2012 at 9:45 PM, atul anand  wrote:

> @navin : +1
>
> On 5/31/12, Navin Kumar  wrote:
> > I think the easiest method to do this problem is this:
> >
> >
> http://k2code.blogspot.in/2011/09/deleting-node-in-singly-linked-list-if.html
> >
> > On Thu, May 31, 2012 at 5:58 PM, Ashish Goel  wrote:
> >
> >> that is what i have done by using recursion<=>stack.
> >>
> >> my code has problem, after  free(pCurr);, i should have return pRest;
> >>
> >> Best Regards
> >> Ashish Goel
> >> "Think positive and find fuel in failure"
> >> +919985813081
> >> +919966006652
> >>
> >>
> >> On Thu, May 31, 2012 at 4:37 PM, atul anand
> >> wrote:
> >>
> >>> then i guess ...it can be done using stack..with O(n) complexity..
> >>> it is similar to finding next greater element 
> >>>
> >>> http://www.geeksforgeeks.org/archives/8405
> >>>
> >>> element in the stack at the end of the algo...are the element which
> will
> >>> remain in the linked list . if stack is not empty then keep poping
> >>> elements
> >>> and create a SLL.
> >>>
> >>>
> >>> On Thu, May 31, 2012 at 4:29 PM, Ashish Goel 
> wrote:
> >>>
>  yes
> 
>  Best Regards
>  Ashish Goel
>  "Think positive and find fuel in failure"
>  +919985813081
>  +919966006652
> 
> 
>  On Thu, May 31, 2012 at 2:34 PM, atul anand
>  wrote:
> 
> > @Ashish :  please clarify this ques...
> >
> > delete a node in SLL if it is less than *any* of the succesor node ..
> >
> > 1 2 8 10 3 4 7 12
> >
> > delete 1,2,8,10,3,4,7
> >
> > ouput will be single node i.e 12
> >
> > dats what question asks?
> >
> > On Thu, May 31, 2012 at 2:16 PM, Ashish Goel 
> > wrote:
> >
> >> the LL is unsorted, is there any better solution that this?
> >>
> >> struct node* deleteNodes(struct node *pHead, struct node *pPrev)
> >> {
> >>   struct  node *pLL = *pHead;
> >>   if (!pLL) return NULL;
> >>   struct node *pCurr = pLL;
> >>
> >>   struct node *pRest = deleteNodes(pCurr->next, pCurr);
> >>   if (!pRest) return pCurr;
> >>   if (pCurr->data data)
> >>   {
> >> if (pPrev) { pPrev->next = pRest; };
> >> free(pCurr);
> >>   }
> >>  else
> >>  {
> >>pCurr->next = pRest;
> >>  }
> >>return pCurr;
> >> }
> >>
> >>
> >> Best Regards
> >> Ashish Goel
> >> "Think positive and find fuel in failure"
> >> +919985813081
> >> +919966006652
> >>
> >> --
> >> You received this message because you are subscribed to the Google
> >> Groups "Algorithm Geeks" group.
> >> To post to this group, send email to algogeeks@googlegroups.com.
> >> To unsubscribe from this group, send email to
> >> algogeeks+unsubscr...@googlegroups.com.
> >> For more options, visit this group at
> >> http://groups.google.com/group/algogeeks?hl=en.
> >>
> >
> >  --
> > You received this message because you are subscribed to the Google
> > Groups "Algorithm Geeks" group.
> > To post to this group, send email to algogeeks@googlegroups.com.
> > To unsubscribe from this group, send email to
> > algogeeks+unsubscr...@googlegroups.com.
> > For more options, visit this group at
> > http://groups.google.com/group/algogeeks?hl=en.
> >
> 
>   --
>  You received this message because you are subscribed to the Google
>  Groups "Algorithm Geeks" group.
>  To post to this group, send email to algogeeks@googlegroups.com.
>  To unsubscribe from this group, send email to
>  algogeeks+unsubscr...@googlegroups.com.
>  For more options, visit this group at
>  http://groups.google.com/group/algogeeks?hl=en.
> 
> >>>
> >>>  --
> >>> You received this message because you are subscribed to the Google
> >>> Groups
> >>> "Algorithm Geeks" group.
> >>> To post to this group, send email to algogeeks@googlegroups.com.
> >>> To unsubscribe from this group, send email to
> >>> algogeeks+unsubscr...@googlegroups.com.
> >>> For more options, visit this group at
> >>> http://groups.google.com/group/algogeeks?hl=en.
> >>>
> >>
> >>  --
> >> You received this message because you are subscribed to the Google
> Groups
> >> "Algorithm Geeks" group.
> >> To post to this group, send email to algogeeks@googlegroups.com.
> >> To unsubscribe from this group, send email to
> >> algogeeks+unsubscr...@googlegroups.com.
> >> For more options, visit this group at
> >> http://groups.google.com/group/algogeeks?hl=en.
> >>
> >
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Algorithm Geeks" group.
> > To post to this group, send email to algogeeks@googlegroups.com.
> > To unsubscribe from this gro

Re: [algogeeks] MS Question: Delete a node in single linked list if it is less than any of the successor nodes

2012-05-31 Thread atul anand
@navin : +1

On 5/31/12, Navin Kumar  wrote:
> I think the easiest method to do this problem is this:
>
> http://k2code.blogspot.in/2011/09/deleting-node-in-singly-linked-list-if.html
>
> On Thu, May 31, 2012 at 5:58 PM, Ashish Goel  wrote:
>
>> that is what i have done by using recursion<=>stack.
>>
>> my code has problem, after  free(pCurr);, i should have return pRest;
>>
>> Best Regards
>> Ashish Goel
>> "Think positive and find fuel in failure"
>> +919985813081
>> +919966006652
>>
>>
>> On Thu, May 31, 2012 at 4:37 PM, atul anand
>> wrote:
>>
>>> then i guess ...it can be done using stack..with O(n) complexity..
>>> it is similar to finding next greater element 
>>>
>>> http://www.geeksforgeeks.org/archives/8405
>>>
>>> element in the stack at the end of the algo...are the element which will
>>> remain in the linked list . if stack is not empty then keep poping
>>> elements
>>> and create a SLL.
>>>
>>>
>>> On Thu, May 31, 2012 at 4:29 PM, Ashish Goel  wrote:
>>>
 yes

 Best Regards
 Ashish Goel
 "Think positive and find fuel in failure"
 +919985813081
 +919966006652


 On Thu, May 31, 2012 at 2:34 PM, atul anand
 wrote:

> @Ashish :  please clarify this ques...
>
> delete a node in SLL if it is less than *any* of the succesor node ..
>
> 1 2 8 10 3 4 7 12
>
> delete 1,2,8,10,3,4,7
>
> ouput will be single node i.e 12
>
> dats what question asks?
>
> On Thu, May 31, 2012 at 2:16 PM, Ashish Goel 
> wrote:
>
>> the LL is unsorted, is there any better solution that this?
>>
>> struct node* deleteNodes(struct node *pHead, struct node *pPrev)
>> {
>>   struct  node *pLL = *pHead;
>>   if (!pLL) return NULL;
>>   struct node *pCurr = pLL;
>>
>>   struct node *pRest = deleteNodes(pCurr->next, pCurr);
>>   if (!pRest) return pCurr;
>>   if (pCurr->data data)
>>   {
>> if (pPrev) { pPrev->next = pRest; };
>> free(pCurr);
>>   }
>>  else
>>  {
>>pCurr->next = pRest;
>>  }
>>return pCurr;
>> }
>>
>>
>> Best Regards
>> Ashish Goel
>> "Think positive and find fuel in failure"
>> +919985813081
>> +919966006652
>>
>> --
>> You received this message because you are subscribed to the Google
>> Groups "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>  --
> You received this message because you are subscribed to the Google
> Groups "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

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

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

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



Re: [algogeeks] MS Question: Delete a node in single linked list if it is less than any of the successor nodes

2012-05-31 Thread Nishant Pandey
if i am getting this questions correctly then we have to delete the element
till its next is not null ??
please comment if i am wrong ?

On Thu, May 31, 2012 at 5:58 PM, Ashish Goel  wrote:

> that is what i have done by using recursion<=>stack.
>
> my code has problem, after  free(pCurr);, i should have return pRest;
>
> Best Regards
> Ashish Goel
> "Think positive and find fuel in failure"
> +919985813081
> +919966006652
>
>
> On Thu, May 31, 2012 at 4:37 PM, atul anand wrote:
>
>> then i guess ...it can be done using stack..with O(n) complexity..
>> it is similar to finding next greater element 
>>
>> http://www.geeksforgeeks.org/archives/8405
>>
>> element in the stack at the end of the algo...are the element which will
>> remain in the linked list . if stack is not empty then keep poping elements
>> and create a SLL.
>>
>>
>> On Thu, May 31, 2012 at 4:29 PM, Ashish Goel  wrote:
>>
>>> yes
>>>
>>> Best Regards
>>> Ashish Goel
>>> "Think positive and find fuel in failure"
>>> +919985813081
>>> +919966006652
>>>
>>>
>>> On Thu, May 31, 2012 at 2:34 PM, atul anand wrote:
>>>
 @Ashish :  please clarify this ques...

 delete a node in SLL if it is less than *any* of the succesor node ..

 1 2 8 10 3 4 7 12

 delete 1,2,8,10,3,4,7

 ouput will be single node i.e 12

 dats what question asks?

 On Thu, May 31, 2012 at 2:16 PM, Ashish Goel  wrote:

> the LL is unsorted, is there any better solution that this?
>
> struct node* deleteNodes(struct node *pHead, struct node *pPrev)
> {
>   struct  node *pLL = *pHead;
>   if (!pLL) return NULL;
>   struct node *pCurr = pLL;
>
>   struct node *pRest = deleteNodes(pCurr->next, pCurr);
>   if (!pRest) return pCurr;
>   if (pCurr->data data)
>   {
> if (pPrev) { pPrev->next = pRest; };
> free(pCurr);
>   }
>  else
>  {
>pCurr->next = pRest;
>  }
>return pCurr;
> }
>
>
> Best Regards
> Ashish Goel
> "Think positive and find fuel in failure"
> +919985813081
> +919966006652
>
> --
> You received this message because you are subscribed to the Google
> Groups "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

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

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



-- 
Cheers,

Nishant Pandey |Specialist Tools Development  |
npan...@google.com |
+91-9911258345

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



Re: [algogeeks] MS Question: Delete a node in single linked list if it is less than any of the successor nodes

2012-05-31 Thread Navin Kumar
I think the easiest method to do this problem is this:

http://k2code.blogspot.in/2011/09/deleting-node-in-singly-linked-list-if.html

On Thu, May 31, 2012 at 5:58 PM, Ashish Goel  wrote:

> that is what i have done by using recursion<=>stack.
>
> my code has problem, after  free(pCurr);, i should have return pRest;
>
> Best Regards
> Ashish Goel
> "Think positive and find fuel in failure"
> +919985813081
> +919966006652
>
>
> On Thu, May 31, 2012 at 4:37 PM, atul anand wrote:
>
>> then i guess ...it can be done using stack..with O(n) complexity..
>> it is similar to finding next greater element 
>>
>> http://www.geeksforgeeks.org/archives/8405
>>
>> element in the stack at the end of the algo...are the element which will
>> remain in the linked list . if stack is not empty then keep poping elements
>> and create a SLL.
>>
>>
>> On Thu, May 31, 2012 at 4:29 PM, Ashish Goel  wrote:
>>
>>> yes
>>>
>>> Best Regards
>>> Ashish Goel
>>> "Think positive and find fuel in failure"
>>> +919985813081
>>> +919966006652
>>>
>>>
>>> On Thu, May 31, 2012 at 2:34 PM, atul anand wrote:
>>>
 @Ashish :  please clarify this ques...

 delete a node in SLL if it is less than *any* of the succesor node ..

 1 2 8 10 3 4 7 12

 delete 1,2,8,10,3,4,7

 ouput will be single node i.e 12

 dats what question asks?

 On Thu, May 31, 2012 at 2:16 PM, Ashish Goel  wrote:

> the LL is unsorted, is there any better solution that this?
>
> struct node* deleteNodes(struct node *pHead, struct node *pPrev)
> {
>   struct  node *pLL = *pHead;
>   if (!pLL) return NULL;
>   struct node *pCurr = pLL;
>
>   struct node *pRest = deleteNodes(pCurr->next, pCurr);
>   if (!pRest) return pCurr;
>   if (pCurr->data data)
>   {
> if (pPrev) { pPrev->next = pRest; };
> free(pCurr);
>   }
>  else
>  {
>pCurr->next = pRest;
>  }
>return pCurr;
> }
>
>
> Best Regards
> Ashish Goel
> "Think positive and find fuel in failure"
> +919985813081
> +919966006652
>
> --
> You received this message because you are subscribed to the Google
> Groups "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

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

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

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



Re: [algogeeks] MS Question: Delete a node in single linked list if it is less than any of the successor nodes

2012-05-31 Thread Ashish Goel
that is what i have done by using recursion<=>stack.

my code has problem, after  free(pCurr);, i should have return pRest;
Best Regards
Ashish Goel
"Think positive and find fuel in failure"
+919985813081
+919966006652


On Thu, May 31, 2012 at 4:37 PM, atul anand  wrote:

> then i guess ...it can be done using stack..with O(n) complexity..
> it is similar to finding next greater element 
>
> http://www.geeksforgeeks.org/archives/8405
>
> element in the stack at the end of the algo...are the element which will
> remain in the linked list . if stack is not empty then keep poping elements
> and create a SLL.
>
>
> On Thu, May 31, 2012 at 4:29 PM, Ashish Goel  wrote:
>
>> yes
>>
>> Best Regards
>> Ashish Goel
>> "Think positive and find fuel in failure"
>> +919985813081
>> +919966006652
>>
>>
>> On Thu, May 31, 2012 at 2:34 PM, atul anand wrote:
>>
>>> @Ashish :  please clarify this ques...
>>>
>>> delete a node in SLL if it is less than *any* of the succesor node ..
>>>
>>> 1 2 8 10 3 4 7 12
>>>
>>> delete 1,2,8,10,3,4,7
>>>
>>> ouput will be single node i.e 12
>>>
>>> dats what question asks?
>>>
>>> On Thu, May 31, 2012 at 2:16 PM, Ashish Goel  wrote:
>>>
 the LL is unsorted, is there any better solution that this?

 struct node* deleteNodes(struct node *pHead, struct node *pPrev)
 {
   struct  node *pLL = *pHead;
   if (!pLL) return NULL;
   struct node *pCurr = pLL;

   struct node *pRest = deleteNodes(pCurr->next, pCurr);
   if (!pRest) return pCurr;
   if (pCurr->data data)
   {
 if (pPrev) { pPrev->next = pRest; };
 free(pCurr);
   }
  else
  {
pCurr->next = pRest;
  }
return pCurr;
 }


 Best Regards
 Ashish Goel
 "Think positive and find fuel in failure"
 +919985813081
 +919966006652

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

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

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



Re: [algogeeks] MS Question: Delete a node in single linked list if it is less than any of the successor nodes

2012-05-31 Thread atul anand
then i guess ...it can be done using stack..with O(n) complexity..
it is similar to finding next greater element 

http://www.geeksforgeeks.org/archives/8405

element in the stack at the end of the algo...are the element which will
remain in the linked list . if stack is not empty then keep poping elements
and create a SLL.

On Thu, May 31, 2012 at 4:29 PM, Ashish Goel  wrote:

> yes
>
> Best Regards
> Ashish Goel
> "Think positive and find fuel in failure"
> +919985813081
> +919966006652
>
>
> On Thu, May 31, 2012 at 2:34 PM, atul anand wrote:
>
>> @Ashish :  please clarify this ques...
>>
>> delete a node in SLL if it is less than *any* of the succesor node ..
>>
>> 1 2 8 10 3 4 7 12
>>
>> delete 1,2,8,10,3,4,7
>>
>> ouput will be single node i.e 12
>>
>> dats what question asks?
>>
>> On Thu, May 31, 2012 at 2:16 PM, Ashish Goel  wrote:
>>
>>> the LL is unsorted, is there any better solution that this?
>>>
>>> struct node* deleteNodes(struct node *pHead, struct node *pPrev)
>>> {
>>>   struct  node *pLL = *pHead;
>>>   if (!pLL) return NULL;
>>>   struct node *pCurr = pLL;
>>>
>>>   struct node *pRest = deleteNodes(pCurr->next, pCurr);
>>>   if (!pRest) return pCurr;
>>>   if (pCurr->data data)
>>>   {
>>> if (pPrev) { pPrev->next = pRest; };
>>> free(pCurr);
>>>   }
>>>  else
>>>  {
>>>pCurr->next = pRest;
>>>  }
>>>return pCurr;
>>> }
>>>
>>>
>>> Best Regards
>>> Ashish Goel
>>> "Think positive and find fuel in failure"
>>> +919985813081
>>> +919966006652
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Algorithm Geeks" group.
>>> To post to this group, send email to algogeeks@googlegroups.com.
>>> To unsubscribe from this group, send email to
>>> algogeeks+unsubscr...@googlegroups.com.
>>> For more options, visit this group at
>>> http://groups.google.com/group/algogeeks?hl=en.
>>>
>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

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



Re: [algogeeks] MS Question: Delete a node in single linked list if it is less than any of the successor nodes

2012-05-31 Thread Ashish Goel
yes

Best Regards
Ashish Goel
"Think positive and find fuel in failure"
+919985813081
+919966006652


On Thu, May 31, 2012 at 2:34 PM, atul anand  wrote:

> @Ashish :  please clarify this ques...
>
> delete a node in SLL if it is less than *any* of the succesor node ..
>
> 1 2 8 10 3 4 7 12
>
> delete 1,2,8,10,3,4,7
>
> ouput will be single node i.e 12
>
> dats what question asks?
>
> On Thu, May 31, 2012 at 2:16 PM, Ashish Goel  wrote:
>
>> the LL is unsorted, is there any better solution that this?
>>
>> struct node* deleteNodes(struct node *pHead, struct node *pPrev)
>> {
>>   struct  node *pLL = *pHead;
>>   if (!pLL) return NULL;
>>   struct node *pCurr = pLL;
>>
>>   struct node *pRest = deleteNodes(pCurr->next, pCurr);
>>   if (!pRest) return pCurr;
>>   if (pCurr->data data)
>>   {
>> if (pPrev) { pPrev->next = pRest; };
>> free(pCurr);
>>   }
>>  else
>>  {
>>pCurr->next = pRest;
>>  }
>>return pCurr;
>> }
>>
>>
>> Best Regards
>> Ashish Goel
>> "Think positive and find fuel in failure"
>> +919985813081
>> +919966006652
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

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



Re: [algogeeks] MS Question: Delete a node in single linked list if it is less than any of the successor nodes

2012-05-31 Thread atul anand
@Ashish :  please clarify this ques...

delete a node in SLL if it is less than *any* of the succesor node ..

1 2 8 10 3 4 7 12

delete 1,2,8,10,3,4,7

ouput will be single node i.e 12

dats what question asks?

On Thu, May 31, 2012 at 2:16 PM, Ashish Goel  wrote:

> the LL is unsorted, is there any better solution that this?
>
> struct node* deleteNodes(struct node *pHead, struct node *pPrev)
> {
>   struct  node *pLL = *pHead;
>   if (!pLL) return NULL;
>   struct node *pCurr = pLL;
>
>   struct node *pRest = deleteNodes(pCurr->next, pCurr);
>   if (!pRest) return pCurr;
>   if (pCurr->data data)
>   {
> if (pPrev) { pPrev->next = pRest; };
> free(pCurr);
>   }
>  else
>  {
>pCurr->next = pRest;
>  }
>return pCurr;
> }
>
>
> Best Regards
> Ashish Goel
> "Think positive and find fuel in failure"
> +919985813081
> +919966006652
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

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



[algogeeks] MS Question: Delete a node in single linked list if it is less than any of the successor nodes

2012-05-31 Thread Ashish Goel
the LL is unsorted, is there any better solution that this?

struct node* deleteNodes(struct node *pHead, struct node *pPrev)
{
  struct  node *pLL = *pHead;
  if (!pLL) return NULL;
  struct node *pCurr = pLL;

  struct node *pRest = deleteNodes(pCurr->next, pCurr);
  if (!pRest) return pCurr;
  if (pCurr->data data)
  {
if (pPrev) { pPrev->next = pRest; };
free(pCurr);
  }
 else
 {
   pCurr->next = pRest;
 }
   return pCurr;
}


Best Regards
Ashish Goel
"Think positive and find fuel in failure"
+919985813081
+919966006652

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



[algogeeks] MS question : string compression

2012-05-25 Thread utsav sharma
Implement a method to perform basic string compression using the counts of
repeated characters.(inplace)

eg:- input: "aaabcdef"
 output:"3a5b1c1d1e1f".

what should be my approach to this problem

if i calculate the size of array required to store the output string
and start from the last of the array then i wldn't get the right answer of
above input case.

and if start from front then i wldn't get the right answer of this input
case
eg:- input: "abcdef"
 output: "1a1b1c1d1e1f"

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



Re: [algogeeks] MS Question

2012-04-01 Thread bharat b
First we divide the large memory into some chunks and we hash them. For
each chunk, we need hash function.
If a thread accesses a memory location, we find which chunk of address it
is accessing, then we hash based on memory location. We can easily identify
what are all threads are accessing a memory location at a time...

On Sat, Mar 31, 2012 at 12:09 PM, Dheeraj Sharma <
dheerajsharma1...@gmail.com> wrote:

> MS IDC interview question:
>
> Given a memory location say from 0 - 1023. Now there are many threads that
> are reading and writing in this memory locations at any time 0t 1t 2t ...
> and so on.
>
> For ex a thread no.4 is writing to memory location 512 at time 3t.
> So we get a quadruple {4,512,W,3t}.
>
> Suppose we have lot of quadruples for lots of threads.At any particular
> time we have to tell which of the threads are doing memory clash.
>
> Memory clash is defined as two thread accessing same memory location with
> time difference less than equal to 5 and atleast one of the thread is doing
> write operation.
>
> That interviewer didnt needed the code bt the approach.I first told him to
> hash the threads based on memory location and search for memory clash
> threads for that memory location,bt he was not understanding how it can be
> implemented for large no. of threads.
> --
> *Dheeraj Sharma*
>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from 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
*
* 

Bharat B | M.Tech II  | C.S.E | IITM
*
*
*Ph: +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.



[algogeeks] MS Question

2012-03-30 Thread Dheeraj Sharma
MS IDC interview question:

Given a memory location say from 0 - 1023. Now there are many threads that
are reading and writing in this memory locations at any time 0t 1t 2t ...
and so on.

For ex a thread no.4 is writing to memory location 512 at time 3t.
So we get a quadruple {4,512,W,3t}.

Suppose we have lot of quadruples for lots of threads.At any particular
time we have to tell which of the threads are doing memory clash.

Memory clash is defined as two thread accessing same memory location with
time difference less than equal to 5 and atleast one of the thread is doing
write operation.

That interviewer didnt needed the code bt the approach.I first told him to
hash the threads based on memory location and search for memory clash
threads for that memory location,bt he was not understanding how it can be
implemented for large no. of threads.
-- 
*Dheeraj Sharma*

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



Re: [algogeeks] MS Question -Reverse a Linked List in size of 2

2012-01-23 Thread Dhaval Patel
NODEPTR krev(NODEPTR head,int k)
{
NODEPTR current=head;
NODEPTR prev=NULL;
NODEPTR next;
int cnt=0;
while(current!=NULL&&cntnext;
current->next=prev;
prev=current;
current=next;
cnt++;
}

if(head!=NULL)
head->next=krev(current,k);

return prev;

}

here k=2

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



Re: [algogeeks] MS Question -Reverse a Linked List in size of 2

2012-01-23 Thread Dhaval Patel
struct node* revll(struct node* root)
{
return reverse(root,NULL);
}

struct node* reverse(struct node* head,struct node* prev)
{
struct node* temp1;
if(head->next==NULL)
{
head->next=prev;
return head;
}
else
{
temp1=reverse(head->next,head);
head->next=prev;
return temp1;
}
}

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



Re: [algogeeks] MS Question -Reverse a Linked List in size of 2

2012-01-23 Thread Ankur Garg
Well for odd cases its lile this

1 ->2->3->4->5

4->5->2->3->1

Also u have to do this in single pass..U can use recursion though


On Tue, Jan 24, 2012 at 12:18 AM, Arun Vishwanathan
wrote:

> node *ptr =head;
>
> //function call is reverse(head,NULL)
>
> void reverse(node *ptr, node *follow)
> {
>if(ptr->next!=NULL && ptr->next->next!=NULL)
>reverse(ptr->next->next,ptr);
>   else
>   if(ptr->next!=NULL && ptr->next->next==NULL)
> {
>   ptr->next->next=follow;
>   head=ptr;
> }
>   ptr->next->next=follow;
>   if(follow!=NULL)
>   follow->next->next=NULL;
> }
>
> @ankur: if odd number of nodes then maybe just ask interviewer how he
> wants it to be and try including that case ;)
>
>
> }
>
> On Mon, Jan 23, 2012 at 10:32 AM, Ankur Garg  wrote:
>
>> wat if u have odd no of nodes
>>
>>
>>
>> On Tue, Jan 24, 2012 at 12:00 AM, atul anand wrote:
>>
>>> one simple way would be using stacks.
>>> push node,node->next;
>>> then pop() , and reversing the pointers.
>>>
>>> On Mon, Jan 23, 2012 at 11:46 PM, Ankur Garg wrote:
>>>
 Say LL is

 1->2->3->4->5->6->7->8

 Then u need to return

 7->8->5->6->3->4->1->2

 U cant swap the values U have to rearrange the ptr...


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

>>>
>>>  --
>>> You received this message because you are subscribed to the Google
>>> Groups "Algorithm Geeks" group.
>>> To post to this group, send email to algogeeks@googlegroups.com.
>>> To unsubscribe from this group, send email to
>>> algogeeks+unsubscr...@googlegroups.com.
>>> For more options, visit this group at
>>> http://groups.google.com/group/algogeeks?hl=en.
>>>
>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>
>
> --
>  "People often say that motivation doesn't last. Well, neither does
> bathing - that's why we recommend it daily."
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

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



Re: [algogeeks] MS Question -Reverse a Linked List in size of 2

2012-01-23 Thread Arun Vishwanathan
node *ptr =head;

//function call is reverse(head,NULL)

void reverse(node *ptr, node *follow)
{
   if(ptr->next!=NULL && ptr->next->next!=NULL)
   reverse(ptr->next->next,ptr);
  else
  if(ptr->next!=NULL && ptr->next->next==NULL)
{
  ptr->next->next=follow;
  head=ptr;
}
  ptr->next->next=follow;
  if(follow!=NULL)
  follow->next->next=NULL;
}

@ankur: if odd number of nodes then maybe just ask interviewer how he wants
it to be and try including that case ;)


}

On Mon, Jan 23, 2012 at 10:32 AM, Ankur Garg  wrote:

> wat if u have odd no of nodes
>
>
>
> On Tue, Jan 24, 2012 at 12:00 AM, atul anand wrote:
>
>> one simple way would be using stacks.
>> push node,node->next;
>> then pop() , and reversing the pointers.
>>
>> On Mon, Jan 23, 2012 at 11:46 PM, Ankur Garg wrote:
>>
>>> Say LL is
>>>
>>> 1->2->3->4->5->6->7->8
>>>
>>> Then u need to return
>>>
>>> 7->8->5->6->3->4->1->2
>>>
>>> U cant swap the values U have to rearrange the ptr...
>>>
>>>
>>>  --
>>> You received this message because you are subscribed to the Google
>>> Groups "Algorithm Geeks" group.
>>> To post to this group, send email to algogeeks@googlegroups.com.
>>> To unsubscribe from this group, send email to
>>> algogeeks+unsubscr...@googlegroups.com.
>>> For more options, visit this group at
>>> http://groups.google.com/group/algogeeks?hl=en.
>>>
>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>



-- 
 "People often say that motivation doesn't last. Well, neither does bathing
- that's why we recommend it daily."

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



Re: [algogeeks] MS Question -Reverse a Linked List in size of 2

2012-01-23 Thread Ankur Garg
wat if u have odd no of nodes



On Tue, Jan 24, 2012 at 12:00 AM, atul anand wrote:

> one simple way would be using stacks.
> push node,node->next;
> then pop() , and reversing the pointers.
>
> On Mon, Jan 23, 2012 at 11:46 PM, Ankur Garg  wrote:
>
>> Say LL is
>>
>> 1->2->3->4->5->6->7->8
>>
>> Then u need to return
>>
>> 7->8->5->6->3->4->1->2
>>
>> U cant swap the values U have to rearrange the ptr...
>>
>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

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



Re: [algogeeks] MS Question -Reverse a Linked List in size of 2

2012-01-23 Thread atul anand
one simple way would be using stacks.
push node,node->next;
then pop() , and reversing the pointers.

On Mon, Jan 23, 2012 at 11:46 PM, Ankur Garg  wrote:

> Say LL is
>
> 1->2->3->4->5->6->7->8
>
> Then u need to return
>
> 7->8->5->6->3->4->1->2
>
> U cant swap the values U have to rearrange the ptr...
>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

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



[algogeeks] MS Question -Reverse a Linked List in size of 2

2012-01-23 Thread Ankur Garg
Say LL is

1->2->3->4->5->6->7->8

Then u need to return

7->8->5->6->3->4->1->2

U cant swap the values U have to rearrange the ptr...

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



Re: [algogeeks] MS question

2012-01-19 Thread bharat b
Assumption here is that we can use 4K memory other than considering
the actual elements storage memory.
we were given the range of elements.. we can use count sort.
for first case, all elements are unique --> we can use 27000 bits to
represent the corresponding numbers==> takes 3375 Bytes < 4KB.
for second case,I couldn't find any better than O(nlogn) algo ...

On 1/19/12, Arun Vishwanathan  wrote:
> Given large number of elements. All elements belong to range 1 to 27000.
> First case no elements repeated and second case elements are repeated.
> memory capacity is 4k. How to sort efficiently?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from 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
*
* 

Bharat B | M.Tech II  | Computer Science & Engineering | IITM
*
*
*Ph: +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.



[algogeeks] MS question

2012-01-18 Thread Arun Vishwanathan
Given large number of elements. All elements belong to range 1 to 27000.
First case no elements repeated and second case elements are repeated.
memory capacity is 4k. How to sort efficiently?

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



Re: [algogeeks] MS Question

2012-01-14 Thread Ankur Garg
@Himanshu

Nice idea..that shud do..but how do we code that ?

regards
Ankur

On Sat, Jan 14, 2012 at 2:23 PM, payal gupta  wrote:

> @himanshu thnx..:)
>
> Regards,
> PAYAL GUPTA,
> 3rd YR ,CSE,
> NIT-BHOPAL.
>
>
> On Fri, Jan 13, 2012 at 9:42 PM, Himanshu Neema <
> potential.himansh...@gmail.com> wrote:
>
>> Let a color below represent a single character in UTF-8 encoding ,
>> which means that each color can span multiple bytes , In example below I
>> denote one byte by one english character . i.e.
>> 'a' or 'b' or 'c'  ,etc.  below takes one byte :
>>
>> Let the string is :
>> x abc def gh ij klmn
>> now to reverse this UTF-8 encoded string in place in two steps :
>> 1) reverse bytes of a multibyte character in place ,
>> after this step the string will look like :
>> x cba fed hg ji nmlk
>> 2) Now apply a normal string reversal algo , i.e , to swap first byte
>> with last byte , swap second byte to second last byte .. and so on ...
>> after this step the string will look like :
>> klmn ij gh def abc x
>>
>> And look we have reversed an UTF-8 encoded string in place :)
>>
>>
>>
>>
>> On Fri, Jan 13, 2012 at 11:13 AM, Supraja Jayakumar <
>> suprajasank...@gmail.com> wrote:
>>
>>> Hi
>>>
>>> Normal string will not work I think. Because it is avriable length
>>> encoding scheme.
>>>
>>> On Fri, Jan 13, 2012 at 11:11 AM, b.kisha...@gmail.com <
>>> b.kisha...@gmail.com> wrote:
>>>
 Is there anything called in-place reversal ??
 UTF-8 is only encoding similar to ASCII but with a huge charecter set.
 So normal string reversal would work fine..



 On Thu, Jan 12, 2012 at 2:02 AM, Ankur Garg wrote:

> How to do this
>
> Write a function to reverse a UTF-8 encoded string in-place ??
>
>
>
>  --
> You received this message because you are subscribed to the Google
> Groups "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from 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.

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

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



Re: [algogeeks] MS Question

2012-01-14 Thread payal gupta
@himanshu thnx..:)

Regards,
PAYAL GUPTA,
3rd YR ,CSE,
NIT-BHOPAL.

On Fri, Jan 13, 2012 at 9:42 PM, Himanshu Neema <
potential.himansh...@gmail.com> wrote:

> Let a color below represent a single character in UTF-8 encoding ,
> which means that each color can span multiple bytes , In example below I
> denote one byte by one english character . i.e.
> 'a' or 'b' or 'c'  ,etc.  below takes one byte :
>
> Let the string is :
> x abc def gh ij klmn
> now to reverse this UTF-8 encoded string in place in two steps :
> 1) reverse bytes of a multibyte character in place ,
> after this step the string will look like :
> x cba fed hg ji nmlk
> 2) Now apply a normal string reversal algo , i.e , to swap first byte with
> last byte , swap second byte to second last byte .. and so on ...
> after this step the string will look like :
> klmn ij gh def abc x
>
> And look we have reversed an UTF-8 encoded string in place :)
>
>
>
>
> On Fri, Jan 13, 2012 at 11:13 AM, Supraja Jayakumar <
> suprajasank...@gmail.com> wrote:
>
>> Hi
>>
>> Normal string will not work I think. Because it is avriable length
>> encoding scheme.
>>
>> On Fri, Jan 13, 2012 at 11:11 AM, b.kisha...@gmail.com <
>> b.kisha...@gmail.com> wrote:
>>
>>> Is there anything called in-place reversal ??
>>> UTF-8 is only encoding similar to ASCII but with a huge charecter set.
>>> So normal string reversal would work fine..
>>>
>>>
>>>
>>> On Thu, Jan 12, 2012 at 2:02 AM, Ankur Garg wrote:
>>>
 How to do this

 Write a function to reverse a UTF-8 encoded string in-place ??



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

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



Re: [algogeeks] MS Question

2012-01-13 Thread Himanshu Neema
Let a color below represent a single character in UTF-8 encoding ,
which means that each color can span multiple bytes , In example below I
denote one byte by one english character . i.e.
'a' or 'b' or 'c'  ,etc.  below takes one byte :

Let the string is :
x abc def gh ij klmn
now to reverse this UTF-8 encoded string in place in two steps :
1) reverse bytes of a multibyte character in place ,
after this step the string will look like :
x cba fed hg ji nmlk
2) Now apply a normal string reversal algo , i.e , to swap first byte with
last byte , swap second byte to second last byte .. and so on ...
after this step the string will look like :
klmn ij gh def abc x

And look we have reversed an UTF-8 encoded string in place :)




On Fri, Jan 13, 2012 at 11:13 AM, Supraja Jayakumar <
suprajasank...@gmail.com> wrote:

> Hi
>
> Normal string will not work I think. Because it is avriable length
> encoding scheme.
>
> On Fri, Jan 13, 2012 at 11:11 AM, b.kisha...@gmail.com <
> b.kisha...@gmail.com> wrote:
>
>> Is there anything called in-place reversal ??
>> UTF-8 is only encoding similar to ASCII but with a huge charecter set.
>> So normal string reversal would work fine..
>>
>>
>>
>> On Thu, Jan 12, 2012 at 2:02 AM, Ankur Garg  wrote:
>>
>>> How to do this
>>>
>>> Write a function to reverse a UTF-8 encoded string in-place ??
>>>
>>>
>>>
>>>  --
>>> You received this message because you are subscribed to the Google
>>> Groups "Algorithm Geeks" group.
>>> To post to this group, send email to algogeeks@googlegroups.com.
>>> To unsubscribe from 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.
>>
>
>
>
> --
> U
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

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



Re: [algogeeks] MS Question

2012-01-12 Thread Supraja Jayakumar
Hi

Normal string will not work I think. Because it is avriable length encoding
scheme.

On Fri, Jan 13, 2012 at 11:11 AM, b.kisha...@gmail.com  wrote:

> Is there anything called in-place reversal ??
> UTF-8 is only encoding similar to ASCII but with a huge charecter set.
> So normal string reversal would work fine..
>
>
>
> On Thu, Jan 12, 2012 at 2:02 AM, Ankur Garg  wrote:
>
>> How to do this
>>
>> Write a function to reverse a UTF-8 encoded string in-place ??
>>
>>
>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from 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.
>



-- 
U

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



Re: [algogeeks] MS Question

2012-01-12 Thread b.kisha...@gmail.com
Is there anything called in-place reversal ??
UTF-8 is only encoding similar to ASCII but with a huge charecter set.
So normal string reversal would work fine..


On Thu, Jan 12, 2012 at 2:02 AM, Ankur Garg  wrote:

> How to do this
>
> Write a function to reverse a UTF-8 encoded string in-place ??
>
>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

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



[algogeeks] MS Question

2012-01-11 Thread Ankur Garg
How to do this

Write a function to reverse a UTF-8 encoded string in-place ??

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



[algogeeks] MS question

2011-10-02 Thread rahul sharma
if element is 0 in matrix then entire row and column should be set to 0

i got this from sumwhr

void makeRowColZero(int (*a)[COL])
{
int i, j, k;
k = 0;
for(i = 0; i < ROW; i++)
for(j = k; j < COL; j++)
{
if(0 == a[i][j])
{
for(k = 0; k < ROW; k++)
a[k][j] = 0;

for(k = 0; k < COL; k++)
a[i][k] = 0;

i++;
j++;
k = j;
continue;
}
}
}



in the end continue???it takes to loop start but if it is not used
even then we can go to start after the loop fiteration is over

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



Re: [algogeeks] MS Question -> Median of a BST without using extra space and in O(n)

2011-09-28 Thread praneethn
convert bst to doubly linked list inorder and find middle element using slow
and fast pointer concept

On Tue, Sep 27, 2011 at 2:18 PM, Ankur Garg  wrote:

> I was thinking of making the tree balanced with equal no of nodes in left
> and right subtree
>
> Median will be root in this case
>
>
> Regards
> Ankur
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

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



Re: [algogeeks] MS Question -> Median of a BST without using extra space and in O(n)

2011-09-27 Thread anshu mishra
int bstMedian(node *root, int n, int &x)
{
if (node->left) return bstMedian(root->left, n, x);
x++;
if (x == n/2) return node->val;
if (node->right) return bstMedian(root->right, n, x);
}
call bstMedian(root, n, 0);

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



Re: [algogeeks] MS Question -> Median of a BST without using extra space and in O(n)

2011-09-27 Thread Dheeraj Sharma
keep a  global pointer and a global variable "check=0"

do inorder traversal..instead of printing the value do

  if(check==0)
 save pointer
check==1
   else
  check==0;

correct me if m wrong

On Tue, Sep 27, 2011 at 2:22 PM, anshu mishra wrote:

> do the inorder traversal as soon as reached at n/2th element that will be
> median.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>



-- 
*Dheeraj Sharma*
Comp Engg.
NIT Kurukshetra

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



  1   2   >