Linear Search in Lists
Which of the following Python functions would best find whether the value 42 exists in the list numbers = [13, 42, 7, 99] using linear search?
- 42 in numbers
- numbers.find(42)
- numbers[42]
- search(42, numbers)
- numbers.contains(42)
Finding Duplicates
What is the simplest way in Python to check if a list my_list has any duplicate elements?
- len(my_list) != len(set(my_list))
- my_list.duplicate()
- my_list.count() u003E 1
- my_list != set(my_list)
- ifDuplicate(my_list)
Bubble Sort Steps
In Bubble Sort, how many passes will it take to sort the list [3, 2, 1] into ascending order?
- 2
- 1
- 3
- 0
- 4
Finding the Maximum Value
How do you find the largest number in a Python list nums = [11, 88, 34, 72]?
- max(nums)
- nums.max()
- findMax(nums)
- maximum(nums)
- nums.largest()
Binary Search Precondition
What must be true about a list before using binary search to quickly find an item?
- The list must be sorted.
- The list must have unique elements.
- The list must be reversed.
- The list must be circular.
- The list must be all integers.
Counting Occurrences
Which Python expression will count the number of times 5 appears in the list data = [1, 5, 2, 5, 6, 5]?
- data.count(5)
- count(data, 5)
- data.occur(5)
- data[5]
- data.times(5)
Reverse a List
Which of these statements will reverse a list lst in place in Python?
- lst.reverse()
- reverse(lst)
- lst.reversed()
- lst = reverse(lst)
- lst = lst.reverse
Selection Sort Characteristic
In selection sort, what is done during each pass through the list?
- The smallest remaining element is found and swapped to its correct position.
- The largest remaining element is always removed.
- Every element is compared to every other element once.
- Elements are inserted into a new sorted list.
- Elements are randomly shuffled and then selected.
Median Calculation
Given list nums = [5, 7, 11], what is the median value?
- 7
- 5
- 11
- 6
- 9
Finding Index of an Item
Which code returns the index of the first occurrence of 'apple' in fruits = ['apple', 'banana', 'apple']?
- fruits.index('apple')
- fruits.find('apple')
- index('apple', fruits)
- fruits.search('apple')
- fruits.location('apple')