Daa Uniti
Daa Uniti
ALGORITHMS
Syllabus:
Total
L T P Credits
Marks
DESIGN AND ANALYSIS
SCSX1001
OF ALGORITHMS 3 0 0 3 100
UNIT 1 : INTRODUCTION TO COMPUTER PROBLEM SOLVING 12 Hrs
Introduction, The Problem-Solving aspect, top-down design-Implementation of Algorithms-program
verification-The efficiency of algorithms-The analysis of algorithms-Fundamental Algorithms: Introduction-
Exchanging the values of two variables-Counting-Summation of a set of Numbers-factorial computation-Sine
function computation-Generation of the Fibonacci sequence-Reversing the digits of an integer, base
converstion-Character to Number conversion.
UNIT 2 : FACTORING METHOD 12 Hrs
Introduction-Finding the square root of a number-The smallest divisor of an integer-The greatest common
divisor of two integers-Generating Prime Numbers-Computing the Prime Factors of an integer-Generation of
Psedo-random Numbers-Raising a Number to a Large Power-Computing the nth Fibonacci Number.
UNIT 3 : ARRAY TECHNIQUES 12 Hrs
Introduction-Array Order Reversal-Array Counting or Histogramming-Finding the maximum Number in a
Set-Removal of Duplicates from an Ordered Array-Partitioning an Array-Finding the kth smallest Element-
Longest Monotone Subsequence.
UNIT 4 : MERGING SORTING AND SEARCHING 12 Hrs
Introduction, The Two-way Merge-Sorting by Selection-Sorting by Exchange-Sorting by Insertion-Sorting by
Diminishing Increment-Sorting by Partitioning-Binary Search-Hash Searching.
UNIT 5 : TEXT PROCESSING AND PATTERN SEARCHING 12 Hrs
Introduction-Text Line Length Adjustment-Left and Right Justification of Text-Keyword Searching in Text-
Text Line Editing-Linear Pattern search- Sublinear Pattern Search.
TEXT BOOK :
1.Dromey.R.G,”How to Solve it by Computer”,Prentice-Hall of India,Eighth Indian
Reprint,1996.
REFERENCE BOOKS :
1.Aho.A.V.,Hopcroft.J.E and Ullman.J.D,”The Design and Analysis of Computer
Algorithms”,Addison-Wesley,Reading Mass.
2.Knuth,D.E.,”The Art of computer programming Vol 1:Fundamental
Algorithms”,Addison – Wesley , Reading Mass
3.Knuth,D.E.,”Mathematical Analysis of algorithms”,Proceedings IFIP
congress,Ljubljana
UNIVERSITY EXAM QUESTION PAPER PATTERN
Max Marks : 80 Exam Duration: 3 Hrs.
PART A : 10 questions of 2 marks each – No choice 20 marks
PART B : 5 questions from each of the FIVE units of internal choice, carrying 12
marks each 60 marks
Aim:
This deals with the complete development of algorithm
for complicated problems. It also deals with the design
techniques and analysis of algorithms for efficiency,
complexity and overall effectiveness.
Objectives:
To analyze the efficiency of different algorithms for the
same problem.
To study the various algorithm design techniques.
UNIT 1 : INTRODUCTION TO COMPUTER PROBLEM SOLVING
Introduction:
• Algorithm
Step by step procedure for solving a problem
• Data structure:
A data structure is a way to store and organize data in order to
facilitate access and modifications.
Pseudo-code
Pseudo-code:
Problem
Example : Find out the maximum number from the given set
of numbers
Use some geometrical or schematic diagrams representing
certain aspects of the problem
4. Similarities among problems:
See if there are any similarities between the current problem
and other problems that we have solved or we have seen solved
Try to solve the problem independently
Binary doubling:
convert the binary numbers to decimal numbers
Example:: 1->1,10->2,11->3,100->4,1000->8
Dynamic programming:
Dynamic programming is an algorithm that can be used
when the solution to a problem can be viewed as the result of
a sequence of decisions.
Example: TRAVELING SALESMAN PROBLEM
•
• 3.3 Documentation of programs
found:=(x=a[lower])
3.5 Program Testing
Check whether the program solves the
smallest possible problem
Check whether it can handle the case
when all data values.
whether it is able to handle all input
condition?
Efficiency of algorithm mainly depends upon
Design
Implementation
Analysis of algorithms
Example :
x:=0;
for i:=1 to n do
begin
x:=x+0.01;
y:=(a*a*a+c)*x*x+b*b*x;
writeln(‘x=‘,x,’y=‘,y)
end
The unnecessary multiplications and additions can be
removed by pre computation before executing the loop
a3c := a*a*a+c;
b2:=b*b;
X:=0;
For i:=1 to n do
begin
x:=x+0.01;
y:=a3c*x*x+b2*x;
writeln(‘x=‘,x,’y=‘,y)
end
5.2 Referencing Array elements :
Example : To Find the maximum and its position in an array
Version 1 :
p:=1;
for i:=2 to n do
if a[i]>a[p] then p:=i;
max:=a[p]
Version 2 :
p:=1;
max:=a[1];
for i:=2 to n do
if a[i]>max then
begin
max:=a[i];
p:=i
end
max : = a[p]
–
– The version 2 is preferred because
the conditional test ( a[i] > max) is
more efficient than the test in version
1
– Use of variable max needs only one
memory reference
– Introduction of variable max makes it
clear what task is to be accomplished
Input Assertion
- should specify any constraints that have been placed
on the
values of input variables used by the program
Example :
Design a program to calculate the quotient q and the remainder r
resulting from the division of x by y
4.3 Verification of program segments with
branches
readln(x,y);
A {assert PA:true}
if x>y then
begin
t:=x;
x:=y;
y:=t;
end
B {assert PB((x<=y)^(x=xo^y=y0))V(x=y0^y=x0)}