Unformatted text preview: remaining portion of the sequence each time. Write pseudocode, either iterative or recursive, for binary search. Argue that the worstcase running time of binary search is ) (lg n Θ . 3. (4 Points) p.39: 24abcd Let ] 1 [ n A L be an array of n distinct numbers. If j i < and ] [ ] [ j A i A > , then the pair ) , ( j i is called an inversion of A . a. (1 Point) List the five inversions of the array ) 1 , 6 , 8 , 3 , 2 ( . b. (1 Point) What array with elements from the set {1, 2, 3, …. ., n } has the most inversions? How many inversions does it have? c. (1 Point) What is the relationship between the running time of insertion sort and the number of inversions in the input array? Justify your answer. d. (1 Point) Give an algorithm that determines the number of inversions in any permutation of n elements in ) lg ( n n Θ worstcase time. (Hint: Modify merge sort.)...
View
Full Document
 Spring '09
 AgoreBack
 Binary Search, Sort, Insertion Sort, 1L, Big O notation, θ

Click to edit the document details