Question 2 : Errors in Code 10 points Below is a function "get Huffman Tree" that is supposed to create a huffman encodi

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

Question 2 : Errors in Code 10 points Below is a function "get Huffman Tree" that is supposed to create a huffman encodi

Post by answerhappygod »

Question 2 Errors In Code 10 Points Below Is A Function Get Huffman Tree That Is Supposed To Create A Huffman Encodi 1
Question 2 Errors In Code 10 Points Below Is A Function Get Huffman Tree That Is Supposed To Create A Huffman Encodi 1 (86.32 KiB) Viewed 40 times
Question 2 : Errors in Code 10 points Below is a function "get Huffman Tree" that is supposed to create a huffman encoding tree from the given frequency array (stored in freq) and its associated character array (stored in sym). In particu- lar, symbol sym has frequency freq. The variable size is the number of frequencies/characters. The program is not supposed to leak any memory. Forest *getHuffmanTree( int freq[], char sym[], int size ) { int i; CharFreq cf; Forest *f = createForest(); Queue *pq = createForest(); 1 2 3 7 8 9 for(i=0; i<size; i++){ cf.sym - (char*)malloc( sizeof (char)*2); cf.freq - freq; cf. sym[0] = sym; enqueue( pq, cf, cf.freq); addNode( f, cf); } 10 11 12 13 14 15 16 while( !isEmpty( pq)) { CharFreq leasti - dequeue ( pq ); CharFreq least2 = dequeue ( pq); 17 18 19 cf.sym - (char*)malloc( sizeof (char)*100); cf->freq = least1.freq + least2.freq; 20 21 22 for(i=0; least1.sym !='\0'; i++) cf. sym least1.sym; 23 24 25 for(j=0; least2.sym !='\0'; j++) cf. sym[i+j] = least2.sym[j]; 27 28 sym[i+j] = '\0'; 29 30 31 addNode( f, cf); setParent( f, cf, least1, least2 ); enqueue( f, cf); 32 33 } 34 35 return f; freeQueue ( pq ); 36 27 } Find at least 5 errors in the code (syntax/runtime/logic/memory) and fill them in the provided table. Give a short description of the error. You can list up to 10 errors. If at least 5 of your answers are correct you will receive full credit. There is no additional credit for finding more errors.
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply