0% found this document useful (0 votes)
23 views

Unitwise Definitions

The document covers fundamental concepts of algorithm analysis, including worst-case, best-case, and average-case scenarios, as well as linear and exponential growth rates. It discusses various sorting algorithms such as Selection Sort, Bubble Sort, Insertion Sort, Merge Sort, and Quick Sort, along with search algorithms like Sequential Search and Binary Search. Additionally, it introduces key problems in algorithmic problem-solving, including the Travelling Salesman Problem and the Knapsack problem, and explains traversal methods for binary trees.

Uploaded by

Ganesh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views

Unitwise Definitions

The document covers fundamental concepts of algorithm analysis, including worst-case, best-case, and average-case scenarios, as well as linear and exponential growth rates. It discusses various sorting algorithms such as Selection Sort, Bubble Sort, Insertion Sort, Merge Sort, and Quick Sort, along with search algorithms like Sequential Search and Binary Search. Additionally, it introduces key problems in algorithmic problem-solving, including the Travelling Salesman Problem and the Knapsack problem, and explains traversal methods for binary trees.

Uploaded by

Ganesh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 6

UNIT I

1) Worst-case − The maximum number of steps taken on any instance of size a.


Best-case − The minimum number of steps taken on any instance of size a.
Average case − An average number of steps taken on any instance of size a.
Amortized − A sequence of operations applied to the input of
size a averaged over time.

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.

3) Algorithm efficiency relates to how many resources a computer needs to


expend to process an algorithm. The efficiency of an algorithm needs to be
determined to ensure it can perform without the risk of crashes or severe delays.
If an algorithm is not efficient, it is unlikely to be fit for its purpose.

4) Algorithmic problem solving is solving problem that require the


formulation of an algorithm for the solution.

5) The Orders of Growth of an algorithm is an approximation of the time


required to run a computer program as the input size increases. The order of
growth ignores the constant factor needed for fixed operations and focuses
instead on the operations that increase proportional to input size.

6) Framework for Analysis

We use a hypothetical model with following assumptions

• Total time taken by the algorithm is given as a function on its input size

• Logical units are identified as one step

• Every step require ONE unit of time

• 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.

7) Units for Measuring Running Time: Count the number of times an


algorithm’s basic operation is executed. (Basic operation: The most important
operation of the algorithm, the operation contributing the most to the total
running time.)

For e.g., The basic operation is usually the most time-consuming operation in
the algorithm’s innermost loop.

UNIT II

1) Time complexity and Space complexity

The efficiency or running time of an algorithm is stated as a function relating


the input length to the number of steps, known as Time complexity, or volume
of memory, known as space complexity.

2) Non-recursive algorithms do not involve function calls to itself. Instead,


they utilise looping structures such as for-loops, while-loops, and do-while
loops, depending on the specific requirements of the problem and programming
language.

3) Recursive Algorithm is defined as an algorithm which can call itself with


smaller (or simpler) input values, and which obtains the result for the current
input by applying simple operations to the returned value for the smaller (or
simpler) input.

UNIT III

1) Brute force approach

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.

3) Bubble Sort also known as Exchange Sort, is a simple sorting algorithm. It


works by repeatedly stepping throughout the list to be sorted, comparing two
items at a time and swapping them if they are in the wrong order. The pass
through the list is duplicated until no swaps are desired, which means the list is
sorted.
4) Sequential Search
Linear search is a type of Sequential searching algorithm where every
element within the input array is traversed and compared with the key element
to be found. If a match is found in the array the search is said to be successful; if
there is no match found the search is said to be unsuccessful and gives the
worst-case time complexity.

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

6) Travelling Salesman Problem


The Travelling Salesman Problem is a graph computational problem where
the salesman needs to visit all cities (represented using nodes in a graph) in a
list just once and the distances (represented using edges in the graph) between
all these cities are known. The solution that is needed to be found for this
problem is the shortest possible route in which the salesman visits all the cities
and returns to the origin city

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 .

8) Breadth First Search (BFS) algorithm traverses a graph in a breadth-ward


motion and uses a queue to remember to get the next vertex to start a search
when a dead end occurs in any iteration.
BFS is basically a node based algorithm which is used to find the shortest path
in the graph between two nodes. BFS moves through all of its nodes which are
connected to the individual nodes.
BFS uses the FIFO (First In First Out) principle while using the Queue to find
the shortest path. However, BFS is slower and requires a large memory space.

9) Depth First Search (DFS) algorithm traverses a graph in a depth-ward


motion and uses a stack to remember to get the next vertex to start a search
when a dead end occurs in any iteration.
DFS uses LIFO (Last In First Out) principle while using Stack to find the
shortest path. DFS is also called Edge Based Traversal because it explores the
nodes along the edge or path. DFS is faster and requires less memory. DFS is
best suited for decision trees.

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)

Uses of Inorder Traversal:


In the case of binary search trees (BST), Inorder traversal gives nodes
in non-decreasing order. To get nodes of BST in non-increasing order,
a variation of Inorder traversal where Inorder traversal is reversed can
be used.

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.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy