Introduction

Introduction - Introduction: Example A k selection problem...

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

View Full Document Right Arrow Icon
1 Introduction: Example z A k selection problem - given a set of numbers, select the k highest number in the list. z How do you do the above task?
Background image of page 1

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

View Full DocumentRight Arrow Icon
2 Solutions z Solution 1 – Read the N numbers into an array, sort the array in decreasing order by some simple algorithm such as bubble-sort, – and then return the element in position k .
Background image of page 2
3 Pseudo Code I z Read N#s into A[N], z Sort the A[N] in decreasing order, z Return A[k].
Background image of page 3

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

View Full DocumentRight Arrow Icon
4 Solutions z Solution 2 – Read the first k elements into an array and sort them (in decreasing order). – Next, each remaining element is read one by one. – As a new element arrives, it is ignored if it is smaller than the k th element in the array. – Otherwise, it is placed in its correct spot in the array, bumping one element out of the array. – When the algorithm ends, the element in the k th position is returned as the answer.
Background image of page 4
5 Pseudo Code II z Read K#s into B[k], z Sort the B[k] in decreasing order, –Read a new #, –If # > B[k] insert # in B[k] –Repeat; z Return B[k].
Background image of page 5

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

View Full DocumentRight Arrow Icon
6 Study of Algorithms I z Machines for executing algorithms – What is the processing speed ? – How large is the processing space (memory)? – What is the organization of the processors ? z Languages for describing algorithms – Language design and translation – Syntax specification and semantics
Background image of page 6
Study of Algorithms II z Foundations of algorithms – What is the minimum number of operations necessary for any algorithm? – What is the
Background image of page 7

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

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

This note was uploaded on 12/28/2010 for the course CSC CSC1110 taught by Professor Cjyuan during the Fall '06 term at CUHK.

Page1 / 28

Introduction - Introduction: Example A k selection problem...

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

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