Quizes Gagnaskipan

Ace your homework & exams now with Quizwiz!

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

A base case condition and a recursive step

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 When the parameter values in the current instance of the function meet certain conditions the recursion will stop 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

The following operation would be considered an edge case:

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

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

Comparing arrays and linked lists, which statement is true?

Data in arrays is stored in contiguous (samliggjandi) memory locations but not linked lists

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 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 returns the sum of the first n natural numbers. The recursive function is: def bar(n): if n == 1: reuturn 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: Recursion always yields the computationally fastest solution Recursion always yields neater solutions than other methods Some problems can only be solved using recursion

The time complexity for adding a new node at the front (head) of a singly-linked list is:

O(1)

An operation retrieves the value of a single item in an array at a specified location. example: print(ass[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)

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) msWhat would be the most common way to describe this operations's time complexity in Big Oh notation?

O(n'2)

The time complexity for fetching a value from a singly-linked list at a specified node (item number n in the list) is:

O(n)

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 operations 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

A data structure has the following operations that add and remove to and from the front and back of the structure, respectively: push_front(value): #time complexity: O(1) push_back(value): #time complexity: O(1) pop_front(): #time complexity: O(1) pop_back(): #time complexity: O(n) Which operations should be used for the most efficient implementation of a queue?

Push_back and pop_front

What does this recursive program do? 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)

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

The acronym FIFO (first-in-first-out) is generally used to describe

The behavior of a queue

The acronym LIFO (last-in-first-out) is generally used to describe

The behavior of a stack

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: 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]

A well implemented deque (double-ended queue) can substitute the behavior of

both a stack and a queue

A programmer is asked to make a function that returns the sum of the first n natural numbers. def bar(n): if n == 1: reuturn 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(1)

A programmer is asked to make a function that calculates n to the power of m. This recursive function: 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

When a linked list does not have reserved memory for an item that is to be added, the program must:

just add another item, as there is no capacity limit on a linked list

A data structure has the following operations that add and remove to and from the front and back of the structure, respectively: push_front(value): #time complexity: O(1) push_back(value): #time complexity: O(1) pop_front(): #time complexity: O(1) pop_back(): #time complexity: O(n) Which operations should be used for the most efficient implementation of a stack?

push_front and pop_front

In order to access the next-to-last node (in front of tail) in a singly-linked list the most efficient possible way for a program is to:

walk the entire list from the head (first node), one step at a time (O(n))


Related study sets

Chapter 11: Interactive Presentation

View Set

Sport Management Quizzes - SRM 222 UNA

View Set

CCNA 2 v7 Modules 14 - 16: Routing Concepts and Configuration

View Set

Exam 2: Questions from powerpoints

View Set

1013 Communication (Patient Teaching) Quiz

View Set

Photosynthesis/Respiration terms

View Set