Re: [algogeeks] Re: Return index of first mismatch bracket "(" or ")"

2011-12-21 Thread atul anand
i guess there is no need of stack , we can take a variable say top;

increment top when open bracket occur "(" and decrement when close bracket
")" occurs.

keep track of first close bracket mismatch i.e when top is zero and current
bracket is ")".

if top!=0
   report min(index,top);

On Tue, Dec 20, 2011 at 11:06 PM, shady  wrote:

> true, we have to look at the entire string to find the first mismatch,
> and its meaning depends on how you interpret it... either way stack
> will solve it :)
>
> On Dec 20, 10:32 pm, Arun Vishwanathan  wrote:
> > @shady: I guess first mismatch means the innermost open brace that doesnt
> > have a close brace. U cannot know that the first brace does not have a
> > closing one unless u look at the entire string.
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > On Tue, Dec 20, 2011 at 9:23 AM, shady  wrote:
> > > ( ( ) ( ( ) ( ( ) ) (  )  for this SAMM faulty index is 0, because the
> > > first bracket has itself found no matching
> >
> > > @atul
> > > ( ( ( () ) ) for this first bracket is faulty as it couldn't find a
> > > closing bracket, , ,
> > > you can keep a stack with map as element
> > > stack< map >
> >
> > > map where integer is the index of the bracket, which is
> stored
> > > as char
> > > idea is similar to don's.
> >
> > > On Tue, Dec 20, 2011 at 10:42 PM, atul anand  >wrote:
> >
> > >> there are multiple mismatch or only one mis-match in the input string.
> >
> > >> if the given string as below :-
> >
> > >> ( ( ( () ) ) -> for this is missing match is for 1st , 2nd or 3rd
> > >> bracket.
> >
> > >> what would be the answer for this.
> >
> > >> On Tue, Dec 20, 2011 at 8:10 PM, zeroByZero  >wrote:
> >
> > >>> In a given string arrary arr[] = "((()())" or any other string return
> > >>> index for which no match is found as for this example is index 0 and
> > >>> for "()()()(()" is index 6
> >
> > >>> --
> > >>> You received this message because you are subscribed to the Google
> > >>> Groups "Algorithm Geeks" group.
> > >>> To post to this group, send email to algogeeks@googlegroups.com.
> > >>> To unsubscribe from 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] Re: Reverse n-Ary Tree and Return List of Leaf Nodes as Output - FYI Google MV

2011-12-21 Thread atul anand
adding break to first loop...just to avoid unnecessary iterations.
if (root->children[i]!=NULL)
   {
 flag=1;
 break;

   }
end for


On Wed, Dec 21, 2011 at 10:59 PM, atul anand wrote:

> @shashank:
>
> yeah here is the algo , please me know if you find any bug:-
>
>
> node *Reverse(node *root,node *pre)
> {
>  flag=0;
>
> for i=0 to n
>if (root->children[i]!=NULL)
>{
>  flag=1;
>}
> end for
>
> if( ! flag)
> {
>   add root to the list;
>   return root;
> }
>
> for(i=0;i {
>
>  pre=reverse(root->children[i],NULL);
>
>  if(pre)
>  {
>   pre->children[i]=root;
>  }
>  }
>
> return root;
>
> }
>
>
>
>
> On Wed, Dec 21, 2011 at 1:08 PM, WgpShashank 
> wrote:
>
>> @atul,, yeah , but can you write some proper psuedo code/ Algorithm then
>> we can discus more about test cases.
>>
>> Thanks
>> Shashank
>>
>> --
>> 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/-/VPZpHM8D_WcJ.
>>
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from 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] Re: Reverse n-Ary Tree and Return List of Leaf Nodes as Output - FYI Google MV

2011-12-21 Thread atul anand
adding one more check :- this one is updated

node *Reverse(node *root,node *pre)
{
 flag=0;

for i=0 to n
   if (root->children[i]!=NULL)
   {
 flag=1;
 break;
   }
end for

if( ! flag)
{
  add root to the list;
  return root;
}

for(i=0;ichildren[i]!=NULL)
 {
pre=reverse(root->children[i],NULL);

  if(pre)
  {
  pre->children[i]=root;
  }
  }
}

return root;

}


On Thu, Dec 22, 2011 at 9:35 AM, atul anand  wrote:

> adding break to first loop...just to avoid unnecessary iterations.
> if (root->children[i]!=NULL)
>{
>  flag=1;
>  break;
>
>}
> end for
>
>
> On Wed, Dec 21, 2011 at 10:59 PM, atul anand wrote:
>
>> @shashank:
>>
>> yeah here is the algo , please me know if you find any bug:-
>>
>>
>> node *Reverse(node *root,node *pre)
>> {
>>  flag=0;
>>
>> for i=0 to n
>>if (root->children[i]!=NULL)
>>{
>>  flag=1;
>>}
>> end for
>>
>> if( ! flag)
>> {
>>   add root to the list;
>>   return root;
>> }
>>
>> for(i=0;i> {
>>
>>  pre=reverse(root->children[i],NULL);
>>
>>  if(pre)
>>  {
>>   pre->children[i]=root;
>>  }
>>  }
>>
>> return root;
>>
>> }
>>
>>
>>
>>
>> On Wed, Dec 21, 2011 at 1:08 PM, WgpShashank 
>> wrote:
>>
>>> @atul,, yeah , but can you write some proper psuedo code/ Algorithm then
>>> we can discus more about test cases.
>>>
>>> Thanks
>>> Shashank
>>>
>>> --
>>> 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/-/VPZpHM8D_WcJ.
>>>
>>> To post to this group, send email to algogeeks@googlegroups.com.
>>> To unsubscribe from 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] Facebook Question

2011-12-21 Thread UTKARSH SRIVASTAV
use k-d tree

On Thu, Dec 22, 2011 at 9:25 AM, atul anand  wrote:

> to find all points which lies on the same quadrant for a specific node(say
> 1) , we have to check all nodes...rite??
> we have to find difference b/w 2 node(frome origin ) is less or greater
> than distance b/w 2 nodes...rite??
>
> so if i am not getting it wrong it wil be O(n^2) anyhow.
>
>
> On Thu, Dec 22, 2011 at 8:14 AM, rahul  wrote:
>
>> @harish What if all the points are in the same quadrant and and are
>> equidistant from 0,0.
>>
>> --
>> 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/-/NjysUthIqgYJ.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from 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.
>



-- 
*UTKARSH SRIVASTAV
CSE-3
B-Tech 3rd Year
@MNNIT ALLAHABAD*

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



Re: [algogeeks] Facebook Question

2011-12-21 Thread atul anand
to find all points which lies on the same quadrant for a specific node(say
1) , we have to check all nodes...rite??
we have to find difference b/w 2 node(frome origin ) is less or greater
than distance b/w 2 nodes...rite??

so if i am not getting it wrong it wil be O(n^2) anyhow.

On Thu, Dec 22, 2011 at 8:14 AM, rahul  wrote:

> @harish What if all the points are in the same quadrant and and are
> equidistant from 0,0.
>
> --
> 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/-/NjysUthIqgYJ.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from 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] Any book suggestion for Data structure and algo.

2011-12-21 Thread DIPANKAR DUTTA
or google This : cs170

On 12/17/11, Abhishek Goswami  wrote:
> ya Sure Thx bro
>
> On Sat, Dec 17, 2011 at 3:15 PM, Rahul  wrote:
>
>> If you have time then Do a Google this
>> www.algo-class.org
>>
>>
>> On Sat, Dec 17, 2011 at 3:13 PM, Abhishek Goswami
>> wrote:
>>
>>> Cool Rahul
>>>
>>>
>>> On Sat, Dec 17, 2011 at 3:09 PM, Rahul  wrote:
>>>
 Google this
 6.046

 You should not ask any more suggestion  till you complete the above

 On Sat, Dec 17, 2011 at 3:07 PM, Abhishek Goswami <
 zeal.gosw...@gmail.com> wrote:

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


-- 
Thanks and Regards,
---
*DIPANKAR DUTTA*
Software Development Engineer
Xen Server - OpenStack Development Team (DataCenter and Cloud)

Citrix R&D India Pvt Ltd
#23 Residency Road, Bangalore - 560 025
Phone: +91 8147830733
Office: Extn: 16429
Email: dipankar.du...@citrix.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] Facebook Question

