binary-search-tree Questions

5

Solved

I'm wondering whether there is a mapping between a sorted array (e.g., [1, 2, 3, 4, 5, 6]) and the representation that one obtains when one constructs a complete binary search tree from this sorted...
Aspen asked 5/4, 2016 at 7:27

5

Solved

Is there a formula to calculate what the maximum and minimum height for an AVL tree, given a certain number of nodes? For example: Textbook question: What is the maximum/minimum height for an AVL ...
Hasbeen asked 11/6, 2015 at 0:2

5

Solved

As far as I know the time complexity between AVL trees and Binary Search Trees are the same in average case, with AVLs beating BSTs in worst case scenarios. This gives me a hint that AVLs are alway...

5

Solved

I don't need code, just an explanation. My textbook says level order: each node at level i is processed before any node at level i+1 My understanding of breadth first searching is that you exp...

2

Solved

So given the following: def inorder(t): if t: inorder(t.left) yield t.key inorder(t.right) x = [ n for n in inorder(r) ] x only contains the root node, why? Here's the full code; note that...
Busily asked 22/4, 2015 at 13:50

5

Solved

Reference: I was asked this question @MS SDE interview, 3rd round. And it's not a homework problem. I also gave it a thought and mentioning my approach below. Question: Modify a BST so that it bec...
Transpierce asked 22/12, 2012 at 9:31

6

Solved

The binary-search algorithm takes log(n) time, because of the fact that the height of the tree (with n nodes) would be log(n). How would you prove this?
Stapleton asked 26/1, 2013 at 16:48

8

I have been trying to wrap my head around this codility question for 1H30,and how to solve with binary search. I found the answer but I cant understand the logic behind it. Can someone who gets it ...
Digitate asked 4/11, 2020 at 14:21

4

Solved

I need to send an email to users based wherever in the world at 9:00 am local time. The server is in the UK. What I can do is set up a time difference between each user and the server's time, which...
Greenway asked 27/5, 2011 at 16:35

14

Solved

Can anyone please explain the difference between binary tree and binary search tree with an example?
Burnie asked 17/6, 2011 at 0:42

3

Solved

I'm trying to solve the following problem: at first we have a bst with root 0 and nothing else. not we add n given numbers like a which: not for instance we start to add n = 7 numbers to the tr...
Ric asked 22/11, 2019 at 5:5

5

Solved

A BST is generated (by successive insertion of nodes) from each permutation of keys from the set {1,2,3,4,5,6,7}. How many permutations determine trees of height two? I been stuck on this simple q...

8

What is the difference between a heap and BST? When to use a heap and when to use a BST? If you want to get the elements in a sorted fashion, is BST better over heap?
Stare asked 27/5, 2011 at 2:30

4

Is there a way to turn a Binary to a sorted array without having to traverse the tree for every array index? Node root; Node runner; int current_smallest; void findsmallest(Node root){ //Pre-ord...
Anciently asked 23/4, 2013 at 23:0

10

Until now, I have been writing a Node class as class Node { private value; private Node left; private Node right; public int getValue() { return value; } public void setValue(int value) ...
Bio asked 29/6, 2012 at 14:3

26

Solved

I was wondering if anybody could help me rework this method to find the height of a binary search tree. So far, my code looks like this. However, the answer I'm getting is larger than the actual he...
Schenk asked 8/4, 2010 at 4:47

4

I am new to Functional programming. The challenge I have is regarding the mental map of how a binary search tree works in Haskell. In other programs (C,C++) we have something called root. We store...

4

Solved

Hi I've made a simple Binary Tree and added a pre-order traversal method. After throwing around some ideas I got stuck on finding a way to return each value from the traverse_pre() method in an arr...

33

I read on here of an exercise in interviews known as validating a binary search tree. How exactly does this work? What would one be looking for in validating a binary search tree? I have written a...
Histoplasmosis asked 1/2, 2009 at 1:41

5

type BSTree a = BinaryTree a data BinaryTree a = Null | Node (BinaryTree a) a (BinaryTree a) deriving Show flattenTree :: BinaryTree a -> [a] flattenTree tree = case tree of Null -> [...
Downcome asked 9/10, 2019 at 12:24

4

Solved

Up until this point, I've been implementing Binary Search Trees with left and right pointers, like: template<typename T> struct BSTNode{ BSTNode* left; BSTNode* right; T data; } I came ...
Chazan asked 31/12, 2016 at 17:18

3

A particular search tree has 6 nodes at level 3. At the next level, there are 24 nodes. What is the branching factor at level 3? The answer is 4, but can someone tell me why, I thought that it was...
Swung asked 13/12, 2017 at 9:18

19

Solved

Given a node in a BST, how does one find the next higher key?
Interflow asked 29/3, 2011 at 11:25

14

This question was asked in a recent coding interview. Q : Given a binary tree, write a program to convert it to a doubly linked list. The nodes in the doubly linked list are arranged in a sequenc...
Brigid asked 16/7, 2012 at 20:18

2

Solved

Given a sorted array, it is very easy to visualize a BST from it in a top-down manner. For example, if the array is [1,2,3,4,5,6,7], we can see that the root will be the middle element, that is 4. ...
Battiste asked 2/10, 2012 at 10:12

© 2022 - 2024 — McMap. All rights reserved.