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;
        }
    }
}

Recommended Answers

All 2 Replies

Are you trying to use LZ77, LZ78, LZW or Statistical Lempel Ziv?

Thanks for your replay.

I am trying to use LZ78.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.