2011-12-21 Thread Algoose chase
Yup, it could be O(n^2) in the worst case.

On Wed, Dec 21, 2011 at 1:59 PM, Carol Smith wrote:

> @Algoose, in worst case, this is still O(n^2), ain't it?
>
> On Wed, Dec 21, 2011 at 12:50 PM, Algoose chase wrote:
>
>> Find the distance between each of the points and the origin(0,0) and sort
>> the points based on this distance.
>> Also, divide the points based on which quadrant they belong.  If the
>> difference between their distance(from origin) between 2 points is less and
>> they belong to the same quadrant, then they are likely to be close. So,
>> instead of comparing each point with every other point as in the O(N^2)
>> solution. We can compare a given point only with a subset of points that
>> appear to be close.
>>
>> On Wed, Dec 21, 2011 at 1:00 AM, SAMMM  wrote:
>>
>>> You are given a list of points in the plane, write a program that
>>> outputs each point along with the three other points that are closest
>>> to it. These three points ordered by distance.
>>> The order is less then O(n^2) .
>>>
>>> For example, given a set of points where each line is of the form: ID
>>> x-coordinate y-coordinate
>>>
>>>
>>> 1  0.0  0.0
>>> 2  10.1 -10.1
>>> 3  -12.212.2
>>> 4  38.3 38.3
>>> 5 79.99 179.99
>>>
>>>
>>>
>>> Your program should output:
>>>
>>>
>>> 1 2,3,4
>>> 2 1,3,4
>>> 3 1,2,4
>>> 4 1,2,3
>>> 5 4,3,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.



