Insertion in a BST – Iterative and Recursive Solution
A Binary Search Tree (BST) is a rooted binary tree, whose nodes each store a key (and optionally, an associated value), and each has two distinguished subtrees, commonly denoted left and right.
Ace your Coding Interview
Get hired by top tech companies with our comprehensive interview preparation.
Get StartedA Binary Search Tree (BST) is a rooted binary tree, whose nodes each store a key (and optionally, an associated value), and each has two distinguished subtrees, commonly denoted left and right.
Given a binary tree, write an iterative and recursive solution to traverse the tree using inorder traversal in C++, Java, and Python.
Given a binary tree, write an iterative and recursive solution to traverse the tree using preorder traversal in C++, Java, and Python.
Given a binary tree, write an iterative and recursive solution to traverse the tree using postorder traversal in C++, Java, and Python.
Given a binary tree, print its nodes level by level in reverse order, i.e., print all nodes present at the last level first, followed by nodes of the second last level, and so on… Print nodes at any level from left to right.
Given a binary tree, print its nodes level by level in spiral order, i.e., all nodes present at level 1 should be printed first from left to right, followed by nodes of level 2 right to left, followed by nodes of level 3 from left to right and so on…
Given a binary tree, print its nodes level by level, i.e., print all nodes of level 1 first, followed by nodes of level 2 and so on… Print nodes for any level from left to right.
This post will detect cycles in a linked list using hashing and Floyd’s cycle detection algorithm.
Given a linked list, sort it using the merge sort algorithm. Merge sort is an efficient, general-purpose sorting algorithm that produces a stable sort, which means that the implementation preserves the input order of equal elements in the sorted output.
Given a string and a dictionary of words, determine if the string can be segmented into a space-separated sequence of one or more dictionary words.
The longest alternating subsequence is a problem of finding a subsequence of a given sequence in which the elements are in alternating order and in which the sequence is as long as possible.
Given an unlimited supply of coins of given denominations, find the total number of distinct ways to get the desired change.