Re: [algogeeks] Amazon Placement Question

2010-08-02 Thread karthik ramanathan
@Ram and Nikhil What kind of traversal you will use to visit each node. How come you will get to know about teh number of nodes at each level that needs to be connected. RK On Sun, Aug 1, 2010 at 2:56 AM, Nikhil Jindal fundoon...@yahoo.co.inwrote: @Ram Kumar: Yes. Simple and affective. Just

Re: [algogeeks] Amazon Placement Question

2010-07-31 Thread Priyanka Chatterjee
@Anand, you are partly correct, thanks for modifying my code On 31 July 2010 00:01, Anand anandut2...@gmail.com wrote: I highlighted the code which I feel need a change. Do let me know if it correct. LinkNode *levelOrderTraversal(node *root, int level) { LinkNode *ptr1, *ptr2, temp;

Re: [algogeeks] Amazon Placement Question

2010-07-31 Thread Nikhil Jindal
@Ram Kumar: Yes. Simple and affective. Just at each node: node-left-side=node-right node-right-side=node-side-left i.e at each node you are setting the side of each of your child. Go on and just do it for all nodes. Done. On Sat, Jul 31, 2010 at 9:39 AM, Ram Kumar

Re: [algogeeks] Amazon Placement Question

2010-07-30 Thread Nikhil Agarwal
There few errors in your code rest is fine.I have updated in line On Fri, Jul 30, 2010 at 9:22 AM, Priyanka Chatterjee dona.1...@gmail.comwrote: On 30 July 2010 02:59, Priyanka Chatterjee dona.1...@gmail.com wrote: Algo: 1. find height of tree 2. do level order traversal

Re: [algogeeks] Amazon Placement Question

2010-07-30 Thread Amit Agarwal
A simple queue implementation will do. -Regards Amit Agarwal blog.amitagrwal.com On Fri, Jul 30, 2010 at 9:22 AM, Priyanka Chatterjee dona.1...@gmail.comwrote: On 30 July 2010 02:59, Priyanka Chatterjee dona.1...@gmail.com wrote: Algo: 1. find height of tree 2. do level order

Re: [algogeeks] Amazon Placement Question

2010-07-30 Thread karthik ramanathan
Do a BFS, by having a queue and keep inserting the nodes into it. You should know how many nodes are there in each level, for which you can have a variable to count the number of nodes in each level. The when you remove from your queue do connect these nodes till your count. You may need to use

Re: [algogeeks] Amazon Placement Question

2010-07-30 Thread vineel yalamarth
Dude, yeah I got the algo, but can u write java code for that On Fri, Jul 30, 2010 at 6:03 PM, karthik ramanathan nathankart...@gmail.com wrote: Do a BFS, by having a queue and keep inserting the nodes into it. You should know how many nodes are there in each level, for which you can have a

Re: [algogeeks] Amazon Placement Question

2010-07-30 Thread Anand
I highlighted the code which I feel need a change. Do let me know if it correct. LinkNode *levelOrderTraversal(node *root, int level) { LinkNode *ptr1, *ptr2, temp; if(root == NULL) return NULL; if(level == 1) return createLinkNode(root); else { ptr1 =

Re: [algogeeks] Amazon Placement Question

2010-07-30 Thread Ram Kumar
DONT DO A BFS!! NOT WORTH IT! CALL THE NEW POINTER AS 'SIDE' POINTER. for every root connect its left and right, for every root connect root-right and root-SIDE-left that ll do -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this

[algogeeks] Amazon Placement Question

2010-07-29 Thread irfan
I attended Amazon placement test today . There was a question where i got confused.It is as follows. Give an algorithm to connect all nodes in one level of a binary tree . 5 5 / \ / \ 8 2

Re: [algogeeks] Amazon Placement Question

2010-07-29 Thread irfan naseef
On Thu, Jul 29, 2010 at 11:35 PM, ashish agarwal ashish.cooldude...@gmail.com wrote: please explain q ..i didnt understand On Thu, Jul 29, 2010 at 11:01 AM, irfan irfannase...@gmail.com wrote: I attended Amazon placement test today . There was a question where i got confused.It is as

Re: [algogeeks] Amazon Placement Question

2010-07-29 Thread srikanth sg
solution is straight forward identifying nodes at different levels and making connection between them using a FLAG node On Thu, Jul 29, 2010 at 11:26 AM, irfan naseef irfannase...@gmail.comwrote: On Thu, Jul 29, 2010 at 11:35 PM, ashish agarwal ashish.cooldude...@gmail.com wrote: please

Re: [algogeeks] Amazon Placement Question

2010-07-29 Thread ashish agarwal
I think use bfs ... On Thu, Jul 29, 2010 at 11:26 AM, irfan naseef irfannase...@gmail.comwrote: On Thu, Jul 29, 2010 at 11:35 PM, ashish agarwal ashish.cooldude...@gmail.com wrote: please explain q ..i didnt understand On Thu, Jul 29, 2010 at 11:01 AM, irfan irfannase...@gmail.com

Re: [algogeeks] Amazon Placement Question

2010-07-29 Thread harit agarwal
are the nodes having an extra pointer for sibling?? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to

Re: [algogeeks] Amazon Placement Question

2010-07-29 Thread Gautham Muthuravichandran
BFS On Thu, Jul 29, 2010 at 11:56 PM, irfan naseef irfannase...@gmail.comwrote: On Thu, Jul 29, 2010 at 11:35 PM, ashish agarwal ashish.cooldude...@gmail.com wrote: please explain q ..i didnt understand On Thu, Jul 29, 2010 at 11:01 AM, irfan irfannase...@gmail.com wrote: I attended

Re: [algogeeks] Amazon Placement Question

2010-07-29 Thread Asit Baran Das
Use a recursive functionthis below function will add up all nodes at the same level. void Traverse(Node n,int level, LinkedList list){ if(n==null) return; if(nlist.size()) list.add(n.value); else list.set(list.get(level)+n.value); Traverse(n.left,level+1,list);

Re: [algogeeks] Amazon Placement Question

2010-07-29 Thread Priyanka Chatterjee
Algo: 1. find height of tree 2. do level order traversal i at each level store the address of each tree node in the data part of a linked node and form linked list of the nodes ii store the header of a linked list at a certain level in an array 3. return

Re: [algogeeks] Amazon Placement Question

2010-07-29 Thread jalaj jaiswal
@ srikant , trhe structure of binary tree have to be modified for this solution right..as nodes may have 3 links On Fri, Jul 30, 2010 at 12:03 AM, ashish agarwal ashish.cooldude...@gmail.com wrote: I think use bfs ... On Thu, Jul 29, 2010 at 11:26 AM, irfan naseef

Re: [algogeeks] Amazon Placement Question

2010-07-29 Thread Priyanka Chatterjee
On 30 July 2010 02:59, Priyanka Chatterjee dona.1...@gmail.com wrote: Algo: 1. find height of tree 2. do level order traversal i at each level store the address of each tree node in the data part of a linked node and form linked list of the nodes ii store