Please post all code in Pseudo code. Please post ORIGINAL answers do not copy from similar questions. Please post in a format that can be directly copied. Reasoning on answers would be most helpful but not required. Thank you in advance for your help.
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 ← ∞
for i ← 0 to n − 1 do
forj ←0ton−1do
ifi̸=j and|A[i]−A[j]|<dmin d m i n ← | 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.
3.a.Consider the definition-based algorithm for adding two n × 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.
(2)Algorithm for finding the distance between the two closest
elements in an array of numbers.
MinDistance(A[0..n − 1])
dmin ← ∞
for i ← 0 to n − 1 do
forj ←0ton−1do
(if(i!=j) and|A[i]−A[j]|<dmin)
dmin ← minimum(dmin,|A[i] − A[j]|)//update dmin with minimum if
(dmin or |A[i] − A[j]|)
return dmin
(3.a)for adding two n × n matrices
Basic operation is to add two numbers
it is performed nxn = (n2) times
Let there are n numbers input by User ,so it is performed n/2
times
(3.b)for multiplication of two n × n matrices
Basic operation is to add two numbers and to multiply two
numbers
To generate one element in output matrix = n additions and n
multiplications required,Total = n+n = 2*n operations
for nxn matrix total operation = n2 * 2*n =
2*n3
Let there are n numbers input by User ,so it is performed (n/2) *2*sqroot(n/2)
Get Answers For Free
Most questions answered within 1 hours.