0% found this document useful (0 votes)
6 views16 pages

Seminar Report Format[1] Shreyas666 Copy

The seminar report discusses the analysis and design of algorithms, emphasizing their importance in computer science and software development. It covers algorithm characteristics, types, analysis of time and space complexity, and the advantages of algorithm analysis, including performance prediction and optimal resource utilization. Additionally, it explores the Branch and Bound technique for solving the Knapsack Problem, detailing its algorithm, time complexity, and real-world applications.

Uploaded by

shreyase991
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)
6 views16 pages

Seminar Report Format[1] Shreyas666 Copy

The seminar report discusses the analysis and design of algorithms, emphasizing their importance in computer science and software development. It covers algorithm characteristics, types, analysis of time and space complexity, and the advantages of algorithm analysis, including performance prediction and optimal resource utilization. Additionally, it explores the Branch and Bound technique for solving the Knapsack Problem, detailing its algorithm, time complexity, and real-world applications.

Uploaded by

shreyase991
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/ 16

VISVESVARYATECHNOLOGICALUNIVERSITY

Jnana Sangama,Belagavi-590018

Seminar Report on
“Analysis & Design of Algorithms (BCS401)”
submitted in the partial fulfillment of the requirement for the award degree of

BACHELOR OF ENGINEERING
in
COMPUTER SCIENCE & ENGINEERING

submitted by

SHREYAS E

1AR23CS097

Under the guidance of


Dr. Mahantesh Mathapati
Professor, Dept. of CSE,
AIEMS, Bengaluru

AIEMS
BENGALURU

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING


2024-25

B. V. V. Sangha’s
AMRUTA INSTITUTE OF ENGINEERING & MANAGEMENT SCIENCES
Bidadi Industrial Area, Bidadi, Bengaluru–562109
TABLE OF CONTENTS

SL Title Page No
.No
1 Introduction to Algorithms 3-4
2 Analysis of Algorithms (Time and Space 5-8
Complexity)
3 Advantages of Algorithms Analysis 9 - 10
4 Topic: Branch and Bound (knapsack problem) 11 - 12
i).Introduction:
ii). Branch and Bound (knapsack problem) Algorithm 13
code
iii).Time complexity of Branch and Bound (knapsack 14 - 15
problem)
iv).Applications of Branch and Bound (knapsack
problem) in real time

ii
Analysis & Design of Algorithms (BCS401) 2024-25

1. INTRODUCTION TO ALGORITHMS

An algorithm is a well-defined, step-by-step procedure or set of rules designed to


perform a specific task or solve a particular problem. Algorithms are fundamental
to computer science and software development, as they form the foundation of
efficient and logical programming. Whether it's searching for information, sorting
data, or performing complex calculations, algorithms play a critical role in ensuring
that these tasks are performed accurately and efficiently.
The concept of algorithms dates back to ancient times. The word "algorithm" is
derived from the name of the Persian mathematician Muhammad ibn Musa al-
Khwarizmi, who wrote a book in the 9th century that introduced systematic
procedures for solving mathematical problems. In modern computing, algorithms
are implemented using programming languages, and their design and analysis are
central to computer science.

Characteristics of a Good Algorithm


A good algorithm must possess the following characteristics:

1. Input: It should take zero or more inputs.


2. Output: It must produce at least one output.
3. Definiteness: All steps must be clearly and unambiguously defined.
4. Finiteness: It should complete after a finite number of steps.
5. Effectiveness: Each step should be basic enough to be carried out.

Dept. of CSE, AIEMS Page3


Analysis & Design of Algorithms (BCS401) 2024-25

Types of Algorithms

Algorithms can be classified into several types based on their purpose and
strategy:
1.Sorting Algorithms: Such as Bubble Sort, Merge Sort, and Quick Sort.
These are used to arrange data in a specific order.
2.Searching Algorithms: Like Linear Search and Binary Search, used to
locate a particular element within a dataset.
3.Recursive Algorithms: These solve problems by calling themselves
with smaller inputs, such as the Tower of Hanoi or Factorial calculation.
4.Dynamic Programming Algorithms: These store results of
subproblems to avoid repeated work, for example, in the Fibonacci series.
5.Greedy Algorithms: These make the best possible decision at each
step, often used in optimization problems.

6.Divide and Conquer Algorithms: These divide the problem into


smaller subproblems, solve them independently, and combine the results
(e.g., Merge Sort).

Applications of Algorithms

Algorithms are everywhere—from search engines like Google,


navigation systems, e-commerce platforms, to machine learning and
artificial intelligence. They are used in data compression, encryption,
graphics rendering, and even in everyday apps like ride-sharing or
recommendation systems.

Dept. of CSE, AIEMS Page4


Analysis & Design of Algorithms (BCS401) 2024-25

2. ANALYSIS OF ALGORITHMS

Algorithm analysis is a fundamental part of computer science that helps


determine the efficiency of algorithms in terms of time (how fast they run) and
space (how much memory they use). This allows developers and engineers to
compare multiple algorithms and select the most suitable one for specific
problems.

