- 博客(2)
- 收藏
- 关注
原创 【算法导论题】实现快排
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
247
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
462
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人