Re: [algogeeks] BST to DLL code: whats wrong with this code........

2012-09-03 Thread manish untwal
if u r getting desired output ? then what is the problem? On Sun, Sep 2, 2012 at 7:24 PM, shubham jain coolshubham...@gmail.comwrote: Hi I am trying to convert the BST to doubly linked list but I am getting desired output with this code Plz correct this code. #includestdio.h

Re: [algogeeks] BST to DLL code: whats wrong with this code........

2012-09-03 Thread nikki
Sorry by mistake i write that Actually I am not getting desired output.. On Mon, Sep 3, 2012 at 11:02 AM, manish untwal manishuntw...@gmail.comwrote: if u r getting desired output ? then what is the problem? On Sun, Sep 2, 2012 at 7:24 PM, shubham jain coolshubham...@gmail.comwrote:

[algogeeks] BST to DLL code: whats wrong with this code........

2012-09-02 Thread shubham jain
Hi I am trying to convert the BST to doubly linked list but I am getting desired output with this code Plz correct this code. #includestdio.h #includestdlib.h typedef struct tree mytree; struct tree { int data; mytree* left; mytree* right; }; void insert(mytree** root,int

Re: [algogeeks] BST question

2011-11-11 Thread UTKARSH SRIVASTAV
correct me if I am wrong #includestdio.h struct node { int data; struct node *left; struct node * right; }*root; int sum(int s,struct node *p,int ar[],int l) { if(p == NULL ) { return 0; } if(p-left == NULL p-right == NULL) { if( s - p-data == 0)

Re: [algogeeks] BST question

2011-11-11 Thread aniket chatterjee
As far as I understand, your solution will always contain the path that essentially start from root. But the actual problem states that the path may not necessarily start from root. On Fri, Nov 11, 2011 at 1:21 PM, UTKARSH SRIVASTAV usrivastav...@gmail.comwrote: correct me if I am wrong

Re: [algogeeks] BST question

2011-11-11 Thread aniket chatterjee
And also your solution prints the root to leaf path that sums up to X. But the path may not contain root as well as leaf also. May be some intermediate 4 nodes (from root to leaf path)sums up to X. Your code doesnt provide the solution for that scenario. On Fri, Nov 11, 2011 at 2:53 PM, aniket

[algogeeks] BST question

2011-11-10 Thread AMAN AGARWAL
Hi All, Please give me the solution of this problem. A binary tree and a number X is given. Find all the paths(not necessarily starting from root) such that the sum equals X. Regards, Aman. -- AMAN AGARWAL Success is not final, Failure is not fatal: It is the courage to continue that counts!

Re: [algogeeks] BST question

2011-11-10 Thread aniket chatterjee
Write a recursive function that will store each root to leaf path in an array. Now for each root to leaf path find the subarray which sums up to X. On Thu, Nov 10, 2011 at 11:53 PM, AMAN AGARWAL mnnit.a...@gmail.com wrote: Hi All, Please give me the solution of this problem. A binary tree

[algogeeks] BST to DLL spirally

2011-09-27 Thread raju
Had this question been already discussed .. someone pls give me the algo/logic. Given a Binary Tree, Convert it into Doubly Linked List where the nodes are represented Spirally. For Example :- A B C ABCGED || ACBDEG D E G ~raju -- You received this message because you are

[algogeeks] BST in file

2011-09-24 Thread Asit Dhal
I need to print a binary search tree in file. When I will retrieve the same tree from the file. I have thought about printing in xml format like this 100 / \ 50 150 / \ / \ 30 70 120 200 Level 0 100 Level 1 50 Level 2 30 /Level2 Level 2

[algogeeks] BST

2011-09-21 Thread prasanth n
Given a binary search tree, design an algorithm which creates a linked list of all the nodes at each depth (i.e., if you have a tree with depth D, you’ll have D linked lists). -- *prasanth* -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To

Re: [algogeeks] BST

