Ada Module 1 Notes
Ada Module 1 Notes
Lecture Notes
on
Prepared By,
Mrs. Prathibha S ,
Assistant Professor,
Department of CSE,PESITM
Module 1-ADA (BCS401)
MODULE -1
1. INTRODUCTION
What is an lgorithm?
4. Finiteness: If we trace out the instruction of an algorithm For all input cases, the
algorithm must terminate after a finite number of steps.
5. EFFECTIVENESS Every nstruction must very basic so that it can be carried out,
in principle, by a person using only pencil & paper.
• Understanding the Problem - From a practical perspective, the first thing you need
to do before designing an algorithm is to understand completely the problem
given.An input to an algorithm specifies an instance of the problem the algorithm
solves. It is very important to specify exactly the set of instances the algorithm needs
to handle.
• Ascertaining the Capabilities of the Computational Device - Once you completely
understand a problem, you need to ascertain the capabilities of the computational
device the algorithm is intended for. Select appropriate model from sequential or
parallel programming model.
• Choosing between Exact and Approximate Problem Solving – The next principal
decision is to choose between solving the problem exactly and solving it
approximately. Because, there are important problems that simply cannot be solved
exactly for most of their instances and some of the available algorithms for solving a
problem exactly can be unacceptably slow because of the problem’s intrinsic
complexity.
• Algorithm Design Technique- An algorithm design technique(or“strategy”or
“paradigm”) is a general approach to solving problems algorithmically that is
applicable toavariety of problems from different areas of computing.They provide
guidancefor designing algorithm for new problems.
• Designing an Algorithm and Data Structures- One should pay close attention to
choosing data structures appropriate for the operations performed by the algorithm.
For example, the sieve of Eratosthenes would run longer if we used a linked list
instead of an array in its implementation. Algorithms + Data Structures = Programs.
• Methods of Specifying an Algorith- Once you have designed an algorithm; you need
to specify it in some fashion.Pseudocode is a mixture of a natural language and
programming language like constructs. Pseudocode is usually more precise than
natural language, and its usage often yields more effective algorithm descriptions.
1. Sorting
2. Searching
3. String Processing
4. Graph problems
5. Geometrical Problems
6. Numerical Problems
7. Combinatorial Problems
Orders ofGrowth
Why this emphasis on the count's order of growth for large input sizes? Because for large
values of n, it is the function's order of growth that counts: just look at table which
contains values of a few functions particularly important for analysis of algorithms.
✓
✓
✓
Worst-Case, Best-Case, AverageCaseEfficiencies
Average-case efficiency: Average time taken(number of times the basic operation will be
executed)to solve all the possible instances(random)of the input.
ASYMPTOTIC NOTATIONS
If f(n) describes the running time of an algorithm, f(n) is O(g(n)) if there exist a positive
constant C and n0 such that, 0 ≤ f(n) ≤ cg(n) for all n ≥ n0
Let g and f be the function from the set of natural numbers to itself. The function f is said
to be Ω(g), if there is a constant c > 0 and a natural number n0 such that c*g(n) ≤ f(n) for
all n ≥ n0
Theta notation encloses the function from above and below. Since it represents the
upper and the lower bound of the running time of an algorithm, it is used for
analyzing the average-case complexity of an algorithm.
Let g and f be the function from the set of natural numbers to itself. The function f is said
to be Θ(g), if there are constants c1, c2 > 0 and a natural number n0 such that c1* g(n) ≤
f(n) ≤ c2 * g(n) for all n ≥ n0.
Mathematical Analysis
1. Input size is the number of elements=n(size of the array)
2. Comparison statement is considered to be the basic operation of the
algorithm.
3. No best, worst, average cases-because the number of comparisons will be same for
all arrays of size n and it is not dependent on type of input.
4. Let C(n) denotes number of comparisons: Algorithm makes one comparison on each
execution of the loop, which is repeated for each value of the loop‘s variable
C(n)= n
Example-2:To check whether all the elements in the given array are distinct
Mathematical Analysis
Mathematical Analysis
1. Input size is order of the square matrix n(no of rows or columns)
2. Multiplication is considered to be the basic operation of the algorithm.
3.No best, worst, average cases-exist .
4.Let M(n) denotes number of comparisons:
Algorithm:
Mathematical Analysis
1. Input size is decimal number n.
Example1:
Tower of Hanoi is a mathematical puzzle where we have three rods (A, B, and C)
and N disks. Initially, all the disks are stacked in decreasing value of diameter i.e., the
smallest disk is placed on the top and they are on rod A. The objective of the puzzle is to
move the entire stack to another rod (here considered C), obeying the following simple
rules:
• Only one disk can be moved at a time.
• Each move consists of taking the upper disk from one of the stacks and placing it on
top of another stack i.e. a disk can only be moved if it is the uppermost disk on a stack.
• No disk may be placed on top of a smaller disk.
The idea is to use the helper node to reach the destination using recursion. Below is the
pattern for this problem:
• Shift ‘N-1’ disks from ‘A’ to ‘B’, using C.
• Shift last disk from ‘A’ to ‘C’.
• Shift ‘N-1’ disks from ‘B’ to ‘C’, using A
oi puzzle ThenumberofmovesM(n)dependsonlyonn.Therecurrenceequationis
WehavethefollowingrecurrencerelationforthenumberofmovesM(n):
If i=n-1,
Mathematical Analysis
A(1)=0
, Taking n=2k