[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 email

[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

[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 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

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 shri.nit...@gmail.com wrote: In a

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 mapint, char mapint, char where

[algogeeks] Re: Suggest a data structure

2011-12-20 Thread shady
?? unclear On Dec 20, 8:34 pm, Sangeeta sangeeta15...@gmail.com 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

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 sinv...@gmail.com wrote: ( ( ) ( ( ) ( ( ) ) ( ) for this SAMM faulty index is 0, because the first bracket has itself found no matching @atul ( (

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 sinv...@gmail.com wrote: ( ( ) ( ( ) ( ( ) ) ( ) for this

[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 aaron.nar...@gmail.com wrote: @shady: I guess first mismatch means the innermost open brace that

[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: Reverse n-Ary Tree and Return List of Leaf Nodes as Output - FYI Google MV

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

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 shashank7andr...@gmail.comwrote: here is my code ListNode list=new LinkeListNode();

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 shashank7andr...@gmail.comwrote: here is my code ListNode list=new LinkeListNode(); public ListNode

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 sunny816.i...@gmail.com 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

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 ankurga...@gmail.com wrote: Hey Shashank Unfortunately I cudnt

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 sharad.emine...@gmail.comwrote: @Anshul AGARWAL Input : 4 2 1 3 4 Expected Output : Yes Your's Code Output : No On 12/20/11, sunny agrawal

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 atul.87fri...@gmail.comwrote: @ankur : for the given tree

[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 verma@gmail.com wrote: I am getting a lot of tle's for this problem. https://www.spoj.pl/problems/BUGLIFE/ Here is my code #includeiostream #includecstdio #includecstring

[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 atul.87fri...@gmail.com wrote: @ankur : for the given tree above instead of parent pointing to

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 rahul...@gmail.com 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

[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 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

[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; ListNode children; } you can try in any language C/C++/java etc. Thanks

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