Problem 1
# Creating a list of numbers
numbers = [5, 3, 9, 1, 6, 8] # A list of integers is created and assigned to the variable "numbers"
# Printing the original list
print(f"Original list: {numbers}") # This line outputs the original list of numbers
# Accessing and printing the second element in the list (Indexing starts from 0)
print(f"Second element in the list: {numbers[1]}") # This line outputs the second element in the list
# Modifying the third element in the list
numbers[2] = 10 # The third element in the list (index 2) is changed to 10
# Appending an element to the end of the list
numbers.append(4) # The append() method adds the value 4 to the end of the list
# Removing an element from the list by value
numbers.remove(1) # The remove() method removes the first occurrence of the value 1 from the list
# Sorting the list in ascending order
numbers.sort() # The sort() method arranges the numbers in the list in ascending order
# Reversing the order of elements in the list
numbers.reverse() # The reverse() method reverses the order of elements in the list
# Printing the modified list
print(f"Modified list: {numbers}") # This line outputs the modified list of numbers
Problem 2
import math
def worst_case_binary_search_iterations(array_length):
iterations = math.ceil(math.log2(array_length))
return iterations
array_length = 30
print(worst_case_binary_search_iterations(array_length)) # Output the worst-case number of iterations
Problem 3
Answer is A