Optimal Binary Search Tree

Given a sorted array keys[0.. n-1] of search keys and an array freq[0.. n-1] of frequency counts, where freq[i] is the number of searches to keys[i]. Construct a binary search tree of all keys such that the total cost of all the searches is as small as possible.

Share

Directed and Undirected Graph

This is small notes about graphs, There are two types of graphs, By just looking at below image you will understand the different of these two graphs. In a directed graph direction matters. i.e. edge V2->V3 means that edge is directed. There is only an edge from V2 to V3 and no edge from V3… Read more

Share

Matrix Chain Multiplication

Given a sequence of matrices, find the most efficient way to multiply these matrices together. The problem is not actually to perform the multiplications, but merely to decide in which order to perform the multiplications. We have many options to multiply a chain of matrices because matrix multiplication is associative. In other words, no matter… Read more

Share

Matrix multiplication notes

Here this is a small notes for matrix multiplication, It is very useful for matrix related algorithms. Lets start with normal multiplication, For example we want to multiply 2 and 3, So normally we can do 2*3 = 6 OR 3*2 = 6 here you can see multiplication is commutative. But it is not always… Read more

Share

Next Higher Number

Find the next higher number with the same digits. Output : Next Highter Number from 1234 is :1243 Next Highter Number from 4132 is :4213 Next Highter Number from 4321 is :0 Next Highter Number from 32876 is :36278 Next Highter Number from 32841 is :34128 Algorithm

Share