2.1-2 For sorting in Non increasing order
INSERTION-SORT(A)
for j 2 to length[A]
do key A[j]
Insert A[j] into the sorted
sequence A[1 _ j - 1].
ij-1
while i > 0 and A[i] < key
do A[i + 1] A[i]
ii-1
A[i + 1] key
2.1-3
Input: A = ha1; a2; ani and a value v.
Chapter 7 Quiz Solution
1.
2.
3.
4.
O(n^2)
C
B
Because in randomized algorithm, worst-case occurs very rarely and we are not
interested in that, so every time pivot number would be random so there are less
chances of getting worst case.
5. Text box page 1
Chapter 4
Answer 1 When sub problem becomes small enough that we no longer recurse it ,
then the recursion is bottoms out.
Answer 2 Different method of solving recursion are as follow:Substitution , Recursion tree and master theorem .
Answer 3 b
Answer 4
CS 312 Fall 15
Name:
CIN:
Quiz 1
1. Define an algorithm
(1 mark)
Informally, an algorithm is any well-defined computational procedure that takes
some value, or set of values, as input and produces some value, or set of values, as
output.
2. Define data st
CS 312 Fall 15
Name:
CIN:
Quiz 2
1. Write the complexity for below algorithm?
int fun(int n)
cfw_
int count = 0;
for (int i = 0; i < n; i+)
for (int j = i; j > 0; j-)
count = count + 1;
return count;
O(n^2)
2.
In a competition, four different functions a
Chapter 5
1. (i) Define Indicator Random Variable.
Answer
(ii) Using Indicator Random Variable, show the expected number of tails after flipping a fair coin
one time. Clearly state your assumptions and the necessary steps.
Answer
Sample space is cfw_H, T.