DDA Unit 1
DDA Unit 1
analysis of
Algorithms
:Unit 1
BCA 4th Sem
Sailaja
Algorithms A finite set of instruction that specifies a sequence of operation is
to be carried out in order to solve a specific problem or class of
problems is called an Algorithm.
❖ An algorithm can be defined as a finite set of steps, which has to be followed
while carrying out a particular problem. It is nothing but a process of
executing actions step by step.
b. Write down a recipe for cooking your favorite dish with the precision
required by an algorithm.
2. Decision making
5. Analyzing an Algorithm
6. Coding an Algorithm
1.Understanding the Problem
1. This is the first step in designing of algorithm.
5. Input (instance) to the problem and range of the input get fixed.
2.Decision making:The Decision making is done on the following:
a) Ascertaining the Capabilities of the Computational Device
In random-access machine (RAM), instructions are executed one
after another (The central assumption is that one operation at a
time). Accordingly, algorithms designed to be executed on such
machines are called sequential algorithms.
• →In some newer computers, operations are executed concurrently, i.e., in
parallel. Algorithms that take advantage of this capability are called parallel
algorithms.
• →Choice of computational devices like Processor and memory is mainly
based on space and time efficiency
b)Choosing between Exact and Approximate Problem Solving:
→The next principal decision is to choose between solving the
problem exactly or solving it approximately.
→If the problem is so complex and not able to get exact solution,
then we have to choose an algorithm called an approximation
algorithm. i.e., produces an Approximate answer. E.g., extracting
square roots, solving nonlinear equations, and evaluating definite
integrals.
c)Algorithm Design Techniques
• An algorithm design technique (or “strategy” or “paradigm”) is a
general approach to solving problems algorithmically that is applicable
to a variety of problems from different areas of computing.
• Though Algorithms and Data Structures are independent, but they are
combined together to develop program. Hence the choice of proper data
structure is required before designing the algorithm.
✓ Sorting
✓ Searching
✓ String processing
✓ Graph problems
✓ Combinatorial problems
✓ Geometric problems
✓ Numerical problems
Sorting
• The sorting problem is to rearrange the elements of a given list in non
decreasing (ascending) or decreasing order (descending) order.
Examples of sorting algorithms
• Selection sort
• Bubble sort
• Insertion sort
• Merge sort
• Heap sort …
• Number of key comparisons is used to determine time complexity of
sorting algorithms
Two properties related to sorting algorithms
• Stability: A sorting algorithm is called stable if it preserves the relative order of
any two equal elements in its input.
A sorting algorithm is called stable if it preserves the relative order of any two
equal elements in its input. In other words, if an input list contains two equal
elements in positions i and j where i < j, then in the sorted list they have to be in
positions i and j , 20 Introduction respectively, such that i < j .
This property can be desirable if, for example, we have a list of students sorted
alphabetically and we want to sort it according to student GPA: a stable
algorithm will yield a list in which students with the same GPA will still be sorted
alphabetically.
• In place: A sorting algorithm is in place if it does not require extra memory,
except, possibly for a few memory units.
An algorithm is said to be in-place if it does not require extra memory, except,
possibly, for a few memory units. There are important sorting algorithms that are
in-place and those that are not.
Searching
• The searching problem : Find a given value, called a search key, in a
given set
• Sequential searching
• Binary searching…
• organizing very large data sets for efficient searching poses special
challenges with important implications for real-world applications
String Matching