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.41: 24abcd Let ] 1 [ n A 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.) 1...
View
Full Document
 Fall '08
 Tantalo,P
 Binary Search, Insertion Sort, Selection Sort, Big O notation, θ

Click to edit the document details