In: Computer Science
Write all your answers for this problem in a text file named aa.txt – for each problem write the problem number and your answer.
1.1 What type of object can be contained in a list (write the letter for the best answer)?
a. String b. Integer c. List d. String and Integer only e. String, Integer, and List can all be contained in a list
1.2 Which statement about the debugger is not correct? a. It is a powerful tool in PyCharm and it can help trace the execution of a program. b. You can set breakpoints in the code to indicate where the computer should pause execution. c. The debugger can step through the program execution, but you cannot see the value of a variable without using a print statement. d. The PyCharm debugger highlights the line it will execute next.
1.3 Binary search takes a smaller number of comparisons to run compared to linear search. However, binary search cannot always be used. What is required for binary search to work?
1.4 Write TRUE or FALSE regarding the following statement: “The Merge Sort algorithm we studied in Chapter 5 was implemented with recursion”
1.5 Suppose a list is defined with the following assignment statement: numbers = [1, 2, 3, 4, 5, 6, 7] If we use the binary search algorithm we studied, how many comparisons (i.e. iterations of the while loop) will it take to find the number 5?
1.6 Suppose a list is defined with the following assignment statement: numbers = [33, 22, 55, 11, 44] Explain in 2-4 sentences in your own words how the Merge Sort (msort) function will sort the above list. Be sure to explain how it will merge and sort the groups for each step.
about python
1.1. e. String, Integer, and List can all be contained in a list.
1.2. d. The PyCharm debugger highlights the line it will execute next.
1.3. The list must be sorted in ascending order according to the ordering used by the comparisons in the search function.
1.4. please mention the detail algorithm.
1.5. Two comparisons required.
comaprison 1: 5> middle point 3 so serach in right of the midle point.
comparison 2: middle point is 5 so element found.
1.6. Merge sort in python code has been given below.
def merge(arr, l, m, r):
n1 = m - l + 1
n2 = r- m
# create temp arrays
L = [0] * (n1)
R = [0] * (n2)
# Copy data to temp arrays L[] and R[]
for i in range(0 , n1):
L[i] = arr[l + i]
for j in range(0 , n2):
R[j] = arr[m + 1 + j]
# Merge the temp arrays back into arr[l..r]
i = 0 # Initial index of first subarray
j = 0 # Initial index of second subarray
k = l # Initial index of merged subarray
while i < n1 and j < n2 :
if L[i] <= R[j]:
arr[k] = L[i]
i += 1
else:
arr[k] = R[j]
j += 1
k += 1
# Copy the remaining elements of L[], if there
# are any
while i < n1:
arr[k] = L[i]
i += 1
k += 1
# Copy the remaining elements of R[], if there
# are any
while j < n2:
arr[k] = R[j]
j += 1
k += 1
# l is for left index and r is right index of the
# sub-array of arr to be sorted
def mergeSort(arr,l,r):
if l < r:
# Same as (l+r)//2, but avoids overflow for
# large l and h
m = (l+(r-1))//2
# Sort first and second halves
mergeSort(arr, l, m)
mergeSort(arr, m+1, r)
merge(arr, l, m, r)
# Driver code to test above
arr = [33,22,55,11,44]
n = len(arr)
print ("Given array is")
for i in range(n):
print ("%d" %arr[i]),
mergeSort(arr,0,n-1)
print ("\n\nSorted array is")
for i in range(n):
print ("%d" %arr[i]),
Detailed steps with picture hase been given below: