In a Binary Search Tree (BST), all keys in left subtree of a key must be smaller and all keys in right subtree must be greater. So a Binary Search Tree by definition has distinct … Read More
Binary Search Tree
Difference between a LinkedList and a Binary Search Tree BST
Pointers
In a linked list, the items are linked together through a single next pointer.
Next Nodes
In a binary tree, each node can have 0, 1 or 2 subnodes, where (in case of a … Read More
K’th Largest Element in BST when modification to BST is not allowed
Given a Binary Search Tree (BST) and a positive integer k, find the k’th largest element in the Binary Search Tree.
Common Ancestor in a Binary Tree or Binary Search Tree
We need to find a Least Common Ancestor of Two given nodes in Binary tree.
[1] / \ [2] [3] / \ / \ [4] [5] [9] [10] / / \ [8] [6] [7]
say
Check Binary Tree is Binary Search Tree or not
To search Binary Search Tree
First lets understand characteristics of BST
• The left subtree of a node contains only nodes with keys less than the node’s key.
• The right subtree of a node
… Read More First lets understand characteristics of BST
• The left subtree of a node contains only nodes with keys less than the node’s key.
• The right subtree of a node
Linked List V/S Binary Search Tree
Linked List :
Node(1) -> Node(2) -> Node(3) -> Node(4) -> Node(5) -> Node(6) -> Node(7)
- In linked list, the items are linked together through a single next pointer.
- Next Node’s Key Can be larger