Solve for Huffman encoding.

Updated on technology 2024-05-25
8 answers
  1. Anonymous users2024-02-11

    This is because everything in your program involves tree[i].weight, where both input and output are %d, and the data type you define weight is float, so there is a type mismatch, and the data you input is not stored in tree[i].weight variable, as for your own algorithm, I didn't look closely.

    The program is modified as follows:

    #include

    #define maxsize 30

    typedef struct

    float weight;

    char flag;

    int lchild;

    int rchild;

    int parent;

    tree;main()

    int n,i,m,p1,p2,j,k,number;

    float minvalue1,minvalue2;

    tree tree[maxsize];

    printf("Please enter the number of nodes");

    scanf("%d",&n);

    m=2*n;

    for(i=0;itree[j].weight))minvalue1=tree[j].weight;

    p1=j;tree[p1].flag=1;

    for(k=1;tree[k].flag!=0;k++)minvalue2=tree[k].weight;

    p2=k;for(j=k+1;j<=number;j++)tree[j].weight))

    minvalue2=tree[j].weight;

    p2=j;tree[p1].parent=i;

    tree[p1].flag=1;

    tree[p2].parent=i;

    tree[p2].flag=1;

    tree[i].lchild=p1;

    tree[i].rchild=p2;

    tree[i].weight=tree[p1].weight+tree[p2].weight;

    for(i=1;i<2*number;i++)printf("%5f",tree[i].weight);Pay attention here!

    printf("");

    for(i=1;Attention here!

  2. Anonymous users2024-02-10

    I feel dizzy when I see such a long **!

  3. Anonymous users2024-02-09

    #include

    #include

    using namespace std;

    typedef struct

    hnodetype;

    typedef struct

    hcodetype;

    void huf(char cha,int m,int n)for(i=0;i>str;

    n=;cout<<"Strings have a total of characters"continue;

    for(j=i;jcoutk++;cout<<"The Huffman encoding for each character is:"

  4. Anonymous users2024-02-08

    Changed, is that okay?

    Enter the number of characters:

    4 Enter each character and weight:

    a 4b 3

    c 2d 4

    a: 4: 10

    b: 3: 01

    c: 2: 00

    d: 4: 11

    4 84 Enter the code: (Note that please enter the standard 01 code here, no other inspection) 10010011

    ABCD press any key to continue. .

  5. Anonymous users2024-02-07

    First of all, only when constructing the tree may appear the same value, but that doesn't matter, which can be taken out by the way, but even after the formation of the same code will definitely not appear, hafuman is to solve the same value coding problem, **a tree from the root to any**leaf**The path is unique,

  6. Anonymous users2024-02-06

    First, analyze the weights of each character:

    a=3,b=7,c=2,d=3,e=5

    Generate a Hoffman tree and get the encoding of each character:

    A = 110, b = 0, c = 1111, d = 1110, e = 10 The average code length is 46 15

  7. Anonymous users2024-02-05

    Hoffman coding has some distinct features:

    1) The coded codes are all different prefix codes, which ensures the unique translatability of the codes.

    2) Due to the variable length of the code. As a result, the decoding time is long, which makes the compression and restoration of Hoffman encoding quite time-consuming.

    3) The coding length is not uniform, and the hardware implementation is difficult.

    4) The coding efficiency of different signal sources is different, when the sign probability of the signal source is negative power of 2, the coding efficiency reaches 100%; If the probabilities of the signal source symbols are equal, the encoding efficiency is the lowest.

    5) Due to"0"with"1"Therefore, the optimal code coded by the above process is not unique, but its average code length is the same, so it does not affect the encoding efficiency and data compression performance.

  8. Anonymous users2024-02-04

    Huffman encoding is a frequency-dependent encoding, first you have to count the frequency of the text in your rolling text delay file, because the content of the text file contains Chinese, so when read with c can only be counted according to bytes, because the bytes in the machine only have a value range of 0 to 255, you can determine that the nodes of the huffman tree we want to build are 256, and the statistical frequency can be solved by using the map container of C++.

Related questions
3 answers2024-05-25

All use linear PCM coding to store ** signals, which is an uncompressed method. Uncompressed formats are also used on audio workstations and digital video recorders (e.g. DVCPRO) where high quality is required. >>>More

9 answers2024-05-25

The KKS power plant identification system originated in Germany. The first edition was officially published in 1978 and revised and enriched in the following years, with the latest version now being the fourth edition in 2000. The KKS identification system identifies individual installations, parts of the installations, and individual equipment in any type of power plant according to their task, type, and location. >>>More

7 answers2024-05-25

Yangfang store, Haidian District, Beijing.

China adopts a four-level six-digit coding system, the first two digits represent the province (municipality, autonomous region), the first third digit represents the postal district, the first fourth digit represents the county (city), and the last two digits represent which delivery area of the city is delivered, that is, the location of the delivery area. >>>More

3 answers2024-05-25

I haven't done this before, and I don't know too much, but you have to take a look!

8 answers2024-05-25

Photoelectric incremental encoders generally refer to the internal composition of high-precision glass gratings and detection elements. The encoder rotates to produce the light on/off, and the optoelectronic components convert it into biphasic pulses or ABZ pulses in different directions for position detection. >>>More