Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

3. Analyze the worst-case running time for each of the following algorithms. You should give your answer in Big-Theta notation. You do not need to

image text in transcribedimage text in transcribed

3. Analyze the worst-case running time for each of the following algorithms. You should give your answer in Big-Theta notation. You do not need to give an input which achieves your worst-case bound, but you should try to give as tight a bound as possible. In the column to the right of the code, indicate the cost of executing each line once. In the next column (all the way to the right), indicate the number of times each line is executed. Below the code, justify your answers (show your work), and compute the total runtime in terms of Big-Theta notation. You may assume that T(n) is the Big-Theta of the high-order term. You need not use Calculus techniques. However, you must show the calculations to determine the closed-form expression for a summation (represented with the symbol). You cannot simply say: ie O(n), for instance. 22 i=1 In both columns, you don't have to put the exact values. For example, putting "c" for constant is fine. We will not be picky about off-by-one errors (i.e., the difference between n and n - 1); however, we will be picky about off-by-two errors (i.e., the difference between n and n - 2). (a) Consider the following algorithm. | Cost | # times run 1 for j 1 1 f(A[1, n]): 2 ans = 0 3 for i = 1 to n-1: 4 i+1 ton: 5 if A[i] > A[j] : 6 ans += 1 7 8 return ans (b) Write an algorithm to multiply two matrices A with dimension n x m and B with dimension m x n. Write your algorithm in pseudocode in Latex, similar in style to the given pseudocode in 3(a). Analyze the worst-case runtime of your algorithm as above. You may use the subroutine zeros([a,b]) to create an array of zeros with dimension a xb. zeros([a, b]) has runtime (ab)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Relational Database Design With Microcomputer Applications

Authors: Glenn A. Jackson

1st Edition

0137718411, 978-0137718412

More Books

Students also viewed these Databases questions

Question

Evaluate 3x - x for x = -2 Answer:

Answered: 1 week ago

Question

What is group replacement? Explain with an example. (2-3 lines)

Answered: 1 week ago

Question

3. What might you have done differently

Answered: 1 week ago

Question

4. Did you rethink your decision?

Answered: 1 week ago