Question: Problem 1 Design an algorithm to find all the common elements in two sorted lists of numbers. For example, for the lists 2 , 5

Problem 1
Design an algorithm to find all the common elements in two sorted lists of
numbers. For example, for the lists 2,5,5,5 and 2,2,3,5,5,7, the output
should be 2,5,5. What is the maximum number of comparisons your algorithm
makes if the lengths of the two given lists are m and n, respectively?
Problem 2:
Consider the following algorithm for finding the distance between the two
closest elements in an array of numbers.
ALGORITHM MinDistance(A[0..n 1])
//Input: Array A[0..n 1] of numbers
//Output: Minimum distance between two of its elements
dmin \infty
for i 0 to n 1 do
for j 0 to n 1 do
if i = j and |A[i] A[j ]|< dmin
dmin |A[i] A[j ]|
return dmin
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.
Problem 3:
1. For each of the following algorithms, in
2. dicate (i) a natural size metric for its
inputs, (ii) its basic operation, and (iii) whether the basic operation count can
be different for inputs of the same size:
a. computing the sum of n numbers
b. computing n!
c. finding the largest element in a list of n numbers
d. Euclids algorithm
e. sieve of Eratosthenes
f. pen-and-pencil algorithm for multiplying two n-digit decimal integers
Problem 4
2. a. Consider the definition-based algorithm for adding two n \times n matrices.
What is its basic operation? How many times is it performed as a function
of the matrix order n? As a function of the total number of elements in the
input matrices?
b. Answer the same questions for the definition-based algorithm for matrix
multiplication.
Problem 5
For each of the following functions, indicate how much the functions value
will change if its argument is increased fourfold.
a. log 2 n
b.n
c. n
d. n^2
e. n^3
f.2^n
Problem 6:
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. n(n +1) and 2000n2
b.100n2 and 0.01n3
c. log2 n and ln n
d. log22 n and log 2 n2
e.2n1 and 2n
f.(n 1)! and n!

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!