This preview shows page 1. Sign up to view the full content.
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
This note was uploaded on 12/03/2009 for the course CS CS101 taught by Professor Agoreback during the Spring '09 term at American College of Gastroenterology.
 Spring '09
 AgoreBack
 Sort

Click to edit the document details