0% found this document useful (0 votes)
4 views69 pages

DAA Module1 Notes-1

The document outlines the course 'Design and Analysis of Algorithms' taught by Dr. L. Sandeep Kumar, focusing on efficient algorithm creation and computational complexity analysis. It covers various algorithm design techniques such as divide and conquer, greedy methods, dynamic programming, backtracking, and branch and bound, along with the fundamentals of algorithm efficiency analysis. Additionally, it discusses the mathematical analysis of both non-recursive and recursive algorithms, providing examples and performance evaluations.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views69 pages

DAA Module1 Notes-1

The document outlines the course 'Design and Analysis of Algorithms' taught by Dr. L. Sandeep Kumar, focusing on efficient algorithm creation and computational complexity analysis. It covers various algorithm design techniques such as divide and conquer, greedy methods, dynamic programming, backtracking, and branch and bound, along with the fundamentals of algorithm efficiency analysis. Additionally, it discusses the mathematical analysis of both non-recursive and recursive algorithms, providing examples and performance evaluations.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 69

24CSEN3001 DESIGN AND ANALYSIS OF ALGORITHMS

DESIGN AND ANALYSIS OF ALGORITHMS

Dr. L. Sandeep Kumar


Assistant Professor, Department of EECE
GITAM Deemed to be University, Visakhapatnam

July 21, 2025


Algorithm

0. 0.0. 2/69
Algorithm

0. 0.0. 3/69
Algorithm

0. 0.0. 4/69
Algorithm

• Design and Analysis of Algo-


rithms (DAA) is a core CSE field
focused on creating efficient
algorithms and understanding
their computational complexity.
• It involves developing meth-
ods to solve problems, analyz-
ing their performance (time and
space requirements), and opti-
mizing them for better efficiency.

0. 0.0. 5/69
Algorithm Design Techniques (Divide & conquer approach)

0. 0.0. 6/69
Algorithm Design Techniques (Greedy method)

• If we follow the greedy approach, we


will first move from starting point to
node C because it has the minimum
cost at that point. But in reality, this
path has the maximum total cost.
However, we were not able to detect it
at the first step.
• Following the greedy method will cost
• By following path A will cost us us the maximum here i.e. 80. In such
50, path B will cost 8(minimum) cases, the greedy approach might not
and path C will cost us 80. give optimal results.

0. 0.0. 7/69
Algorithm Design Techniques (Dynamic Programming)

• Used to solve problems by breaking


them into smaller overlapping
subproblems.
• It is particularly effective for
optimization problems and those with
a recursive structure.
• A classic example is calculating the
Fibonacci sequence using dynamic
programming. Instead of recalculating
the same Fibonacci numbers multiple
times, a dynamic programming
• Dynamic programming (DP) is a
solution stores previously computed
problem-solving approach used values in a table, significantly
in computer science. improving efficiency.
0. 0.0. 8/69
Algorithm Design Techniques (Backtracking)

• Backtracking systematically explores


possible paths, marking visited cells
to avoid cycles, and if a path leads to
a dead end, it "backtracks" to explore
alternative routes.
• The Rat in a Maze problem, solved
using backtracking, involves finding a
path for a rat (or any agent) to
navigate a maze from a starting point
to a destination.

0. 0.0. 9/69
Algorithm Design Techniques (Branch and Bound)

• Branching: Process of generating


subproblems
• Bounding: Ignoring partial solutions
that cannot be better than current
solution.
• Procedure to find Optimal solution
• It eliminates those parts of a search
space which does not contain better
solution (Pruning).

0. 0.0. 10/69
24CSEN3001 DESIGN AND ANALYSIS OF ALGORITHMS
Module 1: INTRODUCTION TO ALGORITHMS AND ANALYSIS

Dr. L. Sandeep Kumar


Assistant Professor, Department of EECE
GITAM Deemed to be University, Visakhapatnam

