Download as pdf or txt
Download as pdf or txt
You are on page 1of 19

Analysis and Design of Algorithms Unit 1

Unit 1 Introduction to Algorithms


Structure:
1.1 Introduction
Objectives
1.2 Concept of Algorithm
Etymology
Definitions of Algorithm
1.3 Role of Algorithm in Computing
Analysis and design of algorithms
Properties of algorithms
Algorithm, program and psuedocode
Use of algorithms in computing
1.4 Fundamentals of Algorithm
Asymptotic notations
Time and space complexity and efficiency
1.5 Important Types of Algorithm
Simple recursive
Backtracking
Divide and conquer
Dynamic programming
Greedy algorithms
Branch and bound algorithms
Brute force algorithms
Randomized algorithms
1.6 Fundamental Data Structures
Data structure definition
Use of data structure
Data structure classification
Data structure characteristics
1.7 Summary
1.8 Glossary
1.9 Terminal Questions
1.10 Answers

Sikkim Manipal University B1480 Page No. 1


Analysis and Design of Algorithms Unit 1

1.1 Introduction
We use algorithms to solve problems in a systematic way. It is difficult to
give a single specific definition for an algorithm. Different fields of
development and study use algorithms to solve their own problems.
Levitin defines algorithm as given below:
“An algorithm is a sequence of unambiguous instructions for solving a
problem, i.e., for obtaining a required output for any legitimate input in a
finite amount of time.”
This unit covers the various definitions of algorithm, its types, properties and
the steps for designing it. This unit gives a brief idea on solving a problem
using different algorithmic problem solving techniques. It also introduces
various data structures, their classification and characteristics.
Objectives:
After studying this unit, you should be able to:
 define ‘Algorithm’
 explain the role of algorithm in computing
 describe the fundamentals of algorithms
 list the important types of algorithms
 describe the fundamental data structures

1.2 Concept of Algorithm


We use computers to solve lots of problems in a fast and accurate way.
Therefore we need efficient algorithms for every process in a computer. The
concept of algorithms is in use from the early years of computation and
study. Let us start with the etymology of algorithms. We will also study the
different definitions of algorithms used to solve problems in different areas.
1.2.1 Etymology
The word ‘algorithm’ is derived from the name of Abu Abdullah Muhammad
Ibn Musa al-Khwarizmi, a 9th-century Persian mathematician, astronomer,
geographer and scholar. This scholar wrote the first book on systematic
solution of linear and quadratic equations namely Kitab al-Jabr wa-l-
Muqabala. The rules for performing arithmetic using Arabic numerals were
originally known as ‘algorism’ but later in the 18th century it was changed to
‘algorithm’.

Sikkim Manipal University B1480 Page No. 2


Analysis and Design of Algorithms Unit 1

1.2.2 Definitions of algorithm


An algorithm is defined as a set of well defined instructions used to
accomplish a particular task. It is considered as the cornerstone of good
programming. The efficiency of algorithms depends upon speed, size and
resource consumption. Different algorithms may finish the same process
with a different set of instructions in more or less time, space, or effort than
others. There is no fixed definition for an algorithm. It varies according to the
area of use.
Various definitions of algorithms are given below:
 It is the exact set of instructions describing the order of actions to
achieve the result of the decision problem in finite time – (Old
interpretation).
 "Algorithm is a finite set of rules that defines the sequence of operations
to solve a specific set of goals and has five important features:
finiteness, definiteness, input, output, efficiency" – (D. Knuth).
 "Algorithms are all systems of calculations performed on strictly defined
rules, which, after a number of steps obviously leads to the solution of
the problem" – (A. Kolmogorov).
 "Algorithm is the exact prescription, defining the computing process,
going from the variable input data to the desired result" – (A. Markov).
 "Algorithm is the exact requirement of the performance in a specific
order of certain operations, leading to the solution of all problems of this
type" – (Philosophical dictionary, ed. M. Rosenthal).
Self Assessment Questions
1. The rules for performing arithmetic using Arabic numerals were originally
known as _____________.
2. The efficiency of algorithms depends upon ____________, ________
and __________ consumption.
3. An algorithm is considered as the cornerstone of ____________.

1.3 Role of Algorithm in Computing


In the previous section we discussed the definitions and basic use of
algorithms. Now, let us see how algorithms are used for computing.
We believe that a computer can do anything and everything that we
imagine. But the truth is that the computers work on algorithms written by

Sikkim Manipal University B1480 Page No. 3


Analysis and Design of Algorithms Unit 1

humans themselves! We need to write more software algorithms due to the


increasing complexity of computers. Algorithms are available for many
different applications and highly advanced systems such as artificial
intelligence. These algorithms may become common in the future.
1.3.1 Analysis and design of algorithms
Analysis of algorithm means to study the specification of the algorithm and
come to conclusions about how the implementation of that algorithm will
perform in general. To analyse an algorithm means to determine the amount
of resources necessary to execute it. Analysis of algorithm gives the
following output:
 Total or maximum memory space needed for the data
 Total size of the code
 Correctness of the result
 Complexity of the process
 Robustness of the process
Most algorithms can work with inputs of arbitrary length. We usually state
the efficiency or running time of an algorithm as a function relating the input
length to the number of steps (time complexity) or storage locations (space
complexity).
Algorithm analysis provides theoretical estimates for the resources needed
by any algorithm which solves a given computational problem. An important
result of analysing is that it allows you to make a quantitative judgment
about the value of one algorithm over another.
Designing an algorithm is the process of creating an algorithm that meets all
the output of analysis phase. Algorithm design is a specific method to create
a mathematical process in solving problems.
We need to consider the following points while designing an algorithm:
 Optimize the algorithm
 Choose proper data structures
 Recognize the problems
 Resolve the problems using well-researched standard problems
Once an algorithm is devised, it is necessary to show that it computes the
correct answer for all legitimate inputs. This process is known as algorithm
validation.
Sikkim Manipal University B1480 Page No. 4
Analysis and Design of Algorithms Unit 1

1.3.2 Properties of algorithms


An algorithm may have zero or more inputs externally and it should produce
one or more output. Also, an algorithm must terminate after a finite number
of steps. Properties of algorithm include:
 Correctness – It should provide correct and accurate output for all
legitimate input.
 Definiteness – Each instruction should be clear, precise and
unambiguous. Input and output must be well defined.
 Finiteness – When we trace out the instructions of an algorithm, it has
to terminate after a finite number of steps, for all cases.
 Effectiveness – Every instruction must be very basic so that it can be
carried out in principle, by a person using only pencil and paper.
 Generality – Algorithms need to have general instructions which can be
applied in any case.
1.3.3 Algorithm, program and psuedocode
An algorithm is a finite set of unambiguous statement to solve a problem in
finite amount of time. It can be natural language expressions designed for
any common man.
A program can be called as an algorithm implemented using the required
data structures. It is the expression of an algorithm in a programming
language with all the language specific codes. Procedure, function and
subroutine are synonyms for a program.
A pseudocode is a compact, informal environment-independent description
of a computer programming algorithm. It uses the structural conventions of a
programming language, but only humans can read it and not machines.
Pseudocode omits details that are not essential for human understanding of
the algorithm, such as variable declarations, system-specific code and
subroutines. There is no specific standard for pseudocode syntax.
Consider the example of bubble sort, which is a straightforward and
simplistic method of sorting an array of numbers.
Algorithm for bubble sort
1) Traverse the array from the beginning to the end
2) For each item, compare it to the next item.
3) If the item is larger than the next item, swap them.
4) Do the same again for all items except the last item.
Sikkim Manipal University B1480 Page No. 5
Analysis and Design of Algorithms Unit 1

5) Do it again for all items except the last two items, and so on.
6) Sort the array when there are only two items left and they have been
swapped (if necessary).
The C program for bubble sort is given below:

C Program for bubble sort


