0% found this document useful (0 votes)
13 views1 page

HW 1 F24

Uploaded by

cemilgunduz42
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views1 page

HW 1 F24

Uploaded by

cemilgunduz42
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

BIL 331:Fall 2024

Homework 1

Assigned Wednesday, October 2. Due Friday, October 11, 23.59. You must upload your answers
to uzak.etu.edu.tr by the deadline.

Problem 1. You are given an array A[1..n], whose elements are non-negative integers. Give a
Θ(n log n) divide-and-conquer algorithm to find the maximum value of A[j] − A[i], where
the indices i, j range over all values such that 1 ≤ i < j ≤ n. Give pseudocode and provide
an analysis of your algorithm by writing a recurrence for its running time and solving it.

Problem 2. Consider an array P [1..n] of 2D points where P [i].x stores the x-coordinate, P [i].y
stores the y-coordinate of the i-th point. A point P [i] is dominated by a point P [j] if P [i].x <
P [j].x and P [i].y < P [j].y. A point is a maximal point if it is not dominated by any other
point in P . In this problem, given an array P of 2D points, you are asked to output all
maximal points in P. Give an O(n lg n) divide-and-conquer algorithm to do that. You
are NOT allowed to presort the array (i.e. you are not allowed to call any sorting method
before calling your algorithm). There are multiple ways of solving this problem using a divide
and conquer approach. I REQUIRE your solution to use a divide and conquer similar to
MergeSort. In other words, the divide step of your algorithm should be as in MergeSort,
just dividing the given array of points into two equal sized subarrays at the middle index in
CONSTANT time. Give pseudocode, explain your algorithm on a small example and give its
runtime analysis.

Problem 3. At TOBB ETU, when the academic year starts every fall, the incoming first-year
students are given a keycard that lets them access buildings, labs and the library. This Fall
semester, the security office realized that some malfunctioning keycards were printed and
mixed with the valid cards. Security knew that strictly less than half of the cards were
malfunctioning, and that those cards had incorrect access codes, while all the valid cards had
the same correct access code. Luckily they have a device which can check if two keycards have
the same access code. When two cards are inserted in the device the device either lights up
green to mean that both cards have same code, or it lights up red if the cards have different
codes. The device cannot determine whether the actual code of a card is. Design an O(n lg n)
divide-and-conquer algorithm that the security office may use to find the valid cards using
only this device. Give pseudocode, explain your algorithm on a small example and give its
runtime analysis.

You might also like