July 21, 2025


OUTLINE

1. Notion of an Algorithm

2. Basics of Algorithmic problem solving

3. Fundamentals of the Analysis of Algorithm Efficiency


4. Mathematical analysis of non-recursive and recursive Algorithms
with examples

5. Important Problem Types:


5.1. Sorting
5.2. Searching
5.3. String processing
5.4. Graph Problems
5.5. Combinatorial Problems
Notion of an Algorithm

Notion of an algorithm
The notion of an algorithm refers to a precise, step-by-step method for solving a spe-
cific problem or performing a computational task. An algorithm must be:
1. Well-defined: Each step must be clear and unambiguous.
2. Finite: It must complete after a finite number of steps.
3. Effective: Each operation should be basic enough to be carried out exactly and
in finite time.
4. Input/Output based: It takes zero or more inputs and produces at least one
output.

1. Notion of an Algorithm 1.0. 13/69


Notion of an Algorithm
1. The design aspect focuses on developing efficient algorithms to solve problems.
2. The analysis involves evaluating their performance in terms of time complexity
and space complexity.
3. This helps in comparing different algorithms and selecting the most suitable one
for a given problem based on efficiency and scalability.

1. Notion of an Algorithm 1.0. 14/69


Algorithmic problem solving
Algorithmic problem solving is a systematic approach to finding solutions to computa-
tional problems using algorithms. The basic steps involved are:

• Understanding the Problem: Clearly define the problem, identify the


1. input and desired output, and understand the constraints.

• Analyzing the Problem: Break down the problem into smaller parts.
2. Determine whether it can be solved using known techniques like di-
vide and conquer, dynamic programming, greedy methods, etc.
• Designing an Algorithm: Devise a step-by-step procedure (algorithm)
3. to solve the problem. Ensure the algorithm is correct, unambiguous,
and can be implemented in code.

2. Basics of Algorithmic problem solving 2.0. 15/69


• Choosing the Right Data Structures: Select suitable data structures
4. (arrays, stacks, queues, trees, graphs, etc.) that can efficiently sup-
port the operations needed by the algorithm.
• Analyzing the Algorithm: Evaluate the performance of the algorithm
5. using: Time complexity (how fast it runs), Space complexity (how
much memory it uses)
• Implementing the Algorithm: Convert the algorithm into a program-
6. ming language, ensuring correctness and efficiency.

• Testing and Debugging: Verify the implementation using various test


7. cases, including edge cases, to ensure reliability and robustness.

2. Basics of Algorithmic problem solving 2.0. 16/69


Fundamentals of the Analysis of Algorithm Efficiency

Analysis of Algorithm Efficiency


The analysis of algorithm efficiency is a core aspect of computer science that helps in
determining how well an algorithm performs, especially as the size of the input grows.
It allows us to compare different algorithms and choose the most suitable one for a
given problem based on performance.

• To evaluate the resources (mainly time and space) required by an


1. algorithm.
Purpose
• To ensure the algorithm is scalable (performs well with increasing
of
input sizes.).
Analysis:
• To predict and compare the behavior of algorithms independent of
hardware.

3. Fundamentals of the Analysis of Algorithm Efficiency 3.0. 17/69


Fundamentals of the Analysis of Algorithm Efficiency
(Contd..)

• Time Efficiency also called time complexity. Measures the amount of


time an algorithm takes to complete as a function of the input size
2. Types (n). Typically analyzed using: 1. Best-case 2. Average-case 3. Worst-
of Effi- case.
ciency:
• Space Efficiency also called space complexity. Refers to the amount of
memory units required by the algorithm in addition to the space needed
for its input and output.

3. • To describe the running time concisely we use asymptotic notation:


Asymp-
◦ Big O (O): Upper bound (worst-case)
totic
◦ Omega (Ω): Lower bound (best-case)
Notation:
◦ Theta (θ): Tight bound (average-case or exact).

