0% found this document useful (0 votes)
41 views17 pages

Ada Dcet

This document provides an overview of algorithms and data structures. It discusses key topics like what an algorithm is, fundamental problem types like sorting and searching, asymptotic analysis methods like Big-O notation, and common data structures. Specific algorithms covered include selection sort, bubble sort, binary search, and merge sort. Fundamental algorithm design concepts are also introduced, such as understanding the problem, designing a solution, and analyzing efficiency.

Uploaded by

108cs18053
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)
41 views17 pages

Ada Dcet

This document provides an overview of algorithms and data structures. It discusses key topics like what an algorithm is, fundamental problem types like sorting and searching, asymptotic analysis methods like Big-O notation, and common data structures. Specific algorithms covered include selection sort, bubble sort, binary search, and merge sort. Fundamental algorithm design concepts are also introduced, such as understanding the problem, designing a solution, and analyzing efficiency.

Uploaded by

108cs18053
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/ 17

SGM Coaching Center

Design & Analysis of Algorithms -05 Marks

Syllabus:- What is an Algorithm? Fundamentals of Algorithmic problem solving, important problem types.
Fundamental data structures, Analysis Framework, Measuring the input size, Units for measuring Running time,
Orders of Growth, Worst-case, Best-case and Average-case efficiencies, Asymptotic Notations and Basic Efficiency
classes, Informal Introduction, O-notation, Ω-notation, θ-notation, Introduction to Brute Force approach,
Selection Sort and Bubble Sort, Sequential search, Exhaustive Search- Travelling salesman Problem and Knapsack
Problem, Depth First Search, Breadth First Search, Introduction to divide and conquer, Merge Sort, Quick Sort,
Binary Search, Binary Tree traversals and related properties, Decrease-and-Conquer- Introduction, Insertion Sort,
Topological Sorting.

Introduction
An algorithm is a sequence of unambiguous instructions for solving a problem, i.e., for obtaining a
required output for any accepted input in a finite amount of time.
This definition can be illustrated by a simple diagram

Example: Algorithm for computing factorial (n)

Fundamentals of Algorithmic problem solving


1) Understanding the problem
2) Ascertain the capabilities of the computational device
3) Design an algorithm
4) Proving an algorithm correctness
5) Analyzing an algorithm
6) Coding an algorithm

Important problem types


1) Sorting
2) Searching
3) String processing
4) Combinatorial problem
5) Geometric problem
6) Numerical problem
7) Graph

SORTING: -The process of re-arranging the given


elements, so that in ascending or descending order is
called sorting. The various algorithms that can be used for
sorting are: bubble sort, quick sort, merge sort, selection
sort, insertion sort, heap sort, etc…
The two properties of sorting technique are,
 Stable: -If the algorithm requires an extra memory space then the sorting algorithm is stable.
Example: Merge sort, bubble sort etc…
 In-place: - if an algorithm doesn’t require any extra memory space except for few memory units, then the
algorithm is said to be in-place. Ex: Quick sort, insertion sort, selection sort etc…

Compiled by- Arun J +91-7795287475


SEARCHING: - Searching problem deals withSGM Coaching
finding Center
a given value called a search key in a given set.(Finding the
location of the element with a given value) Searching can be a straight forward or binary Search algorithm which
is different form.

STRING PROCESSING: -A string is a sequence of character from an Alphabet. It can be text strings which
comprise letters, numbers and special characters. It is mainly used in string handling algorithms.
GRAPH PROBLEM: - One of the interesting areas in algorithm is graph algorithm.
A graph is a collection of points called vertices. Which are connected by line
segment called Edges.
Graphs are used for Modeling, a wide verity of real life application, transportation
and communication network. It includes Graph traversal, Shortest Path and
Topological Sorting Algorithm.

COMBINATORIAL PROBLEM: -TSP and graph coloring problem are example of combinatorial problem, these
are the problem, which is used to find a combinatorial object such as permutation, combination or subset that
satisfy certain constraints.

GEOMETRIC PROBLEM: - They deal with geometric object such as points, line and polygon it also include various
geometric shape such as ∆, O etc. Application for this algorithm is computer graphics, robotics.

Fundamentals of data structure


