Solution to midterm02 session B

Solution to midterm02 session B - Spring 2010 CSE310...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Spring 2010 CSE310 Midterm Examination 02B (in class) Instructions: There are five questions in this paper. Please use the space provided (below the questions) to write the answers. Budget your time to answer various questions and avoid spending too much time on a particular question. This is a closed book examination. You may not consult your books/notes. NAME ASUID Problems Score P1 P2 P3 P4 P5 Total P1. (20 points) (10 pts) This problem is related to order statistics. What is the minimum number of element-wise comparisons needed to find the smallest element and the second smallest element in an un-ordered sequence of n elements? Do not use asymptotic notation in your answer. Solution: In order to find both the smallest and the second smallest elements in an array, n + log n 2 comparisons are needed. First in n/ 2 comparisons, we have n/ 2 groups of 1 st and 2 candidate for 2 nd smallest in each group. In n/ 4 comparisons, we have n/ 4 groups of 1 st and 2 1 candidates for 2 nd smallest in each group. In n/ 2 k comparisons, we have n/ 2 k groups of 1 st and 2 k 1 candidates for 2 nd smallest in each group. In 1 comparison, we have 1 group of 1 st and 2 log n candidates for 2 nd smallest in the group. We need log n 1 comparisons to find the 2 nd smallest element in the 2 log n candidates. Thus, the total number of comparisons is n + log n 2. Grading Keys: 5 pts for correct answer; 3 pts for the answer of the form n + log n + const ; 1 pts for the answer 2 n 3. Use the sequence 8, 4, 7, 3, 6, 2, 5, 1 to illustrate the process for finding the smallest element and the second smallest el- ement. Show all the element-wise comparisons made for this example, in the correct order. Solution: The order of element-wise comparisons is as follows: To find the smallest element: (8, 4), (7, 3), (6, 2), (5, 1), (4, 3), (2, 1), (3, 1) To find the second smallest element: (3, 2), (2, 5) Grading Keys: +0.5 pts for each correct comparison....
View Full Document

This note was uploaded on 02/27/2011 for the course CSE 310 taught by Professor Davulcu,h during the Spring '08 term at ASU.

Page1 / 12

Solution to midterm02 session B - Spring 2010 CSE310...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online