【问题标题】:Sardinas- Patterson algorithm understandingSardinas-帕特森算法理解
【发布时间】:2016-02-06 22:56:21
【问题描述】:

我尝试在此代码字上应用 Sardinas-Patterson 算法: C = {0,01, 0111, 01111, 11110}

但我不明白如何,

我从 0 是 01 的前缀 -> 悬空后缀是 1 列表 = {0,01, 0111, 01111, 11110, 1}

0 是 0111 的前缀 -> 悬空后缀是 111

列表 = {0,01, 0111, 01111, 11110, 1, 111}

0 是 01111 的前缀 -> 悬空后缀是 1111

列表 = {0,01, 0111, 01111, 11110, 1, 111, 1111}

但我不知道如何继续......

很多

【问题讨论】:

    标签: algorithm binary data-compression


    【解决方案1】:

    这是我对algorithm described by wikipedia的解释

    首先,创建一个函数,将两个集合作为输入并生成一组所有悬空后缀:

    SET findSuffixes( SET a, SET b )
    {
        SET result = {}
        for each item x in a
            for each item y in b
            {
                if x is a prefix of y 
                    result.additem( y - x )
                else if y is a prefix of x
                    result.additem( x - y )
            }
        return result
    }
    

    并创建一个函数来检查任何代码字是否出现在给定的集合中:

    BOOL containsCodeword( SET a, SET codewords )
    

    并创建一个判断两个集合是否相同的函数:

    BOOL setIsEqualToSet( SET a, SET b )
    

    那么算法是这样的

    (A) SET codewords = { 0, 01, 0111, 01111, 11110 }
    (B) SET current = findSuffixes( codewords, codewords )
    (C) LIST_OF_SETS previous = {}
        forever
        {
    (D)     if ( containsCodeword( current, codewords) )
               then the code is not uniquely decodable, done
            for ( each set x in previous )
    (E)        if ( setIsEqualToSet( current, x )
                  then the code is uniquely decodable, done
    
    (F)     previous.additem( current )
    (G)     current = findSuffixes( current, codewords )
        }
    

    这是一个有效的例子:

    (A) codewords = { 0, 01, 0111, 01111, 11110 }
    (B) findSuffixes( codewords, codewords )
       0     - 0 = ignored since the result is empty
       01    - 0 = 1
       0111  - 0 = 111
       01111 - 0 = 1111
       11110 - 0 = rejected since 11110 doesn't start with 0
    
       0     - 01 = rejected
       01    - 01 = ignored
       0111  - 01 = 11
       01111 - 01 = 111
       11110 - 01 = rejected
    
       0     - 0111 = rejected
       01    - 0111 = rejected
       0111  - 0111 = ignored
       01111 - 0111 = 1 
       11110 - 0111 = rejected
    
       0     - 01111 = rejected
       01    - 01111 = rejected
       0111  - 01111 = rejected
       01111 - 01111 = ignored
       11110 - 01111 = rejected
    
       0     - 11110 = rejected
       01    - 11110 = rejected
       0111  - 11110 = rejected
       01111 - 11110 = rejected
       11110 - 11110 = ignored
    
        After removing duplicates, current = { 1, 11, 111, 1111 }
    
    (D) current does not contain any of the codewords
    (E) the previous list is empty, so no set in the previous list matches current
    (F) at this point the set { 1, 11, 111, 1111 } is added to the previous list
    
    (G) findsuffixes( current, codewords )
       there are 40 cases to consider
       20 cases where a member of the current set is removed from a member of codewords
       20 cases where a member of codewords is removed from a member of the current set
       most cases are rejected, the only interesting cases are
    
       11110 - 1    = 1110
       11110 - 11   = 110
       11110 - 111  = 10
       11110 - 1111 = 0
    
        So current = { 1110, 110, 10, 0 }
    
    (D) current does contain one of the codewords, so the code in not uniquely decodable
    

    【讨论】:

    • 如何将此算法翻译成伪代码或 java/c++ 代码?
    • 我还不明白算法你能给我另一个代码字的例子,它是 ud 而不是 ud?并一路得到答案?
    • @kfir91 我修复了问题中代码集的示例。您可以看到,手动分析很快变得不可能。唯一可解码的代码必须生成一个以前见过的集合列表,并且必须一直持续到 current 集合与列表中的一个集合完全相同。
    猜你喜欢
    • 2014-12-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-08
    • 1970-01-01
    相关资源
    最近更新 更多