This preview shows pages 1–8. Sign up to view the full content.
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?
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document 2
Solutions
z
Solution 1
– Read the
N
numbers into an array, sort the
array in decreasing order by some simple
algorithm such as bubblesort,
– and then return the element in position
k
.
3
Pseudo Code I
z
Read N#s into A[N],
z
Sort the A[N] in decreasing order,
z
Return A[k].
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document 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.
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].
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document 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
Study of Algorithms II
z
Foundations of algorithms
– What is the
minimum number
of operations
necessary for any algorithm?
– What is 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.
This note was uploaded on 12/28/2010 for the course CSC CSC1110 taught by Professor Cjyuan during the Fall '06 term at CUHK.
 Fall '06
 CJYuan
 Sort

Click to edit the document details