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
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:
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
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)
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
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
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!
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
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
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
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
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
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,
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
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
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
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
--
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
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.
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
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
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
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
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)
{
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
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
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
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
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
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
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
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
/ \
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
@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,
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
@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
@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
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/
--
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
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
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
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
@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
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
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
@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
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
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
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,
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
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.
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
@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
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
@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
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,
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
@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(
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 ?
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
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
@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
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
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:
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
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
66 matches
Mail list logo