You are on page 1of 1

CSIT 5500 Advanced Algorithms

2023 Fall Semester


Written Assignment 1
Handed out: September 18, 2023
Due: 23:59 on October 2, 2023
Please submit a soft copy via the canvas system by the due date and time shown
above. Late assignments will not be graded.

1. (10 points) This question is about red-black tree.

(a) (7 points) Starting from an initially empty red-back tree T , insert the numbers 4, 2, 6,
1, 5, 10, 7, 3, 9, 8 in this order into T . Show the tree T after inserting each number.
You do not need to show other intermediate steps.
(b) (3 points) Starting from the final T that you obtained in (a) above containing the
numbers 1 to 10, delete the numbers 5, 8, 2, in this order. Show the tree T after deleting
each number. You do not need to show other intermediate steps.

2. (10 points)

(a) (6 points) Describe a recursive algorithm that accepts a positive integer n and returns all
possible binary search trees that contains the integers 1, 2, . . . , n. You can either describe
your algorithm in text or in a documented pseudocode.
(b) (2 points) Write down the recurrence for the running time of your recursive algorithm in
(a) with the boundary conditions. Explain your notations.
(c) (2 points) Solve your recurrence to obtain an upper bound on the running time of your
algorithm. Unlike what you learned in class, it may be easier to guess some upper bound
of T (n) and then prove it by mathematical induction. Your answer does NOT have to
be very tight to receive full credits.

3. (10 points) Let p1 , p2 , . . . , pn be n input points in the plane, each specified by its x- and
y-coordinates. Assume that no two input points have the same x- or y-coordinate. Assume
that p1 , p2 , . . . , pn are already sorted in increasing x-coordinate. Describe an algorithm to
find the maxima in O(n) time. Explain why your algorithm is correct and why the running
time is O(n).

4. (10 points) Let X[0..n − 1] and Y [0..n − 1] be two arrays, each containing n numbers in
increasing order. We assume the numbers in X and Y are distinct. Give an O(log n)-time
algorithm to find the median of all numbers in X and Y . That is, if we conceptually put all
numbers in X and Y together and arrange them in increasing order, the middle number in
this ordered list is the desired output and your algorithm needs to find this middle number
in O(log n) time.

You might also like