Re: [algogeeks] Facebook Question

2011-12-21 Thread rahul
@harish What if all the points are in the same quadrant and and are equidistant 
from 0,0. 

-- 
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/-/NjysUthIqgYJ.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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] Facebook Question

2011-12-21 Thread Carol Smith
@Algoose, in worst case, this is still O(n^2), ain't it?

On Wed, Dec 21, 2011 at 12:50 PM, Algoose chase wrote:

> Find the distance between each of the points and the origin(0,0) and sort
> the points based on this distance.
> Also, divide the points based on which quadrant they belong.  If the
> difference between their distance(from origin) between 2 points is less and
> they belong to the same quadrant, then they are likely to be close. So,
> instead of comparing each point with every other point as in the O(N^2)
> solution. We can compare a given point only with a subset of points that
> appear to be close.
>
> On Wed, Dec 21, 2011 at 1:00 AM, SAMMM  wrote:
>
>> You are given a list of points in the plane, write a program that
>> outputs each point along with the three other points that are closest
>> to it. These three points ordered by distance.
>> The order is less then O(n^2) .
>>
>> For example, given a set of points where each line is of the form: ID
>> x-coordinate y-coordinate
>>
>>
>> 1  0.0  0.0
>> 2  10.1 -10.1
>> 3  -12.212.2
>> 4  38.3 38.3
>> 5 79.99 179.99
>>
>>
>>
>> Your program should output:
>>
>>
>> 1 2,3,4
>> 2 1,3,4
>> 3 1,2,4
>> 4 1,2,3
>> 5 4,3,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.



[algogeeks] Re: Kth element of the Increasing Sequence

2011-12-21 Thread SAMMM
Yes Quadratic approach will be naive . I thought initially to take the
input from the Liveware , and do the below :-

And we will computer for the number of unique number possible for 1
digit , Let the number of possible distinct permutation be X . And if
X >= K , then we can generate the single digit number and display the
kth digits ;