1. Time Complexity

Time Complexity refers to the computational time an algorithm takes to


complete, as a function of the input size (usually denoted as n). It gives an idea
of how the runtime grows with the size of the input.

Common Time Complexities:

Complexity Name Example

O(1) Constant Time Accessing array element

O(log n) Logarithmic Time Binary Search

O(n) Linear Time Linear Search

O(n log n) Linearithmic Time Merge Sort

O(n²) Quadratic Time Bubble Sort

O(2ⁿ) Exponential Time Recursive Fibonacci

O(n!) Factorial Time Travelling Salesman

Dept. of CSE, AIEMS Page5


Analysis & Design of Algorithms (BCS401) 2024-25

Best, Worst, and Average Cases:


 Best Case: Minimum time the algorithm can take (e.g., first element is the
target).
 Worst Case: Maximum time the algorithm can take (e.g., target not found).

 Average Case: Expected time over all inputs.

Summary Table: Time Complexity of Common Algorithms

Category Algorithm Best Average Worst

Searching Linear Search O(1) O(n) O(n)

Binary Search O(1) O(log n) O(log n)

Sorting Bubble Sort O(n) O(n²) O(n²)

Merge Sort O(n log n) O(n log n) O(n log n)

Quick Sort O(n log n) O(n log n) O(n²)

Insertion Sort O(n) O(n²) O(n²)

Recursive Fibonacci (naive) O(2ⁿ) O(2ⁿ) O(2ⁿ)

Fibonacci (DP) O(n) O(n) O(n)

Dept. of CSE, AIEMS Page6


Analysis & Design of Algorithms (BCS401) 2024-25

3 . ANALYSIS OF ALGORITHMS

2. Space Complexity
Space Complexity measures the total amount of memory an algorithm uses
relative to the input size, including:

 Input space
 Auxiliary (temporary) space

Like time complexity, space complexity is also expressed using Big O notation.

Space Complexity of Common Algorithms


🔹 Sorting Algorithms

Algorithm Space Notes


Complexity

Bubble Sort O(1) In-place sorting; requires no extra


space

Selection O(1) In-place algorithm


Sort

Insertion Sort O(1) In-place sorting

Merge Sort O(n) Requires additional space for


merging

Quick Sort O(log n) Due to recursion stack

Dept. of CSE, AIEMS Page7


Analysis & Design of Algorithms (BCS401) 2024-25

🔹 Searching Algorithms

Algorithm Space Complexity Notes


Linear Search O(1) No extra space used
Binary Search O(1) (Iterative) / O(log n) Depends on
(Recursive) approach
Hashing O(n) Needs extra space for
hash table

🔹 Dynamic Programming

Algorithm / Use Case Space Notes


Complexity

Fibonacci (memorized) O(n) Stores results of subproblems

Longest Common Subsequence O(n²) 2D table of size n x m


(LCS)

Knapsack Problem O(n W) W = capacity; space used for DP


table

Matrix Chain Multiplication O(n²) Uses 2D table

🔹 Graph Algorithms

Dijkstra's Algorithm O(V + E) Stores distances and priority queue

Floyd-Warshall O(n²) Uses 2D matrix for all-pairs shortest paths

Prim’s / Kruskal’s O(V + E) Space for edge list, sets, or priority queues

Dept. of CSE, AIEMS Page8


Analysis & Design of Algorithms (BCS401) 2024-25

4. ADAVANATAGES OF ALGORITHMS ANALYSIS

1. Performance Prediction
Analyzing algorithms helps predict their performance in terms of:
 Time Complexity (execution time)
 Space Complexity (memory usage)
This prediction helps select the most efficient algorithm for a given task,
especially when handling large datasets.

2. Optimal Resource Utilization


By analyzing algorithms, developers can choose those that use minimum CPU
time and memory, leading to:
 Faster execution
 Lower power consumption
 Better hardware efficiency

3. Scalability Assessment
Algorithm analysis shows how an algorithm behaves as the input size increases.
This helps determine whether an algorithm can handle real-world, large-scale
problems efficiently.

4. Comparison Between Algorithms


When multiple algorithms solve the same problem, analysis helps:
 Compare their efficiency
 Choose the best one for a specific environment or constraint
 Avoid using inefficient or outdated methods

Dept. of CSE, AIEMS Page9


Analysis & Design of Algorithms (BCS401) 2024-25

5. Improved Software Design


Efficient algorithms lead to:
 Responsive applications
 Reduced lag and delays
 Better user experience
Analyzing before implementation ensures well-designed software systems.

6. Cost Reduction
Efficient algorithms reduce:
 Processing time
 Energy consumption
 Cloud/server costs for large systems
This is particularly important in commercial or large-scale software systems.

7. Foundation for Advanced Techniques


Understanding algorithm analysis is essential for:
 Competitive programming
 Data science and AI
 Cybersecurity
 Embedded systems
It provides a base for learning advanced topics like dynamic programming,
greedy methods, graph theory, etc.

8. Error Detection and Debugging


Analyzing the flow and complexity helps identify:
 Inefficient loops or recursion
 Unoptimized code paths
 Bottlenecks in the algorithm
This leads to better debugging and optimization.

Dept. of CSE, AIEMS Page10


Analysis & Design of Algorithms (BCS401) 2024-25

5. Branch And Bound (Knapsack Problem)

i).Introduction:
The Knapsack Problem is one of the most fundamental problems in
combinatorial optimization. It involves selecting a subset of items with given
weights and profits such that the total profit is maximized without exceeding a
specified weight capacity. The 0/1 Knapsack Problem, in particular, restricts
the selection of items to either completely include or exclude them—fractional
inclusion is not allowed.
Solving the 0/1 Knapsack Problem becomes computationally intensive as the
number of items increases because the total number of possible item
combinations grows exponentially. While brute-force methods can solve it by
evaluating all possible combinations, they are inefficient and impractical for
large inputs.
To address this challenge, the Branch and Bound technique is used. It is a
search-based optimization method that divides the problem into smaller
subproblems (branching) and uses a bound function to estimate the best
possible solution from a given state. If the estimated bound is worse than the
current best known solution, the branch is pruned, meaning it is not explored
further.

ii)Branch and bound (knapsack problem)Algorithm code

Input:
 List of n items, each with weight w[i] and profit p[i]
 Knapsack capacity W

Output:
 Maximum total profit achievable without exceeding capacity W

Dept. of CSE, AIEMS Page11


Analysis & Design of Algorithms (BCS401) 2024-25

Steps:
1. Sort items by profit-to-weight ratio in descending order.

2. Initialize:
o Create a root node representing no items taken yet (level = -1, profit
= 0, weight = 0).

o Calculate the upper bound (maximum possible profit) for the root node
using a greedy method (fractional knapsack).

3. Use a priority queue (max-heap) to store live nodes (partial solutions)


sorted by their bound.

4. While the priority queue is not empty:


o Extract the node with the highest bound.
o If the node's bound is less than or equal to the current maximum
profit, discard it (prune).
o Otherwise, generate two child nodes:
 Include the next item:
Update profit and weight by adding the next item’s values.
If weight ≤ W and profit > current max profit, update max
profit.
Calculate bound for this node; if bound > max profit, add to
queue.
 Exclude the next item:
Keep profit and weight same as current node.
Calculate bound for this node; if bound > max profit, add to
queue.
5. Repeat until all promising nodes are explored.
6. Return the maximum profit found.

Dept. of CSE, AIEMS Page12


Analysis & Design of Algorithms (BCS401) 2024-25

iii).Time complexity of Branch and bound(knapsack problem)

Worst-Case Time Complexity

 In the worst case, the algorithm may explore all subsets of the items.

 Since there are 2^n subsets for n items, the worst-case time complexity is
O(2^n).

 This happens if pruning is ineffective and most branches need to be


explored.

Average-Case Time Complexity

 Branch and Bound often performs much better than brute force due to
pruning.

 The efficiency depends heavily on the quality of the bound function and
the order of item processing.

 By sorting items by profit-to-weight ratio, and pruning suboptimal nodes


early, many branches are eliminated.

 The average time complexity is often significantly less than O(2^n) in


practice, but it is problem-dependent and not easy to express precisely.

Summary

Aspect Time Complexity

Worst case O(2^n)

Average case Much better than brute force, depends on pruning effectiveness

Dept. of CSE, AIEMS Page13


Analysis & Design of Algorithms (BCS401) 2024-25

iv).Applications of Branch and bound(knapsack problem)

1. Resource Allocation
Selecting the most profitable combination of resources (items) subject to
capacity constraints, such as budget limits or storage capacity.

Problem Context
A company has a limited budget of ₹100,000 to allocate among several potential
projects or investments. Each project requires a certain investment amount (cost)
and yields an expected profit. The goal is to select a subset of projects to maximize
total profit without exceeding the budget.

Given
Project Cost (Weight) Profit (Value) Profit/Cost Ratio
A 20,000 30,000 1.5
B 50,000 80,000 1.6
C 30,000 50,000 1.67
D 40,000 55,000 1.375
E 10,000 15,000 1.5

Sorted by profit-to-cost ratio (descending): C, B, A, E, D

Branch and Bound Process

1. Start with no projects selected (profit=0, cost=0), calculate bound using


fractional knapsack on remaining projects.

Dept. of CSE, AIEMS Page14


Analysis & Design of Algorithms (BCS401) 2024-25

2. Explore including Project C:

o Cost = 30,000, Profit = 50,000


o Remaining capacity = 70,000
o Calculate bound for this node (include full and fractional parts of
remaining projects).

3. Explore excluding Project C and including Project B next:


o Cost = 50,000, Profit = 80,000
o Remaining capacity = 50,000
o Calculate bound for this node.

4. Prune branches where bound ≤ current max profit.

5. Continue exploring nodes, updating max profit and pruning as you go.

6. Optimal solution found might be Projects B, C, and E or another


combination fitting in ₹100,000.

Dept. of CSE, AIEMS Page15

You might also like