2011Winter2009_Assignment1_solution

2011Winter2009_Assignment1_solution - Department of...

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

View Full Document Right Arrow Icon
1 Department of Computer Science and Engineering York University, Winter 2009 CSE 2011: Assignment 1 Due Date - Monday, April 13, by Noon ! Question 1 Algorithm Design [2 points] Assume an arbitrary set of n distinct numbers ( S ). Devise an algorithm for outputting k smallest elements of S in order , where k<n. (Note: k is not a constant but an easily computable function of n). The number of ‘compare’ (comparison between two elements) operations in your algorithm should be O(n*log(k)) for full credit. The space requirements should not exceed O(n), and only the use of linear data structures is allowed. Give a pseudo-code description of your algorithm, and briefly justify its overall running time and the number of compare operations. Possible Solution: Step 1: Pick and sort first k elements: overall number of compare operations = O(klog(k)) overall running time = O(klog(k)) Annotate this set of k sorted numbers with A. Step 2:
Background image of page 1

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

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

This note was uploaded on 10/30/2010 for the course CSE 2011 taught by Professor Nguyen during the Spring '10 term at Maple Springs.

Page1 / 3

2011Winter2009_Assignment1_solution - Department of...

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

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