#include<stdio.h>
#include<conio.h>
#define SIZE 5
void main()
{
int a[SIZE],n,i,j,temp;
clrscr();
printf("enter the elements ");
for(i=0;i<SIZE;i++)
scanf("%d",&a[i]);
printf("the sorted list is :->\n");
for(i=0;i<SIZE;i++)
for(j=i;j<SIZE-i;j++)
if(a[j]>a[j+1])
{ temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
for(i=0;i<SIZE;i++)
printf("%d",a[i]);
getch();
}

Sikkim Manipal University B1480 Page No. 6


Analysis and Design of Algorithms Unit 1

1.3.4 Use of algorithms in computing


We use algorithms to perform various logical and mathematical operations
such as sorting, searching, merging, logic programming, matrix processing,
parsing, predicting statistics, solving basic geometric problems, displaying
graphics and performing common mathematical calculations.
Sorting algorithms arrange the data elements in a specific order. It can be in
ascending or descending order. Internal sorting is a type of sorting which
arranges data internally in the memory of the computer. Algorithms become
more sophisticated when the number of elements to be sorted is more.
Searching is the process where a particular element is looked up in a
collection of elements. The two basic searching algorithms are linear search
and binary search. Linear search looks up a sequence of data objects one
by one. Binary search is a sophisticated search and is faster than linear
search.
We use merging algorithms to combine sets of elements to form a single set
according to some criteria. Programming uses merge sort which is a basic
algorithm.
Algorithms that manipulate strings include those that arrange text data into
lines and paragraphs or search for occurrences of a given pattern in a
document.
Science and engineering field have a wide range of applications that use
algorithms. Basic algorithms for mathematical computation include those for
generating random numbers, performing operations on matrices, solving
simultaneous equations, and numerical integration.

Activity 1
Write a sorting algorithm, its psuedocode and the program in any
language.

Self Assessment Questions


4. To analyze an algorithm is to determine the amount of ________
necessary to execute it.
5. __________ algorithms are used to combine to sets of elements to form
a single set according to some criteria.

Sikkim Manipal University B1480 Page No. 7


Analysis and Design of Algorithms Unit 1

6. ___________ is the expression of an algorithm in a programming


language with all the language specific codes.

1.4 Fundamentals of Algorithm


Now that we have studied the role of algorithm in computing, let us discuss
the some fundamentals of algorithms.
Algorithms are widely used in various areas of study. We can solve different
problems using the same algorithm. Therefore, all the algorithms must
follow a common standard. In this section we discuss these standards.
1.4.1 Asymptotic notations
A problem may have various algorithmic solutions. In order to choose the
best algorithm for a particular process, you need to be able to judge how
much time a particular solution will take to run. More accurately, you need to
be able to judge how much time two solutions will take to run, and choose
the better of the two.
Asymptotic complexity expresses the main component of cost of the
algorithm. Consider the algorithm for sorting a deck of cards, which
proceeds by repeatedly searching through the deck for the lowest card. The
actual time to perform search and sort each card depends upon the
processor speed. Therefore, we use the below given asymptotic notations to
make the task easier.
Big-O notation – Big-O is the method of expressing the upper bound of the
running time of an algorithm. It is a measure of the longest amount of time it
could possibly take for the algorithm to complete.
For two non-negative functions, f(n) and g(n), if there exists an integer n 0
and a constant c > 0 such that for all integers n > n0, f(n) ≤ cg(n), then f(n) is
Big O of g(n). This is denoted as "f(n) = O(g(n))". If graphed, g(n) serves as
an upper bound to the curve you are analyzing, f(n).
Big-Omega notation – It describes the best that can happen for a given
data size. This has the same definition as Big-O, except that "f(n) ≥ cg(n)",
this makes g(n) a lower bound function, instead of an upper bound function.
For non-negative functions, f(n) and g(n), if there exists an integer n0 and a
constant c > 0 such that for all integers n > n0, f(n) ≥ cg(n), then f(n) is
omega of g(n). We denote this as "f(n) = Ω(g(n))".

Sikkim Manipal University B1480 Page No. 8


Analysis and Design of Algorithms Unit 1

Theta notation – For non-negative functions, f(n) and g(n), f(n) is theta of
g(n) if and only if f(n) = O(g(n)) and f(n) = Ω(g(n)). We denote this as
"f(n) = Θ(g(n))". This implies that the function, f(n) is bounded both from the
top and bottom by the same function, g(n).
Little-O notation – For non-negative functions, f(n) and g(n), f(n) is little o of
g(n) if and only if f(n) = O(g(n)), but f(n) ≠ Θ(g(n)). We denote this as
"f(n) = o(g(n))". This represents a loose bounding version of Big O. g(n)
bounds from the top, but it does not bound the bottom.
Little Omega notation – For non-negative functions, f(n) and g(n), f(n) is
little omega of g(n) if and only if f(n) = Ω(g(n)), but f(n) ≠ Θ(g(n)). We denote
this "f(n) = ω(g(n))".
1.4.2 Time and space complexity and efficiency
The efficiency of algorithms strongly depends on the time and space
complexity. Let us see how it affects the algorithm.
Time complexity – It is a function that describes the time of execution of an
algorithm based on its input parameters. In complex algorithms it is difficult
to find the exact time taken. Therefore we find the order of the functions
expressed in Big-O notation using the asymptotic notations. Complexity
classes are equivalence classes of time complexities which are equal in
Big-O notation. There are meta-complexity classes of time complexities
which have Big-O notations that differ only by some specific parameter. For
instance, O(n2) and O(n3) are both polynomial time complexity classes,
similarly O(2n) and O(3n) are exponential time complexity classes.
The time T(p) taken by a program P is the sum of the compile time and the
runtime. The compile time does not depend on the instance characteristics.
Also we may assume that a compiled program will run several times without
recompilation. So we concern ourselves with just the runtime of a program.
This runtime is denoted by tp. Therefore time complexity can also be known
as the number of instructions which a program executes during its run time.
Space complexity – Space complexity is defined as the amount of memory
that an algorithm needs. A good algorithm minimizes the memory needed.
The space needed by algorithm is the sum of the following components:
 A fixed part that is independent of the characteristics of the input and
outputs. This part typically includes the instruction space, space for
Sikkim Manipal University B1480 Page No. 9
Analysis and Design of Algorithms Unit 1

simple variables and fixed size component variables, space for constant
and so on.
 A variable part that consist of the space needed by components
variables whose size is dependent on the particular problems instance
being solved, the space needed by referenced variables and the
recursion stack space.
The space requirement S(p) of any algorithm P may therefore be written as
S(p) = C+ Sp(instance characteristics), where C is a Constant.
Self Assessment Questions
7. An algorithm that invokes itself within the process is called _______.
8. ______ is the method of expressing the upper bound of an algorithm's
running time.
9. _____________ is defined as the number of memory cells which an
algorithm needs.

1.5 Important Types of Algorithm


Now that we have an idea about the different notations and complexity of
algorithms, let us study some commonly known classification of algorithms.
We group algorithms that use similar problem-solving techniques together.
Let us now discuss the different types of algorithms.
1.5.1 Simple recursive
A simple recursive algorithm solves the basic problems using recursion. It
converts the solution to a simpler sub problem to arrive at the correct
solution. It is called simple because several of the other algorithm types are
inherently recursive.
Example of a recursive algorithm:
To count the number of elements in a list:
1) If the list is empty, return zero; otherwise go to step 2.
2) Leave the first element and go to step 3.
3) Count the element remaining and add one to the result.
4) Start again from step 1.
1.5.2 Backtracking
Backtracking algorithms are based on a depth-first recursive search. It can
be applied only for problems which have the concept of a partial candidate