Data structure can be defined as a representation of data along with its associated operations. It is the
way of organizing and storing data in a computer system so that it can be use efficiently.
Types of data structures
Data structures are primarily divided into two classes,
1. Primitive
2. Non-primitive
Primitive data structures include all the fundamental
data structures that can be directly manipulated by
machine-level instructions. Ex: integer, character,
float, Boolean, etc.
Non-primitive data structures, Refer to all those data
structures that are derived from one or more
primitive data structures.
Non-primitive data structures are further categorized
into two types:
In linear data structures, all the data elements are arranged in a linear or sequential fashion. Examples: Arrays,
Stacks, Queues, Linked lists, etc.
Non-linear data structures, there is no definite order or sequence in which data elements are arranged. For
instance, a non-linear data structure could arrange data elements in a hierarchical fashion. Examples: trees and
graphs.

Fundamentals of the Analysis of Algorithm Efficiency


Analysis framework: -There are 2 kinds of efficiency:
 Time efficiency: also called time complexity, indicates how fast an algorithm runs.
 Space efficiency: also called space complexity, refers to the amount of memory units required by
algorithm in addition to the space needed for it’s I/P & O/P.

Measuring an input 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.

Units for measuring running time


 One possible approach is to count the number of times each of the algorithm’s operations is executed.
Identify the most important operation of the algorithm, called the basic operation.
 As a rule, it is not difficult to identify the basic operation of an algorithm: it is usually the most time-consuming
operation in the algorithm’s innermost loop. For example, most sorting algorithms work by comparing
elements (keys) of a list being sorted with each other; for such algorithms, the basic operation is a key
comparison.
Compiled by- Arun J +91-7795287475
 SGM Coaching
As another example, algorithms for mathematical Center
problems typically involve some or all of the four
arithmetical operations: addition, subtraction, multiplication, and division. Of the four, the most time-
consuming operation is division, followed by multiplication and then addition and subtraction, with the last
two usually considered together.

Worst-case best-case & average-case efficiencies


Worst-case Efficiency: -The worst case efficiency of an algorithm is its efficiency for the worst-case input of
size ‘n’. Which is an input(s) of size ‘n’ for which the algorithm runs the longest time among all possible inputs of
that size.
Best-case Efficiency: -The Best case efficiency of an algorithm is its efficiency for the best-case input of size ‘n’.
Which is an input(s) of size ‘n’ for which the algorithm runs the fastest time i.e in very short time/ quickly among
all possible inputs of that size.
Average-case Efficiency: -when neither the worst case nor the best case does not provide necessary
information about an algorithms behavior or its performance, then average-case must be considered. The input
‘n’ for this case may be random or some typical values or assumptions for the range of n could be selected.

Asymptotic notations and basic efficiency classes


Asymptotic Notations
 The efficiency of an algorithm depends on the amount of time, storage and other resources required to
execute the algorithm. The efficiency is measured with the help of asymptotic notations.
 Asymptotic notations are the mathematical notations used to describe the running time of an algorithm
when the input tends towards a particular value or a limiting value.
 The study of change in performance of the algorithm with the change in the order of the input size is
defined as asymptotic analysis.

For example:
 In bubble sort, when the input array is already sorted, the time taken by the algorithm is linear i.e. the best
case.
 But, when the input array is in reverse condition, the algorithm takes the maximum time to sort the
elements i.e. the worst case.
 When the input array is neither sorted nor in reverse order, then it takes average time. These durations are
denoted using asymptotic notations.
 There are mainly three asymptotic notations:
1. Omega notation - Best
2. Big-O notation- Worst
3. Theta notation- Average
Omega Notation (Ω-notation)
Omega notation represents the lower bound of the running time of an algorithm. Thus, it provides best case
complexity of an algorithm.

Omega gives the lower bound of a function

Compiled by- Arun J +91-7795287475


Big-O Notation (O-notation) SGM Coaching Center
Big-O notation represents the upper bound of the running time of an algorithm.
Thus, it gives the worst case complexity of an algorithm.

Big-O gives the upper bound of a function

Theta Notation (Θ-notation)


