Algorithms: Design and Analysis, Part 1Problem Set #5

1. 

Consider a directed graph with distinct and nonnegative edge lengths and a source  s vertex . Fix a destination vertex  t , and assume that the graph contains at least one  s - t  path. Which of the following statements are true? [Check all that apply.]

2. 

Consider a directed graph  G=(V,E)  and a source vertex  s  with the following properties: edges that leave the source vertex  s  have arbitrary (possibly negative) lengths; all other edge lengths are nonnegative; and there are no edges from any other vertex to the  s source  . Does Dijkstra's shortest-path algorithm correctly compute shortest-path distances (from  s ) in this graph?

Maybe, maybe not (depends on the graph)

Only if we add the assumption that  G  contains no directed cycles with negative total weight.

Never

3. 

Suppose you implement the functionality of a priority queue using a sorted array (e.g., from biggest to smallest). What is the worst-case running time of Insert and Extract-Min, respectively? (Assume that you have a large enough array to accommodate the Insertions that you face.)

Θ(logn)  and  Θ(1)

Θ(n)  and  Θ(n)

Θ(1)  and  Θ(n)

4. 

Suppose you implement the functionality of a priority queue using an unsorted array. What is the worst-case running time of Insert and Extract-Min, respectively? (Assume that you have a large enough array to accommodate the Insertions that you face.)

Θ(1)  and  Θ(logn)

Θ(n)  and  Θ(1)

Θ(n)  and  Θ(n)

5. 

You are given a heap with  n  elements that supports Insert and Extract-Min. Which of the following tasks can you achieve in  O(logn)  time?

None of these.

Find the median of the elements stored in the heap.

Find the largest element stored in the heap.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值