5

今天看到一个新发现的有趣的排序算法。

 2 years ago
source link: https://www.v2ex.com/t/806909
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

V2EX  ›  程序员

今天看到一个新发现的有趣的排序算法。

  olist · 23 小时 32 分钟前 via iPhone · 3004 次点击
新算法:
for i = 1 to n do
for j = 1 to n do
if A[i] < A[j] then
swap A[i] and A[j]

等价的冒泡排序算法:
for i = 1 to n do
for j = i + 1 to n do
if A[i] > A[j] then
swap A[i] and A[j]

算法来源: https://arxiv.org/pdf/2110.01111.pdf

第 1 条附言  ·  22 小时 5 分钟前

第二个算法不是冒泡排序,也不是其它常见排序算法的标准写法。

第 2 条附言  ·  20 小时 59 分钟前

这个算法简单且好记,判断条件是小于号时是升序排序,大于号时是降序排序。但算法的正确性却不显而易见。

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK