Close

Traversals of a binary tree

Traversal algorithms of non-linear data structures like trees are designed to visit/print all the elements in that structure. There are three main traversals of the binary tree. Namely In-order traversal Post-order traversal Pre-order traversal In addition to these, there are inverses of the above algorithms, and there is a level order traversal. In this post…

Subset sum problem

Given a set of numbers and a target value, we have to find if there is any subset whose sum is equal to the target value. For example let the array be {10, 34, 19, 27, 58, 45} and the target sum is 56, we have a subset {10,19,27} with the given sum. We don’t…

Jolly jumpers problem

In this post I introduce you to a competitive programming problem called Jolly jumpers. This problem is available on UVa online judge on this link.  UVa site is one of the first online judge websites which listed programming problems from different competitions like ACM ICPC and IOI and allowed users to solve and submit their…

Searching for an element in the sorted matrix

Given a row wise and column wise sorted two dimensional array or matrix. How to search for an element efficiently? Example of the array can be int[][] matrix = {                   {1,3,5,7,9},                   {10,12,14,16,18},                   {19,21,23,25,27},                   {28,30,32,34,36},                   {37,39,41,43,45}                }; This can be done using the following algorithm.  We start our search with the top right element.  If it…