[algogeeks] Convert a Binary tree into spike.

2010-05-13 Thread vinayan c
Something like this 1 2 3 4 5 67 1 | 2-3 | 4-5-6-7 -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group,

Re: [algogeeks] 400!

2010-05-13 Thread Yalla Sridhar
python int has no bounds, it can scale upto the mem u have available on your computer. On Thu, May 13, 2010 at 7:53 AM, Nikhil Agarwal nikhil.bhoja...@gmail.comwrote: @jitendra: your python code is awesome and it works.:) On Wed, May 12, 2010 at 6:37 PM, divya jain

[algogeeks] Re: Convert a Binary tree into spike.

2010-05-13 Thread Dave
Do a post-order traversal, keeping track of the level in the tree. As you visit each node, remove it from the tree and add it to the spike. Use the left pointer to point to the next level, and the right tree pointer for each level of the spike. If you visit the right subtrees before the left

Re: [algogeeks] Convert a Binary tree into spike.

2010-05-13 Thread Prashant K
use BFS traversal method -- Prashant Kulkarni || Lokaha Samastaha Sukhino Bhavanthu || || Sarve Jana Sukhino Bhavanthu || On Wed, May 12, 2010 at 8:48 PM, vinayan c vinayan1...@gmail.com wrote: Something like this 1 2 3 4

[algogeeks] BST

2010-05-13 Thread jalaj jaiswal
given a bst... find two nodes whose sum is equal to a number k ... in O(n) time and constant space... -- With Regards, Jalaj Jaiswal +919026283397 B.TECH IT IIIT ALLAHABAD -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this

[algogeeks] Re: tree from linked list

2010-05-13 Thread Atul Kumar
array and linked list are not the same so all solutions based on array are wrong. think this way : how to print(or append in a linked list) the binary search tree in the sorted order -- the answer is in-order traversal. you need to do opposite of it here. On May 12, 10:17 am, divya jain

[algogeeks] compute kth smallest element from union of two lists

2010-05-13 Thread divya
You are given two sorted lists of size m and n. Give an O(log m+log n) time algorithm for computing the kth smallest element in the union of the two lists -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to

Re: [algogeeks] Convert a Binary tree into spike.

2010-05-13 Thread vignesh radhakrishnan
do bfs. On 13 May 2010 09:18, vinayan c vinayan1...@gmail.com wrote: Something like this 1 2 3 4 5 67 1 | 2-3 | 4-5-6-7 -- You received this message because you are

[algogeeks] another google telephone interview question

2010-05-13 Thread divya
This problem was asked in google phone interview. We have N element array with k distinct keys(No relation between k N given so assume kN) What is the best method to sort this array without using any extra memory? Please elaborate. -- You received this message because you are subscribed to the

Re: [algogeeks] tree from linked list

2010-05-13 Thread divya jain
the best approach to it is to build a balanced tree from bottom to up rather than top to bottom. On 12 May 2010 22:47, divya jain sweetdivya@gmail.com wrote: thanks a lot to all for their replies.. On 9 May 2010 11:23, rahul rai raikra...@gmail.com wrote: can anyone give me links to

Re: [algogeeks] Re: Convert a Binary tree into spike.

2010-05-13 Thread Sathaiah Dontula
Using BFS we can do it. Thanks, Sathaiah On Thu, May 13, 2010 at 6:48 PM, Dave dave_and_da...@juno.com wrote: Do a post-order traversal, keeping track of the level in the tree. As you visit each node, remove it from the tree and add it to the spike. Use the left pointer to point to the next

[algogeeks] frequency

2010-05-13 Thread jalaj jaiswal
input a character array from the user and output in the following way. example string is amazon.. then output should be a2m1z1o1n1 i did it taking a 26 size array... some better solution ?? -- With Regards, Jalaj Jaiswal +919026283397 B.TECH IT IIIT ALLAHABAD -- You received this message

Re: [algogeeks] Convert a Binary tree into spike.

2010-05-13 Thread Anurag Bhatia
Do a breadth first search on the tree and link all nodes at the same level in the order that you process them --Anurag On Thu, May 13, 2010 at 9:18 AM, vinayan c vinayan1...@gmail.com wrote: Something like this                        1                2               3          4         5    

Re: [algogeeks] Convert a Binary tree into spike.

2010-05-13 Thread jalaj jaiswal
it looks like left child right sibling relation ??? isn't it ? On Thu, May 13, 2010 at 9:18 AM, vinayan c vinayan1...@gmail.com wrote: Something like this 1 2 3 4 5 67 1 | 2-3 | 4-5-6-7

Re: [algogeeks] Re: what will happen in the village

2010-05-13 Thread varun bhatia
can some1 post the solution here..the link by dufus is not working and i'm not able to find any other relevant link to this problem. On Sat, Sep 19, 2009 at 1:44 PM, ankur aggarwal ankur.mast@gmail.comwrote: thanxs dufus. got the soln On Fri, Sep 18, 2009 at 8:20 PM, Dufus

Re: [algogeeks] Convert a Binary tree into spike.

2010-05-13 Thread Jitendra Kushwaha
This can be done with level order traversal of the tree Algorithm count = count2 = 0 1. Push the root in the queue. 2. keep count at each level for root count =1 3. while(queue not empty) 4. push all childs of node at the top of queue in queue 5. count2 += (number of childs of node at

Re: [algogeeks] frequency

2010-05-13 Thread sharad kumar
cant u use a hash map of O(K) where K is distinct elements in string.. On Thu, May 13, 2010 at 8:13 PM, jalaj jaiswal jalaj.jaiswa...@gmail.comwrote: input a character array from the user and output in the following way. example string is amazon.. then output should be a2m1z1o1n1 i

Re: [algogeeks] compute kth smallest element from union of two lists

2010-05-13 Thread vignesh radhakrishnan
This is for kth largest. Change it for kth smallest In fact, this problem is amenable to something very similar to binary search. Suppose my arrays are A and B. The idea is to keep track of two indices, a (for A) and b (for B), such that a + b = k - 1 (it's very important to maintain this

Re: [algogeeks] compute kth smallest element from union of two lists

2010-05-13 Thread Rohit Saraf
exactly .. -- Rohit Saraf Second Year Undergraduate, Dept. of Computer Science and Engineering IIT Bombay http://www.cse.iitb.ac.in/~rohitfeb14 On Fri, May 14, 2010 at 10:07 AM, vignesh radhakrishnan rvignesh1...@gmail.com wrote: This is for

Re: [algogeeks] compute kth smallest element from union of two lists

2010-05-13 Thread Rohit Saraf
This was also asked in my Yahoo! Interview this year. :) -- Rohit Saraf Second Year Undergraduate, Dept. of Computer Science and Engineering IIT Bombay http://www.cse.iitb.ac.in/~rohitfeb14 On Fri, May 14, 2010 at 10:10 AM, Rohit Saraf