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

THE DESIGN AND THE ANALYSIS OF AN ALGORITHM

III SEM BCA


Unit-1 INTRODUCTION OF DAA

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.

Input: Zero or more inputs

Output: At least one output.

Finiteness: N number of steps.

Definiteness: Clear algorithm step.

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?

(i)Understanding the problem/requirement


 Understand the requirement of a user in order to develop and design an
algorithm.
 The requirement of a user can be an overview but as a designer of an algorithm
thedeveloper needs to understand all the processes and sub processes
within thesystem.
(ii)Prepare the complete flow chart of the problem
 Flow chart is a graphical representation to display the sequence of
instruction within an algorithm or a computer program.
 The flow-chart tool helps the developer in preparing a graphical
representation of the problem solving process which results in efficient
design of an algorithm.
iii) Design and analyze an algorithm
 The process of analyzing an algorithm plays an important role while writing a
program and execution of the same on a computer.
 Algorithm designedcan develop alternative algorithms for the same problem
solving process in orderto analyze the same for selection of an optimal
algorithm.
iv)Test the algorithm
 The process of checking the correctness of the algorithm is known as
Yogesha S N
H.O.D of BCA
Vasavi Jnana Peetha First Grade College Page 2
testing where the algorithm is tested fordummy situations and dummy data.
 This method of executing the algorithm is also known as dry run.
v)Write a computer program for the algorithm
The algorithm written at step (iv) can be written in any programming language as
per the requirement of the problem solving process in order to write a computer
program for the problem solving process.

3)Explain importance of problem types?


(i)Sorting: The sorting problem is arranging a sequence of items either in ascending
or descending order based on the requirements of a user .
Some of the sortingalgorithms at present in user are given below:
• Selection sort
• Merge sort
• Bubble sort
• Insertion sort
• Quick sort
• Radix sort
• Heap sort
(ii)Searching: The searching problem is related to searching an item from a list of
items.
Types:
Linear Search
Binary Search
(iii)Graph problems:
 Graph problems involve analysing and manipulating graphs.
 The process of collection vertices and edges.
examples
shortest path problem,Minimum spanning tree problem,Graph coloring
problem ,Topological sort etc

(iv)Strings Processing Problems:


It is a collection of characters and string processing problems involve
manipulating string to perform various operations such as
searching,matching and editing.
Ex:searching for a particular word or pattern in a text file.
(v)Geometric Problems:It involve analysing and manipulating geometric objects
such as point,lines and polygons.

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

4)Explain Fundamental data structures?


Definition: A data structure is a specialized format for organizing and storing
data.
Classification of Data Structures

There are two types


i) primitive data structures
ii) non primitive data structures
(i) primitive data structures:
Data structures that are directly operated upon by machine-level instructions
are known as primitive data structures.
Examples: The integer, float, character , pointer
(ii)non primitive data structures:
Data structures that are not directly operated upon by machine-level
instructions are known as non primitive data structures.
Examples: Arrays,lists,file,stack,Queue,Linked list,Trees,Graphs
There are three types
(i) Arrays
(ii) List
(iii) Files
Yogesha S N
H.O.D of BCA
Vasavi Jnana Peetha First Grade College Page 4
(i)Arrays: Arrays is a same name and same data type.
Types:
a)One dimensional array:It is a one subscript.
syntax: datatype arrayname[size];
example: int a[4];
b) Two dimensional array:It is a two subscripts.
syntax: datatype arrayname[rowsize][columnsize];
example: int a[2][3];
c) Multi dimensional array:It is a more than two subscripts.
syntax: datatype arrayname[S1] [S2] [S3]-----[Sn];
example: int a[2][4][6][8];

Lists:There are two type


(i) linear data structures
(ii) Non linear data structures
(i)linear data structures:
Data items are arranged in a sequential order is called linear data structures.
Examples: stack,Queue,Linked list
(ii)non linear data structures:
Data items are not arranged in a sequential order is called non linear data
Structures.
Examples: Trees,Graphs
(iii)Files: Files are data can be stored.
5) Explain operations of Primitive data structure?
1.Create:To create a new data structure.
example:int x=10;
2.Select:To access the data within the data structure.
example: cin>>x;
3.update:To change data of data structures.
example: int x=15;
4.Destroy:To destroy or remove the data structure from the memory
space.
6) Explain operations of Data structure/ non primitive data structure /
Linear data structure /1d,2d,multi d arrays/linked list?
1. Traversing: The processing of accessing each element exactly once to
perform some operation.
Or

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.

14) Mention different types of Linked list.


There are three types of linked lists.
1. Singly linked list (SLL)
2. Doubly linked list (DLL)
3. Circular linked list (CLL)
15)Define trees.
A tree is a non linear data structure which consists of a collection of noides
arranged in a hierarchical order.
Example:

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.

2)What are the basic asymptotic efficiency classes?

3)What are the different notations of analysis of algorithm or Asymptotic


Notations?
There are three types
(i)Big Oh ( O)
(ii)Big Omega ()
(iii)Big Theta (Θ)

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
}

8) Explain mathematical analysis of recursive algorithms

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.

This analysis can includes several performance metrics such as:


1. Execution Time: It's the actual time taken by the algorithm to run from start
to finish on a particular computing system.
2. Memory Usage: It's the amount of computer memory (RAM) the algorithm
uses during execution.
3. CPU Usage: It refers to the amount of computing resources used by the
algorithm, which is especially important in multitasking systems.
4. 1/0 Operations: In case the algorithm involves reading from or writing to
files or databases, the number and efficiency of these operations are also
considered.
General Plan for the Empirical Analysis of Algorithm Time Efficiency
 Understand the Experiment's Purpose:
 Decide on the Efficiency Metric to be Measured and the Measurement
Unit

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

You might also like