Grokking the Art of Recursion for Coding Interviews
Ask Author
Back to course home

0% completed

10. Inserting a new node in a BST
Table of Contents

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Problem Statement

Write Recursive Approach to Insert New Node in a Binary Search Tree.

Given a binary search tree (BST) and a value to be inserted, write a recursive algorithm to insert a new node with the given value into the BST while maintaining its properties.

Examples

  1. BST Before Insertion:

    4 / \ 2 7 / \ 1 3

    Input Node: 5 Output BST:

    4 / \ 2 7 / \ / 1 3 5

    Explanation: The input node with value 5 is inserted as the left child of node 7.

2

.....

.....

.....

Like the course? Get enrolled and start learning!

Table of Contents

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible