{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Solutions of Theory of Algorithms assignment 7-1

# Solutions of Theory of Algorithms assignment 7-1 - array d...

This preview shows pages 1–2. Sign up to view the full content.

Solutions of Theory of Algorithms Assignment 4 Exercise 7-1 a. x i J 13 19 9 5 12 8 7 4 11 2 6 21 13 0 11 6 19 9 5 12 8 7 4 11 2 13 21 2 0 10 2 19 9 5 12 8 7 4 11 6 13 21 6 1 9 2 6 9 5 12 8 7 4 11 19 13 21 6 3 9 2 5 9 6 12 8 7 4 11 19 13 21 5 1 3 2 4 9 6 12 8 7 5 11 19 13 21 9 2 7 2 4 5 6 12 8 7 9 11 19 13 21 13 2 7 2 4 5 6 12 8 7 9 11 13 19 21 11 9 10 2 4 5 6 12 8 7 9 11 13 19 21 12 4 8 2 4 5 6 11 8 7 9 12 13 19 21 11 4 7 2 4 5 6 9 8 7 11 12 13 19 21 9 4 6 2 4 5 6 7 8 9 11 12 13 19 21 7 4 5 2 4 5 6 7 8 9 11 12 13 19 21 19 10 11 b. Although in the initialization steps in lines 2 and 3 for i and j are outside the range of the array, but they are adjusted inside the While loop; so that i access the first element in the array and j access the last element. c. As j begins the loop by being the last element in the array, and then it decrements by one in every iteration. Therefore, its maximum value is r (the last element ) and its minimum value is p (the first element in the

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: array). d. In HOARE-PARTITION, it searches the array for an element smaller than x, and an element greater than x. but it swaps these two elements only if the index of the smaller element is greater than the index of the greater element. And that leads us to divide the array into two partitions where every element in the first partition is smaller than or equal to all elements in the second partition. e. QUICKSORT HOARE(A, p, r) 1 if p < r 2 then q ← HOARE-PARTITION (A, p, r) 3 QUICKSORT HOARE (A, p, q - 1) 4 QUICKSORT HOARE (A, q + 1, r)...
View Full Document

{[ snackBarMessage ]}

### Page1 / 2

Solutions of Theory of Algorithms assignment 7-1 - array d...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online