I want to find minimum value in a Binary Search Tree. I have written below code. But when i call the function from main and I pribt the return value, it is printing as 0 always.

cal you please help.

```
int findMinimumValue(struct tnode* node)
{
int min=node->data;
if(node->lchild==NULL)
{
return min;
}
else
findMinimumValue(node->lchild);
}
```

Looks like you're not actually returning the value of your recursion call:

```
int findMinimumValue(struct tnode* node)
{
int min=node->data;
if(node->lchild==NULL)
{
return min;
}
else
{
// you need the return here or you're never returning
// anything in this branch
return findMinimumValue(node->lchild);
}
}
```

for that matter not really much need for the variable as it is, what about:

```
int findMinimumValue(struct tnode* node)
{
if (node->lchild == NULL)
return node->data;
else
return findMinimumValue(node->lchild);
}
```

oh, and just as a mention: I would consider using the non-recursive version of this instead; it's also pretty simple:

```
int findMinimumValue(struct tnode* node)
{
while (node->lchild != NULL)
node = node->lchild;
return node->data;
}
```

Similar Questions

I have 2 classes, NonEmptyTree and EmptyTree that implement the Tree interface. toString() method in NonEmptyTree class should return a string: key=>value key=>value key>value etc... I do not

I'm putting together functions for a binary search tree and ran into a wall. I'm working on each situation that might be encountered when a node holding a specified value needs to be removed from the

Why do people use binary search trees? Why not simply do a binary search on the array sorted from lowest to highest? To me, an insertion / deletion cost seems to be the same, why complicate life with

Ok, I have written a binary search tree in OCaml. type 'a bstree = |Node of 'a * 'a bstree * 'a bstree |Leaf let rec insert x = function |Leaf -> Node (x, Leaf, Leaf) |Node (y, left, right) as node

