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

2011-12-20 Thread WgpShashank
@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.c

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

2011-12-20 Thread WgpShashank
@all Reversing the N-ary tree means reversing the pointer nodes pointing to , as i shown above , children back points to their parents .. here is is structure of N-Ary Tree we can think of Class Node { String label; List children; } you can try in any language C/C++/java etc. Thanks Shashan

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

2011-12-20 Thread WgpShashank
@Ankur , we need to reverse the pointer for each node so that points to their parents. thats what reversal a n-Ary tree means hope it help . have a look at my code , its just thought i approached using preorder traversal , but not getting correct answer , seems like missing something Thanks

[algogeeks] Facebook Question

2011-12-20 Thread SAMMM
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

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

2011-12-20 Thread atul anand
@rahul : i dont think so , i guess what u are telling will be like creating mirror image of the tree. On Wed, Dec 21, 2011 at 6:23 AM, rahul wrote: > How do you represent the N-ary tree? If you represent child nodes as a > list, reversing this child node list at each node will solve the > proble

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

2011-12-20 Thread rahul
How do you represent the N-ary tree? If you represent child nodes as a list, reversing this child node list at each node will solve the problem right? I may be wrong. On Dec 20, 10:50 am, atul anand wrote: > @ankur : for the given tree above instead of parent pointing to its child , > it would be

[algogeeks] Re: SPOJ TLE

2011-12-20 Thread KK
Try wid BFS.. thats the only alternative i can think off!! I got acc wid that!! On Dec 6, 12:29 pm, "varma C.S.P" wrote: > I am getting a lot of tle's for this problem. > > https://www.spoj.pl/problems/BUGLIFE/ > > Here is my code > > #include > #include > #include > using namespace std; > > int

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

2011-12-20 Thread Ankur Garg
@Atul Even i thought so..but then the definition of leaf node is that its a node which doesnt have any children...then the answer is root of the original tree so I got confused here :( On Wed, Dec 21, 2011 at 12:20 AM, atul anand wrote: > @ankur : for the given tree above instead of parent poi

Re: [algogeeks] spoj problem:Street parade

2011-12-20 Thread Anshul AGARWAL
Thanx Sharad finally got AC *Anshul Agarwal Nit Allahabad Computer Science** * On Tue, Dec 20, 2011 at 3:16 PM, sharad dixit wrote: > @Anshul AGARWAL > > Input : > 4 > 2 1 3 4 > > Expected Output : > Yes > > Your's Code Output : > No > > On 12/20/11, sunny agrawal wrote: > > @ Anshul > > it wil

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

2011-12-20 Thread atul anand
@ankur : for the given tree above instead of parent pointing to its child , it would be child pointing to its parent after reversing i guess thats wat he is trying to say. On Tue, Dec 20, 2011 at 11:38 PM, Ankur Garg wrote: > Hey Shashank > > Unfortunately I cudnt understand the problem > >

Re: [algogeeks] spoj problem:Street parade

2011-12-20 Thread sharad dixit
@Anshul AGARWAL Input : 4 2 1 3 4 Expected Output : Yes Your's Code Output : No On 12/20/11, sunny agrawal wrote: > @ Anshul > it will be nice if you post your logic rather than Code, and also Code > posting without logic and comments is not allowed in the group. i > don't know who approved th

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

2011-12-20 Thread atul anand
just a thought . to reverse the given tree is like finding inorder successor of the nodes. and every time we find a leaf node add it to the linked list. On Tue, Dec 20, 2011 at 11:23 PM, WgpShashank wrote: > here is my code > > > List list=new LinkeList(); > > public List reverseTreeandRetur

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

2011-12-20 Thread Ankur Garg
Hey Shashank Unfortunately I cudnt understand the problem What do u mean by reversing the tree here :(.. On Tue, Dec 20, 2011 at 11:23 PM, WgpShashank wrote: > here is my code > > > List list=new LinkeList(); > > public List reverseTreeandReturnListContainingAllLeafNOdes(Node n) > { >in

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

2011-12-20 Thread WgpShashank
here is my code List list=new LinkeList(); public List reverseTreeandReturnListContainingAllLeafNOdes(Node n) { int i=0; static int j=0; if(n==null) { n=n.children[++j]; return null; } if(n.children[i]==null) {

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

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

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

2011-12-20 Thread shady
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 brac

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

2011-12-20 Thread Arun Vishwanathan
@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

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

2011-12-20 Thread atul anand
in SAMM example at the end stack has 0,3 . this means both are faulty there is no closing for both On Tue, Dec 20, 2011 at 10:53 PM, shady wrote: > ( ( ) ( ( ) ( ( ) ) ( ) for this SAMM faulty index is 0, because the > first bracket has itself found no matching > > @atul > ( ( ( () ) ) for

[algogeeks] Re: Suggest a data structure

2011-12-20 Thread shady
?? unclear On Dec 20, 8:34 pm, Sangeeta wrote: > The attendence of the student is taken on a blank sheet.suggest a data > structure that would storage and retrieval effient.will your choice > vary in the following cases? > > case1:number of students appearing for exams are 10 to 100 and the >

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

2011-12-20 Thread shady
( ( ) ( ( ) ( ( ) ) ( ) 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

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

2011-12-20 Thread atul anand
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 ar

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

2011-12-20 Thread SAMMM
Continued . Forgot to metion to also keep track of the index of the Closing first bracket ( If tht closing doesn't hav matching opening bracket on it's left ) and at last check for the top of the stack(If present) and the index(if present) . And print the minimum index value of the Stack[top]

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

2011-12-20 Thread SAMMM
This can be done using Stack . For example :- you have got the pattern :- 0 1 2 3 4 5 6 7 8 9 10 11 ( ( ) ( ( ) ( ( ) ) ( ) ... this pattern is wrong the faulty index is at index 3 . void MatchingBracket( char *str ) { while ( str[i++] != '\0' ) { if ( str[i] == '(') push(i); // If

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

2011-12-20 Thread Don
Use a stack to store the index for each open paren. When a close paren is encountered, pop one off the stack. If there is nothing in the stack, remember the index of that close paren. When you have processed the entire string, if there is anything left on the stack, the bottom item is the first unm

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

2011-12-20 Thread zeroByZero
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

[algogeeks] Suggest a data structure

2011-12-20 Thread Sangeeta
The attendence of the student is taken on a blank sheet.suggest a data structure that would storage and retrieval effient.will your choice vary in the following cases? case1:number of students appearing for exams are 10 to 100 and the exam is conducted centrally. case2:number of students appearing

Re: [algogeeks] spoj problem:Street parade

2011-12-20 Thread sunny agrawal
@ Anshul it will be nice if you post your logic rather than Code, and also Code posting without logic and comments is not allowed in the group. i don't know who approved this post but take care of this from next time. On Tue, Dec 20, 2011 at 7:41 PM, Anshul AGARWAL wrote: > problem:street parade:

[algogeeks] spoj problem:Street parade

2011-12-20 Thread Anshul AGARWAL
problem:street parade: http://www.spoj.pl/problems/STPAR/ my code give correct answer for all test case that i run but still it give WA. plz provide me more test cases . my code is #include #include #include using namespace std; int main() { int n,a[1010],b[1010],s[1010],t=0,q=1;

Re: [algogeeks] zig zag problem

2011-12-20 Thread UTKARSH SRIVASTAV
hi i gave anser of longets sequence if there are more than one then I only print one On Tue, Dec 20, 2011 at 12:31 PM, atul anand wrote: > @UTKARSH : > > it should be 1 4 3 7 6 > > why are you skipping 3 even when 143 is in zig zag sequence. > > On Tue, Dec 20, 2011 at 11:26 AM, UTKARSH SRIVASTAV