# Month: October 2013

## Computer Graphics – Lab 19 Line with Stipple Patterns

Sample Input – Write a program to draw line with stipple patterns. Sample Output – [sourcecode lang=”cpp”] glEnable(GL_LINE_STIPPLE); glLineStipple(1,0x00ff); glBegin(GL_LINES); glVertex2f(100,100); glVertex2f(600,600); glEnd(); glFlush(); glDisable(GL_LINE_STIPPLE); [/sourcecode] To compile the above… Read more »

## Check if two Trees are Structurally Similar

Algorithm: Use Recursion. If both the trees are NULL, return true. If only one of the trees is NULL return false. Recursively find if all pairs of corresponding left nodes… Read more »

## How to Delete a Tree

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

Algorithm: Return true if both the trees are empty. Return false if only one of the tree is empty. Return false if root data of one tree is different from… Read more »

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

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()) { temp=Q.front(); Q.pop(); if(temp==NULL) { if(currentSum>maxSum) {… Read more »

## How to Mirror a Binary Tree

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) { tree_node *temp; if(root) { MirrorOfBinaryTree(root->left); MirrorOfBinaryTree(root->right);… Read more »

## 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 used? Answer – Start two… Read more »

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

Algorithm: Use Recursion. Store the data in each path in an array while you traverse. Traverse the left subtree and the right subtree. At the end of each path, ie… Read more »

## Find the Height of a Binary Tree

Algorithm: Use recursion. Find the height of the left subtree. Find the height of the right subtree. Check which is maximum. The maximum height + 1 will be returned.

## SAP Labs Coding Interview Question 1

Question – Reverse a string Conditions – i. I have to reverse word by word. ii. When I reverse a word the Last alphabet of word should be printed as… Read more »