Sikkim Manipal University B1480 Page No. 10


Analysis and Design of Algorithms Unit 1

solution and a quick test of whether it can possibly be completed to a valid


solution.
 It first tests to see if a solution has been found, and if so, returns it
otherwise;
1) For each choice that can be made at this point, make that choice
2) Recur
 If the recursion returns a solution, return it
 If no choices remain, return failure
Example of backtracking algorithm:
Backtracking is used for the eight queens puzzle, that gives all
arrangements of eight queens on a standard chessboard so that no queen
attacks any other. In the common backtracking problems, the partial
candidates are arrangements of k queens in the first k rows of the board, all
in different rows and columns. We can abandon any partial solution that
contains two mutually attacking queens since it cannot possibly be
completed to a valid solution.
1.5.3 Divide and conquer
We use divide and conquer algorithms when there are two or more
recursive calls. A divide and conquer algorithm consists of two parts:
 Divide the problem into smaller sub parts of the same type, and solve
these sub parts recursively.
 Combine the solutions to the sub parts into a solution to the original
problem.
Examples of divide and conquer algorithm:
 Quick sort:
1) Split the array into two parts, and quick sort each of the parts
2) No additional work is required to combine the two sorted parts
 Merge sort:
1) Cut the array in half, and merge sort each half
2) Combine the two sorted arrays into a single sorted array by merging
them
1.5.4 Dynamic programming
A dynamic programming algorithm stores the previous results and uses
them to find new ones. We generally use dynamic programming for
optimization problems. It finds the best solution from the possible ones.