I am making Binary Search Tree and AVL Tree for an assignment. I am having problem when I try to add 1,000,000 elements to Binary Search Tree but I can add key-> value pairs to AVL Tree.(There is n

I have a problem with insertion in Binary search tree in C. I have the following definition of a binary tree(please ignore line numbers): 40 struct WordBT 41 { 42 char *term; 43 struct WordBT *right;

I am trying to become familiar with Clojure and so I've started to implement some basic algorithm and data structures. I currently have a problem with implementing a binary search tree. Here is my cod

I am having trouble outputting a binary search tree. I have to build the tree, and then place all the doubles from the tree in order into a vector, and then output that vector in order. The problem I

I'm working through the exercises in the book Beginning Haskell. Exercise 4-8 is to make a binary search tree an instance of Functor and define fmap. This is what the tree looks like: data BinaryTre

Welcome! I have a recursive public static method named less that takes a tree node (an original binary tree, not really a search tree) and a int parameter that returns if all the values in the tree ar

I'm trying to find the definition of a binary search tree and I keep finding different definitions everywhere. Some say that for any given subtree the left child key is less than or equal to the root

I have a binary tree, it is strange: the root is the highest number, and the other go decreasing... (Example: Huffman tree) I need to make an algorithm that searches a key inside it. I tried a lot but

So I've looked around a lot for some information on how to take elements from a binary search tree and write them to a file, and then later read them back into the tree as a type of load function. I

Suppose i am having an array say 1 5 4 6 8 9 10 22 17 7 9 3 I want to create a binary search tree from this array. I need algorithm to understand that. I have read rest other things related to BST l

Im trying to insert into an array Based Binary Search tree. I am not sure how i prevent overwriting data using left and right indexes... Do i insert leftchild as tree[2 * i + 1] and rightchild as tre

I was wondering if we can use a binary search tree to simulate heap operations (insert, find minimum, delete minimum), i.e., use a BST for doing the same job? Are there any kind of benefits for doing

I am trying to implement a binary search tree in python, but I can't find a solution for delete. If the item is in a leaf, that is simple, but what if the item I want to delete has 2 children which al

When programming a simple binary search tree data structure (non self-balancing), the advice most resources give when deleting a node with two children is to copy the data out of one of the left child

I'm implementing the insert function of a BST, below is my code: data Tree a = Empty | Branch a (Tree a) (Tree a) deriving (Show, Eq) tinsert :: Tree a -> a -> Tree a tinsert Empty a = Branch a

I read about binary search trees that if it is a complete tree (all nodes except leaf nodes have two children) having n nodes, then no path can have more than 1+log n nodes. Here is the calculation I

so I have been trying to get an old c++ binary search tree program of mine to work.It compiles and runs but I do not get the results I would expect. If I insert c,d,a,b in that order and try to remove

I'm reading the Cormen algorithms book (binary search tree chapter) and it says that there are two ways to traverse the tree without recursion: using stack and a more complicated but elegant solution

I'm learning Data Structures & Algorithms now. My lecture notes have an implementation of a binary search tree which is implemented using a recursive method. That is an elegant way, but my questio

If I delete node x and then node y or delete y and the x, after this deleted I will stay with the same binary search tree? I tried a few examples and I think that's true. But how can i prove this?

I am doing homework and I am try to implement some binary search tree functions. I am also very new to programming, and do not have much experience with programming. I have the functions written out,

I had a question of exactly how a binary search tree of strings works. I know and have implemented binary search trees of integers by checking if the new data <= parent data then by branching left

I need a general formula to calculate the minimum height of the binary tree and the maximum height of the binary tree. (not the binary search tree)

I'm trying to eliminate any memory leaks in in my Binary Search tree that I'm making so I made a simple recursive delete method. This is the method that first causes void BST::copy(const BST& othe

I am trying to understand why when deleting a node in a BST tree and having to keep the children and adhering to the BST structure, you have to either take the node's right child (higher value, then n

I have a homework which ask from me to create a struct of binary search tree where its node of the binary search tree is another binary search tree. The first BST has the Surnames of Students and the

I've given the result of in-order traversal of a binary tree (not binary search tree) as: E, D, B, A, G, F, H, C Now I've to find out the result of the post-order traversal of the same tree for which

I have an insert function for a Binary Search Tree and i can not find out why i am getting that error. Even if i put a return FALSE; right before the function ends it still happens. Any help is apprec

Given an arbitrary set of values V and building a tree by inserting values left to right, what does it mean if I'm asked if my orderings of these values (to construct a minimum height and maximum heig

Please explain the difference between a binary search tree and m-way tree?

want to insert element in binary tree. what is wrong in this code. I have a structure with data, left and right as self referencing structure and root as a global variable of type structure initialize

I am really confused about finding an element in binary tree. Question : When we say, search an element in binary tree, maximum in this case, do we assume that the tree is sorted??? If not, take a loo

How much does it cost the search operation in a Binary tree? Is it O(n)?

I have read that std map is implemented using binary search tree data structure. BST is a sequential data structure (like elements in an array) which stores elements in a BST node and maintains elemen

I am stucked on this simple binary search tree very long as my main problem is that the (BST * bst) in function bst_get() is NULL. typedef struct { char *key; void *value; } KVP; typedef struct bst {

Here is one implementation of the remove method for BST. I quote from there: Removing an element from a search tree, although tricky, is conceptually straight-forward with one (common) exception: rem

I need the pseudocode for a C++ that will search through a tree to find the node with the value of “z”. the function is given the root node to the tree to begin with. The tree has the property where e

I am trying to traverse a binary search tree in-order, and place the data (sorted) in an array. for some reason, the pointer to the current position in the array is not moving right. This is the decle

wanting to write a destructor for binary search tree (its supposed to delete all the nodes in a tree) here is what i got so far virtual ~BST() { BSTNode<Data>* node = root; if (node == NULL){ re

I'm using Dr. Racket, language Pretty Big, and I'm trying to make a simple binary search tree in? method, that will return if a value is in the binary search tree or not. It needs to be general, acc

Here i have written a code which inserts numbers in Binary tree. But it gives segmentation fault error. And also it says note: expected ‘struct tree *’ but argument is of type ‘struct node *’ in li

This is probably a simple task for expert coders, but is it possible to recursively traverse a binary unordered tree to find a node? I can do this for a binary search tree, but I'm struggling with how

I'm new to the programming world and I have been stuck in the same problem for couple days. My assignment is to create a binary search tree that takes a string and an integer as parameters and stores

As mentioned in the Title , I have a Binary search tree. I want to convert it to sorted doubly linklist using recursion. My code for each node in tree find max of left sub-tree and assign its right t

I am not asking how to merge two binary search trees, as this question did how to merge two BST's efficiently? I am really asking how to concatenate two trees. So if tree A's all nodes are smaller tha

Given a binary search tree, i need to convert it into a doubly linked list(by traversing in zig zag order) using only pointers to structures in C++ as follows, Given Tree: 1 | +-------+---------+ | |