V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
hit9
V2EX  ›  问与答

全排列quickperm算法的分析

  •  
  •   hit9 · 2013-01-01 00:28:53 +08:00 · 2904 次点击
    这是一个创建于 4146 天前的主题,其中的信息可能已经有所发展或是发生改变。
    算法的网址:quickperm.org

    算法的描述:


    >The Counting QuickPerm Algorithm:

    let a[] represent an arbitrary list of objects to permute
    let N equal the length of a[]
    create an integer array p[] of size N to control the iteration
    initialize p[0] to 0, p[1] to 0, p[2] to 0, ..., and p[N-1] to 0
    initialize index variable i to 1
    while (i < N) do {
    if (p[i] < i) then {
    if i is odd, then let j = p[i] otherwise let j = 0
    swap(a[j], a[i])
    increment p[i] by 1
    let i = 1 (reset i to 1)
    } // end if
    else { // (p[i] equals i)
    let p[i] = 0 (reset p[i] to 0)
    increment i by 1
    } // end else (p[i] equals i)
    } // end while (i < N)


    我看不懂官网的解释,求助下,谢谢。
    1 条回复    1970-01-01 08:00:00 +08:00
    yyai3
        1
    yyai3  
       2013-01-01 10:51:59 +08:00
    只能读懂大概的思路~~感觉和TAOCP里面的Algorithm L很像

    例如{1,2,3,4,5},i=2时,{4,5}不动, 列出{1,2,3}的全排列,然后i=3,{5}不动,列出{1,2,3,4}的全排列。

    数组p[i]就是为了做局部全排列的,但是不清楚是如何标识的。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3221 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 13:01 · PVG 21:01 · LAX 06:01 · JFK 09:01
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.