Theta notation encloses the function from above and below. Since it represents the upper and the lower bound
of the running time of an algorithm, it is used for analyzing the average case complexity of an algorithm.

C2g(n)>=f(n)>=c1g(n)

Basic Asymptotic Efficiency Classes / Orders of growth


The Basic Asymptotic Efficiency Classes in the increasing order of their orders of growth along with their
name are enlisted in the following table.

Compiled by- Arun J +91-7795287475


SGM Coaching Center

Brute Force & Exhaustive Search


Brute force is a straightforward approach to solving a problem, usually directly based on the problem
statement and definitions of the concepts involved.
Selection Sort
 We start selection sort by scanning the entire given list to find its smallest element and exchange it with the
first element, putting the smallest element in its final position in the sorted list.
 Then we scan the list, starting with the second element, to find the smallest among the last n − 1 elements and
exchange it with the second element, putting the second smallest element in its final position.
 After n − 1 passes, the list is sorted.
Best case efficiency is Ω(n2), Average case efficacy is Θ(n2), and worst case efficacy is O(n2)

Bubble sort
 Another brute-force application to the sorting problem is to compare adjacent elements of the list and
exchange them if they are out of order. By doing it repeatedly, we end up “bubbling up” the largest element
to the last position on the list.
 The next pass bubbles up the second largest element, and so on.
 After n − 1 passes the list is sorted.
 Best case efficiency is Ω(n), Average case efficacy is Θ (n2), and worst case efficacy is O(n2)

Sequential search [Linear search]


The algorithm simply compares successive elements of a given list with a given search key until either a
match is encountered (successful search) or the list is exhausted without finding a match (unsuccessful search).

Case Best Case Worst Case Average


Case
Item is 1 n n/2
Present
Item is not n n n
Present

Exhaustive search
Exhaustive search is simply a brute-force approach to combinatorial problems. It suggests generating each
and every element of the problem domain, selecting those of them that satisfy all the constraints, and then finding
a desired element.
We illustrate exhaustive search by applying it to three important problems: the traveling salesman
problem, the knapsack problem, and the assignment problem.
Compiled by- Arun J +91-7795287475
SGM Coaching Center

Traveling salesman problem

 In layman’s terms, the problem asks to find the


shortest tour through a given set of ‘n’ cities that visits
each city exactly once before returning to the city
where it started.

 The problem can be conveniently modeled by a


weighted graph, with the graph’s ‘vertices’
representing the cities and the ‘edge’ weights
specifying the distances. Then the problem can be
stated as the problem of finding the shortest
Hamiltonian circuit of the graph. (A Hamiltonian
circuit is defined as a cycle that passes through all the
vertices of the graph exactly once.)

Knapsack problem
Here is another well-known problem in algorithmic. Given ‘n’ items of known weights w1, w2. . . wn and
values v1, v2, . . . , vn and a knapsack of capacity W, find the most valuable subset of the items that fit into the
knapsack.

The exhaustive-search approach to this problem leads to generating all the subsets of the set of ‘n’ items
given, computing the total weight of each subset in order to identify feasible subsets and finding a subset of the
largest value among them.

Since the number of subsets of an n-element set is 2n, the exhaustive search leads to a Ω(2n)algorithm,
no matter how efficiently individual subsets are generated.

Depth-first search
 Depth-first search starts a graph’s traversal at an arbitrary vertex by marking it as visited. On each iteration,
the algorithm proceeds to an unvisited vertex that is adjacent to the one it is currently in.
 This process continues until a dead end—a vertex with no adjacent
unvisited vertices—is found.
 At a dead end, the algorithm backs up one edge to the vertex it came
from and tries to continue visiting unvisited vertices from there.
 If unvisited vertices still remain, the depth-first search must be restarted
at any one of them. We push a vertex onto the stack when the vertex is
reached for the first time, and we pop a vertex off the stack when it
becomes a dead end.
 DFS is equivalent to Pre-order traversal in the binary trees

Compiled by- Arun J +91-7795287475


 SGM Coaching
It is also very useful to accompany a depth-first Center by constructing the so-called depth-first
search traversal
search forest. The starting vertex of the traversal serves as the root of the first tree in such a forest.
 Tree edge: Edges used by DFS traversal to reach previously unvisited vertices.
 Back edge: Edges connecting vertices to previously visited vertices other than their immediate predecessor