else if ( K > X )  , Calculate the number of possible distinct
permutation for two digit numbers (with n0 2 digit number starting
with Zero) (X) and check for the (Xhttp://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] suggest algo

2011-12-21 Thread atul anand
@Shashank:

well i guess there is one more issue with my algo. if counter is updated
for say number 3.
and heap has already node with value 3 and count 2.

now root could be node with value 5 and count 1.

if i remove root from the heap, then heap will be havingi will be having 2
node with value 3 with count 3 and 2.

On Wed, Dec 21, 2011 at 7:15 PM, WgpShashank wrote:

> @atul approach sounds good but we have to check for each time counts
> updated isn't it  , though even can sort the hash table  & return top k
> number .
> also as i know we have splay tree , even google uses it , to get most
> frequent item .
>
>
> Thanks
> Shashank.
>
>  --
> 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/-/gucYTW56cCsJ.
>
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from 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] Facebook Question

2011-12-21 Thread Algoose chase
Find the distance between each of the points and the origin(0,0) and sort
the points based on this distance.
Also, divide the points based on which quadrant they belong.  If the
difference between their distance(from origin) between 2 points is less and
they belong to the same quadrant, then they are likely to be close. So,
instead of comparing each point with every other point as in the O(N^2)
solution. We can compare a given point only with a subset of points that
appear to be close.

On Wed, Dec 21, 2011 at 1:00 AM, SAMMM  wrote:

> You are given a list of points in the plane, write a program that
> outputs each point along with the three other points that are closest
> to it. These three points ordered by distance.
> The order is less then O(n^2) .
>
> For example, given a set of points where each line is of the form: ID
> x-coordinate y-coordinate
>
>
> 1  0.0  0.0
> 2  10.1 -10.1
> 3  -12.212.2
> 4  38.3 38.3
> 5 79.99 179.99
>
>
>
> Your program should output:
>
>
> 1 2,3,4
> 2 1,3,4
> 3 1,2,4
> 4 1,2,3
> 5 4,3,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] Re: Reverse n-Ary Tree and Return List of Leaf Nodes as Output - FYI Google MV

2011-12-21 Thread atul anand
@shashank:

yeah here is the algo , please me know if you find any bug:-


node *Reverse(node *root,node *pre)
{
 flag=0;

for i=0 to n
   if (root->children[i]!=NULL)
   {
 flag=1;
   }
end for

if( ! flag)
{
  add root to the list;
  return root;
}

for(i=0;ichildren[i],NULL);

 if(pre)
 {
  pre->children[i]=root;
 }
 }

return root;

}




On Wed, Dec 21, 2011 at 1:08 PM, WgpShashank wrote:

> @atul,, yeah , but can you write some proper psuedo code/ Algorithm then
> we can discus more about test cases.
>
> Thanks
> Shashank
>
> --
> 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/-/VPZpHM8D_WcJ.
>
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from 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] Re: Reverse n-Ary Tree and Return List of Leaf Nodes as Output - FYI Google MV

2011-12-21 Thread atul anand
i guess there is one more if i am not wrong;

  if(n==null)
   {
n=n.children[++j];
return null;
   }

here when n==NULLyou are doing n.children[++j].will give
segmentation fault.

On Wed, Dec 21, 2011 at 7:05 PM, WgpShashank wrote:

> @all just a small bug found after discussing with one of the friend , i
> forgot to put the for loop , in 2nd if condition .
>
>
> Thanks
> Shashank
>
> --
> 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/-/1cMtxb4Fy8wJ.
>
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from 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] Re: Reverse n-Ary Tree and Return List of Leaf Nodes as Output - FYI Google MV

2011-12-21 Thread atul anand
@Ankur : didnt understand , how you want to represent n-ary using this
structure.

struct node{
int data;
   node* left;
   node* sibling;
}

if root has 5 children then how will root point to its children using 2
pointers( left ,sibiling)

On Wed, Dec 21, 2011 at 3:13 PM, Ankur Garg  wrote:

