This preview shows pages 1–2. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: else binSearch(element e, sortedArray[m:length(sortedArray)]) } In the worst case scenario, we have to keep “dividing and conquering” until we get either one or two elements. As such, the worst case runtime is Θ (log n), with it being a base2 logarithm. 3a) An inversion is basically a pair in the wrong order; they are: (2, 1), (3, 1), (8, 6), (8, 1) and (6, 1). b) A set in the completely “wrong” (i.e., descending) order (i.e., {n, n1, n1,… 1}) would have the most inversions, more specifically, (n*(n–1))/2 inversions. c) Insertion sort looks for elements that are out of order. The fewer inversions an array has, the faster the runtime, which is squarely proportional to the number of inversions. d) int invCount(Array A) { ct = 0 n = length(A) for a = 1 to n { for b = a to (n1) { if A[a] > A[b] then ct++ } }...
View
Full
Document
This note was uploaded on 11/16/2010 for the course CMPS 101 taught by Professor Tantalo,p during the Spring '08 term at University of California, Santa Cruz.
 Spring '08
 Tantalo,P

Click to edit the document details