Gagnaskipan hlutapróf 1

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

An operation on a list is measured to complete in an amount of time that can be calculated by the following formula:

(3 + 6*n + 2*n^2) ms

When designing a recursive function (that executes correctly) what must be included?

A base case condition and a recursive step

The following operation would be considered an edge case:

All of the other options are true: Adding an item to an empty list. Removing an item from an empty list. Setting the value at index 9 (lis[9] = x ) in a list with 09 items (len(lis) == 9).

A function is recursive and runs and returns correctly. Which of the following statements made about any such function is true?

All of the other options are true: Called with certain values, it might actually not recur (call itself again) at all Every time it calls itself, it does so with different parameter values than those of the current instance When the parameter values in the current instance of the function meet certain conditions the recursion will stop

In an implementation of a dynamic array, once the array is fully used but an additional item must be added, the program must

Allocate memory for a bigger array and copy all items between arrays

Analysis of running time generally means:

Finding a function that describes how the size or values of input data affect the running time of a program or algorithm.

What does the capacity variable in a dynamic array implementation represent?

How many items, in total, the array can hold, before its next resize is necessary

A programmer is asked to make a function that returns the sum of the first n natural numbers. This recursive function is what they come up with: def bar(n): if n == 1: return n return n + bar(n) What change is needed for it to work?

In the recursive call we need to call bar(n-1) instead of bar(n)

A function is recursive and runs and returns correctly. Which statement is true?

It has at least one code path without a call to itself

A programmer is asked to make a function that calculates n to the power of m. This recursive function is what they come up with: def bar(n, m): return n * bar(n, m-1) We test it on the positive integers 2 and 3: print(bar(2, 3)) How will it behave?

It will recur endlessly and never return

A programmer is asked to make a function that returns the sum of the first n natural numbers. This recursive function is what they come up with: def bar(n): if n == 1: return n return n + bar(n) We test it on the natural number 6: print(bar(6)) How will it behave?

It will recur endlessly and never return

Which of the following statements about recursive functions is true?

None of the other options are true: Some problems can only be solved using recursion Recursion always yields neater solutions than other methods Recursion always yields the computationally fastest solution

An operation retrieves the value of a single item in an array at a specified location. Example: print(arr[5]) What is the worst-case time complexity of an efficient implementation?

O(1) - constant time

What is the time complexity of the following operation? n is a positive integer value. def oper(n): s = n while s > 1: s = s / 2

O(log2n)

What is the time complexity of the following operation?n is a positive integer value. def oper(n): s = 0 for i in range(n): s += 2

O(n)

An operation inserts a single item to the beginning (index:0) of an array. What is the worst-case time complexity of an efficient implementation?

O(n) - linear time

An operation removes a single item from an array at a specified location. What is the worst-case time complexity of an efficient implementation?

O(n) - linear time

What would be the most common way to describe this operations's time complexity in Big Oh notation? (3 + 6*n + 2*n^2) ms

O(n^2)

Look at this recursive program: def foo(a_str, n): if n == 0: return 0 n -= 1 if a_str[n] == 'a': return 1 + foo(a_str, n) return foo(a_str, n) What does it do?

Returns the number of times 'a' occurs in the first n letters of a_str

The following statement about O(1) (Constant time) and O(n) (Linear time) is true:

The latter is dependant on the input size (or input values) but the former is not.

The following statement about O(n) (Linear time) and O(log2n) (Logarithmic time) is true:

The latter would generally be considered a better time complexity than the former.

The following can be limiting factors on how many iterations a recursive function can do:

The maximum space allowed for storing descriptions of currently active function calls

The following statement about O(n) (Linear time) and O(n2) (Quadratic time) is true:

The running times of both are dependant on the input size (or input values).

A programmer is asked to make a function that calculates n to the power of m. This recursive function is what they come up with: def bar(n, m): return n * bar(n, m-1) What change is needed for it to work?

We need to add a condition: if m == 0: return 1

What is the output of the following program in Python: a = [2,3] b = a b.append(1) print(a)

[2, 3, 1]

What is the output of the following program in Python: a = [2,3] b = a b = b + [1] print(a)

[2, 3]


संबंधित स्टडी सेट्स

Chapter 6 Econ 201 Multiple Choice

View Set

Clinical Chemistry: Adrenal Function

View Set

6: SELLING AND MARKETING RESEARCH

View Set

ATR4610 - Exam 3 Review(Ch. 17, 18, 21, 22)

View Set

Basic Services Provided By A Crime Lab

View Set