Question: Question 1: Write a function that takes as a parameter a list of triples and returns a list of the third elements of each of


Question 1: Write a function that takes as a parameter a list of triples and returns a list of the third elements of each of the entries in the original list. Thus, if your function was passed the list: [(1,2,3),(4,5,6),(7,8,9)] then it would return [3,6,9] You may assume that the input is well-formed. You may hand this in as a function definition in a cell of a .ipynb file or as hand written text. Question 2: Consider the following code segment: for i in range (12): do_this_function(i) Part a) Re-write the code segement using a while-loop in place of the for loop. Assume that the function do_this_function has been defined. Part b) In what way is the behavior of while-loop version you wrote in part a) the same as the for-loop version provided above and in what way is its behavior different? You may hand this in as a code and comments in a cell of a .ipynb file or as hand written text. Question 3: Add the following binary numbers showing carries. 1010111 + 1011110 You can use a web calculator to check your work. They key issue here is that you show when a number is carried. You should hand this in as a picture of hand work. If you have technical difficulties with that, you may hand this in as formatted text but you must be very careful to format your work so that the formatting is clear when I am marking it. Question 4: Write a function that takes in a list of numbers as a parameter and returns the second largest number in the list. You may assume that the input parameter is a list with length at least two, that all of the entries in the list are numbers, and that there are no duplicates of the largest number in the list. You may hand this in as a code and comments in a cell of a .ipynb file or as hand written text. Question 5: Consider the binary search algorithm. Part a) Explain why binary search doesn't work on unsorted lists. Part of your goal in this explanation is to convince me that you understand how binary search does work for sorted lists. Part b) Given that binary search doesn't work in some cases where linear search does work, explain what it is about binary search that is better than linear search. Part of your goal in this explanation is to convince me that you understand how linear search works. You may hand this in as comments in a cell of a .ipynb file, as typewritten text using some other common text format, or as hand written text
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
