0% found this document useful (0 votes)
12 views6 pages

Data Structure Assignment

The document discusses different types of algorithms in data structures. It lists brute force, greedy, recursive, backtracking, divide and conquer, dynamic programming, and randomized algorithms. It states that backtracking algorithm is the best as it starts with one option, tries to solve the problem with it, and if it fails it backtracks to previous options rather than trying all possibilities at once like brute force. Backtracking builds the solution by searching possible solutions and tracing back to failure points to try other options.

Uploaded by

Noor Fatima
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)
12 views6 pages

Data Structure Assignment

The document discusses different types of algorithms in data structures. It lists brute force, greedy, recursive, backtracking, divide and conquer, dynamic programming, and randomized algorithms. It states that backtracking algorithm is the best as it starts with one option, tries to solve the problem with it, and if it fails it backtracks to previous options rather than trying all possibilities at once like brute force. Backtracking builds the solution by searching possible solutions and tracing back to failure points to try other options.

Uploaded by

Noor Fatima
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/ 6

ASSIGNMENT

NAME: NOOR FATIMA

ROLL NO: BS-COMP.SC-S-061

SEMESTER: 3RD

Submitted To: Sir USMAN AZIZ


( Algorithm & Its Types )
An algorithm consists of instructions or steps that are followed in a specific order to solve a
problem. Algorithms are used in many fields, including computer science, mathematics, and
logistics. An algorithm is made of well-defined steps, including mathematical operations,
conditional statements, and loops executed in a specific order.

➢ How many Types of algorithms in data Structure?


Types of Algorithms: -
Here is a list of the most important type of algorithms to begin with:

• Brute Force algorithm


• Greedy algorithm
• Recursive algorithm
• Backtracking algorithm
• Divide & Conquer algorithm.
• Dynamic programming algorithm
• Randomized algorithm

➢ Discuss their Types of algorithms in data structure and which


algorithm is better?
Brute Force Algorithm: -
The simplest possible algorithm that can be devised to solve a problem
is called the brute force algorithm. To device an optimal solution first we need to get a
solution at least and then try to optimize it. Every problem can be solved by brute force
approach although generally not with appreciable space and time complexity. As the name
suggests, they are straightforward methods of solving a problem that relies on sheer
computing power and trying every possibility rather than advanced techniques to improve
efficiency.
Greedy Algorithm: -
In this algorithm, a decision is made that is good at that point
without considering the future. This means that some local best is chosen and considers it as
the global optimal. There are two properties in this algorithm.

Greedily choosing: the best option

Optimal substructure property: If an optimal solution can be found by retrieving the


optimal solution to its subproblems.

❖ Applications
▪ Sorting: Selection Sort, Topological sort
▪ Prim’s & Kruskal’s algorithms
▪ Coin Change problem
▪ Fractional Knapsack Problem
▪ Job Scheduling algorithm
Recursive Algorithm: -
This is one of the simplest to devise algorithms as it does not
require specifically think about every subproblem. This means we just need to think about the
existing cases and the solution of the simplest subproblem, all other complexity will be
handled by it automatically. Recursion is a very powerful tool although we should always
take care of memory management here as recursion works using recursive stack which is
called every time recursion function is invoked. Recursion simply means calling itself to
solve its subproblems.

❖ Time Complexity: O(n)

Although always remember to give the base case else the loop will continue to infinity giving
memory error. This algorithm is simpler to design and implement.

Backtracking Algorithm: -
It is an improvement to the brute force approach. Here we start
with one possible option out of many available and try to solve the problem if we can solve
the problem with the selected move then we will print the solution else we will backtrack and
select some other and try to solve it. It is a form of recursion, it’s just that when a given
option cannot give a solution, we backtrack to the previous option which can give a solution
and proceed with other options.

❖ Applications
▪ Generating all Binary strings
▪ N-Queens Problem
▪ Knapsack Problem
▪ Graph coloring Problem
Divide & Conquer algorithm; -
This technique can be divided into the following three parts:

Divide: This involves dividing the given problem into smaller problems.

Conquer: Solve the smaller problems by calling recursively until solved.

Combine: Combine the smaller problems to get the final solution of the whole problem.

❖ Applications:
▪ Binary Search
▪ Merge Sort & Quick Sort
▪ Median Finding
▪ Matrix Multiplication

Dynamic Programming Algorithm: -


This is the most sought out algorithm as it provides the most
efficient way of solving a problem. It’s simply means remembering the past and apply it to
future corresponding results and hence this algorithm is quite efficient in terms of time
complexity.

Dynamic Programming has two properties:

Optimal Substructure: An optimal solution to a problem contains an optimal solution to its


subproblems.

Overlapping subproblems: A recursive solution contains a small number of distinct


subproblems.

❖ Applications
▪ Longest Common Subsequence, Longest Increasing Subsequence, longest etc.
▪ Bellman-Ford algorithm
▪ Chain Matrix multiplication
▪ Subset Sum
▪ Knapsack Problem & many more.
Randomized Algorithm: -
As the name suggests this is an algorithm type that makes its
decision since random numbers i.e., it uses random numbers in its logic. The best example to
explain this algorithm is choosing the pivot element in quicksort.

❖ Applications
▪ Randomized Quick Sort
▪ Karger’s Algorithm etc.
( Best & Better Algorithm )
According to my point of view:
“BACKTRACKING ALGORITHM” is best and better
algorithm just because:

In this algorithm, we start with 1 possible option out of many others that are available
and try to solve the problem. If we can solve the problem with the selected move, then we
will print the solution else we end up backtracking and selecting some other option and then
try solving it. This is a form of recursion, but when a given option cannot give a solution, we
backtrack to the previous option which can give a solution and proceed with other options.

The backtracking algorithm basically builds the solution by searching among all possible
solutions. Using this algorithm, we keep on building the solution following criteria.

Whenever a solution fails, we trace back to the failure point and build on the next solution
and continue this process till we find the solution, or all possible solutions are looked after.

You might also like