Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
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 What is the maximum number of comparisons your algorithm
makes if the lengths of the two given lists are m and n respectively?
Problem :
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
dmin infty
for i to n do
for j to n do
if i j and Ai Aj dmin
dmin Ai Aj
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 :
For each of the following algorithms, in
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 penandpencil algorithm for multiplying two ndigit decimal integers
Problem
a Consider the definitionbased 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 definitionbased algorithm for matrix
multiplication.
Problem
For each of the following functions, indicate how much the functions value
will change if its argument is increased fourfold.
a log n
bn
c n
d n
e n
fn
Problem :
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 log n and ln n
d log n and log n
en and n
fn and n
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started