Exam 11: Computer Science Thinking: Recursion, Searching, Sorting and Big O

arrow
  • Select Tags
search iconSearch Question
flashcardsStudy Flashcards
  • Select Tags

Which of the following statements a), b) or c) is false?

Free
(Multiple Choice)
4.9/5
(43)
Correct Answer:
Verified

B

What should the question mark (?) in the following for statement be replaced with, so that the statements will calculate 5!? In [1]: factorial = 1 In [2]: for number in range(5, 0, ?): )..: factorial *= number )..: In [3]: factorial Out[3]: 120

Free
(Multiple Choice)
4.9/5
(31)
Correct Answer:
Verified

C

The following fibonacci function calculates the nth Fibonacci number recursively: In [1]: def fibonacci(n): )..: if n in (0, 1): # base cases )..: return n )..: else: )..: return fibonacci(n - 1) + fibonacci(n - 2) )..: Which of the following statements is false?

Free
(Multiple Choice)
4.9/5
(38)
Correct Answer:
Verified

A

Which of the following statements a), b) or c) is false?

(Multiple Choice)
4.8/5
(31)

Which of the following statements a), b) or c) is false?

(Multiple Choice)
4.9/5
(41)

Which of the following statements a), b) or c) is false?

(Multiple Choice)
4.8/5
(35)

An algorithm that tests whether the first array element is equal to any of the other array elements requires at most n - 1 comparisons, where n is the number of array elements. Which of the following statements is false?

(Multiple Choice)
4.8/5
(36)

Which of the following statements about the binary search of an array in ascending order is false?

(Multiple Choice)
4.8/5
(38)

Which of the following statements about binary search of an array in ascending order is false?

(Multiple Choice)
4.8/5
(34)

Suppose an algorithm is designed to test whether the first element of an array is equal to the second. If the array has 10 elements, this algorithm requires one comparison. If the array has 1000 elements, it still requires only one comparison. Which of the following statements is false:

(Multiple Choice)
4.7/5
(29)

Suppose you have an algorithm that tests whether any element of an array is duplicated elsewhere in the array. The first element must be compared with all the other array elements. The second element must be compared with all the other array elements except the first (it was already compared to the first). The third element must be compared with all the other array elements except the first two. In the end, this algorithm makes (n - 1) + (n - 2) + … + 2 + 1 Or N2/2 - n/2 Comparisons. Which of the following statements a), b) or c) is false?

(Multiple Choice)
5.0/5
(40)

The following code implements a simple linear search. In [1]: def linear_search(data, search_key): )..: for index, value in enumerate(data): )..: if value == search_key: )..: return *** )..: return -1 )..: )..: In the statement return ***, what should replace *** to indicate where the search key was found?

(Multiple Choice)
4.8/5
(31)

Which of the following statements a), b) or c) is false?

(Multiple Choice)
4.8/5
(45)

Which of the following statements is false?

(Multiple Choice)
4.9/5
(36)

Which of the following statements a), b) or c) is false?

(Multiple Choice)
5.0/5
(46)

Which of the following statements is false?

(Multiple Choice)
4.8/5
(34)

Which of the following statements a), b) or c) is false?

(Multiple Choice)
4.8/5
(33)

Which of the following statements is false?

(Multiple Choice)
4.8/5
(41)
close modal

Filters

  • Essay(0)
  • Multiple Choice(0)
  • Short Answer(0)
  • True False(0)
  • Matching(0)