You are browsing the archive for 2010 September.

Print All Combinations of a Number as a Sum of Candidate Numbers

September 30, 2010 in backtracking

Given a target number, and a series of candidate numbers, print out all combinations, so that the sum of candidate numbers equals to the target.
Read the rest of this entry →

Serialization/Deserialization of a Binary Tree

September 29, 2010 in binary tree

Design an algorithm and write code to serialize and deserialize a binary tree. Writing the tree to a file is called ‘serialization’ and reading back from the file to reconstruct the exact same binary tree is ‘deserialization’.

Read the rest of this entry →

Saving a Binary Search Tree to a File

September 28, 2010 in binary tree

Describe an algorithm to save a Binary Search Tree (BST) to a file in terms of run-time and disk space complexity. You must be able to restore to the exact original BST using the saved format.

Read the rest of this entry →

How to Pretty Print a Binary Tree

September 18, 2010 in binary tree

Have you ever thought of pretty-printing a binary tree?
Read the rest of this entry →

Printing a Binary Tree in Zig Zag Level-Order

September 18, 2010 in binary tree

Given a binary tree, print out the tree in zig zag level order (ie, from left to right, then right to left for the next level and alternate between). Output a newline after the end of each level. Read the rest of this entry →

Binary Tree Level-Order Traversal Using Depth First Search (DFS)

September 17, 2010 in binary tree

Given a binary tree, print out the tree in level order (ie, from left to right, level by level). Output a newline after the end of each level. Breadth First Search (BFS) is not allowed. Read the rest of this entry →

Printing a Binary Tree in Level Order

September 16, 2010 in binary tree

Given a binary tree, print out the tree in level order (ie, from left to right, level by level). Output a newline after the end of each level. Read the rest of this entry →

Determine if a Binary Tree is a Binary Search Tree (BST)

September 14, 2010 in binary tree

Write a function isBST(BinaryTree *node) to verify if a given binary tree is a Binary Search Tree (BST) or not.

Read the rest of this entry →

Detecting a Loop in a Singly Linked List

September 11, 2010 in linked list

Given a singly linked list, find if there exist a loop.

Read the rest of this entry →

Splitting Linked List

September 11, 2010 in linked list

Given a list, split it into two sublists — one for the front half, and one for the back half. If the number of elements is odd, the extra element should go in the front list. So FrontBackSplit() on the list {2, 3, 5, 7, 11} should yield the two lists {2, 3, 5} and {7, 11}.

Read the rest of this entry →

Number of 1 bits

September 9, 2010 in bit operations

Write a function that takes an unsigned integer and returns the number of ’1′ bits it has. Read the rest of this entry →

Fun with Bit Operations

September 8, 2010 in bit operations

What does the following function mystery() do?

Read the rest of this entry →