Data Structure Assignment
Data Structure Assignment
SEMESTER: 3RD
❖ 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.
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.
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
❖ 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.