DAA Unit - 1
DAA Unit - 1
ALGORITHMS (DAA)
(VR 23)
B.Tech CSE (AI&ML) III-I
(AY: 2025-26)
Introduction:
What is DAA?
Design and Analysis of Algorithms
(DAA) is a fundamental subject in computer
science and engineering.
What is an Algorithm?
An algorithm is a step-by-step procedure
or a set of rules to solve a specific problem
or perform a task.
Design & Analysis
Design of Algorithms:
Design refers to how we create an algorithm
to solve a problem effectively. It involves
choosing the best strategy based on:
Problem type
Input size
Resources (time and memory)
Common algorithm design techniques:
Divide and Conquer
Greedy Method
Dynamic Programming
Backtracking
Analysis of Algorithms:
Analysis means studying the performance
of an algorithm.
Main factors:
Time Complexity: How fast does the algorithm run?
Space Complexity: How much memory does it use?
Importance of DAA
Helps choose the best algorithm for a problem.
Saves time and computing resources.
UNIT – IV
Greedy method: General method, applications-
Job sequencing with deadlines, knapsack
problem, Minimum cost spanning trees, Single
source shortest path problem. Basic Traversal
and Search Techniques: Techniques for Binary
Trees, Techniques for Graphs, Connected
UNIT-V
Branch and Bound: General method,
applications - Traveling salesperson problem, 0/1
knapsack problem - LC Branch and Bound
solution, FIFO Branch and Bound solution.
NP-Hard and NP-Complete problems: Basic
concepts, non-deterministic algorithms, NPHard
and NP-Complete classes, Cook’s theorem.
programming language
3. Person should have 3. Programmer
Domain knowledge
4. Analyze 4. Testing
ALGORITHM SPECIFICATIONS
→ To analyze time complexity we need to calculate step count for a given algorithm.
→ Every meaningful statement in the algorithm is called step.
Step count = The no. of steps required by an algorithm .
Performance Analysis Conti….
Rules for defining steps in an algorithm:
1. Comments → require 0 steps
2.Assignment statements → require 1 step
3. Return statement → requires 1 step
4. For loop → requires n + 1 steps (n for loop entries & 1 for loop exit)
5. If/else conditions → require 1 step
1.Constant Time Complexity – O(1): The algorithm takes the same
amount of time, no matter how big or small the input is
int sum(int a, int b)
{
return a + b; Always takes 1 step, so time complexity is O(1)
}
2.Linear Time Complexity – O(n): The time increases directly with
the input size.
for (int i = 0; i < n; i++) {
sum = sum + i; Total steps ≈ 2n + 1, which simplifies to O(n)
}
ORDER OF GROWTH
(OR)
COMPARISON OF FUNCTIONS
ASYMPTOTIC NOTATIONS
Asymptotic Notation is a mathematical tool used to describe time complexity of
algorithms.
It represents how the running time or resource usage of an algorithm grows with
input size.
Focuses on asymptotic growth: how a function behaves as input becomes very
large.
Asymptotic Notation = growth calculator for algorithms.
Helps predict how slow or fast your solution will be.
Asymptotic Notations are useful for representing the time complexity of a
particular algorithm in various forms.
1. Best Case: The minimum amount of time require to complete a task
2. Worst Case: The maximum amount of time require to complete a task
3. Average Case: The average amount of time required to complete a task.
ASYMPTOTIC NOTATIONS
Asymptotic Notations are classified as:
1.Big oh (O)notation 4.Little oh notation
2.Big omega (Ω) notation 5.Little omega(Ω) notation
3.Theta(Θ) notation
1.Big oh (O)notation :
It is used to represent worst case time complexity.
It is used to represent the upper bound value of time
It is denoted by O.
Let f(n) and g(n) be two functions. We say: f(n) = O(g(n)) iff there exist
constants c > 0 and n₀ ≥ 0 such that: f(n)≤c*g(n) for all
n≥n0
ASYMPTOTIC NOTATIONS
2.Big omega (Ω) notation:
It is used to represent best case time complexity.
It is used to represent the lower bound value of a particular algorithm
It is denoted by Ω.
Let f(n) and g(n) be two functions. We say: f(n) = O(g(n)) if there exist constants
c > 0 and n₀ ≥ 0 such that: f(n) ≥ c*g(n) for all n≥n0
ASYMPTOTIC NOTATIONS
3.Theta(Θ) notation :
It is used to represent average case time complexity.
It is defines both lower and upper bound value of particular algorithm
It is denoted by Θ.
Let f(n) and g(n) be two functions. f(n) = Θ(g(n)) if there are two positive
constants c1 and c2 and a value n0, such that c1.g(n) ≤ f(n) ≤ c2.g(n) for
all n ≥ n0
ASYMPTOTIC NOTATIONS
4.Little oh (o) notation :
Little-o notation shows that one function grows much slower than another
function when input size n becomes very large.
It is denoted by o (small oh).
We write: f(n)=o(g(n)) if f(n) grows slower than g(n),
& never catches up, even when n becomes very big.
we can say that f(n) = o(g(n)) means,
5. Little omega(Ω) notation:
Little-omega notation shows that one function
grows much faster than another function as the
input size n becomes very large.
It is denoted by ω.
if f(n) grows faster than g(n), and eventually
leaves it behind completely when n gets very big
f(n)=ω(g(n)). 0 <= cg(n) < f(n) for all n ≥ no}
Project Title 1: Efficient Product Search in a Sorted
Inventory List - Binary Search
linear search.
Project Title 1: Efficient Product Search in a Sorted
Inventory List - Binary Search
Modules/Phases
1. Requirement Analysis:
Core Areas Understand input: Sorted list of products
of Focus
(IDs or names).
Define expected output: Position or
• DIVIDE-AND-
CONQUER message if product not found
2. Design:
• BINARY
SEARCH Design a flowchart or pseudo code for
ALGORITHM binary search
Input: sorted list, target product
•PERFORMANCE
ANALYSIS Output: index or "Product not
found"
Project Title 1: Efficient Product Search in a Sorted
Inventory List - Binary Search
Pseudo code:
def binary search(arr, target):
Core Areas low = 0
of Focus high = len(arr) – 1
while low <= high:
• DIVIDE-AND-
CONQUER mid = (low + high) // 2
if arr[mid] == target:
• BINARY return mid # Product
SEARCH
ALGORITHM found
elif arr[mid] < target:
•PERFORMANCE
ANALYSIS
low = mid + 1
else:
high = mid – 1
return -1 # Product not found
Project Title 1: Efficient Product Search in a Sorted
Inventory List - Binary Search
3. Implementation
Use Python to implement:
Core Areas Sorted product inventory list.
of Focus
Binary search function.
Middle item
Last item
Missing item
Project Title 1: Efficient Product Search in a Sorted
Inventory List - Binary Search
5. Performance Analysis
Compare binary search vs linear
Core Areas
of Focus search:
Execution time
• DIVIDE-AND- Number of comparisons
CONQUER
Use time module in Python:
• BINARY
SEARCH
ALGORITHM
import time
start = time.time()
•PERFORMANCE
ANALYSIS
binary_search(products,
"Mouse")
end = time.time()
print("Time taken:", end -
Project Title 1: Efficient Product Search in a Sorted
Inventory List - Binary Search
• DIVIDE-AND-
Learn divide-and-conquer strategy practically.
CONQUER
•PERFORMANCE
ANALYSIS O(n)).
Efficient Product Search System – Fast Lookup in a Large,
Sorted Inventory
Real-World Application Scenario:
Core
Areas of
E-commerce platforms, retail software,
Focus
and inventory management systems
often deal with massive catalogs of
•DIVIDE-
AND- products.
CONQUER
•DIVIDE-AND-
CONQUER Search Query: Product name or ID
return None
# Example usage
search_id = int(input("Enter Product ID to search: "))
result = binary_search(products, search_id)
if result:
print("\n Product Found:")
print(f"ID: {result['id']}")
print(f"Name: {result['name']}")
print(f"Price: ₹{result['price']}")
print(f"Stock: {result['stock']} units")
else:
print("\n Product not found in inventory.")
Project Title 2: Efficient Report Card Generation
Using Merge Sort
Problem Statement:
Core
To design and implement the Merge Sort algorithm to sort
Areas of
student marks and generate a structured report card. This
Focus
project demonstrates the importance of sorting techniques in
organizing academic data effectively.
• DIVIDE-
AND- Objectives:
CONQUER
Understand how divide-and-conquer is applied in merge
sort.
• MERGE
SORT Implement the merge sort algorithm using Python (or any
ALGORITHM
language).
• PERFORMA Apply the algorithm to sort student marks for report card
NCE
ANALYSIS generation.
Compare performance with other sorting techniques (e.g.,
bubble sort).
Present a well-formatted report card using sorted data.
Project Title 2: Efficient Report Card Generation
Using Merge Sort
Modules/Phases
Core
Areas of 1. Requirement Analysis:
Focus Input: List of student names with corresponding marks.
Expected Output: Sorted list of students based on
• DIVIDE-
AND-
marks (ascending/descending), along with grades.
CONQUER
• MERGE
2. Design:
SORT Design a flowchart or pseudo code for merge sort.
ALGORITHM
Input: List of marks or (student name, marks) pairs.
• PERFORMA
NCE Output: Sorted list and grade assignment.
ANALYSIS
Project Title 2: Efficient Report Card Generation
Using Merge Sort
3. Implementation:
Core Use Python to implement:
Areas of
◦ Student data input (name and marks)
Focus
◦ Merge sort algorithm
• DIVIDE- ◦ Grade assignment logic
AND-
CONQUER Display report card sorted by marks.
4. Testing:
• MERGE
SORT Test with different number of students:
ALGORITHM
◦ Small (5–10 students)
• PERFORMA
NCE ◦ Medium (50 students)
ANALYSIS
◦ Large (100+ students)
Sort in both ascending and descending orders.
Validate correctness and stability of sorting.
Project Title 2: Efficient Report Card Generation
Using Merge Sort
5. Performance Analysis:
Core Compare merge sort vs bubble sort or any basic sorting.
Areas of Measure:
Focus
◦ Execution time
• DIVIDE- ◦ Number of comparisons
AND-
Use time module:
CONQUER
python
• MERGE
SORT import time
ALGORITHM
start = time.time()
• PERFORMA
NCE merge_sort(student_marks)
ANALYSIS
end = time.time()
print("Time taken:", end - start)
Project Title 2: Efficient Report Card Generation
Using Merge Sort
7. Expected Output:
• MERGE
SORT A sorted report card displaying:
ALGORITHM
◦ Student names
• PERFORMA
NCE ◦ Marks
ANALYSIS
◦ Grades (A/B/C etc.)
Performance comparison report
Project Title 2: Efficient Report Card Generation
Using Merge Sort
8. Real-World Applications:
Core E-commerce: Sorting products by price or rating.
Areas of Hospitals: Sorting patient data by priority.
Focus
Banking: Sorting transactions by amount/date.
• DIVIDE- Library Systems: Sorting books by title or author.
AND-
CONQUER
• MERGE
Conclusion
SORT Learn how merge sort applies divide-and-conquer
ALGORITHM
practically.
• PERFORMA
NCE Understand sorting algorithm complexity (O(n log n)).
ANALYSIS
Apply sorting to a real-life problem (student report card).
Project Title 3: Performance-Oriented Salary
Sorting in HR Systems Using Quick Sort
Problem Statement:
Core To implement and evaluate the Quick Sort algorithm,
Areas of
which operates on the divide-and-conquer principle, and
Focus
apply it to sort employee data by salary in an HR
management system. The goal is to optimize data
• DIVIDE-AND-
CONQUER handling, salary-based queries, and reporting in a time-
STRATEGY
efficient manner.
• QUICK SORT
Objectives:
ALGORITHM Understand how Quick Sort operates internally.
Sort employee salary records efficiently using Quick Sort.
• IN-PLACE
SORTING Use the sorted data to enhance HR system features like
reporting and payroll.
• PERFORMANC
Compare Quick Sort with other sorting algorithms in
E
COMPARISON terms of time complexity and resource usage.
Handle both ascending and descending sorting logic as
needed.
Project Title 3: Performance-Oriented Salary
Sorting in HR Systems Using Quick Sort
Core
Areas of Modules/Phases
Focus
Core 3. Implementation:
Areas of ◦ Programming Language: Python (or Java/C++)
Focus
◦ Inputs:
• DIVIDE-AND-
Employee name
CONQUER Salary
STRATEGY
◦ Apply Quick Sort to the salary list.
• QUICK SORT ◦ Display sorted records.
ALGORITHM
4. Testing:
• IN-PLACE ◦ Test with employee lists of:
SORTING
10 records (small)
• PERFORMANC 50 records (medium)
E
COMPARISON 100+ records (large)
◦ Validate sorting logic and execution time.
Project Title 3: Performance-Oriented Salary
Sorting in HR Systems Using Quick Sort
Core
Areas of
Focus
Conclusion
• DIVIDE-AND-
CONQUER
This project demonstrates the real-world utility of
STRATEGY Quick Sort in HR systems. Its speed and in-place
sorting capability make it ideal for managing large
• QUICK SORT employee datasets efficiently. By integrating
ALGORITHM
algorithmic logic with real-time systems, we bring
• IN-PLACE
theoretical computer science into practical use.
SORTING
• PERFORMANC
E
COMPARISON