in the traversal.
 Cross edge: Edge that connects an unvisited vertex to vertex other than its immediate predecessor. (connects
siblings)
Below Figure provides an example of a depth-first search traversal, with the traversal stack and corresponding
depth-first search forest shown as well.

Breadth first search


 It proceeds in a concentric manner by visiting first all the vertices that are adjacent to a starting vertex, then
all unvisited vertices two edges apart from it, and so on, until all the vertices in the same connected
component as the starting vertex are visited.
 If there still remain unvisited vertices, the algorithm has to be restarted at an arbitrary vertex of another
connected component of the graph. It is convenient to use a queue to trace the operation of breadth-first
search.
 The queue is initialized with the traversal’s starting vertex, which is marked as visited. On each iteration, the
algorithm identifies all unvisited vertices that are adjacent to the front vertex, marks them as visited, and
adds them to the queue.

Below Figure provides an example of a breadth-first search traversal, with the traversal queue and corresponding
breadth-first search forest shown.

Compiled by- Arun J +91-7795287475


SGM Coaching Center
Divide-and-Conquer
Divide-and-conquer algorithms work according to the following
general plan:
 Divide: A problem is divided into several sub problems
of the same type, ideally of about equal size.
 Conquer: The sub problems are solved
 Combine: If necessary, the solutions to the sub
problems are combined to get a solution to the original
problem.

Divide-and-conquer technique is ideally suited for


parallel computations, in which each sub problem can be solved
simultaneously by its own processor.

Merge sort
Merge sort is a perfect example of a successful
application of the divide-and conquer technique. It sorts a given
array A[0..n − 1] by dividing it into two parts A[0..⌊n/2⌋− 1] and
A[⌊n/2⌋..n − 1]sorting each of them recursively, and then merging
the two smaller sorted arrays into a single sorted one.

The merging of two sorted arrays can be done as follows.


 Two pointers are initialized to point to the first elements
of the arrays being merged.
 The elements pointed to are compared, and the smaller
of them is added to a new array being constructed; after
that,
 The index of the smaller element is incremented to point
to its immediate successor in the array it was copied
from.
 This operation is repeated until one of the two given
arrays is exhausted, and then the remaining elements of
the other array are copied to the end of the new array.

Best case efficiency is Ω(n log(n)), Average case efficacy is θ(n log(n)), and worst case efficacy is O(n log(n))

Quick sort
Quicksort is the other important sorting algorithms that is based on the divide-and conquer approach. A
partition is an arrangement of the array’s elements so that all the elements to the left of some element A[s] are
less than or equal to A[s], and all the elements to the right of A[s] are greater than or equal to it. A[s] is called as
pivot element.

A[s] will be in its final position in the sorted array, and we can continue sorting the two subarrays to the left and
to the right of A[s] independently
Best case efficiency is Ω(n log(n)), Average case efficacy is θ(n log(n)), and worst case efficacy is O(n2).

Compiled by- Arun J +91-7795287475


SGM Coaching Center

Binary search
Binary search is efficient algorithm for searching in a sorted array. It works by comparing a search key K
with the array’s middle element A[m]. If they match, the algorithm stops; otherwise, the same operation is
repeated recursively for the first half of the array ifK <A[m], and for the second half ifK >A[m]

Binary Tree traversals and related properties.


A binary tree T is defined as a finite set of nodes that is either empty or consists of a root and two
disjoint binary trees TL and TR called, respectively, the left and right subtree of the root.
The most important divide-and-conquer algorithms for binary trees are the three classic traversals:
1. Preorder 2. Inorder 3. Postorder
All three traversals visit nodes of a binary tree recursively,
1. In the preorder traversal, the root is visited before the left and right subtrees are visited (in that order).
2. In the inorder traversal, the root is visited after visiting its left subtree but before visiting the right
subtree.
3. In the postorder traversal, the root is visited after visiting the left and right subtrees (in that order).

Compiled by- Arun J +91-7795287475


