0% found this document useful (0 votes)
8 views20 pages

Presentation (2) - 1

college 2

Uploaded by

onepiecezoro9883
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)
8 views20 pages

Presentation (2) - 1

college 2

Uploaded by

onepiecezoro9883
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/ 20

1

TOPIC :ALGORITHM
(CONTINUOUS ASSESSMENT -1)

NAME : TUHIN PAL


ROLL : 11000223053
STREAM : INFORMATION TECHNOLOGY
SEMSTER : 3TH
SUBJECT: DATA STRUCTURE AND ALGORITHM
PAPER CODE : PCC – CS301

TUHINPAL_11000223053
What is Algorithms

EXAMPLE
Definition of Algorithm
Algorithm to find the largest of three number
An algorithm is a set of commands that must be
Stape 1 :Rede the three number as a b c
followed for a computer to perform calculations
or other problem-solving operations . According State 2 : if (a >b) and (a>c)Then a is largest, go to stape 4
to its formal definition, an algorithm is a finite
set of instructions carried out in a specific order Stape 3 : if (b>a) and (b>c) then b is largest Else c is largest
to perform a particular task.
Stape 4: stope

TUHINPAL_11000223053
3
Use of Algorithm
1.Manufacturing: Algorithms are used to optimize
production processes and supply chain
management, reducing waste and increasing
efficiency.

2.Finance: Algorithms are used to analyze financial


data and make predictions, enabling traders and
investors to make informed decisions.

3.Healthcare: Algorithms are used to process and


analyze medical images, assist in diagnosing
diseases, and optimize treatment plans.4Retail:
Algorithms are used for customer relationship
management, personalized product
recommendations, and pricing optimization.

4.Transportation: Algorithms are used to optimize


routes for delivery and transportation, reducing fuel
consumption and increasing delivery speed.

5.Energy: Algorithms are used to optimize energy


generation, distribution, and consumption, reducing
waste and increasing efficiency.

6.Security: Algorithms are used to detect and


prevent security threats, such as hacking, fraud,
and cyber-attacks
TUHINPAL_11000223053
Characteristics of an Algorithm 4

Clear and Unambiguous Well-defined Inputs


The algorithm should be unambiguous. Each of its If an algorithm says to take inputs, it should be well-
stops should be clear in all aspects and must lead to defined inputs. It may or may not take input
only one meaning

Well-defined Outputs Finiteness


The algorithm must clearly define what output will The algorithm must be finite, ie. it should terminate
be yielded and it should be well-defined as well. It after a finite time.
should produce at least 1 output

Language Independent: Feasible


Algorithm must be language-independent, ie, it The algorithm must be simple, generic,
must be just plain instructions that can he and practical, such that it can be
implemented in any language, and yet the output executed using reasonable constraints
TUHINPAL_11000223053
will be the same, as expected and resources.
5

#It is easy to understand.


#An algorithm is a step-wise
representation of a solution to a given
problem.

#Writing an algorithm takes a long time so it is


time-consuming.
#Understanding complex logic through
algorithms can be very difficult.
TUHINPAL_11000223053
What is the Brute Force Algorithm? 6
Types of Algorithms
+----------------------+
| Start |
+----------------------+
A brute force algorithm is a |

Brute Force Algorithm v

simple, comprehensive search +----------------------+


| In itializ e variables |
+----------------------+
strategy that systematically |
Recursive Algorithm v
explores every option until a +----------------------+
| Ge nerate first |

problem’s answer is discovered. | candid ate solutio n |

Backtracking Algorithm +----------------------+

It’s a generic approach to |


v
+----------------------+
problem-solving that’s employed | Check candidate |
Searching Algorithm | so lution |
when the issue is small enough +----------------------+
|

to make an in-depth v

Sorting Algorithm
+----------------------+
| So lution correct? |
investigation possible. However, +----------------------+
/ \
because of their high temporal yes no
Hashing Algorithm / \

complexity, brute force v v


+------------+ +---------------------+

techniques are inefficient for


| So lution | | Gen erate next |
| found | | cand idat e solut ion |
Divide and Conquer Algorithm +------------+ +---------------------+
large-scale issues |
v
|
v
+------------+ +----------------------+

Greedy Algorithm | En d | | A ll solutio ns trie d? |


+------------+ +----------------------+
/ \
yes no
/ \
Dynamic Programming Algorithm v v
+-------------+ +----------------------+
| No solutio n | | Go back to ch eck |
| found | | candidate so lution |

Randomized Algorithm +-------------+ +----------------------+


|
v
+------------+
| En d | TUHINPAL_11000223053
+------------+
What is Recursion? 7
Types of Algorithms

+----------------------------+
| Start |
The process in which a function calls
Brute Force Algorithm +----------------------------+
itself directly or indirectly is called |
v
recursion and the corresponding +----------------------------+
Recursive Algorithm function is called a recursive function.
| Step 1: Define a base case |
| Identify the simplest case |
+----------------------------+
Using a recursive algorithm, certain |

Backtracking Algorithm problems can be solved quite easily. v


+----------------------------+
Examples of such problems are | Step 2: Define a recursive |
| case |
Searching Algorithm Towers of Hanoi (TOH), Inorder | Break problem into smaller |
| subproblems |
/Preorder/ Postorder Tree Traversals, +----------------------------+
DFS of Graph, etc. A recursive |
Sorting Algorithm function solves a particular problem by
v
+----------------------------+
| Step 3: Ensure the |
calling a copy of itself and solving | recursion terminates |
Hashing Algorithm smaller subproblems of the original
| Make sure the recursion |
| reaches the base case |
problems. Many more recursive calls +----------------------------+
|
Divide and Conquer Algorithm can be generated as and when v
+----------------------------+
required. It is essential to know that | Step 4: Combine the |
| solutions |
we should provide a certain case in | Combine solutions of |
Greedy Algorithm
order to terminate this recursion | subproblems
+----------------------------+
|

process. So we can say that every |


v
Dynamic Programming Algorithm time the function calls itself with a +----------------------------+
| End |
simpler version of the original +----------------------------+
Randomized Algorithm problem.
TUHINPAL_11000223053
What is Backtracking Algorithm? 8
Types of Algorithms

+-----------------------+
| Start |
Brute Force Algorithm Backtracking is a problem-solving +-----------------------+
algorithmic technique that involves |
v

Recursive Algorithm finding a solution incrementally by +-----------------------+


| Choose an option |
trying different options and +-----------------------+
|
undoing them if they lead to a dead v
Backtracking Algorithm end. +-----------------------+
| Is the option valid? |
+-----------------------+
| Yes | No |
Searching Algorithm It is commonly used in situations +-----------+-----------+
| |
where you need to explore multiple v v

Sorting Algorithm possibilities to solve a problem, like +-----------------------+


| Is the solution |
searching for a path in a maze or | complete?
+-----------------------+
|

solving puzzles like Sudoku. When | Yes | No |


Hashing Algorithm a dead end is reached, the
+----------+------------+
| |
algorithm backtracks to the v v
+-----------------------+
Divide and Conquer Algorithm previous decision point and | Record the solution |
+-----------------------+
explores a different path until a |
v
Greedy Algorithm solution is found or all possibilities +-----------------------+
have been exhausted | End
+-----------------------+
|

Dynamic Programming Algorithm

Randomized Algorithm
TUHINPAL_11000223053
What Searching Algorithms ? 9
Types of Algorithms

+-----------------------------+
| Start |
Brute Force Algorithm Searching algorithms are +-----------------------------+
|
essential tools in computer v
+-----------------------------+
Recursive Algorithm science used to locate | Initialize Search Parameters|
specific items within a +-----------------------------+
|
collection of data. These v
Backtracking Algorithm algorithms are designed to
+-----------------------------+
| Is the List Empty? |
+-----------------------------+
efficiently navigate through | Yes | No |
Searching Algorithm data structures to find the +-----------+-----------------+
| |
desired information, making v v
+-----------------------------+
Sorting Algorithm them fundamental in various | End |
+-----------------------------+
applications such as |

Hashing Algorithm databases, web search v


+-----------------------------+
engines, and more. | Check Current Element
+-----------------------------+
|

| Target Found | Target Not|


Divide and Conquer Algorithm | | Found |
+-----------------+-----------+
| |
v v
Greedy Algorithm +-----------------------------+
| Record the Position |
+-----------------------------+
|
Dynamic Programming Algorithm v
+-----------------------------+
| End |
+-----------------------------+
Randomized Algorithm
TUHINPAL_11000223053
What is Sorting? 10
Types of Algorithms
+---------------------------+
| Start |
+---------------------------+
|
v
Brute Force Algorithm Sorting refers to +---------------------------+
| Initialize the List |
rearrangement of a given +---------------------------+
|
Recursive Algorithm array or list of elements v
+---------------------------+
according to a comparison | Set Initial Position |

Backtracking Algorithm operator on the elements. +---------------------------+


|
The comparison operator is v
+---------------------------+
used to decide the new | Compare Elements |
Searching Algorithm order of elements in the
+---------------------------+
|
respective data structure. v
+---------------------------+
Sorting Algorithm Sorting means reordering of | Swap if Necessary |
+---------------------------+
all the elements either in |
v
Hashing Algorithm ascending or in descending +---------------------------+
order. | Move to Next Position |
+---------------------------+
|
Divide and Conquer Algorithm v
+---------------------------+
| Is the List Sorted? |
+---------------------------+
Greedy Algorithm | Yes | No |
+-------------+-------------+
| |
v v
Dynamic Programming Algorithm +---------------------------+
| End |
+---------------------------+
|
Randomized Algorithm v
+---------------------------+
| Compare Elements |
+---------------------------+ TUHINPAL_11000223053
What is Hashing? 11
Types of Algorithms
+----------------------------+
| Start |
+----------------------------+
|
Brute Force Algorithm Hashing refers to the v
+----------------------------+
process of generating a | Initialize Hash Tab le |
+----------------------------+

Recursive Algorithm fixed-size output from |


v

an input of variable size +----------------------------+


| Input Key |
using the mathematical +----------------------------+
Backtracking Algorithm |

formulas known as hash v


+----------------------------+
functions. This | Comp ute Hash Value
+----------------------------+
|

Searching Algorithm technique determines |


v

an index or location for +----------------------------+


| Is Po sitio n Emp ty? |

Sorting Algorithm the storage of an item in +----------------------------+


| Yes | No |

a data structure. +---------------+------------+


| |
v v
Hashing Algorithm +----------------------------+
| Insert Key-Valu e Pair |
+----------------------------+
|

Divide and Conquer Algorithm v


+----------------------------+
| C ontinue Inserting ? |
+----------------------------+
| Yes | No |
Greedy Algorithm +---------------+------------+
| |
v v
+----------------------------+

Dynamic Programming Algorithm


| Input Key |
+----------------------------+
|
v
+----------------------------+
Randomized Algorithm | End
+----------------------------+
|

TUHINPAL_11000223053
What is Divide and Conquer Algorithm ? 12
Types of Algorithms
+---------------------------+
| Start |
+---------------------------+
|
v
+---------------------------+
Brute Force Algorithm | Divide the Problem |
Divide and Conquer +---------------------------+
Algorithm is a problem- |
v
Recursive Algorithm solving technique used to +---------------------------+
| Is the Subproblem Size |
solve problems by dividing | Small Enough to Solve |
| Directly? |
Backtracking Algorithm the main problem into +---------------------------+
subproblems, solving them | Yes | No |
+---------------+-----------+

Searching Algorithm individually and then merging | |


v |
them to find solution to the +---------------------------+
| Solve the Subproblem |
original problem. In this | Directly |
Sorting Algorithm article, we are going to +---------------------------+
|
discuss how Divide and v
+---------------------------+
Hashing Algorithm Conquer Algorithm is helpful | Combine the Solutions of |
| Subproblems |
and how we can use it to +---------------------------+
Divide and Conquer Algorithm solve problems |
v
+---------------------------+
| Is the Original Problem |
| Solved? |
Greedy Algorithm +---------------------------+
| Yes | No |
+---------------+-----------+
| |
Dynamic Programming Algorithm v |
+---------------------------+
| Output the Solution |
+---------------------------+
Randomized Algorithm |
v
+---------------------------+
| End |
TUHINPAL_11000223053
+---------------------------+
What is Greedy Algorithms ? 13
Types of Algorithms
+---------------------------+
| St art |
+---------------------------+
|
v
+---------------------------+
Brute Force Algorithm Greedy algorithms are a class of
| Initialize the Solutio n |
+---------------------------+

algorithms that make locally


|
v

Recursive Algorithm optimal choices at each step with


+---------------------------+
| De fine the Set of Choices |

the hope of finding a global


+---------------------------+
|

optimum solution. In these


v
Backtracking Algorithm +---------------------------+

algorithms, decisions are made


| Select the Best Local |
| Op tion |

based on the information


+---------------------------+

Searching Algorithm
|

available at the current moment


v
+---------------------------+

without considering the


| Is the Ch oice Fe asible? |
+---------------------------+
Sorting Algorithm consequences of these decisions
| Yes | No |
+---------------+-----------+

in the future. The key idea is to


| |
v |

select the best possible choice at


+---------------------------+
Hashing Algorithm | Add Choice to Solution |

each step, leading to a solution


+---------------------------+
|

that may not always be the most


v
Divide and Conquer Algorithm +---------------------------+

optimal but is often good enough


| A re All C hoices |
| C onsidered? |

for many problems.


+---------------------------+
| Yes | No |
Greedy Algorithm +---------------+-----------+
| |

In this article, we will understand


v |
+---------------------------+

Dynamic Programming Algorithm greedy algorithms with