> A better representation for a n-ary tree would be
>
> struct node{
> int data;
>node* left;
>node* sibling;
> }
>
> Like in a binary tree the second ptr points to its right child . Here it
> points to its sibling.This one saves space and also We know in each level
> we have how many nodes
> @Shashank,
> I think we can reverse the n-ary tree ,but again my doubt is what will be
> leaf nodes then in that case , It seems it will be original root , so i was
> confused . anyway , I will concentrate on reversing the tree only for now
> based on ur definition.
>
> Regards
> Ankur
>
>
> On Wed, Dec 21, 2011 at 1:08 PM, WgpShashank 
> wrote:
>
>> @atul,, yeah , but can you write some proper psuedo code/ Algorithm then
>> we can discus more about test cases.
>>
>> Thanks
>> Shashank
>>
>> --
>> 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/-/VPZpHM8D_WcJ.
>>
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from 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.



[algogeeks] Re: Reverse n-Ary Tree and Return List of Leaf Nodes as Output - FYI Google MV

2011-12-21 Thread rahul
How abt representing the tree as a graph. If you represent it in
adjacency mattix or as a map of edges e.g. Edge{from}{to}=edge weight,
which could be a constant in this case. all you need to is to reverse
the pairs.

Order of complexity is o(e) and you can reach to leaf nodes and push
them in a list

On Dec 21, 1:43 am, Ankur Garg  wrote:
> A better representation for a n-ary tree would be
>
> struct node{
>     int data;
>    node* left;
>    node* sibling;
>
> }
>
> Like in a binary tree the second ptr points to its right child . Here it
> points to its sibling.This one saves space and also We know in each level
> we have how many nodes
> @Shashank,
> I think we can reverse the n-ary tree ,but again my doubt is what will be
> leaf nodes then in that case , It seems it will be original root , so i was
> confused . anyway , I will concentrate on reversing the tree only for now
> based on ur definition.
>
> Regards
> Ankur
>
> On Wed, Dec 21, 2011 at 1:08 PM, WgpShashank 
> wrote:
>
>
>
>
>
>
>
> > @atul,, yeah , but can you write some proper psuedo code/ Algorithm then
> > we can discus more about test cases.
>
> > Thanks
> > Shashank
>
> > --
> > 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/-/VPZpHM8D_WcJ.
>
> > To post to this group, send email to algogeeks@googlegroups.com.
> > To unsubscribe from 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] Re: Reverse n-Ary Tree and Return List of Leaf Nodes as Output - FYI Google MV

2011-12-21 Thread Ankur Garg
A better representation for a n-ary tree would be

struct node{
int data;
   node* left;
   node* sibling;
}

Like in a binary tree the second ptr points to its right child . Here it
points to its sibling.This one saves space and also We know in each level
we have how many nodes
@Shashank,
I think we can reverse the n-ary tree ,but again my doubt is what will be
leaf nodes then in that case , It seems it will be original root , so i was
confused . anyway , I will concentrate on reversing the tree only for now
based on ur definition.

Regards
Ankur

On Wed, Dec 21, 2011 at 1:08 PM, WgpShashank wrote:

> @atul,, yeah , but can you write some proper psuedo code/ Algorithm then
> we can discus more about test cases.
>
> Thanks
> Shashank
>
> --
> 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/-/VPZpHM8D_WcJ.
>
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from 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] suggest algo

2011-12-21 Thread WgpShashank
@atul approach sounds good but we have to check for each time counts 
updated isn't it  , though even can sort the hash table  & return top k 
number .
also as i know we have splay tree , even google uses it , to get most 
frequent item . 


Thanks
Shashank.

-- 
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/-/gucYTW56cCsJ.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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] Re: Kth element of the Increasing Sequence

2011-12-21 Thread WgpShashank
@Samm, Don't you think quadratic approach will be naive ? we can use 
comparator while checking .thining how we can do it more better ?


Thanks
Shashank 

-- 
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/-/DwBnc3Y9FF4J.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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] Re: Reverse n-Ary Tree and Return List of Leaf Nodes as Output - FYI Google MV

2011-12-21 Thread WgpShashank
@all just a small bug found after discussing with one of the friend , i 
forgot to put the for loop , in 2nd if condition .

Thanks
Shashank

-- 
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/-/1cMtxb4Fy8wJ.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.