SGM Coaching Center
Decrease-and-Conquer
The decrease-and-conquer technique is based on exploiting the relationship between a solution to a given
instance of a problem and a solution to itssmaller instance. Once such a relationship is established, it can be
exploited either top down or bottom up.
There are three major variations of decrease-and-conquer:
1. decrease by a constant
2. decrease by a constant factor
3. variable size decrease
In the decrease-by-a-constant variation, the size of an instance is reduced by the same constant on each iteration
of the algorithm. Typically, this constant is equal to one

The decrease-by-a-constant-factor technique suggests reducing a problem instance by the same constant factor
on each iteration of the algorithm. In most applications, this constant factor is equal to two.

Finally, in the variable-size-decrease variety of decrease-and-conquer, the size-reduction pattern varies from one
iteration of an algorithm to another. Euclid’s algorithm for computing the greatest common divisor provides a
good example of such a situation.

Insertion sort
Insertion sort is an application of decrease and conquer technique. It is a comparison based sort in which
the sorted array is built on one entry at a time.

The procedure is similar to the way we play cards. After shuffling the cards we pick each card and insert
it into the proper place. So that cards in hand are arranged with ascending order. The same technique is being
followed in insertion sort.

Best case efficiency is Ω(n2), Average case efficacy is θ(n2), and worst case efficacy is O(n2).

Topological sorting
Topological sorting is a sorting method to list the vertices of the graph in such an order that for every
edge in the graph, the vertex where the edge starts is listed before the vertex where the edge ends.
There is no solution for topological sorting if there is a cycle in the digraph. The diagraph must be a
Directed Acyclic Graph (DAG).
Topological sorting problem can be solved by using
1. DFS Method
2. Source removal method
DFS Method:
 Perform DFS traversal and note the order in which vertices become dead ends. (Popped order)
 Reverse the order, yields the topological sorting.

Compiled by- Arun J +91-7795287475


Source removal method SGM Coaching Center
 Purely based on decrease and conquer
 Repeatedly identify in a remaining diagraph a source which is a vertex with no incoming edges.
 Delete it along with all the edges outgoing from it.

Applications of topological sorting


1. They include instruction scheduling in program compilation
2. cell evaluation ordering in spreadsheet formulas
3. Resolving symbol dependencies in linkers.

Time complexities of different Sorting algorithms:-

Time complexities of different Searching algorithms:-


Algorithm Time Complexity
Best Average Worst
Linear search Ω(1) Θ(n) O(n)
Binary search Ω(1) Θ(log n) O(log n)

Compiled by- Arun J +91-7795287475


SGM Coaching Center
DCET-2021

Design & Analysis of Algorithm (DAA)


1. Last step in process of problem solving is to
a) Design an solution b) Understand a problem
c) Coding the algorithm d) Analyse the algorithm

2. Second step-in problem-solving process is to


2.

a) Coding the algorithm b) Organizing the data


c) Design a solution d) define a problem

3. Thing to keep in mind while solving a problem is


a)Input data b) Output data c) Stored data d) All of above

4. First step in process of problem solving is to


a) Design an solution b) Understand a problem
c) Coding the algorithm d) Analyse the algorithm

5. A sequence of unambiguous instructions for solving a problem


a) Program b)Data c)Algorithm d) Flow chart

6. There are ______steps to solve the problem


a) Seven b) Four c) Six d) Two

7. Following is true for understanding of a problem


a) knowing the knowledgebase b) Understanding the subject on which the problem is based
c) Communication with the client d)All of the above

8. While solving the problem with computer the most difficult step is __________.
a) Describing the problem b) Finding out the cost of the software
c) Writing the computer instructions d) Testing the solution

9. Which of the following is incorrect? Algorithms can be represented:


a) As pseudo codes b) as syntax c) as programs d) as flowcharts

10. O-notation provides an asymptotic


a) Upper bound b) Light bound c) Lower bound d) None of these

11. When an algorithm is written in the form of a programming language, it becomes a _________
a) Flowchart b) Program c) Pseudo code d) Syntax

12. Which of the following case does not exist in complexity theory?
a) Best case b) Worst case c) Average case d) Null case

13. What is the efficiency for an algorithm that generates all subsets of an n- element set?
a) Cubic b) Linear c) Exponential d) Factorial

14. What is the efficiency for an algorithm that generates all permutations of an n- element set?
a) Cubic b) Linear c) Exponential d) Factorial

15. What is the efficiency for an algorithm with three embedded loops?
a) Cubic b) Linear c) Exponential d) Factorial

16. What is the efficiency for an algorithm with two embedded loops?
a) Cubic b) Linear c) Exponential d) Quadratic

Compiled by- Arun J +91-7795287475


SGM Coaching Center

17. Two main measures for the efficiency of an algorithm are


a) Processor and memory b) Complexity and capacity
c) Time and space d) Data and space

18. The space factor when determining the efficiency of algorithm is measured by
a) Counting the maximum memory needed by the algorithm
b) Counting the minimum memory needed by the algorithm
c) Counting the average memory needed by the algorithm
d) Counting the maximum disk space needed by the algorithm

19. The time factor when determining the efficiency of algorithm is measured by
a) Counting microseconds b) Counting the number of key operations
c) Counting the number of statements d) Counting the kilobytes of algorithm

20. The complexity of linear search algorithm is


a) O(n) b) O(log n) c) O(n2) d) O(n log n)

21. The complexity of Binary search algorithm is


a) O(n) b) O(log n) c) O(n2) d)O(n log n)

22. The complexity of merge sort algorithm is


a) O(n) b) O(log n) c) O(n2) d) O(n log n)

23.The complexity of Bubble sort algorithm is


a) O(n) b) O(log n) c) O(n2) d) O(n log n)

24. The worst case complexity for insertion sort is


a) O(n) b) O(log n) c) O(n2) d) O(n log n)

25. The complexity of Fibonacci series is


a) O(2n) b) O(log n) c) O(n2) d) O(n log n)

26. The worst case occur in quick sort when


a) Pivot is the median of the array b) Pivot is the smallest element
c) Pivot is the middle element d) None of the mentioned

27. The worst case complexity of quick sort is


a) O(n) b) O(log n) c) O(n2) d) O(n log n)

28. How many passes are required to sort a file of size n by bubble sort method?
a) N2 b) N c) N-1 d) N/2

29. The worst-case time complexity of Selection Exchange Sort is________.


a) O(n2) b) O(log n) c) O(n) d) O(n logn)

30. The algorithm like Quick sort does not require extra memory for carrying out the sorting procedure. This
technique is called __________.
a) In-place b) Stable c) Unstable d) In-partition

31. Which of the following sorting procedures is the slowest?


a) Quick sort b) Heap sort c) Shell sort d) Bubble sort

32. Which of the following sorting methods would be most suitable for sorting a list which is almost sorted?
a) Bubble Sort b) Insertion Sort c) Selection Sort d) Quick Sort

33. A sort which compares adjacent elements in a list and switches where necessary is ____.
a) Insertion sort b) Heap sort c) Quick sort d) Merge sort
Compiled by- Arun J +91-7795287475
SGM Coaching Center

34. A sort which iteratively passes through a list to exchange the first element with any element less than it
and then repeats with a new first element is called
a) Insertion sort b) Selection sort c) Heap sort d) Quick sort

35. The number of swapping’s needed to sort the numbers 8, 22, 7, 9, 31, 19, 5, 13 in ascending order, using
bubble sort is
a) 10 b) 9 c) 13 d)14

36. The way a card game player arranges his cards as he picks them one by one can be compared to
a) Quick sort b) Merge sort c) Insertion sort d) Bubble sort

37. Quick sort efficiency can be improved by adopting


a) Non-recursive method b) Insertion method c) Tree search method d) None of the above

38. For the improvement of efficiency of quick sort the pivot can be
a) The first element b) The mean element c) The last element d) None of the above

39. Selection sort is basically a method of repeated


a) Interchange b) Searching c) Position adjustment d) None of the above

40. Number of selections required to sort a file of size N by straight selection requires
a) N – 1 b) log N c) O(N2) d) None of the above

41. What is the advantage of selection sort over other sorting techniques?
a) It requires no additional storage space b) It is scalable
c) It works best for inputs which are already sorted d) It is faster than any other sorting technique

42. The given array is a={3,4,5,2,1}. The number of iterations in bubble sort and selection sort respectively are,
a) 4 and 4 b) 4 and 5 c) 2 and 4 d) 2 and 5

43. What is the complexity of selection sort?


a) O(nlogn) b) O(logn) c) O(n) d) O(n2)

45. Merge sort uses which of the following algorithm to implement sorting?
a) Backtracking b) Greedy algorithm c) Divide and conquer d) Dynamic programming

46. What is the time complexity of standard merge sort?


a) O(n log n) b) O(n2) c) O(n2 log n) d) O(n log n2)

47. Merge sort uses which of the following method to implement sorting?
a) Merging b) Partitioning c) Selection d) Exchanging

48. Quick Sort can be categorized into which of the following?


a) Brute Force technique b) Divide and conquer c) Greedy algorithm d) Dynamic programming

49. Which of the following is not true about QuickSort?


a) In-place algorithm b) Pivot position can be changed
c) Adaptive sorting algorithm d) Can be implemented as a stable sort

50. How many passes does an insertion sort algorithm consist of?
a) N b) N-1 c) N+1 d) N2

51. What is the running time of an insertion sort algorithm if the input is pre-sorted?
a) Ω(N2) b) Ω(N log N) c) Ω(N) d) Ω(M log N)

52. What will be the number of passes to sort the elements using insertion sort?14, 12,16, 6, 3, 10
a) 6 b) 5 c) 7 d) 1

Compiled by- Arun J +91-7795287475


SGM Coaching Center

53. For the following question, how will the array elements look like after second pass using insertion sort?
34, 8, 64, 51, 32, 21
a)8, 34, 64, 51, 32, 21 b) 8, 32, 34, 51, 64, 21
c) 8, 21, 64, 51, 32, 34 d) 8, 21, 32, 51, 64, 34

54. Which of the following real time examples is based on insertion sort?
a) Arranging a pack of playing cards b) database scenarios and distributes scenarios
c) Arranging books on a library shelf d) real-time systems

55. Which of the following sorting algorithms is the fastest for sorting small arrays?
a) Quick sort b) Insertion sort c) Shell sort d) Heap sort

56. Topological sort can be applied to which of the following graphs?


a) Undirected Cyclic Graphs b) Directed Cyclic Graphs
c) Undirected Acyclic Graphs d) Directed Acyclic Graphs

57. Topological sort starts from a node which has?


a) Maximum Degree b) Minimum Degree c) Any degree d) None of the mentioned

58 What can be the applications of topological sorting?


a) Finding prerequisite of a task b) Finding Deadlock in an Operating System
c) Finding Cycle in a graph d) All of the mentioned

59. Topological sort is equivalent to which of the traversals in trees?


a) Pre-order traversal b) Post-order traversal
c) In-order traversal d) Level-order traversal

60. Data structures used in BFS?


a) Array b) Linked list c) Stacks d) Queues

61. Data structures used in DFS?


a) Array b) Linked list c) Stacks d) Queues

62. A straight forward approach to solving a problem, usually directly based on the problem statement and
definitions of the concept involved.
a) Brute Force b) Dynamic program c) Greedy technique d) Program

63. Breadth First Search is equivalent to which of the traversal in the Binary Trees?
a) Pre-order Traversal b) Post-order Traversal
c) Level-order Traversal d) In-order Traversal

64. The efficiency of BFS when graph is represented in the form of adjacency matrix is______
a) O(n) b)O(Θ(|V|2 ) c) Θ(|V|+|E|) d) Θ(|V|2)

65. Topological sorting problem can be solved by using.


a) Source removal method b) DFS method c) Both a) & b) d) None of these

66. The algorithm design technique used for Insertion sort is_____
a) Brute Force b) Decrease & Conquer c) Divide & Conquer d) Greedy technique

67. The major variations or factors of Decrease & Conquer is


a) Decrease by a constant b) Decrease by a constant factor
c) Variable size decrease d) All of these

68. Breadth-First search method of graph traversal cannot be used to determine


Compiled by- Arun J
a) Connectivity b) Acyclicity c) Tree edges +91-7795287475
d) Articulation points
SGM Coaching Center

69. Depth -First search method of graph traversal cannot be used to determine
a) Connectivity b) Acyclicity c) Tree edges d) Minimum edge path

70. The Breadth First Search traversal of a graph will result into?
a) Linked List b) Tree c) Graph with back edges d) All of the mentioned

71. Brute force strategy of designing algorithms depends on using


a) The problem statements and definitions directly
b) Solution of a smaller instance of the same problem
c) The combined solutions of smaller sub problems
d) The solution to a simpler instance of the same problem

72. While traversing a binary tree the root is visited before the left and right subtree are visited
a) Pre-order b) In-order c) Post-order d) None of these

73. While traversing a binary tree the root is visited after visiting its left subtree but before visiting its right
subtree
a) Pre-order b) In-order c) Post-order d) None of these

74. While traversing a binary tree the root is visited after visiting the left and right subtrees
a) Pre-order b) In-order c) Post-order d) None of these

75. The algorithms like merge sort, quick sort and binary search are based on
a) Brute Force b) Decrease & Conquer c) Divide & Conquer d) Greedy technique

76. What is a randomized Quick Sort?


a) The leftmost element is chosen as a pivot b) The rightmost element is chosen as a pivot
c) Any element in an array is chosen as a pivot d) A random number is generated which is used as a pivot

77. Which of the following algorithm is not stable


a) Bubble sort b) Quick sort c) Merge sort d) Insertion sort

78. Knapsack problem belongs to ___________ problems


a) Optimization b) Linear solution c) Sorting d) Searching

79. The running time of quick sort depends heavily on selection of


a) Number of inputs b) Arrangements of elements in an array
c) Size zero elements d) Pivot element

80. A person wants to visit some places. He starts from a vertex and then wants to visit every place connected
to this vertex and so on. What algorithm he should use?
a) Depth First Search b) Breadth First Search
c) Trim’s algorithm d) None of the mentioned

81. Time Complexity of Breadth First Search is? (V – number of vertices, E – number of edges)
a) O(V + E) b) O(V) c) O(E) d) None of the mentioned

Compiled by- Arun J +91-7795287475


SGM Coaching Center

Previous year question Papers


DCET - 2018
1. Which of the following case does not exists in complexity theory?
1) Best case 2) Worst case 3) Average case 4) Null case

2. ______________ is the last step in solving the problem.


1) Understanding the problem 2) Identifying the problem
3) Evaluate the solution 4) None

3. Which is the best sorting technique when the list is already sorted?
1) Insertion sort 2) Bubble sort 3) Merge sort 4) Selection sort

4. Two main measures for the efficiency of an algorithm are


1) Process & memory 2) Complexity & Capacity 3) Time & Space 4) Date &Space

5. The complexity of linear search is ________


1) O(1) 2) O(logn) 3) O(n) 4) O(nlogn)

DCET - 2019
1. Finding the location of the element with a give value is
(A) Traversal (b) Search (C) Sort (D) None of these

2. How many passes are require to sort a file of size ‘n’ by bubble sort method?
(A) n2 b) n – 1 (C) n (D) n/2

3. The performance of algorithm depends on


(a) Memory & CPU (B) Data & information (C) Determination & dedication (D)Time & space

4. The Knapsack problem belongs to the domain of ________ problems.


(A) Optimization (B) Linear solution (C) Sorting (D) Searching

5. Step-by-step procedure is known as


(A) Program (B) Flowchart (C) Algorithm (D) All of these

DCET - 2020
1. The complexity of merge sort algorithm is
a. O(n) b. O(log n) c. O(n2) d. O(n log n)

2. The time complexity of linear search is


a. O(1) b. O(log n) c. O(n) d. O(n log n)

3. Knapsack problem is an example of


a. Greedy algorithm b. Dynamic programming
c. Divide and conquer d. Decrease and conquer

4. The relationship between number of back edges and number of cycles in DFS is
a. Both are equal b. Back edges are half of cycles
c. Back edges are on quarter of cycle d. There is no relationship between number of edges and cycles

5. DFS is equivalent to which of the traversal in binary tree


a. Pre-Order traversal b. Post-order traversal
c. In-order traversal d. Level order traversal
Compiled by- Arun J +91-7795287475

You might also like