Week 7 – CST370 – Design and Analysis of Algorithms
This week we learned about several programing techniques and
algorithms. We started with counting sort, which is an algorithm that does not
use comparison to sort. It is used to sort integer values in a range. The next
algorithm we studied was the Radix sort algorithm. This algorithm is also non-comparison
based and sorts numbers composed of digits and no range is required. You need
to use the counting sort algorithm on each digit, and you sort them using the
range 0-9 for decimal numbers.
We also covered dynamic programming. This is an algorithm
design technique for solving problems with overlapping subproblems. Instead of
solving overlapping subproblems over and over, you solve them once and record
the results in a table from which a solution to the original problem can then
be obtained. An example of this technique can be illustrated using Fibonacci Numbers
where you must compute F(n) by adding F(n-1) + F(n-2) for n > 1. With
Dynamic programming, we can use an array to keep the results of the previous
two functions such as F[i] = F[i – 1] + F[i – 2].
The last three algorithms; Warshall’s Algorithm, Floyd’s Algorithm,
and Prim’s Algorithm deal with graph traversals. Warshall’s and Floyd’s algorithms
are based on a similar idea. Warshall’s algorithms uses transitive closure of a
directed graph with n vertices and an n x n Boolean matrix. The cells in this
matrix will have a 0 or a 1 if there exists a nontrivial path from the ith vertex
to the jth vertex. Floyd’s algorithm uses a similar technique to find the
lengths of the shortest paths from each vertex to all other vertices given a
weighted connected graph.
Prim’s Algorithm connects vertices in the cheapest way
possible so that there will be a path between every pair of points using a
minimum spanning tree (MST). First, we start with a tree T1 consisting
of a vertex. Next, we grow T1 by adding one vertex at a time. Next,
we construct Ti + 1 from T1 by adding a vertex not in Ti that
is closest to those already in Ti. Finally, we continue until all
the vertices are included.
Comments
Post a Comment