Sunteți pe pagina 1din 1

CMPE 300 ANALYSIS OF ALGORITHMS 27.11.

2013
MIDTERM

1. Suppose that we are given an array A[1:n] with the special property that A[1]≥A[2] and
A[n-1]≤A[n]. We say that an element A[i] is a local minimum if it is less than or equal to
both of its neighbors, or more formally, if A[i-1]≥A[i] and A[i]≤A[i+1]. For example,
there are six local minima in the following array (shown in bold):

9 7 7 2 1 3 7 5 4 7 3 3 4 8 6 9

We can obviously find a local minimum in O(n) time by scanning through the array. Write
in pseudocode an algorithm that finds a local minimum (it is sufficient to find only one
local minimum) in O(log n) time in the worst-case. Explain clearly that your algorithm is
correct. Briefly analyze W(n) (you do not need to give a complete analysis; just show that
it executes in O(log n) time).
(Note that, with the given boundary conditions, the array must have at least one local
minimum. You can assume that n≥3.)

2. Write the insertion sort algorithm in pseudocode and analyze its average case complexity
exactly. Your analysis must be clear and show every detail in your reasoning.

3. Answer the following questions about parallel algorithms:


a) What are the main approaches in designing a parallel algorithm? Explain each one
briefly.
b) Write the possible architectures according to Flynn’s taxonomy. Explain each one
briefly.
c) Write the possible data access models with respect to the read/write operations in
PRAMs. Explain each one briefly.
The explanations should not be long, but should include all the basic and important points.

Notes:
 Where pseudocode is required, the syntax of the pseudocode must be strictly followed. No
points will be given if the syntax is not followed or any other language (e.g. C) is used.
 Questions 1,3:35 points; 2:30 points
 Time: 1:30 hours
 Close notes and books

Ben bu dünyaya yanlış gelmiş olacağım ben,


Ben öyle her insandan, o kadar uzağım ben.
Yine bu gözlerimdir okşanacak şey arar,
Yoksa içimde başka bir dünya hasreti var.

Uyanır gibi birden bir korkulu rüyadan,


-O içimden sevdiğim, benim olan dünyadan,
Bir ses bana: "Gel!" dese, ben o sesi işitsem;-
Kimsecikler duymadan bir kapı açıp gitsem!

S-ar putea să vă placă și