Sikkim Manipal University B1480 Page No. 11


Analysis and Design of Algorithms Unit 1

Dynamic programming algorithms require optimal substructure and


overlapping sub problems:
 Optimal substructure: Optimal solution contains optimal solutions to
sub problems.
 Overlapping sub problems: Overlapping sub problems are solutions to
sub problems that can be stored and reused in a bottom-up manner.
This differs from divide and conquer algorithm, where sub problems
generally need not overlap.
Example of dynamic programming algorithm:
The steps required to find the nth Fibonacci number is given as follows:
1) If n is zero or one, return one; otherwise,
2) Compute or look up in a table, Fibonacci (n-1) and Fibonacci (n-2)
3) Find the sum of these two numbers
4) Store the result in a table and return it
Since finding the nth Fibonacci number involves finding all smaller Fibonacci
numbers, the second recursive call has little work to do and the solutions
thus formed may be preserved and used again later.
1.5.5 Greedy algorithms
An optimization problem is one in which you want to find, not just a solution,
but the best solution. It works by making the decision that seems most
promising at any moment. It never reconsiders this decision, irrespective of
the situation that arises later. It works to achieve a local optimum at each
step and finally finds the global optimum.
Example of greedy algorithm:
Counting money: Suppose you want to count out a certain amount of
money, using the fewest possible notes and coins. A greedy algorithm that
would do this would be:
At each step, take the largest possible note or coin.
Example: To make Rs.6.39, you can choose:
1) a Rs. 5 note
2) a Rs.1 note , to make Rs. 6
3) a 25p coin, to make Rs. 6.25
4) A 10p coin, to make Rs. 6.35
5) four 1p coins, to make Rs. 6.39
Here, the greedy algorithm always gives the optimum solution.
Sikkim Manipal University B1480 Page No. 12
Analysis and Design of Algorithms Unit 1

1.5.6 Branch and bound algorithms


We use branch and bound algorithms generally for optimization problems.
We form a tree of sub problems in branch and bound algorithm. We
consider the original problem to be the “root problem”. We use a method to
construct an upper and lower bound for a given problem.
At each node, apply the bounding methods:
 If the bounds match, it is taken as a feasible solution to that particular sub
problem.
 If bounds do not match, split the problem represented by that node, and
make the two sub problems into children nodes.
Continue, using the best known feasible solution to solve every other node
of the tree.
Example of branch and bound algorithm:
Travelling salesman problem: A salesman has to visit each of n cities once
and wants to minimize the total distance traveled:
 Consider the root problem to be the problem of finding the shortest route
through a set of cities visiting each city once
 Split the node into two child problems:
1) Shortest route visiting city A first
2) Shortest route not visiting city A first
 Continue subdividing similarly as the tree grows
1.5.7 Brute force algorithms
A brute force algorithm simply tries all possibilities until a satisfactory
solution is found. Brute force algorithm is:
 Optimizing: It finds the best solution. This may require finding all
solutions. But, if a value for the best solution is known, it may stop when
any best solution is found. Finding the best path for a travelling
salesman is an example.
 Satisfying: It stops as soon as a solution is found that is good enough.
Finding a travelling salesman path that is within 20% of optimal is an
example.
Often, brute force algorithms take exponential time to find a solution. We
can use various heuristics and optimizations to improve brute force
algorithm.

Sikkim Manipal University B1480 Page No. 13


