Module 1 Very Important Questionsthis Questions Are Not Available in Model Question Paper
Module 1 Very Important Questionsthis Questions Are Not Available in Model Question Paper
1. What is an Algorithm? What are the properties of an algorithm? Explain with example (4)
(OR) Define algorithm. Explain the characteristics of an algorithm. (6)
2. Define Space complexity and time complexity of an algorithm (6)
3. Design an algorithm to search an element in an array using sequential search. Discuss the
worst case, best case and average case efficiency of an algorithm. (8) (OR)
What is the worst case, best case and average case efficiencies of sequential search? (8)
4. Give the recursive algorithm to solve Tower of Hanoi problem. Shoe that the efficiency
of this algorithm is exponential. (6) (OR)
Illustrate mathematical analysis of recursive algorithm for Towers of Hanoi Problem (8)
5. Discuss the Important problem types and fundamental data structures. (8) (OR)
Mention the important problem types considered for design and analysis. Explain any
two problem types. (5) (OR)
List and explain the important problem types that are solved by computer (7)
6. Explain the working of bubble sort with example. Give its time efficiency. (8)
MODULE I
Algorithm Definition
An algorithm is a sequence of unambiguous instructions for solving a problem, i.e., for
obtaining a required output for any legitimate input in a finite amount of time.
Properties of an Algorithm
i. Input: Zero or more quantities are externally supplied
ii. Output: At least one quantity is produced.
iii. Definiteness: Each instruction is clear and unambiguous. It must be perfectly
clear what should be done.
iv. Finiteness: If we trace out the instruction of an algorithm, then for all cases,
the algorithm terminates after a finite number of steps.
v. Effectiveness: Every instruction must be very basic so that it can be carried
out, in principle, by a person using only pencil and paper. It is not enough that
each operation be definite as in criterion c; it also must be feasible
Notion of an Algorithm
2. Explain the Asymptotic notations with examples. (8) (OR)
Explain the Asymptotic notations BigO, BigOmega, Big Theta used to compare
orders of growth of an algorithm (6) (OR)
What are asymptotic notations? List and describe the various asymptotic notations
with an example of each. (8)
Asymptotic Notations
The efficiency analysis framework concentrates on the order of growth of an
algorithm’s basic operation count as the principal indicator of the algorithm’s
efficiency
To compare and rank such orders of growth, computer scientists use three
notations :
O(big oh)
Ω(big omega)
Θ (big theta) and
o(little oh)
O(big oh)
A function t(n) is said to be in O(g(n)), denoted t(n)∈O(g(n)), if t (n) is bounded
above by some constant multiple of g(n) for all large n, i.e., if there exist some
positive constant c and some nonnegative integer n0 such that t(n) ≤ cg(n) for all
n ≥ n0
Informally, O(g(n)) is the set of all functions with a lower or same order of
growth as g(n). Note that the definition gives us a lot of freedom in choosing
specific values for constants c and n0.
Examples: n ∈ O(n2), 100n + 5 ∈ O(n2), n(n - 1) ∈ O(n2)
Θ (big theta)
Theta notation A function t(n) is said to be in Θ(g(n)), denoted t(n) ∈ Θ(g(n)),if t
(n) is bounded both above and below by some positive constant multiples of g(n)
for all large n, i.e., if there exist some positive constants c1 and c2 and some
nonnegative integer n0 such that c2g(n) ≤ t(n) ≤c1g(n) for all n ≥ n0.
2. Define Space complexity and time complexity of an algorithm and compute the time
complexity of Fibonacci numbers algorithm (6)
Space Complexity
Total amount of computer memory required by an algorithm to complete its
execution is called as space complexity of that algorithm. The Space required by
an algorithm is the sum of following components
A fixed part that is independent of the input and output. This includes memory
space for codes, variables, constants and so on.
A variable part that depends on the input, output and recursion stack. ( We call
these parameters as instance characteristics)
Space complexity is measured with respect to the space/memory required
Space complexity depends on following factors
o Program space
Space required for storing the machine program generated by the
compiler or assembler
o Data Space
Space required to store variables, constants etc.
o Stack Space
Space required to store the return address along with the
parameters that are passed to the functions, local variables etc.
Now-a-days space requirement is not a big task due to technological innovations
with improved computer speed and memory size.
Time Complexity
Indicates how fast the algorithm executes
Clearly it is associated with algorithm
Time complexity depends on following factors
o Computer Speed
o Choice of programming language
o Compiler used
o Choice of algorithm
o Number(size) of inputs/outputs
Time complexity do not have direct control over the speed of the computer, programming
language and compiler
Mainly depends upon two factors
o Choice of algorithm
o Number(size) of inputs/outputs
Algorithm uses n as a parameter to find the order of growth
Parameter n indicates the no. of inputs/size of inputs
Most of the time the value of n is directly proportional to size of the data
to be processed
Therefore, all algorithms will run longer on larger inputs
So the time complexity of an algorithm depends on size of the input n,
hence time complexity is always expressed in terms of n
o Investigation of average case efficiency is more difficult than the best-case and
worst-case
4. Give the recursive algorithm to solve Tower of Hanoi problem. Shoe that the efficiency
of this algorithm is exponential. (6) (OR)
Illustrate mathematical analysis of recursive algorithm for Towers of Hanoi Problem (8)
Combinatorial Problems
o Generally speaking, combinatorial problems are the most difficult problems in
computing, from both a theoretical and practical standpoint
o Their difficulty stems from the following facts.
First, the number of combinatorial objects typically grows extremely fast with
a problem’s size, reaching unimaginable magnitudes even for moderate-sized
instances.
Second, there are no known algorithms for solving most such problems
exactly in an acceptable amount of time.
o Example: Shortest path, spanning tree problems, graph coloring problem
6. Explain the working of Bubble sort with example. Give it time efficiency (8)
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, until after n − 1 passes
the list is sorted. Pass i (0 ≤ i ≤ n − 2) of bubble sort can be represented by the following
diagram:
Example