Problem Solving With Algorithms Quiz Quiz

  1. 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?

    1. 42 in numbers
    2. numbers.find(42)
    3. numbers[42]
    4. search(42, numbers)
    5. numbers.contains(42)
  2. Finding Duplicates

    What is the simplest way in Python to check if a list my_list has any duplicate elements?

    1. len(my_list) != len(set(my_list))
    2. my_list.duplicate()
    3. my_list.count() u003E 1
    4. my_list != set(my_list)
    5. ifDuplicate(my_list)
  3. Bubble Sort Steps

    In Bubble Sort, how many passes will it take to sort the list [3, 2, 1] into ascending order?

    1. 2
    2. 1
    3. 3
    4. 0
    5. 4
  4. Finding the Maximum Value

    How do you find the largest number in a Python list nums = [11, 88, 34, 72]?

    1. max(nums)
    2. nums.max()
    3. findMax(nums)
    4. maximum(nums)
    5. nums.largest()
  5. Binary Search Precondition

    What must be true about a list before using binary search to quickly find an item?

    1. The list must be sorted.
    2. The list must have unique elements.
    3. The list must be reversed.
    4. The list must be circular.
    5. The list must be all integers.
  6. Counting Occurrences

    Which Python expression will count the number of times 5 appears in the list data = [1, 5, 2, 5, 6, 5]?

    1. data.count(5)
    2. count(data, 5)
    3. data.occur(5)
    4. data[5]
    5. data.times(5)
  7. Reverse a List

    Which of these statements will reverse a list lst in place in Python?

    1. lst.reverse()
    2. reverse(lst)
    3. lst.reversed()
    4. lst = reverse(lst)
    5. lst = lst.reverse
  8. Selection Sort Characteristic

    In selection sort, what is done during each pass through the list?

    1. The smallest remaining element is found and swapped to its correct position.
    2. The largest remaining element is always removed.
    3. Every element is compared to every other element once.
    4. Elements are inserted into a new sorted list.
    5. Elements are randomly shuffled and then selected.
  9. Median Calculation

    Given list nums = [5, 7, 11], what is the median value?

    1. 7
    2. 5
    3. 11
    4. 6
    5. 9
  10. Finding Index of an Item

    Which code returns the index of the first occurrence of 'apple' in fruits = ['apple', 'banana', 'apple']?

    1. fruits.index('apple')
    2. fruits.find('apple')
    3. index('apple', fruits)
    4. fruits.search('apple')
    5. fruits.location('apple')