Sei sulla pagina 1di 2

Homework 4

CSc 4520/6520 Design and Analysis of Algorithms


Fall 2018
Due: 11:00pm, Nov. 3rd, 2018

1. Let a volatile graph be an undirected graph in which the weight of each


edge varies every time we query it. That is, when we request the weight
w(e) of edge e, we obtain an approximate value ŵ(e) defined as follows:

ŵ(e) = w(e) + η, where η ∼ N (0, σ).

Here, N (0, σ) is a Gaussian distribution with mean zero and standard


deviation σ.
(a) (20 pts) Write pseudocode for Volatile-Shortest-Path(G, u, v, p),
an algorithm that finds the correct shortest path between vertices
u and v on a volatile graph G with confidence p. You’re free to
define confidence in the way that best fits your algorithm, but it
must hold that as p grows, the probability that your algorithm
returns the true shortest path should also grow.
(b) (10 pts) Describe a type of volatile graph with σ > 0 for which
Dijkstra’s algorithm is guaranteed to return the correct answer.
2. Let B be a k-nary heap. That is, instead of just having two children,
as in a binary heap, each node of B has k children. As with binary
heaps, though, B we fill B level by level and from left to right.
(a) (20 pts) Rewrite the pseudocode for Max-Heapify, Build-
Max-Heap, and Heapsort to handle a k-nary heap.
(b) (10 pts) What is the complexity of the above three algorithms
as a function of k? In other words, as the number of children
per node grows, do these operations get more or less expensive?
Justify your answer.

1
3. Let Q be a capacity-limited list of FIFO queues. In other words, Q has
a top-level list of sub-queues. As new elements gets added to Q, we
add them to the first available sub-queue. We always extract the first
element in the first sub-queue. When that queue reaches a maximum
capacity c, we create a new queue and add the elements to this new
sub-queue instead. When we extract an element, we have to move
the the elements between the different sub-queues so that each sub-
queue except the last one remains filled to capacity. When a sub-queue
becomes empty, we delete it.

(a) (15 pts) Do an amortized analysis of the Insert and Delete


operations on Q. You can use any of the techniques studied in
class.
(b) (Extra credit: 15 pts) Write pseudocode to implement the
Insert and Delete operations.

Potrebbero piacerti anche