Questions tagged [binary-search-trees]

169 questions
10
votes
1 answer

Data structure for handling intervals

I am trying to create a data structure for handling the subsets of the real line of the form $[x,y)$. That is, suppose $X \subseteq \mathbb{R}$ and the data structure supports two types of operations: $add(X, [x,y))$ and $remove(X,[x,y))$. Each of…
10
votes
4 answers

What is "rank" in a binary search tree and how can it be useful?

I am having a bit of trouble wrapping my mind around what a ranked binary search tree is and why having a rank is important. I am hoping that someone can clarify a few things for me. What I have looked into: From what I have read, a ranked binary…
7
votes
3 answers

If inorder traversal of a tree is in ascending order will the tree definitely be a BST?

For a binary search tree (BST) the inorder traversal is always in ascending order. Is the converse also true?
6
votes
2 answers

Balanced Binary Search Tree Two-Sum with Constraints

My question spawns from this question. The question is straightforward: Can we find whether there exist 2 values in a balanced binary search tree where their sum equals a given target value? Now the constraints: Constant additional space in…
ryan
  • 4,533
  • 1
  • 16
  • 41
5
votes
4 answers

Why use binary search trees when hash tables exist?

Hash tables perform lookup, insertion, and deletion in O(1) time (expected and amortized) while the different variants of binary search tree (BST) - treap, splay, AVL, red-black - offer at best O(log n). So, in a course on data structures, is the…
wsaleem
  • 581
  • 6
  • 10
5
votes
1 answer

What is the advantage of leaf trees vs. node trees?

In the book "Advanced Data Structures", Chapter 2 ("Search Trees"), the author, Peter Braß, mentions two versions of binary trees (emphases in the quoted text are mine): "...two different models of search trees, either of which can be combined…
Aky
  • 225
  • 1
  • 8
5
votes
0 answers

Completeness of red-black tree operations

Red-black trees are defined to have the following invariants: The nodes are in sorted order (it is a binary search tree). The root is black, and leaves are black. Every red node has black children. Every path to the root passes through the same…
4
votes
1 answer

BST representation of Hash Tables

I'm reading this book Cracking Coding Interview. In this book author is speaking about BST representation of Hash Tables. I googled a lot for BST Representation of Hash Table. Code in C++ but didn't find any link or example. Can someone help me with…
abhimanyuaryan
  • 209
  • 3
  • 7
4
votes
2 answers

Which of the following sequences could not be the sequences of nodes examined in a binary search tree?

Suppose that we have numbers between $1$ and $1000$ in a binary search tree and want to search for the number $363$. Which of the following sequences could not be the sequences of nodes examined a) 924,220,911,244,898,258,362,363$ b)…
Squanchinator
  • 143
  • 1
  • 1
  • 5
4
votes
3 answers

What purpose do the leaves in a range trees serve?

I'm getting into algorithms and I came upon range trees. What confuses me is the leaves in a range tree, since for example: When you remove the leaves: It's just a regular BST. And, every implementation I see of a range tree/range searching, for…
4
votes
1 answer

Big O vs. Big Theta for AVL tree operations

On the Wikipedia page for AVL trees, the time/space complexity for common operations is stated both for average case (in Big Theta) and worst case (in Big O) scenarios. I understand both Big O and Big Theta in general but am having trouble…
4
votes
0 answers

Understanding the Transition points of a BST

I'm trying to understand the definition of Transition point of a BST, as given in Demaine, Erik D., et al. "Dynamic optimality-almost." SIAM Journal on Computing 37.1 (2007): 240-251 Define the transition point for [a node] y at time i to be the…
4
votes
3 answers

Why is Binary Heap never unbalanced?

My professor asks this question: Binary Search tree has Rotation Method to prevent it from degenerating into a linear structure (unbalanced tree). Why is there no need for such method for Binary Heaps?
3
votes
1 answer

Average height of a BST with n Nodes

I have to find the maximum, minimum, and average height of a BST with n nodes. After doing some researching I found that the maximum height is $n-1$ and the minimum height is $\log_2(n+1)-1$. My question is how do I get the average height of a BST…
3
votes
0 answers

If I randomly swap pairs of inputs how unbalanced will a binary search tree become?

Treesort sorts input by putting input into a binary search tree and then flattening the tree. In some cases the tree can become unbalanced and so a self-balancing tree is required. There is no requirement for a self-balancing tree if the input is…
1
2 3
11 12