0% found this document useful (0 votes)
12 views12 pages

Module 1 Very Important Questionsthis Questions Are Not Available in Model Question Paper

Uploaded by

SHASHI N
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)
12 views12 pages

Module 1 Very Important Questionsthis Questions Are Not Available in Model Question Paper

Uploaded by

SHASHI N
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/ 12

MODULE I

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

1. What is an Algorithm? What are the properties of an algorithm? Explain with


example (4) (OR) Define algorithm. Explain the characteristics of anProf Priya(6)
algorithm. D
(OR) Define algorithm with specifications for writing algorithm (6)

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)

n3 ∉ O(n2), 0.00001n3 ∉ O(n2), n4 + n + 1 ∉ O(n2)


Ω(big omega)
 Definition: A function t(n) is said to be in Ω(g(n)), denoted t(n)∈Ω(g(n)), if t(n) is
bounded below by some positive 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)
≥ c g(n) for all n ≥ n0.
 Here is an example of the formal proof that n3 ∈Ω(n2): n3 ≥ n2 for all n ≥ 0, i.e.,
we can select c = 1 and n0 = 0.

Θ (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)

The general framework for analyzing the efficiency of algorithms:


 Time efficiency
 Space efficiency
Time efficiency: also called time complexity, indicates how fast an algorithm in question
runs.
Space efficiency: also called space complexity, refers to the amount of memory units
required by the algorithm in addition to the space needed for its input and output

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

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)
Sequential Search
Straight forward algorithm that searches for a given item in a list of n elements by checking
successive elements of the list until either a match with the search key is found or the list is
exhausted

 Searching for a specific item in an array of n elements results in three situations


 Worst-case Efficiency
o Efficiency of an algorithm for the input of size n for which the algorithm takes the
longest time to execute among all possible inputs
o The algorithm makes the largest number of key comparisons among all possible
inputs of size n
Cworst(n) = n
 Best-case Efficiency
o Efficiency of an algorithm for the input of size n for which the algorithm takes the
least time to execute among all possible inputs
o Algorithm runs the fastest among all possible inputs of that size
o The search element presents at the beginning of the list
Cbest(n) = 1
 Average-case Efficiency
o Efficiency of an algorithm for the input of size n for which the algorithm takes
average number of comparisons to execute
o The search element presents at the middle of the list
o Required only for randomized input
o For successful search i.e p = 1 average no. of key comparison is
Cavg(n) = (n+1)/2
o For unsuccessful search i.e p = 0 average no. of key comparison is
Cavg(n) = 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)

Tower of Hanoi puzzle


 In this puzzle, There are n disks of different sizes that can slide onto any of three pegs
 Initially, all the disks are on the first peg in order of size, the largest on the bottom and the
smallest on top
 The goal is to move all the disks to the third peg, using the second one as an auxiliary, if
necessary. We can move only one disk at a time, and it is forbidden to place a larger disk on
top of a smaller one. The problem has an elegant recursive solution, which is illustrated in
Figure.
1. If n = 1, we move the single disk directly from the source peg to the destination peg.
2. To move n>1 disks from peg 1 to peg 3 (with peg 2 as auxiliary),
o First move recursively n-1 disks from peg 1 to peg 2 (with peg 3 as auxiliary),
o then move the largest disk directly from peg 1 to peg 3, and,
o finally, move recursively n-1 disks from peg 2 to peg 3 (using peg 1 as auxiliary).
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)

 Important Problem Types


o Important problem types: Sorting, Searching, String processing, Graph problems,
Combinatorial problems.
 1. Sorting
o The sorting problem is to rearrange the items of a given list in non-decreasing order.
o Although some algorithms are indeed better than others, there is no algorithm that
would be the best solution in all situations.
o Some of the algorithms are simple but relatively slow, while others are faster but
more complex; some work better on randomly ordered inputs, while others do better
on almost-sorted lists; some are suitable only for lists residing in the fast memory,
while others can be adapted for sorting large files stored on a disk; and so on.
o Two properties of sorting algorithm:
 A sorting algorithm is called stable if it preserves the relative order of any two
equal elements in its input.
 The second notable feature of a sorting algorithm is the amount of extra
memory the algorithm requires. An algorithm is said to be in-place if it does
not require extra memory, except, possibly, for a few memory units.
o Example: Bubble sort, merge sort, quick sort, insertion sort etc.
 1.4.2. Searching
o The searching problem deals with finding a given value, called a search key, in a
given set
o There are plenty of searching algorithms to choose from
o They range from the straight forward sequential search to a spectacularly efficient
but limited binary search and algorithms based on representing the underlying set in
a different form more conducive to searching
o The latter algorithms are of particular importance for real-world applications because
they are indispensable for storing and retrieving information from large databases
o Example: Sequential search, Binary search
 1.4.3. String Processing
o In recent decades, the rapid proliferation of applications dealing with non-numerical
data has intensified the interest of researchers and computing practitioners in string-
handling algorithms.
o A string is a sequence of characters from an alphabet. String-processing algorithms
have been important for computer science in conjunction with computer languages
and compiling issues
o Example: Brute force sting matching
 1.4.4. Graph Problems
o One of the oldest and most interesting areas in algorithmics is graph algorithms.
o Informally, a graph can be thought of as a collection of points called vertices, some
of which are connected by line segments called edges
o Graphs can be used for modeling a wide variety of applications, including
transportation, communication, social and economic networks, project scheduling,
and games
o Studying different technical and social aspects of the Internet in particular is one of
the active areas of current research involving computer scientists, economists, and
social scientists
o Example: BFS, DFS, Dijkstra’s algorithm, Prim’s Algorithm, Kruskal Algorithm

 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

You might also like