Looking for Computer Science / Rekenaarwetenskap - 144 test answers and solutions? Browse our comprehensive collection of verified answers for Computer Science / Rekenaarwetenskap - 144 at stemlearn.sun.ac.za.
Get instant access to accurate answers and detailed explanations for your course questions. Our community-driven platform helps students succeed!
This double loop fills an n-by-n matrix. Its running time as a function of n is:
for i in range(n):
for j in range(n):
c[i][j] = 1.0 if i == j else 0.0
Towers of Hanoi and 'print all subsets of n elements' both run in time proportional to 2ⁿ. This order of growth is called:
Why does concatenating a single character onto a string take time proportional to the string's current length (not constant time)?
Insertion sort takes about 8 seconds to sort 10 000 random ints. Using its order of growth, roughly how long to sort 20 000 random ints?
n items are added to an empty list. Loop L uses a.insert(0, x) each time; loop R uses a.append(x) each time. Which loop is quadratic?
Scanning a sorted array from the front (brute-force linear search) to find a random PRESENT key uses, on average, about:
Why does the text prefer tilde (~) / order-of-growth notation over big-O for PREDICTING performance?
Compared with insertion sort, mergesort (as in merge.py) needs:
Insertion sort does the MOST work (about n²/2 compares) on which input?
Consider building a reversed copy of a string s of length n. Because strings are immutable, the running time is:
reverse = ''
for i in range(n):
reverse = s[i] + reverse