Question: 1 . ( 1 0 points ) Design an algorithm to find all the common elements in two sorted lists of numbers. For example, for
points Design an algorithm to find all the common elements in two sorted lists of numbers. For example, for the lists and the output should be
a points Algorithm design, pseudo code only.
b points What is the maximum number of comparisons your algorithm makes if the lengths of the two given lists are m and n respectively?
points Consider the following algorithm for finding the distance between the two closest elements in an array of numbers.
ALGORITHM MinDistanceAn
Input: Array An of numbers
Output: Minimum distance between two of its elements
dmininfty
for i to n do
for j to n do
if ij and Ai Aj dmin
dmin Ai Aj
return dmin
a points What is its basic operation?
b points How many times is it performed as a function of the matrix order n
c points Make as many improvements as you can in this algorithmic solution to the problem. If you need to you may change the algorithm altogether; if not, improve the implementation given.
points Consider the definitionbased algorithm for adding two n times n matrices.
a points What is its basic operation?
b points How many times is it performed as a function of the matrix order n
points Consider the definitionbased algorithm for matrix multiplication.
a points What is its basic operation?
b points How many times is it performed as a function of the matrix order n
points For each of the following functions, indicate how much the functions value will change if its argument is increased fourfold?
a logn;
bn;
c n;
d n;
en
points For each of the following pairs of functions, indicate whether the first function of each of the following pairs has a lower, same, or higher order of growth to within a constant multiple than the second function.
a nn and n;
bn and n
c logn and lnn
dn and n
en and n
points Use the informal definitions of OTheta and Omega to determine whether the following assertions are true or false.
a nn in On
b nn in On
c nn in Theta n
d nn in Omega n
e nn in Omega n
points Consider the following algorithm.
ALGORITHM Mysteryn
Input: A nonnegative integer n
S
for i to n do
S S i i
return S
a points What does this algorithm compute?
b points What is its basic operation?
c points How many times is the basic operation executed? You need to compute Cn
d points What is the efficiency class of this algorithm?
points Consider the following algorithm.
ALGORITHM EnigmaAn n A is a matrix
Input: A matrix An n of real numbers
for i to n do
for j i to n do
if Ai j Aj i
return false
return true
a points What does this algorithm compute?
b points What is its basic operation?
c points How many times is the basic operation executed? You need to compute Cn
d points What is the efficiency class of this algorithm?
points, bonus Consider the following recursive algorithm.
ALGORITHM Qn
Input: A positive integer n
if n return
else return Qn n
a points Set up a recurrence relation for this functions values and solve it to determine what this algorithm computes.
b points Set up a recurrence relation for the number of multiplications made by this algorithm and solve it
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
