Description
Problem 1: [15%] ( [GTG] Exercise R-8.11, page 350 )
Problem 2: [35%] ( [GTG] Exercise C-8.57, page 355 )
Let π be a given binary tree with π nodes. The distance between two nodes π and π in π is the number of edges along the unique simple path between π and π, i.e., ππ+ ππ β 2ππ, where π is the lowest common ancestor (LCA) of π and π, and ππ₯ denotes the depth of node π₯ in π. The diameter of π is the maximum distance between two nodes in π (i.e., the distance between the farthest pair of nodes in π). Give an efficient algorithm for computing the diameter of π and analyze its running time.
[Note: Each node of T stores an element and a pair of references to its left and right children. Other than that, nodes of T do not have any additional space to store extra information, not even their depths. Also, you should not attempt to create a clone of T with extra spaces in the clone nodes. Hint: use a post-order traversal of T with strengthened post-condition. As an example, see how we use a composite Result type as the return type in the EulerTour algorithm , LS8, pp: 20-21.]
1
Problem 3: [20%] ( [GTG] Exercise C-9.38, page 398 )
Tamarindo Airlines wants to give a first-class upgrade coupon to the top log π of their frequent flyers, based on the number of miles accumulated, where π is the number of the airlinesβ frequent flyers. The algorithm they currently use, which runs in π(π log π) time, sorts the flyers by the number of miles flown and then scans the sorted list to pick the top log π flyers.
They have hired you as their chief software engineer.
Give an algorithm that identifies the top log π flyers in π(π) time.
Problem 4: [30%] Dynamic Median Finder (DMF):
We want to design a DMF ADT that maintains a collection of comparable elements and supports the following operations on the collection:
β’ insert(e): inserts a given element π in π(log π) time,
β’ getMed(): returns the median in π(1) time,
β’ removeMed(): removes and returns the median in π(log π) time, where π denotes the current number of elements in the collection.
Give an implementation of the DMF ADT using two heaps as the only instance variables.
[The median of a collection of π elements is the π/2 π‘β smallest element (ties broken arbitrarily). For instance, the median of ο‘4, 9, 1ο± is 4, the median of ο‘9, 3, 3ο± is 3, the median of ο‘9, 9, 1, 2ο± is 2, and the median of ο‘17, -4, 13, -7, 13, 15, 5, 2ο± is 5.]
What files to submit:
β’ a3sol.pdf : Describe solutions to the problems with detailed explanations and illustrations of your algorithmic design ideas, all your pseudo-codes, convincing proofs of correctness and time complexity analysis.
β’ Submitting java source codes are optional.
2




Reviews
There are no reviews yet.