| End
+---------------------------+
|

examples. We will also look at


|
v

problems and their solutions


+---------------------------+
Randomized Algorithm | Select the Best Local |

using the greedy approach.


| Op tion |
+---------------------------+
TUHINPAL_11000223053
What is Dynamic Programming ? 14
Types of Algorithms
+---------------------------+
| St art |
+---------------------------+
|
v

Brute Force Algorithm +---------------------------+


| Initialize the Solutio n |
+---------------------------+
Dynamic Programming is a |
v
Recursive Algorithm method used in mathematics +---------------------------+
| De fine the Set of Choices |
and computer science to +---------------------------+
|

Backtracking Algorithm solve complex problems by v


+---------------------------+
breaking them down into | Select the Best Local |
| Op tion |
simpler subproblems. By +---------------------------+
Searching Algorithm |
solving each subproblem v
+---------------------------+
only once and storing the | Is the Ch oice Fe asible? |
+---------------------------+
Sorting Algorithm results, it avoids redundant | Yes | No |
+---------------+-----------+
computations, leading to |
v
|
|

Hashing Algorithm more efficient solutions for a +---------------------------+


| Add Choice to Solution |
wide range of problems. This +---------------------------+
|

Divide and Conquer Algorithm article provides a detailed v


+---------------------------+
exploration of dynamic | A re All C hoices
| C onsidered?
|
|
programming concepts, +---------------------------+

Greedy Algorithm illustrated with examples.


| Yes | No |
+---------------+-----------+
| |
v |
+---------------------------+
Dynamic Programming Algorithm | End
+---------------------------+
|

|
v

Randomized Algorithm +---------------------------+


| Select the Best Local |
| Op tion |
+---------------------------+
TUHINPAL_11000223053
What is Randomized Algorithms ? 15
Types of Algorithms
+--------+
| St art |
+---+----+
|
v
Randomized algorithms in data +---+----+
| Inpu t |
Brute Force Algorithm structures and algorithms (DSA) are +---+----+
|
algorithms that use randomness in v
+----------------+
Recursive Algorithm their computations to achieve a | Random Cho ice |
| (Gene rat e R ) |
desired outcome. These algorithms +---+------------+
|

Backtracking Algorithm introduce randomness to improve v


+------------------+
efficiency or simplify the algorithm | Pr oce ss (f(X, R))|
+---+--------------+
design. By incorporating random |

Searching Algorithm choices into their processes,


v
+------------------+
| Check Co ndition |
randomized algorithms can often +---+--------------+
|
Sorting Algorithm provide faster solutions or better +------v------+
| Ye s |
approximations compared to | (C ondition |
| Satisfied) |

Hashing Algorithm deterministic algorithms. They are +------v------+


|
particularly useful in situations where v
+---+----+
exact solutions are difficult to find or | Outp ut |
Divide and Conquer Algorithm +---+----+
when a probabilistic approach is |
v
acceptable. +---+----+
| End |
Greedy Algorithm +--------+
|
For example, in Randomized Quick v
+---+----+

Dynamic Programming Algorithm Sort, we use a random number to | No |


+---v--------+
pick the next pivot (or we randomly | R and om |
| C hoice |

Randomized Algorithm shuffle the array). Typically, this | (Generate |


| New R) |
randomness is used to reduce time +------------+
|
complexity or space complexity in v
+---+----+
TUHINPAL_11000223053
other standard algorithms | Pr oce ss |
| (f (X, R))|
+----------+
sparse matrix
16
Matrix types having most of their elements set to zero are called sparse matrices. In other terms, the definition of a
sparse matrix is one in which the number of 0 entries is greater than the number of non-zero elements

1) Why is a sparse matrix required if we can use


the simple matrix to store elements?
There are the following benefits of using the sparse
matrix -

Storage - We know that a sparse matrix contains lesser


non-zero elements than zero, so less memory can be
used to store elements. It evaluates only the non-zero
elements.

Computing time: In the case of searching in sparse


matrix, we need to traverse only the non-zero
elements rather than traversing all the sparse matrix
elements. It saves computing time by logically
designing a data structure traversing non-zero
elements.

TUHINPAL_11000223053
sparse matrix
17

TUHINPAL_11000223053
Single number
18

TUHINPAL_11000223053
Single number
19

TUHINPAL_11000223053
20

Conclusion
we extend our heartfelt
gratitude to Dennis Ritchie
for his creation of the C
programming language. His
pioneering work has
profoundly shaped modern
computing, inspiring
countless programmers
and innovations. Thank you,
Dennis Ritchie, for your
lasting impact on the world
of technology.

TUHINPAL_11000223053

You might also like