0

Hi All,

My data set consist of numeric values 0s and 1s. I have designed a code that enables me to compress the string (rwo) to substring based on LZ algorthim. However, it seems that the substring is not correct as you can see in the following example:

reading file -------------------> writing file
Example 1. 100010000000000100--------->{1,0,001,0000,0000001,00}
Example 2. 001001110010010000--------->{0,01,0011,10010,01000,0}

The correct answer should be like this see this but unfortunately i could not design it correctelly.
S = 010110011 ------------------------>substrings {0, 1, 01, 10, 011},
S= 001001------------------------------->substring {0,01,001}

Thank you very much in advance.

The is the code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace LZComplex
{
    class LZComplexity
    {
        private List<string> vocabularys;

        public LZComplexity()
        {
            vocabularys = new List<string>();
        }
               public int calcComplexity(string p_binarySequence)
        {
            int n = p_binarySequence.Length;
            int before_pos;

            int c = 1, j = 0, i = -1;
            int k = 1, kmax = 1;
            bool stop = false;

            vocabularys.Clear();

            vocabularys.Add(p_binarySequence[0].ToString());
            before_pos = 0;

            while (!stop)
            {
                if (p_binarySequence[i + k] != p_binarySequence[j + k])
                {
                    if (k > kmax)
                        kmax = k;

                    i = i + 1;

                    if (i == j)
                    {
                        
                        c = c + 1;
                        j = j + kmax;
                        vocabularys.Add(p_binarySequence.Substring(before_pos+1,j-before_pos));
                        before_pos = j;

                        if (j + 1 > n-1)
                        {
                            stop = true;
                        }
                        else 
                        {
                            i = -1;
                            k = 1;
                            kmax = 1;
                        }
                    }else
                    {
                        k = 1;
                    }
                }else{
                    k = k + 1;
                    if (j + k > n-1)
                    {
                        vocabularys.Add(p_binarySequence.Substring(before_pos + 1, (n-1) - before_pos));
                        
                        c = c + 1;
                        stop = true;
                    }
                }
            }
            return c;
        }

        public List<string> getVocabularys()
        {
            return vocabularys;
        }
    }
}
2
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by Nony2007
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.