Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

If a program takes 20 microseconds to process a list of 10 numbers. How long would you expect it to take to process a list

If a program takes 20 microseconds to process a list of 10 numbers. How long would you expect it to take to process a list of 100 numbers? Answer the question in the different scenarios below, where T(n) represents the runtime as a function of n, the list size and k is a constant. Express the answer in appropriate units whenever it's bigger than 1000 microseconds (e.g. milliseconds, seconds, minutes, days, months, years)

. a)T(n) = k

b) T(n) = k (logn)

c) T(n) = k (sqrt(n))

d) T(n) = kn

e) T(n) = k *nlogn

f) T(n) = k (n^2)

g) T(n) = k (n^3)

h) T(n) = k(n^4)

i) T(n) = k (2n)

Show the steps.

Here are the notes about rule of thumbs.

T(n) k : T(n + r ) = k I f we increase the input size by any amount, the runtime is unchanged. Called "constant time"

T(n) klog(n) : T(n 2 ) klog(n 2 ) = 2klog(n) = 2T(n) If we square the input size, the runtime is doubled. Called "log time"

T(n) ksqrt(n) : T(4n) ksqrt(4n) = 2ksqrt(n) = 2T(n) If we quadruple the input size, the runtime is doubled . Called "sqrt time" See the general rule below when the scaling factor is something other than 4.

T(n) knlog(n) : T(2n) k(2n)log(2n) = 2kn(logn) + 2kn = 2T(n) + 2kn For large input sizes, If we double the input size, the runtime is slightly more than doubled. Called linearithmic or just "nlogn time."

More formally:

T(2n) / T(n) k(2n)log(2n) / (knlog(n)) = 2k (logn + 1) / logn = 2 + 2k/logn 2+ as n .

Also we have the relation T(n2) = kn2 log(n2) = 2n kn log(n ) = 2n T(n). Meaning If we square the input size, the runtime is multiplied by twice the original input size.

One more: T(n 3) = kn 3log(n 3) which equal 3n 2 knlog(n) = 3n 2 T(n). So, If we cube the input size, the runtime is multiplied by three times the original input size squared.

More generally if we raise the input size n to power p, the runtime is multiplied by pn(p-1).

T(n) = k(logn)2 T(n 2) = k (log n 2) 2 = k( 2 log n) 2 = 4k(log n) 2. = 4T(n). If we square the input size, the runtime is multiplied by 4.

And more generally for T(n) = k(logn) p, if we square the input size the runtime is multiplied by 2 p. If we cube the input size the runtime is multiplied by 3 p and so on..

T(n) kn : T(2n) k(2n) = 2kn = 2T(n) If we double the input size, the runtime is doubled. Called "linear time"

T(n) kn2 T(2n) k(2n)2 = 4kn2 = 4T(n) If we double the input size, the runtime is quadrupled. Called "quadratic time"

T(3n) k(3n)2 = 9kn2 = 9T(n) If we triple the input size, the runtime is multiplied by nine.

T(rn) k(rn)2 = (r2)kn2 = (r2)T(n) If we multiply the input size by r, the runtime is multiplied by r squared.

T(n) kn(logn)2 T(n2) = k(n2)(log(n2))2 = 4nT(n) If we square the input size, the runtime is multiplied by four times the original input size.

T(n) = n2log (n). Then T(n 2) 2n 2 T(n) and T(n 3) 3n 4T(n). Check this! Also think about generalizing to find rules for T(n) = n k log(n)

T(n) kn3 T(2n) k(2n)3 = 8kn3 = 8T(n) If we double the input size then the runtime is multiplied by eight. Called "cubic time"

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

Data Management Databases And Organizations

Authors: Richard T. Watson

2nd Edition

0471180742, 978-0471180746

More Books

Students also viewed these Databases questions