Topic — Add New » Posts Last Poster Freshness
Amazon Banglore Online Written 4 kartik 1 week

You are given a function getInorderSuccessor which takes a BST (Binary Search Tree) as it's parameter. Every node has an extra pointer "next" , which is intialized to null, fill next with node pointers which represent Inorder Successor.

In a binary tree, inorder successor of a node is the next node in inorder traversal of the binary tree. Inorder successor is NULL for the last node in inorder traversal.

In BST, inorder successor of an input node can also be defined as the node w...

Traversal of binary search trees 4 1 week

I came across this problem about In-order Traversal of binary search tree without using a stack or recursion. Hint says to assume that testing of pointers for equality is a legitimate operation.I'm stuck finding the solution to this problem. Please give me some direction. I'm not looking for the code. Just give me the right direction.

inbuilt container for building a balanced BST in stl c++ 1 gaurav 1 week

let say we want to build a binary search tree(BST) in a c++.
we can use a map for that.
map builts the "balanced" BST in the form of red black tree.

now we want to a built a balanced BST in which we also want to modify the contents of
internal nodes while inserting a node in bst.
e.g each node has a member 'count' which is equal to number of nodes in left subtree. In this case
we need to modify internal nodes too.
In this case which inbuilt contain...

Largest Binary Search Tree in a given Binary Tree 8 aayush kumar 2 weeks

Given a binary tree, find the largest binary SEARCH tree in this binary tree.

When I mean largest, the tree with maximum number of nodes. And the binary search tree should be a sub-tree in the given binary tree.

Note: Not every binary tree is a binary search tree

Binary Tree to BST 14 Abhi 2 weeks

convert a binary tree to binary search tree inplace. We cant use any extra space.

binary search tree 1 1 month

Help! My home work is to create a binary search tree with integers.

The program below print out inorder, preorder, postorder traversals. How do I code to get number of leaf nodes, number of nodes with one child, number of nodes with two child, max and min leaf nodes, height of tree and if the tree is balanced?

_____________________________________________________

#include <iostream>
using namespace std;

const int nil = 0;
class treenode_type ...

Amazon Interview Question for Software Engineer/Developer (More than 5 Years) 11 1 month

A Binary tree ( Need not be BST) node has three pointers. Left child, right child and parent pointer. Another pointer is added called ExtraID which points to either NULL or one of the inorder successor. Inorder successor means , if we list nodes in InOrder, Inorder successor is a valid node on right side of the node in the list. Find an O(n) algorithm to analyze a given binary tree and identify nodes with invalid ExtraIDs.

Amazon
Given a node of BST, make it the root 5 vpshastry 2 months

Given a node of a BST, modify it in such a way that the given node becomes the root. The tree should still be BST. One way I could get is store the Inoder traversal of the tree. Find that node in the traversal and recursively make the BST.

Convert a BST into a sorted doubly linked list (No extra space allowed) 4 3 months
node *BST_to_list ( Node *n) {

    if (!n) return NULL;

    Node *left = BST_to_list (n->left);
    Node *right = BST_to_list (n->right);
    Node *origLeft = left;

    // Left and Right trees have been converted to linked lists,
   //  now merge them along with the current node.

    if (left) {
        while (left->left)  // leftNode pointer becomes the next pointer in the DLL.
            left = left->left;
        left->left = node;
    }
    node->right = left;  /...
no of nodes in a bst 2 kartik 3 months

wrute a c program to calculate the no of nodes in a bst

Merge two BSTs 5 3 months

Problem: Merge two BSTs .

#include<iostream>

class node{
 public:
  int d;
  node* l;
  node* r;
 node(int x):d(x),l(0),r(0){}
};
void add(int x,node *&a){//lower or equal value to the left BST
  if(!a)a=new node(x);
  else if(x>a->d)add(x,a->r);
  else add(x,a->l);
}
void print(node *a){
  if(a){
    print(a->l);
    std::cout<<a->d<<" ";
    print(a->r);
  }
}
void merge(node *&a,node *&b){//merge b into a
  if(b==0)return;
  els...
implement a stack (push and pop) using binary search tree 5 3 months

how to implement a stack (push and pop) using binary search tree??

Median of BST 9 4 months

Given a BST (Binary search Tree), how will you find median in that?
Constraints:
-No extra memory.
- Algorithm should be efficient in terms of complexity.

Convert Zig Zag level order Traversal of Tree to Doubly Linked List 14 5 months

Consider a Binary Tree. Binary tree must be converted to a doubly linked list in Zig Zag level order Traversal in constant space i.e in place without creating extra nodes .
Conditions :
1)The right pointer of the node must be the next pointer in the doubly linked list.
2)The left pointer of the node must be the previous pointer in the doubly linked list.
For Example consider the below Binary Tree

                                            1
                 ...
Trees 4 Mani 6 months

Given a binary tree , return the root of the largest BST in it if present else return null.

Trees 6 6 months

How do I find kth largest element in a BST ?

Google Interview Question about Trees 3 Anand 6 months

Least common ancestor of a binary tree, BST ? complexity ?