Question: Question 1 Recall the permutations function from Section 11.5 in the textbook. def permutations(word) : result = [] if len(word) == 0 : result.append(word) return

Question 1

Recall the permutations function from Section 11.5 in the textbook.

def permutations(word) :

result = []

if len(word) == 0 :

result.append(word)

return result

else:

for i in range(len(word)) :

shorter = word[ : i] + word[i + 1 : ]

shorterPermutations = permutations(shorter)

for string in shorterPermutations :

result.append(word[i] + string)

return result

What is the base case for this function?

Question options:

The empty list

Any list containing exactly one character

The empty string

Any string containing exactly one character

Question 2

If an element is present in a list of length n, how many element visits, on average, are necessary to find it using a linear search?

Question options

n/2

n

2n

n2

Question 3

What must hold true after 5 iterations of selection sort when it is working to sort a list of 10 elements?

Question options

Exactly 5 more iterations are always necessary to complete the sort

Exactly 4 more iterations are always necessary to complete the sort

Up to 5 more iterations may be needed to complete the sort

Up to 4 more iterations may be needed to complete the sort

Question 4

Consider a list with n elements. If we visit each element n times, how many total visits will there be?

Question options:

n

2n

nn

n2

Question 5

After 9 iterations of selection sort working on an list of 10 elements, what must hold true?

Question options

The largest element is correctly placed by default.

One more iteration is needed to complete the sort.

The smallest element is incorrectly placed.

The largest element is incorrectly placed.

Question 6

Which element does selection sort place in the correct location during each iteration?

Question options

The smallest in the list

The smallest element that has not been placed in the correct location during a prior iteration

The largest element in the list

A random element

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!