Generate All Strings of n bits.

Objec­tive: Generate All Strings of n bits, consider A[0..n-1] is an array of size n.

Example :

n = 3

Output

:
[0, 0, 0]    [1, 0, 0]    [0, 1, 0]    [1, 1, 0]

[0, 0, 1]     [1, 0, 1]     [0, 1, 1]    [1, 1, 1]

Read more

Print the Bottom View of the Binary Tree.

Objec­tive: Given a binary tree, print it in Bottom View of it.

What is Bottom View: Bottom view means when you look the tree from the bottom the nodes you will see will be called the bottom view of the tree. See the exam­ple below.

Bottom View of a Binary Tree

as you can see in the example above,8, 4, 9, 5, 3, 7 is the bottom view of the given binary tree.

Read more

Inorder Predecessor and Successor in Binary Search Tree

Objective: Given a Binary Search Tree, Find predecessor and Successor of a given node.

What is Predecessor and Successor :

When you do the inorder traversal of a binary tree, the neighbors of given node are called Predecessor(the node lies behind of given node) and Successor (the node lies ahead of given node).

Example:

Inorder Predecessor and Successor in Binary Search Tree

Approach:

Read more

In an Array, find the Smallest Subarray with Sum Greater than the Given Value

Objective: Given an array and an integer, find the smallest subarray whose sum is greater than the given integer.

Examples:

arrA[] = { 1, 5, 20, 70, 8}
Integer = 97
Output : Min Length = 3 Subarray = [20, 70, 8]

 
arrA[] = { 1, 10, 3, 40, 18}
Integer = 50
Output : Min Length = 2 Subarray = [40, 18]

Approach:

Naive Approach: Use 2 loops. Time Complexity – O(n2).

Better Approach: Time Complexity – O(n)

Read more