![](https://img-blog.csdnimg.cn/20201014180756926.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
算法导论题
文章平均质量分 57
fluttering_
这个作者很懒,什么都没留下…
展开
-
【算法导论题】实现快排
Implement Quicksort and answer the following questions.(1) How many comparisons will Quicksort do on a list of n elements that all have the same value?(2) What are the maximum and minimum number of comparisons will Quicksort do on a list of n elements, g原创 2022-07-10 16:50:08 · 250 阅读 · 1 评论 -
【算法导论题】描述一个运行时间为Q(nlgn)的算法,给定n个整数的集合S和另一个整数x,该算法能确定S中是否存在两个其和刚好为x的元素。
1.采用归并算法对数列进行排序,O(nlgn)。2.在有序数组中找是否有两数之和等于目标值,采用双指针法,O(n)。分:将数组分为左右两个数组治:递归调用归并排序MergeSort合:将两个有序数组合并:合:java代码:二、两数之和(有序数列)双指针法:用i,j分别指向数组首和尾,临时和sum=arr[i]+arr[j],比较sum和target,若,则j++。java代码:...原创 2022-07-10 16:46:40 · 468 阅读 · 0 评论