3. Fundamentals of the Analysis of Algorithm Efficiency 3.0. 18/69


Fundamentals of the Analysis of Algorithm Efficiency
(Contd..)
Identify the basic operations:
4. Steps • Typically loops comparisons and assignments.
in An-
alyzing • Determine the input size: Denoted by n.
an Al- • Count the number of basic operations as a function of n.
gorithm:
• Apply asymptotic notation to express time or space complexity.

• Helps in selecting the most optimal algorithm for real-world prob-


5. Im- lems.
portance:
• Essential for performance-critical applications like 1. search engines
2. operating systems or 3. real-time systems.

3. Fundamentals of the Analysis of Algorithm Efficiency 3.0. 19/69


Mathematical analysis of non-recursive and recursive
Algorithms with examples

Mathematical analysis of algorithms


• Mathematical analysis of algorithms is crucial for understanding how an algorithm
performs in terms of time and space complexity.
• This analysis is done differently for non-recursive and recursive algorithms.

Why
Mathe- • To compare algorithms independently of machine and compiler.
matical • To evaluate scalability with input size.
Anal-
ysis?: • To determine 1. best 2. average and 3. worst-case performance.

4. Mathematical analysis of non-recursive and recursive Algorithms with examples 4.0. 20/69
Mathematical analysis of non-recursive and recursive
Algorithms with examples (Contd..)
Analysis of Non-recursive Algorithms with examples

Non-recursive Algorithms
• A non-recursive algorithm, also known as an iterative algorithm, solves a problem
by repeatedly executing a set of instructions until a condition is met, without calling
itself (recursion).

Exam- • Linear Search (Iterative) • Binary Search (Iterative Vers.)


ples: • Bubble Sort • Fibonacci (Iterative)
• Matrix Multiplication • Iterative Factorial

4. Mathematical analysis of non-recursive and recursive Algorithms with examples 4.0. 21/69
Mathematical analysis of non-recursive and recursive
Algorithms with examples (Contd..)
Analysis of Non-recursive Algorithms with examples

1. Linear Search Algorithm


Consider the array arr[ ] = 10, 50, 30, 70, 80, 60, 20, 90, 40 and key = 30

• Best-case: Key is at index 0 → Ω(1).


• Worst case: Key is not present or at
end → O(n).
• Average-case (assuming uniform dis-
tribution): ≃ n2 → θ(n).

4. Mathematical analysis of non-recursive and recursive Algorithms with examples 4.0. 22/69
Mathematical analysis of non-recursive and recursive
Algorithms with examples (Contd..)
Analysis of Non-recursive Algorithms with examples

1. Linear Search Algorithm


Linear search executes in O(n) time where n is the number of elements in the array.
Obviously, the best case of linear search is when Key is equal to the first element of
the array. In this case, only one comparison will be made. Likewise, the worst case
will happen when either Key is not present in the array or it is equal to the last element
of the array. In both the cases, n comparisons will have to be made. However, the
performance of the linear search algorithm can be improved by using a sorted array.

4. Mathematical analysis of non-recursive and recursive Algorithms with examples 4.0. 23/69
Mathematical analysis of non-recursive and recursive
Algorithms with examples (Contd..)
Analysis of Non-recursive Algorithms with examples

2. Bubble Sort Algorithm


Consider the unsorted array A[ ] = 5, 6, 1, 3.

4. Mathematical analysis of non-recursive and recursive Algorithms with examples 4.0. 24/69
Mathematical analysis of non-recursive and recursive
Algorithms with examples (Contd..)
Analysis of Non-recursive Algorithms with examples

2. Bubble Sort Algorithm

• Best-case: Already sorted (if opti-


mized with a flag) → Ω(n).
• Worst case: Reverse order → O(n2 ).
• Average-case: → θ(n2 ).

4. Mathematical analysis of non-recursive and recursive Algorithms with examples 4.0. 25/69
Mathematical analysis of non-recursive and recursive
Algorithms with examples (Contd..)
Analysis of Non-recursive Algorithms with examples

2. Bubble Sort Algorithm


The basic methodology of the working of bubble sort is given as follows:
• In Pass 1, A[0] and A[1] are compared, then A[1] is compared with A[2], A[2] is
compared with A[3], and so on. Finally, A[N − 2] is compared with A[N − 1]. Pass
1 involves n − 1 comparisons and places the biggest element at the highest index
of the array.
• In Pass 2, A[0] and A[1] are compared, then A[1] is compared with A[2], A[2] is
compared with A[3], and so on. Finally, A[N − 3] is compared with A[N − 2]. Pass
2 involves n-2 comparisons and places the second biggest element at the second
highest index of the array.

4. Mathematical analysis of non-recursive and recursive Algorithms with examples 4.0. 26/69
Mathematical analysis of non-recursive and recursive
Algorithms with examples (Contd..)
Analysis of Non-recursive Algorithms with examples

2. Bubble Sort Algorithm


• In Pass 3, A[0] and A[1] are compared, then A[1] is compared with A[2], A[2] is
compared with A[3], and so on. Finally, A[N − 4] is compared with A[N − 3].
Pass 3 involves n − 3 comparisons and places the third biggest element at the
third highest index of the array.
• In Pass n − 1, A[0] and A[1] are compared so that A[0] < A[1]. After this step, all
the elements of the array are arranged in ascending order.

4. Mathematical analysis of non-recursive and recursive Algorithms with examples 4.0. 27/69
Mathematical analysis of non-recursive and recursive
Algorithms with examples (Contd..)
Analysis of Non-recursive Algorithms with examples
Complexity of Bubble Sort:
In bubble sort, we have seen that there are N − 1 passes in total. In the first pass,
N −1 comparisons are made to place the highest element in its correct position. Then,
in Pass 2, there are N − 2 comparisons and the second highest element is placed in
its position. Therefore, to compute the complexity of bubble sort, we need to calculate
the total number of comparisons. It can be given as: f (n) = (n − 1) + (n − 2) + (n −
3)+. . . +3 + 2 + 1
f (n) = n(n−1)
2
2
f (n) = n2 + O(n) = O(n2 )
Therefore, the complexity of bubble sort algorithm is O(n2 ). It means the time required
to execute bubble sort is proportional to n2 , where n is the total number of elements
in the array
4. Mathematical analysis of non-recursive and recursive Algorithms with examples 4.0. 28/69
Mathematical analysis of non-recursive and recursive
Algorithms with examples (Contd..)
Analysis of Recursive Algorithms with examples

Recursive Algorithm
Algorithm that calls itself to solve smaller instances of the same problem. It breaks
down a problem into subproblems and solves them recursively, combining the solu-
tions to get the final answer. Key features include a base case that terminates the
recursion and a recursive step that calls the function itself with a smaller input.

Exam- • Factorial (Recursive) • Tower of Hanoi


ples: • Fibonacci Sequence (Recursive) • Merge Sort
• Binary Search (Recursive) • Quick Sort

4. Mathematical analysis of non-recursive and recursive Algorithms with examples 4.0. 29/69
Mathematical analysis of non-recursive and recursive
Algorithms with examples (Contd..)
Analysis of Recursive Algorithms with examples

Recursive factorial
Let us take an example of calculating factorial of a number, n!.
We multiply the number with factorial of the number that is 1 less than that number. In
other words, n! = n × (n − 1)!. Let us say we need to find the value of 5!.
5! = 5 × 4 × 3 × 2 × 1 · · · = 120
This can be written as 5! = 5 × 4!, where 4! = 4 × 3!
Therefore, 5! = 5 × 4 × 3!
Similarly, we can also write, 5! = 5 × 4 × 3 × 2!
Expanding further 5! = 5 × 4 × 3 × 2 × 1!
We know, 1! = 1

4. Mathematical analysis of non-recursive and recursive Algorithms with examples 4.0. 30/69
Mathematical analysis of non-recursive and recursive
Algorithms with examples (Contd..)
Analysis of Recursive Algorithms with examples
Recursive factorial: Every recursive
function must have a base case and a
recursive case. For the factorial func-
tion,
Base case : When n = 1, the result
will be 1 as 1! = 1.
Recursive case: factorial function will
call itself but with a smaller value
of n, this case can be given as
factorial(n) = n × factorial(n − 1).

4. Mathematical analysis of non-recursive and recursive Algorithms with examples 4.0. 31/69
Mathematical analysis of non-recursive and recursive
Algorithms with examples (Contd..)
Analysis of Recursive Algorithms with examples
Greatest Common Divisor: The greatest common divisor of two numbers (integers) is
the largest integer that divides both the numbers.
We can find the GCD of two numbers re-
cursively by using the Euclid’s algorithm that
states

GCD(a,
{ b) =
b, if b divides a.
GCD(b, a mod b), otherwise.

4. Mathematical analysis of non-recursive and recursive Algorithms with examples 4.0. 32/69
Mathematical analysis of non-recursive and recursive
Algorithms with examples (Contd..)
Analysis of Recursive Algorithms with examples

4. Mathematical analysis of non-recursive and recursive Algorithms with examples 4.0. 33/69
Mathematical analysis of non-recursive and recursive
Algorithms with examples (Contd..)
Analysis of Recursive Algorithms with examples

Fibonacci Sequence (Recursive)


The Fibonacci series can be given as
0 1 1 2 3 5 8 13 21 34 55 . . .
That is, the third term of the series is the sum of the first and second terms. Similarly,
fourth term is the sum of second and third terms, and so on. Now we will design a
recursive solution to find the nth term of the Fibonacci series. The general formula
can be given
 as

0, if n=0
FIB(n) = 1, if n=1


FIB(n − 1) + FIB(n − 2), Otherwise
As per the formula, FIB(0) =0 and FIB(1) = 1. So we have two base cases.
4. Mathematical analysis of non-recursive and recursive Algorithms with examples 4.0. 34/69
Mathematical analysis of non-recursive and recursive
Algorithms with examples (Contd..)
Analysis of Recursive Algorithms with examples

4. Mathematical analysis of non-recursive and recursive Algorithms with examples 4.0. 35/69
Important Problem Types

5. Important Problem Types: 5.1. Sorting 36/69


Important Problem Types

5. Important Problem Types: 5.1. Sorting 37/69


Important Problem Types

5. Important Problem Types: 5.1. Sorting 38/69


Important Problem Types
Sorting

• Sorting means arranging the elements of an array so that they are placed in some
relevant order which may be either ascending or descending.
• It puts the elements of a list in a certain order, which can be either numerical
order, lexicographical order, or any user-defined order.
• There are two types of sorting:
◦ Internal sorting which deals with sorting the data stored in the computers memory
◦ External sorting which deals with sorting the data stored in files. External sorting
is applied when there is voluminous data that cannot be stored in the memory.
• Sorting on Multiple Keys: Many a times, when performing real-world applica-
tions, it is desired to sort arrays of records using multiple keys. For example, in
a big organization we may want to sort a list of employees on the basis of their
departments first and then according to their names in alphabetical order.

5. Important Problem Types: 5.1. Sorting 39/69


Important Problem Types
Sorting

Practical Considerations for Internal Sorting


• Number of sort key comparisons that will be performed.
• Number of times the records in the list will be moved.
• Best case performance.
• Worst case performance.
• Average case performance.
• Stability of the sorting algorithm where stability means that equivalent elements
or records retain their relative positions even after sorting is done.

5. Important Problem Types: 5.1. Sorting 40/69


Important Problem Types
Sorting

Insertion
sort Bubble
sort
Selection
sort
Sorting Heap
Techniques sort
Merge
sort
Radix
Quick sort
sort

5. Important Problem Types: 5.1. Sorting 41/69


Important Problem Types
Sorting

Bubble Sort

5. Important Problem Types: 5.1. Sorting 42/69


Important Problem Types
Sorting

Bubble Sort

5. Important Problem Types: 5.1. Sorting 43/69


Important Problem Types
Sorting

Bubble Sort

5. Important Problem Types: 5.1. Sorting 44/69


Important Problem Types
Sorting

Bubble Sort

5. Important Problem Types: 5.1. Sorting 45/69


Important Problem Types
Sorting

Bubble Sort

5. Important Problem Types: 5.1. Sorting 46/69


Important Problem Types
Sorting
Complexity of Bubble Sort:
In bubble sort, we have seen that there are N1 passes in total. In the first pass, N1
comparisons are made to place the highest element in its correct position. Then, in
Pass 2, there are N2 comparisons and the second highest element is placed in its
position. Therefore, to compute the complexity of bubble sort, we need to calculate
the total number of comparisons. It can be given as: f (n) = (n − 1) + (n − 2) + (n −
3)+. . . +3 + 2 + 1
f (n) = n(n−1)
2
2
f (n) = n2 + O(n) = O(n2 )
Therefore, the complexity of bubble sort algorithm is O(n2 ). It means the time required
to execute bubble sort is proportional to n2 , where n is the total number of elements
in the array

5. Important Problem Types: 5.1. Sorting 47/69


Searching
Searching is the process of finding some particular element in the list. If the element
is present in the list, then the process is called successful and the process returns the
location of that element, otherwise the search is called unsuccessful.
1. Linear Search: Linear search is the simplest search algorithm and often called sequen-
tial search. In this type of searching, we simply traverse the list completely and match
each element of the list with the item whose location is to be found. If the match found
then location of the item is returned otherwise the algorithm return NULL.
2. Binary search Binary search is a searching algorithm that works efficiently with a sorted
list. How do we find words in a dictionary? We first open the dictionary somewhere in
the middle. Then, we compare the first word on that page with the desired word whose
meaning we are looking for. If the desired word comes before the word on the page, we
look in the first half of the dictionary, else we look in the second half. Again, we open a
page in the first half of the dictionary and compare the first word on that page with the
desired word and repeat the same procedure until we finally get the word. The same
mechanism is applied in the binary search.

5. Important Problem Types: 5.2. Searching 48/69


Searching
Linear Search: Linear search is mostly used to search an unordered list of elements (array
in which data elements are not sorted). For example, if an array A[ ] is declared and initialized
as, int A[ ] = 10, 8, 2, 7, 3, 4, 9, 1, 6, 5; and the value to be searched is VAL = 7,

value 7 is present in the array or not. If yes,


then it returns the position of its occurrence.
Here, POS = 3 (index starting from 0)

then searching means to find whether the


5. Important Problem Types: 5.2. Searching 49/69
Searching

Complexity of Linear Search Algorithm:

• Linear search executes in O(n) time where n is the number of elements in the array.
Obviously, the best case of linear search is when VAL is equal to the first element of the
array.
• In this case, only one comparison will be made. Likewise, the worst case will happen
when either VAL is not present in the array or it is equal to the last element of the array.
• In both the cases, n comparisons will have to be made. However, the performance of the
linear search algorithm can be improved by using a sorted array.

5. Important Problem Types: 5.2. Searching 50/69


Searching

5. Important Problem Types: 5.2. Searching 51/69


Searching

5. Important Problem Types: 5.2. Searching 52/69


Searching
Binary Search Algorithm:
• Let us consider how this mechanism is applied to search for a value in a sorted array.
Consider an array A[ ] that is declared and initialized as int A[ ] = 0, 1, 2, 3, 4, 5, 6, 7, 8,
9, 10; and the value to be searched is VAL = 9.
• The algorithm will proceed in the following manner. BEG = 0, END = 10, MID = (0 + 10)/2
=5
• Now, VAL = 9 and A[MID] = A[5] = 5 A[5] is less than VAL, therefore, we now search for
the value in the second half of the array.
• So, we change the values of BEG and MID. Now, BEG = MID + 1 = 6, END = 10, MID =
(6 + 10)/2 =16/2 = 8 VAL = 9 and A[MID] = A[8] = 8 A[8] is less than VAL, therefore, we
now search for the value in the second half of the segment.
• So, again we change the values of BEG and MID. Now, BEG = MID + 1 = 9, END = 10,
MID = (9 + 10)/2 = 9 Now, VAL = 9 and A[MID] = 9.

5. Important Problem Types: 5.2. Searching 53/69


Searching
Binary Search Algorithm:
• In this algorithm, we see that BEG and END are the beginning and ending positions of
the segment that we are looking to search for the element.
• MID is calculated as (BEG + END)/2. Initially, BEG = lower_bound and END = up-
per_bound. The algorithm will terminate when A[MID] = VAL. When the algorithm ends,
we will set POS = MID. POS is the position at which the value is present in the array.
• However, if VAL is not equal to A[MID], then the values of BEG, END, and MID will be
changed depending on whether VAL is smaller or greater than A[MID].
(a) If VAL < A[MID], then VAL will be present in the left segment of the array. So, the value
of END will be changed as END = MID 1.
(b) If VAL > A[MID], then VAL will be present in the right segment of the array. So, the
value of BEG will be changed as BEG = MID + 1.

5. Important Problem Types: 5.2. Searching 54/69


Searching

Binary Search Algorithm:


5. Important Problem Types: 5.2. Searching 55/69
Searching

Complexity of Binary Search Algorithm:


• The complexity of the binary search algorithm can be expressed as f(n), where n
is the number of elements in the array.
• The complexity of the algorithm is calculated depending on the number of com-
parisons that are made.
• In the binary search algorithm, we see that with each comparison, the size of the
segment where search has to be made is reduced to half.
• Thus, we can say that, in order to locate a particular value in the array, the total
number of comparisons that will be made is given as 2f (n) > n or f (n) = log2 n

5. Important Problem Types: 5.2. Searching 56/69


Searching

5. Important Problem Types: 5.2. Searching 57/69


Searching

5. Important Problem Types: 5.2. Searching 58/69


String Processing: An Important Problem Type
Algorithms for manipulating and analyzing character strings are called string-processing
algorithms. Strings are essential for encoding and processing textual data in computer
programs. They are collections of characters, such as letters, numerals, and symbols.

5. Important Problem Types: 5.3. String processing 59/69


String Matching

5. Important Problem Types: 5.3. String processing 60/69


String Matching

5. Important Problem Types: 5.3. String processing 61/69


Naive String Matching algorithm

5. Important Problem Types: 5.3. String processing 62/69


Naive String Matching algorithm

5. Important Problem Types: 5.3. String processing 63/69


String Processing: KMP algorithm

5. Important Problem Types: 5.3. String processing 64/69


String Processing: KMP algorithm

5. Important Problem Types: 5.3. String processing 65/69


String Processing: KMP algorithm

5. Important Problem Types: 5.3. String processing 66/69


String Processing: KMP algorithm

5. Important Problem Types: 5.3. String processing 67/69


Graph Problems
Assignment for the students
List of Topics
• Breadth First Search
• Depth First Search
• Topological Sorting

5. Important Problem Types: 5.4. Graph Problems 68/69


Combinatorial Problems
Assignment for the Students
List of Topics
• Travelling Salesman Problem
• Graph Coloring Problem

5. Important Problem Types: 5.5. Combinatorial Problems 69/69

You might also like