Unitwise Definitions
Unitwise Definitions
2) The growth rate could be categorized into two types: Linear and Exponential.
If the algorithm is increased in a linear way with an increasing in input size, it
is Linear growth rate. And if the running time of the algorithm is increased
exponentially with the increase in input size, it is Exponential growth rate.
• Total time taken by the algorithm is given as a function on its input size
• Total time taken = Total Num. of steps executed Input’s size: Time required
by an algorithm is proportional to size of the problem instance.
For e.g., more time is required to sort 20 elements than what is required to sort
10 elements.
For e.g., The basic operation is usually the most time-consuming operation in
the algorithm’s innermost loop.
UNIT II
UNIT III
A Brute Force approach is an approach that finds all the possible solutions to
find a satisfactory solution to a given problem. The brute force algorithm tries
out all the possibilities till a satisfactory solution is not found.
2) Selection Sort
Selection Sort algorithm selects the smallest element from the unsorted array
and swapped with the leftmost element, and that element becomes a part of the
sorted array. This process continues moving unsorted array boundaries by one
element to the right.
5) Exhaustive Search
Exhaustive Search is a Brute-Force algorithm that systematically enumerates all
possible solutions to a problem and checks each one to see if it is a valid
solution. This algorithm is typically used for problems that have a small and
well-defined search space, where it is feasible to check all possible solutions
7) Knapsack problem
In Knapsack problem, given the weights and profits of N items, in the form
of {profit, weight} put these items in a knapsack of capacity W to get the
maximum total profit in the knapsack. In Fractional Knapsack, we can break
items for maximizing the total value of the knapsack .
UNIT IV
1) Insertion Sort
In Insertion Sort, an array of size N in ascending order iterate over the
array and compare the current element (key) to its predecessor, if the key
element is smaller than its predecessor, compare it to the elements before.
Move the greater elements one position up to make space for the swapped
element.
2) Topological Sorting
Topological sorting for Directed Acyclic Graph (DAG) is a linear
ordering of vertices such that for every directed edge u-v, vertex u comes
before v in the ordering.
Note: Topological Sorting for a graph is not possible if the graph is not
a DAG.
3) Merge Sort
Merge sort is defined as a sorting algorithm that works by dividing an
array into smaller subarrays, sorting each subarray, and then merging the
sorted subarrays back together to form the final sorted array.
4) Quick Sort
Quick sort is a highly efficient sorting algorithm and is based on
partitioning of array of data into smaller arrays. A large array is partitioned
into two arrays one of which holds values smaller than the specified value,
say pivot, based on which the partition is made and another array holds
values greater than the pivot value.
Quick sort partitions an array and then calls itself recursively twice to sort
the two resulting sub arrays.
5) Binary Search
A Binary Search Tree is a data structure used in computer science for
organizing and storing data in a sorted manner. Each node in a Binary
Search Tree has at most two children, a left child and a right child, with
the left child containing values less than the parent node and
the right child containing values greater than the parent node.
6) Types of Binary tree traversals
Tree Data Structure can be traversed in following ways:
Inorder Traversal
Preorder Traversal
Postorder Traversal
Inorder Traversal:
Algorithm Inorder(tree)
Traverse the left subtree, i.e., call Inorder(left->subtree)
Visit the root.
Traverse the right subtree, i.e., call Inorder(right->subtree)
Preorder Traversal:
Algorithm Preorder(tree)
Visit the root.
Traverse the left subtree, i.e., call Preorder(left->subtree)
Traverse the right subtree, i.e., call Preorder(right->subtree)
Uses of Preorder:
Preorder traversal is used to create a copy of the tree. Preorder
traversal is also used to get prefix expressions on an expression tree.
Postorder Traversal:
Algorithm Postorder(tree)
Traverse the left subtree, i.e., call Postorder(left->subtree)
Traverse the right subtree, i.e., call Postorder(right->subtree)
Visit the root
Uses of Postorder:
Postorder traversal is used to delete the tree.