401 HW 2
Homework 2
Mateo Viteri - mvite4
Christian Penaloza - cpena29
Anthony Valenzo - avale34
\today
Binary Search
(a) Including the initial one, how many total calls will be made for BinarySearch(A, 1, 10, 13)?
4 calls
(b) Including the initial one, how many total calls will be made for BinarySearch(A, 1, 10, 0)?
3 calls
(c) Including the initial one, how many total calls will be made for BinarySearch(A, 1, 10, 3)?
5 calls
Intersecting Lines
(a) The algorithm would store pairs into tuples, sort them by their first element (bottom points), and then get the list of second elements (top points) with the new order. Then we use the merge-sort algorithm shown in class to count inversions and return that number of inversions.
(b) Let
For each corresponding pair
Add
Sort
Let
For each
Add
Return
(c) An intersection occurs when
(d) Both for loops take
Since
Playing Hooky
(a) Write your answer for Question 3, part (a) here.
(b) Write your answer for Question 3, part (b) here.
(c) Write your answer for Question 3, part (c) here.
References
“Divide and Conquer - Inversion Count.” YouTube, uploaded by Neso Academy, 22 June 2021, https://www.youtube.com/watch?v=7_AJfusC6UQ. Accessed 20 Sept. 2026.
“Gemini.” Google, Sept. 2026 version, https://gemini.google.com. Accessed Sept. 2026. Used for grammar and Latex formatting.