Printing border nodes of Binary Tree

Given a Binary tree, Write code to print all the boundary nodes in counter clockwise order. For example, for the below binary tree, The output should be: A, B, D, H, I, F, G, C, A . Boundary Nodes are traversed in anti-clockwise order.

Null pointers in a Binary tree

Given a Binary Tree with n Nodes (you may arrange these nodes any way you want to). How many NULL pointers will be there ? You want options also :).. here are the options A) n         B) n+1         C) n-1         D) None

Sorting a linked list

Write a function to sort the given unsorted linked list. Input list: 6 -> 7 -> 0 -> 1 -> 8 -> 2 -> 4 -> 3 Output list: 0 -> 1 -> 2 -> 3 -> 4 -> 6 -> 7 -> 8

Next greater power of 2

Given an unsigned int n, find the integer greater than or equal to n which is a power of 2. For example: Input Output —– —— 6 8 12 16 64 64

Non-recursive solution to tower of hanoi

We discussed problem of Tower of Hanoi earlier and written a recursive function to solve the problem, Recursive functions take lot of extra memory (New activation record for each call on the stack) (A detailed analysis of recursion is done in this post of mine). Todays question is to write a Non-recursive function to solve […]

Tower of Hanoi code

Tower of Hanoi is a Mathematical Game. There are 3 pegs (Rods) and number of discs, each of different size, which can be inserted into the rods. All discs are initially inserted into one rod in increasing order (smallest at the top and largest disc at the bottom). You have to move all the discs […]

Find size of a struct without using sizeof operator

How will you find the size of a structure in C/C++ language without using sizeof operator. (Note: sum of sizes of all fields of a structure may not be equal to the exact memory allocated to the structure. See, Method-1 in solution).

Implement two stacks in one array

Given a linear memory (in the form of an array). Implement two stacks such that memory is used in an optimal manner. i.e if user wants to push an element in either of the two stacks, then the implementation should not give error until the entire array is full (So cannot use half array for […]