算法设计|COMP3027/COMP3927 Algorithm Design

联系我们: 手动添加方式: 微信>添加朋友>企业微信联系人>13262280223 或者 QQ: 1483266981

This unit provides an introduction to the design techniques that are used to find efficient algorithmic solutions for given problems. The techniques covered include greedy, divide-and-conquer, dynamic programming, and adjusting flows in networks. Students will extend their skills in algorithm analysis. The unit also provides an introduction to the concepts of computational complexity and reductions between problems.

这是一份sydney悉尼大学COMP3027/COMP3927 的成功案例

算法设计|COMP3027/COMP3927 Algorithm Design

问题 1. Problem: Show that Big Oh relationships are transitive. That is, if f(n)=O(g(n))f(n)=O(g(n)) and g(n)=O(h(n))g(n)=O(h(n)), then f(n)=O(h(n))f(n)=O(h(n)).

证明 .

Solution: We always go back to the definition when working with the Big Oh mathrm{Oh}. What we need to show here is that f(n)≤c3h(n)f(n) leq c_{3} h(n) for n>n3n>n_{3} given that f(n)≤c1g(n)f(n) leq c_{1} g(n) and g(n)≤c2h(n)g(n) leq c_{2} h(n), for n>n1n>n_{1} and n>n2n>n_{2}, respectively. Cascading these inequalities, we get thatf(n)≤c1g(n)≤c1c2h(n)??for?n>n3=max(n1,n2). begin{aligned} & qquad f(n) leq c_{1} g(n) leq c_{1} c_{2} h(n) & text { for } n>n_{3}= max left(n_{1}, n_{2} right) . end{aligned}

问题 2.

Problem: Give an efficient algorithm to determine whether two sets (of size mm and nn, respectively) are disjoint. Analyze the worst-case complexity in terms of mm and nn, considering the case where mm is substantially smaller than nn.

证明 .

Solution: At least three algorithms come to mind, all of which are variants of sorting and searching:

First sort the big set – The big set can be sorted in O(nlogn)O(n log n) time. We can now do a binary search with each of the mm elements in the second, looking to see if it exists in the big set. The total time will be O((n+m)logn)O((n+m) log n).First sort the small set-The small set can be sorted in O(mlogm)O(m log m) time. We can now do a binary search with each of the nn elements in the big set, looking to see if it exists in the small one. The total time will be O((n+m)logm)O((n+m) log m).Sort both sets – Observe that once the two sets are sorted, we no longer have to do binary search to detect a common element. We can compare the smallest elements of the two sorted sets, and discard the smaller one if they are not identical. By repeating this idea recursively on the now smaller sets, we can test for duplication in linear time after sorting. The total cost is O(nlogn+mlogm+n+m)O(n log n+m log m+n+m).

So, which of these is the fastest method Clearly small-set sorting trumps bigset sorting, since logm

发表回复