## How to Delete a Tree

[wpdm_package id=’1354′] Algorithm: [sourcecode lang=”cpp”] void DeleteBinaryTree(tree_node *root) { if(!root) return; DeleteBinaryTree(root->left); DeleteBinaryTree(root->right); free(root); } [/sourcecode]

## Check if two Trees are Mirrors of each other

[wpdm_package id=’1359′] Algorithm: Return true if both the trees are empty. Return false if only one of the tree is empty. Return false if root…

## Find the level with Maximum Sum in a Binary Tree

[wpdm_package id=’1361′] Algorithm: [sourcecode lang=”cpp”] int FindLevelWithMaxSum() { tree_node *temp; int level=0, maxLevel=0; std::queue<tree_node *> Q; int currentSum=0, maxSum=0; if(!root) return 0; Q.push(root); Q.push(NULL); while(!Q.empty())…

## How to Mirror a Binary Tree

[wpdm_package id=’1363′] Algorithm: Use Recursion. Find the left node and corresponding right node each time using recursion. Swap the nodes. [sourcecode lang=”cpp”] void MirrorOfBinaryTree(tree_node *root)…

## Implement 2 Stacks using 1 Array

Question – How do we implement 2 Stacks using 1 Array? One stack routines should not show a exception unless every slot in array is…

## Print the Root-to-Leaf Paths in a Binary Tree

[wpdm_package id=’1365′] Algorithm: Use Recursion. Store the data in each path in an array while you traverse. Traverse the left subtree and the right subtree.…

## Find the Height of a Binary Tree

[wpdm_package id=’1349′] Algorithm: Use recursion. Find the height of the left subtree. Find the height of the right subtree. Check which is maximum. The maximum…

## SAP Labs Coding Interview Question 1

[wpdm_package id=’1421′] Question – Reverse a string Conditions – i. I have to reverse word by word. ii. When I reverse a word the Last…

## Insert into a Binary Tree

[wpdm_package id=’1373′] Algorithm: Use the level order traversal or Breadth First Traversal. Insert the element where we find the left/right node as NULL. [sourcecode lang=”cpp”]…

## Checking if a String is Palindrome using Stacks

[wpdm_package id=’1375′] Algorithm: Create a Stack. Till the half of the string length, push the characters of the string into the stack. If it is…