简体   繁体   English

排序算法的图形比较

[英]Graphing Comparisons of Sorting Algorithms

Task: I need to graph the number of comparisons(y axis) to the number of arguments in my array(x axis) for Insertion Sort and Quick Sort. 任务: 对于插入排序和快速排序,我需要将比较数(y轴)与数组中的参数数(x轴)作图。

Question: I was wondering if I could use the average time complexities in order to do this. 问题:我想知道是否可以使用平均时间复杂度来做到这一点。

Insertion Sort: O(n^2)= 1 element in my array(x axis) 1 comparison (y axis) 插入排序:O(n ^ 2)=我数组中的1个元素(x轴)1个比较(y轴)

Quick Sort: O(n log(n)) = 1 element in my array(x axis) 0 comparisons ( y axis) 快速排序:O(n log(n))=我数组中的1个元素(x轴)0个比较(y轴)

Similar/Helpful Question asked: https://cs.stackexchange.com/questions/3/why-is-quicksort-better-than-other-sorting-algorithms-in-practice 提出类似/有用的问题: https : //cs.stackexchange.com/questions/3/why-is-quicksort-better-than-other-sorting-algorithms-in-practice

我会说是的,除非您需要在排序函数中使用计数器来获取针对每个数组长度进行的比较的实际数量,这将取决于元素本身。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM