Professional Documents
Culture Documents
DAA UNIT 1 Notes
DAA UNIT 1 Notes
1.What is an algorithm?Explain?
Algorithm is sequence of instruction to given particular
Problem.
Or
Algorithm is a step by step procedure to solve a given problem.
Algorithm criteria
i)Input: Zero or more quantities are externally supplied.
ii)Output: At least one quantity is produced.
iii)Definition: Each instruction is clear and unambiguous.
iv)finiteness: If we trace out the instructions of an algorithm, then for all cases,
the algorithm terminates after a finite number of steps.
v)Effectiveness: Every instruction must very basic so that it can be carried out,
in principle, by a person using only pencil & paper.
example:
Algorithm-I
step 1: start
step 2: declare a,b,c
step 3: read a,b
step 4: c=a+b
step 5: display c
step 6: stop
Yogesha S N
H.O.D of BCA
Vasavi Jnana Peetha First Grade College Page 1
2.Explain FUNDAMENTALS OF ALGORITHMIC PROBLEM SOLVING?
Yogesha S N
H.O.D of BCA
Vasavi Jnana Peetha First Grade College Page 3
Ex:Graphics,robotics etc
(vi)Combinatorial Problems:It invove computations with numbers.
Ex:Finding roots of equations,Performing matrix operations etc
Yogesha S N
H.O.D of BCA
Vasavi Jnana Peetha First Grade College Page 5
The process of visiting one data element to another data elements.
2. Insertion: The process of adding a new element into the given collection
of data elements.
3. Deletion: The process of removing an existing data element from the
given
collection of data elements
4. Searching: The process of finding the location of a data element in the
given collection of data elements.
5. Sorting: The process of arrangement of data elements in ascending or
descending order.
6. Merging: The process of combining the elements of two structures to form
a single structure.
7)Define stack.
A stack is an ordered collection of insert a new items and the removal of
existing items always take place at the same end is called top of the stack.
It is also known as LIFO(Last In First Out)
8)Define PUSH and POP.
PUSH : The process of insert a new items to the top of the stack.
POP : The process of remove the existing items from the top of the stack.
9) What are the Operations of stack?
stack( ) :creates a new stack that is empty.
push(item): adds a new item to the top of the stack.
pop( ): removes the top item from the stack.
peek( ): returns the top item from the stack but does not remove it.
isEmpty( ): tests whether the stack is empty.
size( ): returns the number of items on the stack.
10) Define Queue.
A Queue is an ordered collection of insert a new items and the removal of
existing items at the different end.
It is also known as FIFO(First In First Out)
11) Define REAR and FRONT.
REAR : The process of insert a new items to the Queue.
FRONT : The process of remove the existing items from Queue.
12) What are the Operations of Queue?
Queue( ): creates a new queue that is empty.
enqueue(item): adds a new item to the rear of the queue. This
operation is generally called as push.
Yogesha S N
H.O.D of BCA
Vasavi Jnana Peetha First Grade College Page 6
dequeue( ): removes the front item from the queue. The queue is
modified. This operation is generally called as pop.
isEmpty( ): tests to see whether the queue is empty.
size( ): returns the number of items in the queue.
13) Define Linked list.
A linked list is a linear collection of data elements called nodes and the linear
order is given by means of pointers.
16)Define Graph.
A graph is a set of vertices and edges which connect them.
Yogesha S N
H.O.D of BCA
Vasavi Jnana Peetha First Grade College Page 7
UNIT 1 CHAPTER-2
FUNDAMENTALS OF THE ANALYSIS OF ALGORITHM EFFICIENCY
1.Explain the Analysis Framework?
The Analysis Framework is a systematic approach of evaluating the
efficiency of an algorithm.
It involves measuring the algorithm’s performance in terms of its time
complexity space complexity.
i)space complexity: Total amount of computer memory required by an
algorithm to complete its execution is called as space complexity of that
algorithm.
when a program is under execution it uses the computer memory for
THREE reasons. They are as follows.
a) Instruction Space: It is the amount of memory used to store compiled
version of instructions.
b) Environmental Stack: It is the amount of memory used to store
information of functions at the time of function call.
c) Data Space: It is the amount of memory used to store all the variables
and constants.
ii)Time complexity:It is the total amount of time required by an algorithm to
complete its execution.
some other parameters are also used to find out efficiency of an algorithm and
the list of the parameters is given below:
Size of input
Running time
Worst, Best and Average scenarios
Asymptotic Notations
a)Size of input: The efficiency of algorithm is also evaluated based on the input
size of an algorithm.
b)Running time: The efficiency of an algorithm based on running depends on
the measuring unit used to measure running time.
c)Worst, Best and Average scenarios:
Worst-case efficiency refers to the maximum amount of time an algorithm
takes to complete its task.
Best-case efficiency refers to the minimum amount of time an algorithm takes
to complete its task.
Average-case efficiency refers to how long an algorithm takes on average over
all possible inputs.
Yogesha S N
H.O.D of BCA
Vasavi Jnana Peetha First Grade College Page 8
d)Order of Growth:
Order of growth is how the time of execution depends on the length of the
input.
e)Asymptotic Notations: The efficiency of an algorithm is measure using
asymptotic notations where three notations O(big Oh), (big omega), Θ(big
theta) are used.
Yogesha S N
H.O.D of BCA
Vasavi Jnana Peetha First Grade College Page 9
Yogesha S N
H.O.D of BCA
Vasavi Jnana Peetha First Grade College Page 10
Yogesha S N
H.O.D of BCA
Vasavi Jnana Peetha First Grade College Page 11
7)Explain mathematical analysis of Non recursive algorithms?
Mathematical analysis of algorithms involves using mathematical tools
and techniques to determine the efficiency of an algorithm in terms of
its time and space complexity.
This type of analysis is theoretical in nature, as it doesn't involve actually
running the algorithm.
It predicts the algorithm performance based on the algorithm's structure
and operations.
The efficiency of an algorithm is typically expressed using Big O notation,
which provides an upper bound on the time or space complexity in the
worst-case scenario.
General Plan for Analysing the Time Efficiency of Non Recursive
Algorithms
Selection of a Parameter Indicating Input Size:
Identification of the Algorithm's Basic Operation
Reason for Basic Operation to be Executed more than Once
Set up a Sum that Expresses how many Times the Basic Operation is
Executed
Derivation of a Closed-form Formula or Determination of the Order
of Growth
Example: Finding the Largest Element in an Array
Algorithm:Max(A [0... - n – 1)
//To find the largest element in a given array
//Input: An array A [0.... n - 1 ]
//Output:The largest element in A[0.. n - 1 ]
{
max = A[0]
for i = 0 to n-1 do
{
if A[i] > max
max= A[i];
}
return max
}
Yogesha S N
H.O.D of BCA
Vasavi Jnana Peetha First Grade College Page 12
A recursive algorithm is that in which the algorithm is called repeatedly
until certain condition is reached.
So the algorithm should have a stopping condition otherwise it may go
to an infinite loop.
Recursions can be implemented in two ways: Direct and Indirect.
i)Direct Method: In this type, the function / algorithm calls itself repeatedly
until a stopping condition is reached.
Example:
Fact(int n)
{
if (n == 0) do
return 1
else
return (n Fact (n-1));
}
ii)Indirect Method: In this type, the function calls another function which
eventually causes the same function to be called. So the function indirectly
calls itself through another function.
Example
Fact(int a):
{
……………..
Fact1(a-1);
………………
}
Fact1(int b)
{
………………..
Fact(b-1);
……………
}
General Plan for Analysing the Time Efficiency of Recursive Algorithms
Selection of a Parameter Indicating Input Size:
Identification of the Algorithm's Basic Operation
Reason for Basic Operation to be Executed more than Once
Yogesha S N
H.O.D of BCA
Vasavi Jnana Peetha First Grade College Page 13
Setting up a recurrence relation, with an appropriate initial condition,
for expressing the number of times the basic operation is executed.
Solving the recurrence relation for finding the complex function and
order of growth.
Example:
Factorial of a Number
algorithm for finding the factorial of 'n' using direct way approach:
Algorithm:Fact (n)
// Computing n! for an arbitrary non-negative integer
//Input: A non-negative integer 'n'
// Output: Factorial of 'n' (n!)
{
if n == 0
return 1
else
return n*Fact(n-1)
}
9)Explain Empirical analysis of algorithm?
Empirical analysis of algorithms is a process that involves implementing the
algorithm in a specific programming language, executing the program with
various input sizes, and observing its performance. This process is particularly
important in assessing the practical efficiency of algorithms.
Yogesha S N
H.O.D of BCA
Vasavi Jnana Peetha First Grade College Page 14
Decide on Characteristics of the Input Sample
Prepare a Program Implementing the Algorithm
Run the Algorithm on the Sample's Inputs and Record the Data Observed
Analyze the Data Obtained
10)Define complexity of algorithm.
The complexity of algorithm is the function which gives the running time or
storage space requirement of the algorithm in terms of the size of input data.
Yogesha S N
H.O.D of BCA
Vasavi Jnana Peetha First Grade College Page 15