FAQ Database Discussion Community


Get position of a value in a BST's inorder list(without creating the list)

java,binary-search-tree
I am totally stuck on this problem. I need to output the position of a value in an inorder list (First index 0). The caveat is that I can't create the list and search through it. For each node I have a variable that contains information about how many nodes...

Java : setting object to null within a method has no effect (Reusing code)

java,algorithm,reference,binary-search-tree
I am trying to write a method to delete a Node from a Binary Search Tree. Here is my method to delete a node. public void delete(int deletionNodeValue) { Node<Integer> nodeToBeDeleted = getNode(deletionNodeValue); if(nodeToBeDeleted == null) return; // No node with such value exists throw an error if(isLeafNode(nodeToBeDeleted)) { nodeToBeDeleted...

Tracing through a Binary Tree

java,binary-tree,binary-search-tree
I have the following Binary tree 3 / \ 5 2 / \ / 1 4 6 My weekness is recursion, so please bear with me, and I need your help to trace through it to get it right. I have the following code, and what it does is print...

Searching for Word Object in Binary Search Tree

java,binary-search-tree,frequency
The object of this function is to get user input to find a word that has been added to the Binary Search Tree. Then using my search algorithm in BST, if the word is found, then print out the frequency of the word. My approach was to take user input...

Binary Search Tree Template

c++,binary-search-tree
I'm fairly new to c++ and I've recently received a project to create my own Binary Search Tree using a Template. The goal is for the Binary Tree to be able to take in any kind of data type. IntBinaryTree.h should be able to take in object of EmployeeInfo. I've...

How to insert strings in BST

c#,oop,data-structures,binary-tree,binary-search-tree
I know how to insert integers into binary search tree Smaller to the left Larger to the right But that formula would be applicable only if Data/Key is integer. So i want to know how do i insert strings into BST I have searched the google but couldn't find any...

Prevent duplicates from being added to Binary Search Tree

java,recursion,nodes,binary-search-tree
This is homework. Please don't give me just code. The assignment was to implement several methods that a BST uses; among those, was add(T data) and remove(T data). I was able to successfully implement them. Here were the guidelines for the two methods: public void add(T data) If the data...

Binary Search Tree insertion - root remains null

java,binary-search-tree
I'm new to Java, I want to create a Binary Search Tree class with insertion and preorder traversal, but when I finish the insertion the root object remains null and the compiler throws NullPointerException during the preorder traversal. My node class: class Node { int info; Node left; Node right;...

C++: Which Data Type in STXXL is suitable to create External Memory Binary Search Tree?

c++,pointers,vector,binary-search-tree,stxxl
I want to create an External Memory Binary Search Tree Data Structure whose data sits in the external memory using stxxl as a library. For this purpose, which Data Type in STXXL is suitable to use as nodes in the Tree. If we use stxxl:Vector as the Nodes of the...

timing experiment on bst in haskell

haskell,binary-search-tree,timing
Hi i am trying to learn haskell and compare its performance to other languages when i run the following code.. module BST ( Tree, singletonTree, insert, member ) where import System.IO import System.IO.Error hiding (try) import Control.Exception import Data.Char import System.CPUTime -- -- Take the string and convert it to...

Find root of minimal height which is not BST

algorithm,data-structures,tree,binary-tree,binary-search-tree
I'm struggling with following problem: Write function which for given binary tree returns a root of minimal height which is not BST or NIL when tree is BST. I know how to check if tree is BST but don't know how to rewrite it. I would be grateful for an...

Implementing hashCode for a BST

java,binary-search-tree,equals
In Java to compare two objections for equality, you must implement both the equals method and the hashCode method. I need to compare two BSTs for equality. How do I implement the hashCode method in such a case? Now, implementing the hashCode on the Node class is simple enough: imagine...

order an array to make a somewhat-balanced binary search tree

java,arrays,binary-search-tree
Although the purpose of this question will probably not make a difference, I will state it anyway. I am working on making a method that performs Dijkstra's Algorithm on a graph. The algorithm requires a set U of unvisited cities. When a city is visited, it must be removed from...

Why does binary search tree tend to become unbalanced to the right?

java,algorithm,binary,binary-tree,binary-search-tree
This is from Heap lecture slide 8. Add, peek, and remove make sense to me as to why those operations are O(log n)- traversing through BST cuts tree in half after each move. Can anyone explain the intuition behind the last sentence though, that "The tree tends to become unbalanced...

Stack Overflow in binary tree insertion

insert,stack-overflow,binary-search-tree
PROCEDURE CreateNode (info: CHAR): BST; VAR bst : BST; BEGIN NEW(bst); bst^.elem := info; bst^.left := NIL; bst^.right := NIL; RETURN bst; END CreateNode; PROCEDURE Insert (info: CHAR; VAR t: BST); BEGIN IF t = NIL THEN t := CreateNode(info); ELSIF Compare(info, t^.elem) = greater THEN Insert(info, t^.right); ELSIF Compare(info,...

Putting things into a queue when the queue is in a template?

c++,binary-search-tree
Assume I had some binary search tree that worked and declared two like this: BinaryTree<string, queue<int> > * tree1 = new BinaryTree<string, queue<int>>; BinaryTree<string, int> * tree2 = new BinaryTree<string, int >; And lets say for the second one this worked perfectly: tree2->Add("Yoyo", 10); How would you add values to...

Remove recursively from a binary search tree

java,algorithm,recursion,binary-search-tree
This is homework; please don't just give me code I have two methods: remove(T data) and removeRec(Node<T> node, T data). In its current state, it seems my code only removes the root node of the BST. @Override public T remove(T data) { if (data == null) { throw new IllegalArgumentException("Data...

How to store all the data of BST into an array list?

java,list,binary-search-tree
Like the question says Im trying to make an array list which has all the data in each of the nodes in a binary search tree. public List storeKeyValues(){ List keyvalues = new ArrayList(); boolean notdone = false; temp = root; if(temp == null){ return null; } else{ list.add(temp.data); while(!notdone){...

Binary Search Tree String Insertion/Delete/Print

java,math,binary-search-tree
I want to insert, delete and print strings in this BST using a public method, as opposed to a boolean or void - so I have to return. In my insert method I am trying to check for null, and left and right sides of the tree. In the case...

balanced binary tree, order and between operation in O(logn) [closed]

algorithm,data-structures,binary-tree,binary-search-tree,avl-tree
But I ran into a challenge when I took an exam some days ago. If we have balanced binary tree with n vertices and store the number of children in the sub-tree for each node (i.e number of children that this node as a root has). How we can do...

Recursively search binary tree

java,algorithm,data-structures,graph,binary-search-tree
I'm supposed to search for a given album from a binary tree and return it. Here's what I have so far: public AlbumNode getAlbum(AlbumNode root, String name) { if (root != null) { if(root.left != null) getAlbum(root.left, name); if(root.right != null) getAlbum(root.right, name); } if(root.getName().equals(name)) return root; return null; }...

Shortest path in a custom binary search tree

java,algorithm,recursion,binary-search-tree,graph-theory
This a question from a coding competition The original question can be found here http://www.olympiad.org.za/olympiad/wp-content/uploads/2014/03/2013-PO-Question-Paper.pdf Question 5 SHORTEST PATH THROUGH THE HALL [by Alan Smithee of Hulsbos High] The hall is packed wall to wall with rows of chairs, but in each row there are exactly two chairs missing. The...

How to find the height of the deepest full level in a binary search tree? [closed]

c++,binary-search-tree
For example, given the tree: 10 5 15 0 6 12 20 // full -5 2 8 14 16 22 4 18 24 26 The value returned by the function highestFull(BinaryNodeX<Comparable> *t) would be 3 as the height of the deepest full level is three....

Menu Driven Java Program to implement Binary Search Tree. Cant get the Tree structure to add nodes beyond the root (insert function)

java,data-structures,binary-search-tree
Beyond the root, I couldn't add any more nodes permanently. Once a tree object is created in the insert function, on the next entry into the insert function it is being nullified, so only root is present. I can't find the problem and it's driving me crazy. Someone please help,...

Why does my program not check the number of arguments correctly?

c,command-line-arguments,binary-search-tree,stderr
Okay so I am writing code for a binary search tree that must read in strings from an input file: "input.txt" and I am trying to feed my program command line arguments. My program is supposed to take two command line args, the name of the program then the name...

Get top 10 and last 10 from a million records

java,binary-tree,binary-search-tree,priority-queue
I have a report which shows 2-4 million records. I get the records from oracle to java and push it to an excel report. All this is already done! Now, I also need to add a new tab with top 10 and last 10 records. What would be the best...

Having difficulty with removing a node from my binary search tree

c++,recursion,binary-search-tree,deleting
I am creating a binary search tree that needs to be able to delete a node and return true if the node was properly deleted, or false if the value doesn't exist in the tree. I am doing this because I need to delete more than one number and I...

BST traversal pre-order

algorithm,binary-search-tree
In a BST pre-order traversal,I do not see the result I would have expected. Please help confirm whether it is an issue with the code or my understanding of how pre-order traversal would work. Node: class node implements Comparable<node>{ int v; node left; node right; node(int v){ this.v=v;} boolean equals(node...

Find median in binary search tree

algorithm,tree,binary-search-tree,median
Write the implementation of the function T ComputeMedian() const that computes the median value in the tree in O(n) time. Assume that the tree is a BST but is not necessarily balanced. Recall that the median of n numbers is defined as follows: If n is odd, the median is...

Generic C for binary trees

c,generics,search,binary-tree,binary-search-tree
How is it possible to write generic c? I started writing a collection of balanced trees (scapegoat, splay, aa and so on) and find many things in common. Example is destroy function found below. Can such function and those similar be defined with void pointers without causing "dereferencing void* pointer...

Traversal in tree/linked list structure

c,data-structures,linked-list,binary-search-tree,traversal
It is kind of like a hybrid tree/linked list structure. Here's how I defined the structure struct node { nodeP sibling; nodeP child; nodeP parent; char name[100]; }; a node has a child, that is connected to a linked list. Other elements on the linked list may have their...

What is the best way to clear a BST for garbage collection?

java,garbage-collection,binary-search-tree
I want to clear a BST so as to take advantage of the garbage collector. So, to clear a BST, is it sufficient to set the root to null, so that I end up with a bunch of abandoned nodes with no pointers to them? Or is it better to...

Max integer with same strings, in a red black tree

algorithm,data-structures,binary-search-tree,red-black-tree
I have a tree with a set of numbers, where each number has 2 strings associated :a and b. So the structure looks like: a-number-b for each node. I want to get the maximum number in the tree where a=b in O(log n) worst case run time. My approach: Tried...

Unable to print elements in binary search tree

c,data-structures,binary-search-tree
My code is not printing the elements of binary search tree: //x is the element to be inserted //structure of program typedef struct BST { int info; struct BST *left; //pointer to left node struct BST *right; //pointer to right node } bst; //global root variable bst *root; void insert(int...

Binary Search Tree Haskell

haskell,functional-programming,binary-search-tree
I have an insert function for a Binary Search Tree in Haskel. My insert functions first two lines look like this insert :: (Ord a) => BST a -> a -> BST a insert Nil x = Node x Nil Nil I know the function works, I have tested it...

Finding the minimum and maximum height in a AVL tree, given a number of nodes?

binary-search-tree,avl-tree
Is there a formula to calculate what the maximum and minimum height for an AVL tree, if given a certain number of nodes? (this is for a intro java prog. class). For example, there is a question : Textbook question: What is the maximum/minimum height for an AVL tree of...

Understanding recursive calls in deleting a node from a Binary Search Tree

c,recursion,binary-search-tree
The function to delete a node in a BST with the given key is as follows: struct node* deleteNode(struct node* root, int key) { // base case if (root == NULL) return root; // If the key to be deleted is smaller than the root's key, // then it lies...

Counting Nodes with single child in BST [closed]

c++,binary-search-tree,tree-traversal
i have this question : implement function int countSingle(), which uses Breadth-First Traversal (BFT) in order to count how many nodes in the tree have a single child. so the code below is what i thought of to solve it , is there another way of doing this or a...

Find the parent node of a node in binary search tree

c++,binary-search-tree,nodes
So I want to find the parent node of a Node in a binary tree. Suppose that I input 30,15,17,45,69,80,7 in the tree through a text file. The tree should be 30 15 45 7 17 69 80 And here is my code : Node* BST::searchforparentnode(Node* pRoot, int value) {...

Error while inserting element into binary search tree

c++,binary-tree,binary-search-tree
The program creates a binary search tree from a sorted array of numbers and adds elements to it. struct Tree { Tree *left_son, *right_son; int head, key; }; Tree *tree(int *a, int left, int right) { Tree *tree1 = new Tree; int mid = middle(left,right); tree1->head = a[mid]; if (left...

Deleting a Leaf node BST

c,delete,binary-search-tree
i've trying to implement an AVL tree just for the sake of learning. I managed to make the insertion, but im stuck at the deletion. I have a problem deleting a leaf node (the one-child case works just fine). the problem is that when i delete the node it doesn't...

Segmentation fault when using if statement with pointers (BST tree)

c++,c,pointers,segmentation-fault,binary-search-tree
I'm trying to implement a binary search tree in C, more specifically looking for the predecessor. However, whenever I try to run the program I get the segmentation vault. Here's the code in question: #include <stdio.h> #include <stdlib.h> struct tree { int a; tree *left; tree *right; tree *prev; }*root=NULL;...

BST total depth complication

python,binary-search-tree,depth
Here is an excerpt of a working BST: class BinaryTree(): def __init__(self,rootid): self.left = None self.right = None self.rootid = rootid def getLeftChild(self): return self.left def getRightChild(self): return self.right def setNodeValue(self,value): self.rootid = value def getNodeValue(self): return self.rootid I decided not to display every function of the class above, only...

Errors in finding the median in binary search tree

c++,algorithm,tree,binary-search-tree,median
Write the implementation of the function T findMedian() const that computes the median value in the tree in O(n) time. Assume that the tree is a BST but is not necessarily balanced. Recall that the median of n numbers is defined as follows: If n is odd, the median is...

Find the median of binary search tree, C++

c++,algorithm,vector,time-complexity,binary-search-tree
Once I was interviewed by "One well known company" and the interviewer asked me to find the median of BST. int median(treeNode* root) { } I started to implement the first brute-force solution that I came up with. I fill all the data into a std::vector<int> with inorder traversal (to...

Why is the height of every binary search tree not O(log n)

algorithm,binary-search-tree
Studying for an algorithms exam, and I read that the height of every BST is not O(log n). Does this fact have something to do with the tree being balanced? Is the height of every balanced BST O (log n), and unbalanced tree something else (if so what is it)?...

Why would one use a heap over a self balancing binary search tree?

data-structures,tree,heap,binary-search-tree,avl-tree
What are the uses of heaps? Whatever a heap can do can also be done by a self-balancing binary search tree like an AVL tree. The most common use of heap is to find the minimum (or maximum) element in O(1) time (which is always the root). This functionality can...

Does a return statement stop the recursive stack from continuing?

c++,recursion,binary-search-tree
I'm coding up a search_key algorithm for a binary search tree and am having issues. I'm traversing the binary search tree and comparing the nodes using an in-order traversal algorithm using the basic recursion technique. However, when the conditional hits (search_key == node[x]->value) and I return the node, it seems...

To print the boundary of Binary Tree

algorithm,tree,binary-tree,binary-search-tree,graph-algorithm
I have been asked in an interviews to print the boundary of the Binary Tree. For example. 1 / \ 2 3 / \ / \ 4 5 6 7 / \ \ 8 9 10 Answer will be : 1, 2, 4, 8, 9, 10, 7, 3 I have...

Binary search tree largest value

python,binary-tree,binary-search-tree
I am trying to find the largest value in a binary search tree. The sample solution is given below, but I'm trying to understand if there's anything wrong with my solution? My problem with the sample solution is that it seems to check whether each node is not None twice:...

Algorithm time complexity with binary search

time,big-o,time-complexity,binary-search-tree,binary-search
I am trying to figure out what the time complexity of my algorithm is, I have algorithm with binary search, which is in general O(log n), I know. But I search between two constants, namely x=1 and x = 2^31 - 1 (size of integer). I think that in the...

Given a BST, and a node in BST, make that node, as new root of the tree

algorithm,data-structures,tree,binary-search-tree
Given a BST, and a node in BST, make that node, as new root of the tree. But still maintain the tree as BST after making this node as root. I tried as follows: Take given node as root, if its on left of original root then make original root...

Skewed Trees relation to Binary Search Tree

data-structures,binary-tree,binary-search-tree
I know what Binary search tree is and I know how they work. But what does it take for it to become a skewed tree? What I mean is, do all nodes have to go on one side? or is there any other combination? Having a tree in this shape...

Why does my node still appear when I set it to null?

java,binary-search-tree,nodes
I'm making a BST (Binary Search Tree). I would like some help with my delete method, it seem that when I set that node to null it stills appear when I display it with my display methods (preorder,inorder,postorder). Here is my node linked list class public class Node<T> { public...

Haskell foldr on list

haskell,functional-programming,binary-search-tree
I have a member function in Haskell for a BST. I am trying to use foldr to check if every element in the list is in the BST. My member functions works for single elements and the first line looks like this. member ::(Ord a) => BST a -> a...

In order Traversal Breaking Out Of Recursive Loop

java,recursion,binary-search-tree
I've search around SOF for a while and read similar post. I didn't find any of those answers satisfactory. The issue i'm having is that I want to traverse a tree until 'the root node' and a target node are the same. If the 'root' == target, I want to...

Adding sum of frequencies whille solving Optimal Binary search tree

algorithm,binary-search-tree
I am referring to THIS problem and solution. Firstly, I did not get why sum of frequencies is added in the recursive equation. Can someone please help understand that with an example may be. In Author's word. We add sum of frequencies from i to j (see first term in...

Binary Tree static methods in Java

java,binary-tree,binary-search-tree,static-methods
I have these instance methods in my Java implementation of Binary Tree and Search Binary Tree: getSize(), getHeight(), getDepth(), getPreOrder(), getInOrder(), getPostOrder() and getLevelOrder(). These methods use the root of the tree in others recursive methods that have a parameter Node. Which is more appropiate to use from the point...

Maximum width of a Binary Tree using preorder traversal

c++,data-structures,tree,binary-tree,binary-search-tree
I want to get the maximum width of a Binary tree. In this method using Pre-order traversal width can be calculated. But I can't understand it properly. Please explain how the function getMaxWidthRecur() works. // A utility function that returns maximum value in arr[] of size n int getMax(int arr[],...

What is meant by complexity of O(log n)?

algorithm,data-structures,tree,binary-tree,binary-search-tree
Consider this example of binary search tree. n =10 ;and if base = 2 then log n = log2(10) = 3.321928. I am assuming it means 3.321 steps(accesses) will be required at max to search for an element. Also I assume that BST is balanced binary tree. Now to access...

Binary search tree intersection

algorithm,tree,binary-search-tree,complexity-theory
I have 2 binary search trees T1 and T2 with same number of nodes n >= 1. For each node P we have LEFT(P) and RIGHT(P) for links between nodes and KEY(P) for value off the node. The root of T1 is R1 and root of T2 is R2. I...

C binary tree sort - extending it

c,binary-tree,binary-search-tree
I need some help in C Help me to extend the binary tree sort on C. I need to return a sorted array in sort function. here it is: #include <stdio.h> #include <stdlib.h> struct btreenode { struct btreenode *leftchild ; int data ; struct btreenode *rightchild ; } ; void...

Recursive Binary Search Java

java,recursion,binary-search-tree
I have an arraylist called sArray that holds a large list of correctly spelled words. I need to send a word to this recursive binary search method (key) and determine whether or not it is spelled correctly or not. I understand how a recursive binary search works however I am...

Binary search tree, constant NULL return

c,binary-search-tree
I wrote a phonebook search using binary trees. Everything in the code works fine, except for when I'm prompted to type in whose number I'm searching. Then the search_phonebook function return NULL by default. I can't crack what it is. #include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> #define MAX_NUM...

In BST, which traversal is required to visit all keys in decreasing order, assuming as a comparator?

data-structures,binary-search-tree,comparator
In BST, which traversal is required to visit all keys in decreasing order, assuming as a comparator? The answer is Reverse In- And I was wondering why this is the case. And what if it is to visit all keys in increasing order, what would be the answer from the...

Method recursion (Java)

java,recursion,binary-search-tree
I ran into a perplex situation while I was trying to understand the binary search tree. I am baffled by the way the method recursion is happening here when a method is called, say inOrder(). Below is the code: public class Node { int data; Node left; Node right; public...

StackOverflow while adding elements to a BST java

java,stack-overflow,binary-search-tree
private Node put(Node x, Float longitude, Float latitude, String place, String address) { if (x == null) return new Node(longitude, latitude, place, address, 1); int cmpX = longitude.compareTo(x.longitude); int cmpY = latitude.compareTo(x.latitude); if (cmpX < 0 | (cmpX == 0 && cmpY < 0)) { if (x.left == null) {...

How to calculate depth of each node in Binary Search Tree?

java,binary-search-tree,treenode
My task is to calculate depth of each node and store it in 'depth' given in Node class. But I don't know how I should approach this task. I was looking for some example in the internet but haven't found any appropriate to my task. This is the code of...

depth of Binary Search Tree recursively

java,recursion,binary-search-tree,depth
THIS IS HOMEWORK, DO NOT POST CODE. Please and thank you. I have been assigned to create a method that calculates the depth of a particular in a BST. To do this, I am to @Override a method public int depth(T data). So, to find it recursively, I need to...

How to compare two strings for a binary search tree

c,binary-tree,binary-search-tree
I am trying to compare two strings to see where it should go as a leaf node from the root and so fourth. I keep trying to use string compare and I get an error. I am very unfamiliar with binary trees in c and need help inserting nodes. Here...

Unable to get left/right in TreeNode class

java,binary-search-tree,treenode
I was working on a problem regarding to binary search tree using java. The name of the built-in class in TreeNode. In the solution, it shows However, when I did the implementation myself, I am not able to do "root.left" or "root.right". I was wondering if I missed anything? Thanks!...

Tree elements not displaying in correct order

c,tree,binary-search-tree,tree-traversal
I am trying to build a simple tree program and traverse it in inorder,preorder and postorder formats. The code I am using is this : #include <stdio.h> #include <stdlib.h> struct node { int info; struct node* lchild; struct node* rchild; }; typedef struct node* NODE; NODE getNode() { NODE temp;...

Red-Black tree: Split/Concatenate in log(n) time

algorithm,split,concatenation,binary-search-tree,red-black-tree
According to Ron Wein your able to do split and concatenation of red-black tree's in O(log(n)) time. See his artikle: Efficient Implementation of Red-Black Trees with Split and Catenate Operations However I'm still not convinced that the running time of split really is true. The idea is that split uses...

Does a Red-Black Tree modify the left-to-right order of its leaves when it re-balances itself?

algorithm,data-structures,binary-search-tree,red-black-tree,tree-balancing
In other words, If you were to read the values of the leaves in a red black tree from left-to-right immediately after an insertion, would that order remain the same after performing balancing operations on the tree?

(fixing a code for) racket— deleting a node from a tree

racket,binary-search-tree
So I'm currently stuck in the intermediate level of racket, and have looked at various codes, but most of them I can't figure out I'm trying to delete a node from a binary search tree So, I've so far come up with this, which includes an empty node and the...

Can someone explain how the recursion works for an inorder BST traversal?

recursion,binary-search-tree,inorder
I realize a code for an inorder traversal would look something like if left[x] != NULL recurse left process right[x] !=NULL recurse right I coded everything up, works fine. I then started to think more and have over-thought the process and now am lost in how the recursion actually works....

Recursive Binary Search for Spellcheck is missing some words

java,recursion,binary-search-tree,spell-checking
I have a dictionary file that contains a list of words, and I read that file into the array list sArray. I then have a book where I use a string parser to take every string from this book and send it to the binary search method, bSearch. bSearch will...

Deleting nodes in a binary search tree in python?

python,python-3.x,binary-search-tree,nodes
so I'm stuck on a question in my computer science class, it asks for me to extend our previously written binary search tree class, and add a way to delete nodes from the tree, this will have to take into consideration if that node has 0, 1, or 2 children....

How to populate a file with random numbers?

c++,algorithm,sorting,binary-tree,binary-search-tree
So Basically I am trying to "populate" a file with 10^3 completely random numbers, so I could add them later to a Binary search tree. Here is the populate function I worked on so far: void populateFile(BinarySearchTree b) { int random_integer; srand( time( NULL ) ); std::ofstream myfile; string line;...

Binary Search Tree DataStructure in Python

python,binary-search-tree
I'm trying to teach myself Python, coming from C++, so I decided to try and build a simple BST. I managed to get my insert method working correctly, but I do not know why my printTree method fails. The interpreter gives me the error: Traceback (most recent call last): File...

Inorder successor in a reversed binary search tree

binary-search-tree,inorder
I have a slight confusion on inorder successor/predecessor if the BST is flipped. What I meant when the BST is flipped/reversed is that when all elements in the right subtree is smaller and all elements in the left subtree is greater. Normally the right subtree has greater value. What if...

How to assign a string passed through a function to a structure member? C programming

c,struct,binary-tree,binary-search-tree
Okay so i am trying to pass an array of chars through a function, then assign that string of chars to the member of a structure for a binary search tree. my files are to be split up and i cant seem to figure out what i am doing wrong....

What is wrong with my function testing for membership in a binary search tree?

haskell,types,binary-search-tree,membership
Lets say I have the following datatype: data BinaryTree a = EmptyTree | Node a (BinaryTree a) (BinaryTree a) deriving (Eq, Ord, Show) and the following function member a EmptyTree = False member a (Node x l r) | a < x = member a l | a > x...

Why is add in unbalanced Binary Search Tree O(n)?

java,algorithm,data-structures,binary-tree,binary-search-tree
This is the implementation of add in Binary Search Tree from BST Add private IntTreeNode add(IntTreeNode root, int value) { if (root == null) { root = new IntTreeNode(value); } else if (value <= root.data) { root.left = add(root.left, value); } else { root.right = add(root.right, value); } return root;...

Use of anonymous inner class in traversing a binary search tree

java,binary-search-tree,anonymous-inner-class
Update: how best can I add up the durations without modifying the interface? I cannot access a method of an instance of an anonymous inner class. I get a compile-time error for the sum.totalTime() call -- "the method totalTime() is undefined for the type Traverser" I have a Traverser interface....

request for member in something not a structure or union, but its a struct

c,binary-search-tree,strncmp
this code is a binary search tree I'm doing for my school assignment. #include "binary_tree.h" #include <stdio.h> #include <stdlib.h> #include <string.h> #define MAXLEN 10 Node* create_tree() { return NULL; } void insert_tree(Node** root, char* nname, char* number) { if (*root==NULL){ Node* node = (Node *)malloc(sizeof(Node)); strncpy(node->name , nname, MAXLEN); strncpy(node->number...

Binary Search tree in Scheme

functional-programming,scheme,binary-search-tree
I have a scheme function where I have a list and I am trying to put the numbers into a Binary Search Tree one by one. However, I keep getting "unspecified return value" (define (insertB L) (if (not (null? L)) (begin (let() BST (insert (car L) BST)) (insertB (cdr L))...