0% found this document useful (0 votes)
18 views5 pages

CENG 383 - Midterm - 2024 - 2025 - Fall

This document is a midterm exam for the CENG 383 Algorithms course at Çankaya University, scheduled for December 6, 2024. It consists of four questions covering topics such as recurrence relations, code analysis for function calls, max heap verification, and a 2D binary search algorithm. The exam is closed book, closed notes, and has a total time limit of 100 minutes.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views5 pages

CENG 383 - Midterm - 2024 - 2025 - Fall

This document is a midterm exam for the CENG 383 Algorithms course at Çankaya University, scheduled for December 6, 2024. It consists of four questions covering topics such as recurrence relations, code analysis for function calls, max heap verification, and a 2D binary search algorithm. The exam is closed book, closed notes, and has a total time limit of 100 minutes.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Çankaya University

Department of Computer Engineering


2023/2024 Fall CENG 383 Algorithms Midterm 6 December, 2024
Closed Book, Closed Notes, No Calculators/Electronic devices Allowed Time Allowed: 100 minutes

Name & Surname: _____________________________ Student No:______________ Sign:

Q1(25p) Q2(35p) Q3(20p) Q4(20p) Total

Q1) Consider following recurrence relation and answer questions


T(n) = 3T(n/3) + n2 where T(1)=2
a) (10p)Use a recursion tree to find closed form of T(n)
b) (10p)Use repeated substitution to find closed form of T(n)
c) (5p) Use Master Theorem to find closed form of T(n)
Answers Q1 a)
Q2-(35p) For each of the following pieces of code, find the number of times op() is called as a function of the input size
n. Express your answer in terms of the Big-Theta notation. Explain

(5p) for (i = 1; i < n; i *= 2)


op();

(5p) for (i = 10; i < n + 5; i *= 3)


op();

(5p) for (i = 1; i <= n * n - 10; i++)


for (j = 1; j <= i; j ++)
op();

(10p) void f(int n) {


if (n == 0) return;
for (int i = 0; i < n; i++)
op();
f(n-1);
}

(10p)for (i = 1; i <= n; i++)


for (j = 1; j <= i; j++)
for (k = 1; k <= j; k++)
op();
Q3-(20p)Given an array A indexed at 1, describe a process by which we could determine whether or not the array
represents a max heap. Write the pseudocode for an algorithm which does this. What is the time complexity of this
process?
Q4) (25p)Suppose the two-dimensional array A of size n × m, which is indexed as A[0, ..., n-1][0, ..., m-1], contains
integers with the property that every entry is greater than or equal to the entry directly above it and is greater than or
equal to the entry directly to the left of it.

An example of such an array is:

2 5 8 12 18 22 27
4 7 11 15 20 26 30
6 10 14 19 24 28 33
8 13 17 22 27 31 36
10 16 21 25 30 34 39
12 18 23 28 32 37 42
14 20 26 31 36 40 45

Write the pseudocode for a function binarysearch2d which locates a target entry in the array and returns the location.
Your algorithm should use a 2D version of binary search.

Hint: In the above example, the middle entry is 22 (at position A[3][3], corresponding to the 4th row and 4th column in
1-based indexing).
Master Theorem

You might also like