2011-09-21 Thread saurabh agrawal
Do a BFS of the tree, keep a separator to masrk where a level ends.. create the linklist for every level. On Wed, Sep 21, 2011 at 6:00 PM, prasanth n nprasnt...@gmail.com wrote: Given a binary search tree, design an algorithm which creates a linked list of all the nodes at each depth (i.e., if

[algogeeks] BST

2011-08-04 Thread Rahul Mittal
www.spoj.pl/problems/BST/ -- 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,

Re: [algogeeks] BST

2011-07-31 Thread Shubham Maheshwari
take countr to be a static variable ... that shud do the job ...!! btw ...if thats nt the case ... thn i m nt pretty sure wat u are asking to be done ... On Sun, Jul 31, 2011 at 2:12 AM, Rahul Mittal rahulmitta...@gmail.comwrote: help me with this we need to find out how many times a function

[algogeeks] BST Question

2011-07-30 Thread Mani Bharathi
connect all sibling nodes of a binary search tree -- 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/-/GWAhIi6vaxAJ. To post to this group, send email to

Re: [algogeeks] BST Question

2011-07-30 Thread saurabh singh
please give an example. On Sat, Jul 30, 2011 at 12:10 PM, Mani Bharathi manibharat...@gmail.comwrote: connect all sibling nodes of a binary search tree -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To view this discussion on the web

Re: [algogeeks] BST Question

2011-07-30 Thread aditi garg
Do u mean something like level order traversal?? On Sat, Jul 30, 2011 at 12:11 PM, saurabh singh saurab...@gmail.com wrote: please give an example. On Sat, Jul 30, 2011 at 12:10 PM, Mani Bharathi manibharat...@gmail.comwrote: connect all sibling nodes of a binary search tree --

[algogeeks] BST

2011-07-30 Thread Rahul Mittal
help me with this we need to find out how many times a function is recursively called while inserting a node in bst. insert (number X, node N) increase the counter C by 1 if X is less than the number in node N if N has no left child

[algogeeks] BST

2011-06-29 Thread Nishant Mittal
how to find kth smallest element in BST... -- 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.

Re: [algogeeks] BST

2011-06-29 Thread rajeev bharshetty
http://mukeshiiitm.wordpress.com/2010/04/07/finding-kth-smallest-element-in-binary/ I think this solves the problem :) Rajeev On Wed, Jun 29, 2011 at 8:07 PM, Nishant Mittal mittal.nishan...@gmail.comwrote: how to find kth smallest element in BST... -- You received this message because you

Re: [algogeeks] BST

2011-06-29 Thread sunny agrawal
At each node if we store the Number of nodes in the left subtree.we can find kth smallest in O(lgn) else do a inorder traversal for k nodes On Wed, Jun 29, 2011 at 8:07 PM, Nishant Mittal mittal.nishan...@gmail.comwrote: how to find kth smallest element in BST... -- You received this

Re: [algogeeks] BST

2011-06-29 Thread piyush kapoor
Order Statistics Tree On Wed, Jun 29, 2011 at 8:15 PM, sunny agrawal sunny816.i...@gmail.comwrote: At each node if we store the Number of nodes in the left subtree.we can find kth smallest in O(lgn) else do a inorder traversal for k nodes On Wed, Jun 29, 2011 at 8:07 PM, Nishant Mittal

Re: [algogeeks] BST

2011-06-29 Thread Swathi
This should be very simple... follow inorder.. Inorder(Node* node, int counter, int N) { if(node == null)return; Inorder(node-left, counter, N); counter++; if(counter == N) { print(node-data); return; } Inorder(node-right, counter, N); } On Wed, Jun 29, 2011 at 9:03 PM, piyush kapoor

Re: [algogeeks] BST

2011-06-29 Thread Anantha Krishnan
Check this http://ideone.com/o8gF2 On Wed, Jun 29, 2011 at 10:28 PM, Swathi chukka.swa...@gmail.com wrote: This should be very simple... follow inorder.. Inorder(Node* node, int counter, int N) { if(node == null)return; Inorder(node-left, counter, N); counter++; if(counter == N) {

Re: [algogeeks] BST

2011-06-19 Thread kumar vr
Balance the tree and return the Root. On Sun, Jun 19, 2011 at 12:10 AM, hary rathor harry.rat...@gmail.comwrote: then you can use iterative method instead of recursion ... -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this

[algogeeks] BST

2011-06-18 Thread Akshata Sharma
How to find median of a Binary Search Tree without storing it in a linear data structure by in-order traversal? -- 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

Re: [algogeeks] BST

2011-06-18 Thread Vipul Kumar
traverse the BST , get the count of no. of nodes . now inorder traverse again till n/2 . and print that node On Sat, Jun 18, 2011 at 11:18 PM, Akshata Sharma akshatasharm...@gmail.com wrote: How to find median of a Binary Search Tree without storing it in a linear data structure by in-order

Re: [algogeeks] BST

2011-06-18 Thread Akshata Sharma
if no recursion and extra space is allowed?? On Sat, Jun 18, 2011 at 11:20 PM, Vipul Kumar vipul.k.r...@gmail.comwrote: traverse the BST , get the count of no. of nodes . now inorder traverse again till n/2 . and print that node On Sat, Jun 18, 2011 at 11:18 PM, Akshata Sharma

Re: [algogeeks] BST

2011-06-18 Thread hary rathor
then you can use iterative method instead of recursion ... -- 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] BST+Heap

2011-06-08 Thread Akshata Sharma
A rooted binary tree with keys in its nodes has the binary search tree property (BST property) if, for every node, the keys in its left subtree are smaller than its own key, and the keys in its right subtree are larger than its own key. It has the heap property if, for every node, the keys of its

[algogeeks] BST insertion

2011-01-28 Thread Roshan
I m Trying to make BSTand checking if node already there just return ,trying to return 1 but here its returning 0 , lease help // btree.cpp : Defines the entry point for the console application. // #include stdafx.h #includestdio.h #includestdlib.h #includeconio.h struct Node { int

[algogeeks] BST to Double Linked List Without Using Extra Space

2010-11-24 Thread vamsee marpu
Hi, Can anybody help me in solving the following problem: Convert a binary search tree in to a doubly linked list in level order without using extra space : BST 1 / \

Re: [algogeeks] BST Question

2010-10-24 Thread Praveen Baskar
oh ya thanks now i got it On Sun, Oct 24, 2010 at 9:54 AM, preetika tyagi preetikaty...@gmail.comwrote: @Praveen- In this case, we will not ignore the right subtree of the root (-10, which is less than zero) while traversing the tree. On Sat, Oct 23, 2010 at 9:06 PM, Praveen Baskar

Re: [algogeeks] BST Question

2010-10-23 Thread nishaanth
@Praveenit is not possible..in a BST *all the nodes* on the right subtree are greater than the node :) On Sat, Oct 16, 2010 at 3:26 PM, Praveen Baskar praveen200...@gmail.comwrote: @nishaanth: wat if the left child of the right node has a negative value On Thu, Oct 14, 2010 at 11:12 AM,

Re: [algogeeks] BST Question

2010-10-23 Thread Praveen Baskar
i think it is possible nishaanth please do take a look at this example -10 /\ -11 8 /\ -5 10 -5 is greater than -10 On Sat, Oct 23, 2010 at 11:19 PM, nishaanth

Re: [algogeeks] BST Question

2010-10-23 Thread preetika tyagi
@Praveen- In this case, we will not ignore the right subtree of the root (-10, which is less than zero) while traversing the tree. On Sat, Oct 23, 2010 at 9:06 PM, Praveen Baskar praveen200...@gmail.comwrote: i think it is possible nishaanth please do take a look at this example

Re: [algogeeks] BST Question

2010-10-16 Thread Praveen Baskar
@nishaanth: wat if the left child of the right node has a negative value On Thu, Oct 14, 2010 at 11:12 AM, nishaanth nishaant...@gmail.com wrote: Just see the value of the node at every point, if it is greater than zero dont recurse the right sub-tree, as simple as it is.print the node u

[algogeeks] BST Question

2010-10-13 Thread Narsimha Raju
HI A BST is given you need to print all the negative numbers. Sol: Inorder traversal will work. but i want to ignore the right sub trees based on the value at the root. (i.e efficient sol) -- Regards, C. Narsimha Raju MS, IIIT Hyderabad. http://research.iiit.ac.in/~narsimha_raju/ --

Re: [algogeeks] BST Question

2010-10-13 Thread nishaanth
Just see the value of the node at every point, if it is greater than zero dont recurse the right sub-tree, as simple as it is.print the node u inspected if it is less than zero. -- S.Nishaanth, Computer Science and engineering, IIT Madras. -- You received this message because you are

[algogeeks] BST

2010-10-08 Thread Anand
Binary search Tree was given. Find 4ths smallest element. -- 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] BST

2010-10-08 Thread Mukesh Gupta
4th element of inorder traversal On Fri, Oct 8, 2010 at 11:49 PM, Anand anandut2...@gmail.com wrote: Binary search Tree was given. Find 4ths smallest element. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send

[algogeeks] BST in BT

2010-09-25 Thread mac adobe
How would you identify a binary search tree of maximum nodes in a binary tree ? -- 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] BST Problem

2010-08-07 Thread Manjunath Manohar
@priyanka i agree with u... but wat i thot was if v had a tree with parent pointers...we can have one pointer at the left most and another at the rightmost subtree respectivelyand move along the pointers.. I need ur discussion on thisi think the implementation wud be

Re: [algogeeks] BST sort

2010-08-06 Thread Satya
u need to write a recursive function. All leaf nodes in complete BST are from n/2+1n. n/2+1 element will be the beginning element(least left child) for our resultant sorted array. U can get the parent of the element by doing the floor(n/2/+1), get the right child of the parent by

Re: [algogeeks] BST sort

2010-08-06 Thread Satya
typo! floor(n/2/+1) == floor((n/2/+1)/2) . Satya On Fri, Aug 6, 2010 at 5:27 PM, Satya satya...@gmail.com wrote: u need to write a recursive function. All leaf nodes in complete BST are from n/2+1n. n/2+1 element will be the beginning element(least left child) for our

Re: [algogeeks] BST Problem

2010-08-06 Thread Priyanka Chatterjee
@algoboy: If you want to use extra space go with sharad's algo: do inorder traversal , store in a buffer and use 2 pointer method. T(n) =O(n) , S(n)=O(n) If you don't want to use extra space , convert BST into circular DLL or DLL and use 2 pointer algorithm. (conversion of BST into DLL is a

[algogeeks] BST Problem

2010-08-05 Thread AlgoBoy
in a BST..given k..find two nodes ...whose values sum to k.. -- 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

[algogeeks] BST sort

2010-08-05 Thread AlgoBoy
sort a BST represented like an array...(similar to representation of HEAP) -- 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

[algogeeks] BST

2010-07-23 Thread Priyanka Chatterjee
Given a binary search tree of n nodes, find two nodes whose sum is equal to a given number k in O(n) time and constant space. (ignoring recursion stack space) I have got O(nlogn) time , O(1) space and O(n) time, O(n) space. Please help me out with O(n) time and O(1) space. -- Thanks Regards,

Re: [algogeeks] BST with duplicates?

2010-07-02 Thread saurabh gupta
Disagree a BST can have duplicate entries the 'equal to' term in the definition allows that I am surprised to see in the Wiki: From the above properties it naturally follows that: - Each node (item in the tree) has a distinct key. The example in the question is definitely wrong in the

[algogeeks] BST with duplicates?

2010-07-01 Thread amit
Can a BST have duplicate entries ?? .8 .../...\ .7..9 /..\/..\ ...6...8..8...10 i.e is this a BST . -- 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.

Re: [algogeeks] BST with duplicates?

2010-07-01 Thread sharad kumar
no a bst cant hve duplicates -- 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 algogeeks+unsubscr...@googlegroups.com. For more

Re: [algogeeks] BST with duplicates?

2010-07-01 Thread mohit ranjan
@Amit as per wiki, BST definition is - The left subtree of a node contains only nodes with keys *less than the node's key*. - The right subtree of a node contains only nodes with *keys greater than or equal to the node's key*. so, this following example is not a BST... Mohit On

Re: [algogeeks] BST

2010-06-24 Thread Chakravarthi Muppalla
I think in-order traversal would solve the problem. On Thu, Jun 24, 2010 at 4:24 PM, Anurag Sharma anuragvic...@gmail.comwrote: I once posted it to my blog. Perhaps its the same you are asking : http://anuragsharma-sun.blogspot.com/2010/03/converting-bst-to-circular-doubly.html Anurag

Re: [algogeeks] BST...doubt.......

2010-06-16 Thread Anurag Sharma
@sharad height will be log2(n) only in case of balanced BST. what if its terribly unbalanced, you may get height as 'n' as well ! :) So you will have to go till the bottom of the tree to see the depth and find the height accordingly. Anurag Sharma On Wed, Jun 16, 2010 at 9:12 AM, Anurag Sharma

[algogeeks] BST...doubt.......

2010-06-15 Thread ajay kumar
Write a pseudo code 4 that..using c/c++... how can we find the depth(height) of BST ? -- 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,

Re: [algogeeks] BST...doubt.......

2010-06-15 Thread Amir hossein Shahriari
here's a recursive solution int depth(Node n){ if (n==NULL) return 0; else return 1 + max( depth( n.right ) , depth( n.left ) ); } calling depth(root) will yield the height of the tree On 6/15/10, ajay kumar ajaykr@gmail.com wrote: Write a pseudo code 4 that..using

Re: [algogeeks] BST...doubt.......

2010-06-15 Thread sharad kumar
@ajay:recursively count the number of nodes then use formula h=log2(number of nodes) On Wed, Jun 16, 2010 at 5:39 AM, Amir hossein Shahriari amir.hossein.shahri...@gmail.com wrote: here's a recursive solution int depth(Node n){ if (n==NULL) return 0; else return 1 + max(

Re: [algogeeks] BST...doubt.......

2010-06-15 Thread Anurag Sharma
height of current node = max(height of left child, height of right child) +1 Hope now you get that? :) Anurag Sharma On Tue, Jun 15, 2010 at 5:31 PM, ajay kumar ajaykr@gmail.com wrote: Write a pseudo code 4 that..using c/c++... how can we find the depth(height) of BST ?

Re: [algogeeks] BST

2010-05-14 Thread divya jain
form a sorted array from inorder traversal of tree. now take to pointers one to the beginning of array and other at the end. now check if the sum of element is greater than reqd sum then increment 1st ptr. if their sum is less than reqd sum then decrement 2nd ptr. if their sum is equal to the

Re: [algogeeks] BST

2010-05-14 Thread Navin Naidu
use a hash table. Add the frst element in the hash table. From second element, check if the diff (sum - element) is present in the hash table or not. On Fri, May 14, 2010 at 4:20 PM, Rohit Saraf rohit.kumar.sa...@gmail.comwrote: @divya : i guess... it wont work. consider Array

Re: [algogeeks] BST

2010-05-14 Thread anna thomas
@rohit: Divya's soltn works in this way, if the sum of 2 nos is less than req sum, increment the 1st ptr(ptr at beginning of array). If sum req sum, then decrement the 2nd ptr(ptr at end of array) In ur example: ptr1 pts to 1 and ptr2 to 123456 (sum 6) dec ptr2 1+4 = 5 (sum 6) inc ptr2: 2+4 =6

Re: [algogeeks] BST

2010-05-14 Thread Rohit Saraf
hmmm i already realised that and even mailed that before :) and if we want to use constant space do not make an array. the bst itself is good enough to do what we are doing. On 5/14/10, anna thomas annathoma...@gmail.com wrote: @rohit: Divya's soltn works in this way, if the sum of 2 nos is

Re: [algogeeks] BST

2010-05-14 Thread Yalla Sridhar
if the tree has parent pointer then we can apply similar approach,, increment and decrenent... and can also be done in O(1) have to poninters pointed to the min and max nodes and them move pointers by checking the sums.. On Fri, May 14, 2010 at 5:03 PM, anna thomas annathoma...@gmail.com wrote:

[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] BST represented in array

2007-03-24 Thread vim
hi guys plz explain how to sort elements of BST represented using array in o(n) time --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to