Analysis and Design of Algorithms Unit 1

 Heuristic: A thumb rule that helps you decide which possibilities to look
at first.
 Optimization: A way to eliminate certain possibilities without fully
exploring them.
1.5.8 Randomized algorithms
A randomized algorithm or a probabilistic algorithm uses a random number
at least once during the computation to make a decision. It employs a
degree of randomness as part of its logic.
Examples of randomized algorithm are:
 Quick sort uses a random number to choose a pivot
 Trying to factor a large prime by choosing random numbers as possible
divisors
Self Assessment Questions
10. A ____________ algorithm converts the solution to a simpler sub
problem to arrive at the correct solution.
11. A ______________ algorithm simply tries all possibilities until a
satisfactory solution is found.
12. ___________ algorithms are based on a depth-first recursive search.

1.6 Fundamental Data Structures


Now that we have seen the classification of algorithms, let us study the
fundamentals of data structures. We require various data structures while
programming. Every data structure that we choose for a particular program
depends on the basic objective of the program.
1.6.1 Data structure definition
A data structure is a set of data elements grouped together under one
name. It means a set of rules that hold the data together. The data elements
are also known as members and can have different types and different
lengths. Data structures can have other data structures. This is known as
nesting of data structures. Modern programming languages allow the
programmer to create user-defined data structures.
1.6.2 Use of data structure
Almost all computer programs use data structures. Data structures are an
essential part of algorithms. We can use it to manage huge amount of data

Sikkim Manipal University B1480 Page No. 14


Analysis and Design of Algorithms Unit 1

in large databases. Some modern programming language emphasis more


on data structures than algorithms. We use data structures such as priority
queue, binary heaps, and binomial heaps to build complex algorithms.
1.6.3 Data structure classification
There are many data structures that help us to manipulate the data stored in
the memory. Let us study the different data structure classifications in this
section.
Primitive and Non-primitive Data Structures – Primitive data structures
are the basic data structures that can be used directly in machine
instructions. Examples of primitive data structures are integer, character,
Boolean, string, double, float. Non primitive data structures are the data
structures that are derived from primitive data structures. Examples of non
primitive data structures are array, stack, queue, list etc.
Array – It is a set of same data elements grouped together. Arrays can be
one dimensional or multi dimensional. We store elements in an array in
continuous locations and identify the array using the location of the first
element of the array.
Stack – It is a last in first out (LIFO) data structure. The fundamental
operations performed on a stack are push and pop. Push is used to insert
an element into the stack and pop is used to retrieve an element from the
stack. The stack operations are shown in figure 1.1.

Figure 1.1: Stack Operations

Sikkim Manipal University B1480 Page No. 15


Analysis and Design of Algorithms Unit 1

Queue – It is a first in first out (FIFO) data structure. The basic operations
on a queue are enqueue and dequeue. Enqueue is used for insertion and
dequeue is used for retrieval of elements
List – It is a sequence of data elements connected to each other where
every element has a link field which refers to the location of the next
element. Different types of lists are linked list, doubly linked lists, skip list,
jump list etc.
Tree – It is a hierarchical representation of elements as nodes linked with
each other. The fist element of the tree structure is known as the root. Each
node has a sub node known as child node. The node without a child node is
known as leaf node. Binary tree is a type tree structure.
Homogeneous and heterogeneous data structures – Non primitive data
structures can be homogenous or heterogeneous. Homogeneous data
structure has all the elements of same data type in it. Example of a
homogeneous data structure is an array. Heterogeneous data structure
contains different types of data elements in it. Example of a heterogeneous
data structure is a record.
Static and dynamic data structures – We classify data structures as static
and dynamic considering the time of memory allocation. The system
allocates memory for static data structure at the compile time itself (design
time allocation). For a dynamic data structure memory is allocated during
run time (through functions such as calloc(), malloc()).
Linear and non-linear data structures – We classify data structures as
linear and non linear based on the type of relationship between its elements.
Linear data structure such as arrays and lists maintains a constant and
direct relationship between its elements. Non-linear data structures such as
a tree do not maintain a constant and direct relationship between their
elements.
1.6.4 Data structure characteristics
Choosing the best data structure for a program is a challenging task. Same
task may have suitable different data structures for it. We derive new data
structures for complex tasks using the already existing ones. We need to
compare the characteristics before choosing the right data structure. The
table 1.1 shows the characteristics of the commonly used data structures.

Sikkim Manipal University B1480 Page No. 16


Analysis and Design of Algorithms Unit 1

Table 1.1: Characteristics of Data Structures

Data structure Advantages Disadvantages


Array Easy to insert elements Fixed size
Fast access of elements Slow search
if the index is known Slow deletion of elements
Stack Last-in, first-out access Only small number of operations
Good for simple can be performed
programming No random access of elements
possible
Queue First-in, first-out access Memory consumption is more
Easy to insert than stack
East to delete

List Easy to insert Slow search


East to delete
Tree Quick search Deletion algorithm is complex
Quick inserts
Quick deletes

Activity 2
Write a program to sort two arrays and identify the data structures used
in it.

Self Assessment Questions


13. A ______ is a set of data elements grouped together under one name.
14. _________ data structure has all the elements of same data type in it.
15. For ____________ data structure, the memory is allocated at the
compile time itself.

1.7 Summary
Let us summarize what we have discussed in this unit.
An algorithm is defined as a set of instructions describing the sequence of
actions to achieve the result of the problem with limited resources. The word
‘algorithm’ is derived from the name of Abu Abdullah Muhammad ibn Musa
al-Khwarizmi, a 9th-century Persian mathematician.

Sikkim Manipal University B1480 Page No. 17


Analysis and Design of Algorithms Unit 1

Algorithm has a major role in computing. Analysis of algorithm means a


detailed study of the specification of the algorithm and arriving at
conclusions about how the implementation of that algorithm will perform in
general. Designing an algorithm is a process that actually implements the
algorithm in order to get the desired results. Properties of algorithm are
correctness, definiteness, finiteness and effectiveness. An algorithm differs
from a program and a psuedocode. Different types of algorithms are simple
recursive, backtracking, divide and conquer, dynamic programming, greedy
algorithm, branch and bound algorithm, brute force algorithm, randomized
algorithm.
Data structures are a set of data elements grouped together under one
name. It is classified as primitive and non primitive, homogeneous and
heterogeneous, static and dynamic, linear and non linear. We study the
characteristics of data structures in order to choose the best from them.

1.8 Glossary

Terms Description
Subroutine A program unit which does not return any value through
its name and has a number of arguments.
Optimization Problem Optimization problem is a computational problem which
has the objective to find the best of all possible solutions.

1.9 Terminal Questions


1. What are the properties of an algorithm?
2. What are asymptotic notations?
3. Explain greedy algorithm with a suitable example.
4. How are data structures classified?
5. Compare the characteristics of different types of data structures.

1.10 Answers
Self Assessment Questions
1. Algorism
2. Speed, size, resources
3. Good programming
4. Resources

Sikkim Manipal University B1480 Page No. 18


Analysis and Design of Algorithms Unit 1

5. Merging
6. Programs
7. Direct recursive
8. Big – O
9. Space complexity
10. Simple recursive
11. Brute force
12. Backtracking
13. Data structure
14. Homogeneous
15. Static
Terminal Questions
1. Refer section 1.3.2 – Properties of algorithms
2. Refer section 1.4.1 – Asymptotic notations
3. Refer section 1.5.5 – Greedy algorithm
4. Refer section 1.6.3 – Data structure classification
5. Refer section 1.6.4 – Data structure characteristics

References
 Cormann, Thomas (1990). Introduction to algorithms. The MIT press,
Cambridge
 Levitin, A. (2003). Introduction to the analysis and design of algorithms.
Dorling Kindersley, India
 Wirth, N. (1991). Algorithms + Data Structures = Programs. Jay Print
Pack publications, New Delhi

E-References
 http://www.brpreiss.com
 http://www.esirav.info/definitions of algorithms, By Reality Software,
copyright 2000
 http://www.stackoverflow.com/stack overflow internet services.

Sikkim Manipal University B1480 Page No. 19

You might also like