Fundamentals of Algorithmic Problem Solving
Fundamentals of Algorithmic Problem Solving
statement completely.
Ask questions for clarifying the doubts about the problem.
Identify the problem types and use existing algorithm to find solution.
Input (instance) to the problem and range of the input get fixed.
b. Pseudo code
c. Flowchart
(v)Analyzing an Algorithm
a. For an algorithm the most important is efficiency. In fact, there are
(vi)Coding an Algorithm
a. The coding / implementation of an algorithm is done by a suitable
that does not change its value) outside the loop, collecting common
sub-expressions, replacing expensive operations by cheap ones,
selection of programming language and so on should be known to
the programmer.
d. Typically, such improvements can speed up a program only by a
2) Searching: The searching problem deals with finding a given value, called
which are connected by line segments called edges. Some of the graph
problems are graph traversal, shortest path algorithm, topological sort,
traveling salesman problem and the graph-coloring problem and so on.
Algorithms as a Technology.
There a huge number of real life applications where, algorithms play the major
and vital role. Few of such applications are discussed below.
Another great milestone is the Human Genome Project which has great
progress towards the goal of identification of the 100000 genes in human
DNA, determining the sequences of the 3 billion chemical base pairs that
make up the human DNA, storing this huge amount of information in
databases, and developing tools for data analysis. Each of these steps
required sophisticated and efficient algorithms.
Getting Started
In this section, we will discuss the need for analysis of algorithms and how to
choose a better algorithm for a particular problem as one computational
problem can be solved by different algorithms.
Algorithms are often quite different from one another, though the objective of
these algorithms are the same. For example, we know that a set of numbers
can be sorted using different algorithms. Number of comparisons performed
by one algorithm may vary with others for the same input. Hence, time
complexity of those algorithms may differ. At the same time, we need to
calculate the memory space required by each algorithm.
The algorithm analysis framework consists of the following:
Measuring an Input’s Size
Units for Measuring Running Time
Orders of Growth
Worst-Case, Best-Case, and Average-Case Efficiencies
Orders of Growth
A difference in running times on small inputs is not what really
distinguishes efficient algorithms from inefficient ones. Some common
orders of growth seen often in complexity analysis are:
O(1) constant
O(log n) logarithmic
O(n) linear
O(n log "n log n"
n)
O(n2) quadratic
O(n )
3
cubic
nO(1)
polynomial
2O(n) exponential
EXAMPLE:
Consider the Sequential Search algorithm
SequentialSearch(A[0..n - 1], K)
Clearly, the running time of this algorithm can be quite different for the same
list size n. In the worst case, there is no matching of elements or the first
matching element can found at last on the list. In the best case, there is matching
of elements at first on the list.
The worst-case efficiency of an algorithm is its efficiency for the worst case
input of size n. The algorithm runs the longest among all possible inputs of that
size.
The best-case efficiency of an algorithm is its efficiency for the best case input
of size n. The algorithm runs the fastest among all possible inputs of that size n.
In sequential search, If we search a first element in list of size n. (i.e. first
element equal to a search key).
The Average case efficiency lies between best case and worst case. To analyze
the algorithm’s average case efficiency, we must make some assumptions about
possible inputs of size n.