且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

为什么链表的归并排序空间复杂度为 O(log(n))?

更新时间:2023-09-16 16:17:22

Mergesort 是一种递归算法.每个递归步骤都会在堆栈上放置另一个帧.排序 64 个项会比排序 32 个项多递归一步,而且实际上是说空间需求为 O(log(n)) 时所指的堆栈大小.

Mergesort is a recursive algorithm. Each recursive step puts another frame on the stack. Sorting 64 items will take one more recursive step than 32 items, and it is in fact the size of the stack that is referred to when the space requirement is said to be O(log(n)).