SlideShare a Scribd company logo
1 of 6
The assigment is overdue now. I will up the price I am willing
to pay to have it done. It must be completed by the latest on the
8th. However I would greatly preffer for it to be finished on the
7th. I will add $20 to the price if you can complete it by then.
I need the files to run in Eclipse. Please upload them as such.
See my file as an example.
They must be coded in java.
This is for a 200 level data structures class so please match that
level accordingly.
I need java Test cases and comments please. (see my example
file)
I have included part of the previous assigment so you can see
what mine looks like and it also may have things you may need
like map etc. Though I cannot guarantee all of it is working
properly. (named example)
-----
The Task
Okay, we are finally going to finish off the Huffman
application. Last week, we got to the point where we could
build the tree and do some simple encoding and decoding. The
problem with our technique is that we were converting text into
Strings of 0s and 1s. Hopefully, the vast majority realized that
this is the opposite of actual compression. Our goal was to
reduce
the number of bits required to encode a character. Instead, we
blew it up, replacing one character with a whole String of them!
Ouch.
So, we are going to do some bit level work, and learn how to
write binary data out to files and read it back in again. The
second issue that we have is that once we have an encoded file,
we don't have a good way to decode it without first having the
original source file, which rather defeats the purpose of
compressing the file in the first place. Thus, we need to store a
copy of the tree in the coded file. Of course, we want to store
the tree in a format we can read back out again, and also doesn't
take up too much room...
Background: Canonical form
We would like our Huffman codes to be
canonical
. I gave you an algorithm for picking which character to add
next to your Huffman tree that comes close to producing
canonical codes, but, sadly, I have to admit it has a flaw. There
is an edge case that it can never compensate for. So, we are
going to have to do some more work to get it into the canonical
form.
The canonical form adds two rules to the way Huffman codes
work. First, all codes of a given bit length have
lexicographically consecutive values (i.e., not just in order, but
immediately consecutive), in the same order as the symbols they
represent, and second, shorter codes lexicographically precede
longer ones. An example will make this a little clearer...
Suppose we have some piece of text in which the characters
A,B,C,and D appear, with the following frequencies [A:1, B:5,
C:6, D:2]. We could put these into a Huffman tree and come out
with the following codes:
A
001
B
01
C
1
D
000
This is not in canonical form. The first rule is broken because A
comes before D, but 000 should precede 001. The second rule is
broken because C had a shorter code than B, but 01 precedes 1
lexicographically. Here is an alternate assignment of codes that
does satisfy the rule:
A
110
B
10
C
0
D
111
0 precedes 10, which precedes 11x, and 110 and 111 are
lexicographically consecutive.
The algorithm for deriving canonical codes is fairly
straightforward, provided we start by knowing the lengths of the
codes. The trick is to think of the codes as binary numbers. The
first code, which is given to the lexicographically smallest
symbol with the shortest code, is 0, padded out with 0s to be as
long as the symbol's code. In our example, C has the shortest
code (length 1), so its code is 0 (if C's code has been length
three, the code would have been 000). We then increment the
code (counting in binary), which will produce the
lexicographically consecutive code. If the next symbol has a
longer code, we pad the code with 0s to the right to match the
code length (in other words, we perform a left shift or a
multiply by 2). Thus, the next code would be 1, but B has a
longer code length, so it gets the code 10. To move to A, we
increment (11), and shift again to get 110. D has the same code
length as A, so it gets 111.
Why is this interesting? Well, it means that we can recover the
entire tree starting only from knowledge about the length of the
codes. So, when we want to store our tree in a file with our
data, we just have to record the character followed by the length
of its code. Cool, huh?
Part one: Generate canonical codes [25 pts]
We can keep all of the work that we did in the last assignment,
but the tree that we produce is no longer the tree that we want
to keep. Its sole purpose is to provide us with the initial code
lengths for generating the canonical codes. Instead of traversing
the tree and loading the reverse lookup into a map, you are
going to traverse the tree and collect symbols and their code
lengths, dumping them into a new priority queue as we go. I
suggest tweaking your old wrapper class that held symbols and
frequencies to be a more generic pairing of counts and symbols,
so you can reuse it for symbols and code lengths (this is
probably just some renaming to make it more general purpose).
You will want to write a new Comparator that will return these
items to you in order first by code length (shortest first) and
then in lexicographic order (a to z).
You should then write a new private method called
buildTreeFromMap
which takes in a PriorityQueue of your wrapper objects as an
argument. In this method you will use the PriorityQueue to
implement the above algorithm to build the Huffman tree
(which the algorithm I provided just specifies the codes, you
will want to build up into a tree that represents the given code
words). The tree that results from this process is the one to save
as an instance variable (for decode). Now is when you will
build the Map that you need for encode (you should be able to
reuse the code you had for building it before). The old
buildTreeFromFile
should obviously call
buildTreeFromMap
once it has built the code length map.
Part two: File handling [40 pts]
We can finally get to the actual application! The first step will
be to encode the file. Start by making one additional tweak to
buildFromFile
that saves the
File
object in an instance variable. Write a new function called
saveCompressedFile
, which will take a single
File
object as an argument. This file will be the destination for the
compressed file. This function will first write the tree
representation to the destination file. Start by writing an integer
that says how many character, code lengths pairs to expect (this
tells the reader how many bytes of the file are consumed by the
tree). Then write out each character followed by the length of
its code. Following the tree, you can start writing the
compressed data from the file. This works just like encode,
walking character by character, except that you will want to
write bits, rather than Strings holding 0s and 1s (we'll talk
about this in class).
You will then want to write the compliment to this. The
difference here, however, is that we don't have the original
source data to build the tree again. So I want you to write a
second static factory method called
newTreeFromCompressedFile
. Like
newTreeFromFile
, this will create a new HuffmanTree object and then call a
private instance method called
buildFromCompressedFile
, to which it passes the compressed file. This should read the
tree description out of the file, dumping the symbols and code
lengths into a priority queue as it reads. It should then call
buildTreeFromMap
to initialize the tree and the reverse lookup map.
Finally, write a method called
saveExpandedFile
, which takes in a destination
File
and processes the original file, using the tree to decode the
data.
If you encounter errors in either compressing or decompressing
with respect to unknown codes, throw a
CharConversionException.
A little help
To help you get started, here is a skeleton of the HuffmanTree
that includes som of the old functionality from the last
homework: -- huffmanTree -- see attatched
---
Java Tests needed
The assignment info from the previous assignment is attatched.
It explains how other things such as map are supposed to be
built.
Huffman tree skeleton is also attatched.

More Related Content

Similar to The assigment is overdue now. I will up the price I am willing to pa.docx

Introductionto Xm Lmessaging
Introductionto Xm LmessagingIntroductionto Xm Lmessaging
Introductionto Xm LmessagingLiquidHub
 
Objectives Assignment 09 Applications of Stacks COS.docx
Objectives Assignment 09 Applications of Stacks COS.docxObjectives Assignment 09 Applications of Stacks COS.docx
Objectives Assignment 09 Applications of Stacks COS.docxdunhamadell
 
Sienna 12 huffman
Sienna 12 huffmanSienna 12 huffman
Sienna 12 huffmanchidabdu
 
Clean Code Tutorial maXbox starter24
Clean Code Tutorial maXbox starter24Clean Code Tutorial maXbox starter24
Clean Code Tutorial maXbox starter24Max Kleiner
 
Article link httpiveybusinessjournal.compublicationmanaging-.docx
Article link httpiveybusinessjournal.compublicationmanaging-.docxArticle link httpiveybusinessjournal.compublicationmanaging-.docx
Article link httpiveybusinessjournal.compublicationmanaging-.docxfredharris32
 
Scanned by CamScannerModule 03 Lab WorksheetWeb Developmen.docx
Scanned by CamScannerModule 03 Lab WorksheetWeb Developmen.docxScanned by CamScannerModule 03 Lab WorksheetWeb Developmen.docx
Scanned by CamScannerModule 03 Lab WorksheetWeb Developmen.docxanhlodge
 
Questions4
Questions4Questions4
Questions4hccit
 
cs262_intro_slides.pptx
cs262_intro_slides.pptxcs262_intro_slides.pptx
cs262_intro_slides.pptxAnaLoreto13
 
Write Your Own JVM Compiler
Write Your Own JVM CompilerWrite Your Own JVM Compiler
Write Your Own JVM CompilerErin Dees
 
Creating your own Abstract Processor
Creating your own Abstract ProcessorCreating your own Abstract Processor
Creating your own Abstract ProcessorAodrulez
 
Parallel Programming: Beyond the Critical Section
Parallel Programming: Beyond the Critical SectionParallel Programming: Beyond the Critical Section
Parallel Programming: Beyond the Critical SectionTony Albrecht
 
The Ring programming language version 1.10 book - Part 100 of 212
The Ring programming language version 1.10 book - Part 100 of 212The Ring programming language version 1.10 book - Part 100 of 212
The Ring programming language version 1.10 book - Part 100 of 212Mahmoud Samir Fayed
 

Similar to The assigment is overdue now. I will up the price I am willing to pa.docx (20)

topic_perlcgi
topic_perlcgitopic_perlcgi
topic_perlcgi
 
Introductionto Xm Lmessaging
Introductionto Xm LmessagingIntroductionto Xm Lmessaging
Introductionto Xm Lmessaging
 
Objectives Assignment 09 Applications of Stacks COS.docx
Objectives Assignment 09 Applications of Stacks COS.docxObjectives Assignment 09 Applications of Stacks COS.docx
Objectives Assignment 09 Applications of Stacks COS.docx
 
Sienna 12 huffman
Sienna 12 huffmanSienna 12 huffman
Sienna 12 huffman
 
CPP Homework Help
CPP Homework HelpCPP Homework Help
CPP Homework Help
 
Text compression
Text compressionText compression
Text compression
 
Clean Code Tutorial maXbox starter24
Clean Code Tutorial maXbox starter24Clean Code Tutorial maXbox starter24
Clean Code Tutorial maXbox starter24
 
Huffman
HuffmanHuffman
Huffman
 
Huffman
HuffmanHuffman
Huffman
 
Article link httpiveybusinessjournal.compublicationmanaging-.docx
Article link httpiveybusinessjournal.compublicationmanaging-.docxArticle link httpiveybusinessjournal.compublicationmanaging-.docx
Article link httpiveybusinessjournal.compublicationmanaging-.docx
 
Exploitation Crash Course
Exploitation Crash CourseExploitation Crash Course
Exploitation Crash Course
 
Scanned by CamScannerModule 03 Lab WorksheetWeb Developmen.docx
Scanned by CamScannerModule 03 Lab WorksheetWeb Developmen.docxScanned by CamScannerModule 03 Lab WorksheetWeb Developmen.docx
Scanned by CamScannerModule 03 Lab WorksheetWeb Developmen.docx
 
Questions4
Questions4Questions4
Questions4
 
cs262_intro_slides.pptx
cs262_intro_slides.pptxcs262_intro_slides.pptx
cs262_intro_slides.pptx
 
Write Your Own JVM Compiler
Write Your Own JVM CompilerWrite Your Own JVM Compiler
Write Your Own JVM Compiler
 
Creating your own Abstract Processor
Creating your own Abstract ProcessorCreating your own Abstract Processor
Creating your own Abstract Processor
 
Parallel Programming: Beyond the Critical Section
Parallel Programming: Beyond the Critical SectionParallel Programming: Beyond the Critical Section
Parallel Programming: Beyond the Critical Section
 
The Bund language
The Bund languageThe Bund language
The Bund language
 
Lec5 Compression
Lec5 CompressionLec5 Compression
Lec5 Compression
 
The Ring programming language version 1.10 book - Part 100 of 212
The Ring programming language version 1.10 book - Part 100 of 212The Ring programming language version 1.10 book - Part 100 of 212
The Ring programming language version 1.10 book - Part 100 of 212
 

More from rtodd17

The Assignment consists of 3 Parts.Part I  Journal 200 words s.docx
The Assignment consists of 3 Parts.Part I  Journal 200 words s.docxThe Assignment consists of 3 Parts.Part I  Journal 200 words s.docx
The Assignment consists of 3 Parts.Part I  Journal 200 words s.docxrtodd17
 
The assignment consists of a Discussion that should be at least .docx
The assignment consists of a Discussion that should be at least .docxThe assignment consists of a Discussion that should be at least .docx
The assignment consists of a Discussion that should be at least .docxrtodd17
 
The Assignment (minimum 2–3 pages)Create an annotated bib.docx
The Assignment (minimum 2–3 pages)Create an annotated bib.docxThe Assignment (minimum 2–3 pages)Create an annotated bib.docx
The Assignment (minimum 2–3 pages)Create an annotated bib.docxrtodd17
 
The assignment (3–5 pages)Briefly describe the specific cultu.docx
The assignment (3–5 pages)Briefly describe the specific cultu.docxThe assignment (3–5 pages)Briefly describe the specific cultu.docx
The assignment (3–5 pages)Briefly describe the specific cultu.docxrtodd17
 
The Assignment (3–4 pages)For this Assignment, perform the .docx
The Assignment (3–4 pages)For this Assignment, perform the .docxThe Assignment (3–4 pages)For this Assignment, perform the .docx
The Assignment (3–4 pages)For this Assignment, perform the .docxrtodd17
 
The Assignment (1-page)  The Reading  to use for both paragraphs is.docx
The Assignment (1-page)  The Reading  to use for both paragraphs is.docxThe Assignment (1-page)  The Reading  to use for both paragraphs is.docx
The Assignment (1-page)  The Reading  to use for both paragraphs is.docxrtodd17
 
The Assignment (3–4 pages)Based on the theory demonstrated i.docx
The Assignment (3–4 pages)Based on the theory demonstrated i.docxThe Assignment (3–4 pages)Based on the theory demonstrated i.docx
The Assignment (3–4 pages)Based on the theory demonstrated i.docxrtodd17
 
The Assignment (3–4 pages)Describe the concerns held by both .docx
The Assignment (3–4 pages)Describe the concerns held by both .docxThe Assignment (3–4 pages)Describe the concerns held by both .docx
The Assignment (3–4 pages)Describe the concerns held by both .docxrtodd17
 
The assessment portion of the nursing process is where the nurse.docx
The assessment portion of the nursing process is where the nurse.docxThe assessment portion of the nursing process is where the nurse.docx
The assessment portion of the nursing process is where the nurse.docxrtodd17
 
The assignment (3 – 4 pages)Analyze the history of the profession.docx
The assignment (3 – 4 pages)Analyze the history of the profession.docxThe assignment (3 – 4 pages)Analyze the history of the profession.docx
The assignment (3 – 4 pages)Analyze the history of the profession.docxrtodd17
 
The Assignment (2–4 pages)Provide a transcript of what happen.docx
The Assignment (2–4 pages)Provide a transcript of what happen.docxThe Assignment (2–4 pages)Provide a transcript of what happen.docx
The Assignment (2–4 pages)Provide a transcript of what happen.docxrtodd17
 
The articles about the 2011 horn of Africa famine note several dif.docx
The articles about the 2011 horn of Africa famine note several dif.docxThe articles about the 2011 horn of Africa famine note several dif.docx
The articles about the 2011 horn of Africa famine note several dif.docxrtodd17
 
The Assignment (2–4 pages)Discuss something important you lea.docx
The Assignment (2–4 pages)Discuss something important you lea.docxThe Assignment (2–4 pages)Discuss something important you lea.docx
The Assignment (2–4 pages)Discuss something important you lea.docxrtodd17
 
The Assignment (2–3 pages)Your submission should include the.docx
The Assignment (2–3 pages)Your submission should include the.docxThe Assignment (2–3 pages)Your submission should include the.docx
The Assignment (2–3 pages)Your submission should include the.docxrtodd17
 
The assignment (2–3 pages)Explain the similarities and .docx
The assignment (2–3 pages)Explain the similarities and .docxThe assignment (2–3 pages)Explain the similarities and .docx
The assignment (2–3 pages)Explain the similarities and .docxrtodd17
 
The assignment (2–3 pages)Identify the human services adminis.docx
The assignment (2–3 pages)Identify the human services adminis.docxThe assignment (2–3 pages)Identify the human services adminis.docx
The assignment (2–3 pages)Identify the human services adminis.docxrtodd17
 
The Assignment (2–3 pages)Based on the program or policy ev.docx
The Assignment (2–3 pages)Based on the program or policy ev.docxThe Assignment (2–3 pages)Based on the program or policy ev.docx
The Assignment (2–3 pages)Based on the program or policy ev.docxrtodd17
 
The Assignment (2–3 pages)Explain the effects of sexual tra.docx
The Assignment (2–3 pages)Explain the effects of sexual tra.docxThe Assignment (2–3 pages)Explain the effects of sexual tra.docx
The Assignment (2–3 pages)Explain the effects of sexual tra.docxrtodd17
 
The article must be current to Law Enforcement or other Criminal.docx
The article must be current to Law Enforcement or other Criminal.docxThe article must be current to Law Enforcement or other Criminal.docx
The article must be current to Law Enforcement or other Criminal.docxrtodd17
 
The assignment (1–2pages)Describe the diverse populatio.docx
The assignment (1–2pages)Describe the diverse populatio.docxThe assignment (1–2pages)Describe the diverse populatio.docx
The assignment (1–2pages)Describe the diverse populatio.docxrtodd17
 

More from rtodd17 (20)

The Assignment consists of 3 Parts.Part I  Journal 200 words s.docx
The Assignment consists of 3 Parts.Part I  Journal 200 words s.docxThe Assignment consists of 3 Parts.Part I  Journal 200 words s.docx
The Assignment consists of 3 Parts.Part I  Journal 200 words s.docx
 
The assignment consists of a Discussion that should be at least .docx
The assignment consists of a Discussion that should be at least .docxThe assignment consists of a Discussion that should be at least .docx
The assignment consists of a Discussion that should be at least .docx
 
The Assignment (minimum 2–3 pages)Create an annotated bib.docx
The Assignment (minimum 2–3 pages)Create an annotated bib.docxThe Assignment (minimum 2–3 pages)Create an annotated bib.docx
The Assignment (minimum 2–3 pages)Create an annotated bib.docx
 
The assignment (3–5 pages)Briefly describe the specific cultu.docx
The assignment (3–5 pages)Briefly describe the specific cultu.docxThe assignment (3–5 pages)Briefly describe the specific cultu.docx
The assignment (3–5 pages)Briefly describe the specific cultu.docx
 
The Assignment (3–4 pages)For this Assignment, perform the .docx
The Assignment (3–4 pages)For this Assignment, perform the .docxThe Assignment (3–4 pages)For this Assignment, perform the .docx
The Assignment (3–4 pages)For this Assignment, perform the .docx
 
The Assignment (1-page)  The Reading  to use for both paragraphs is.docx
The Assignment (1-page)  The Reading  to use for both paragraphs is.docxThe Assignment (1-page)  The Reading  to use for both paragraphs is.docx
The Assignment (1-page)  The Reading  to use for both paragraphs is.docx
 
The Assignment (3–4 pages)Based on the theory demonstrated i.docx
The Assignment (3–4 pages)Based on the theory demonstrated i.docxThe Assignment (3–4 pages)Based on the theory demonstrated i.docx
The Assignment (3–4 pages)Based on the theory demonstrated i.docx
 
The Assignment (3–4 pages)Describe the concerns held by both .docx
The Assignment (3–4 pages)Describe the concerns held by both .docxThe Assignment (3–4 pages)Describe the concerns held by both .docx
The Assignment (3–4 pages)Describe the concerns held by both .docx
 
The assessment portion of the nursing process is where the nurse.docx
The assessment portion of the nursing process is where the nurse.docxThe assessment portion of the nursing process is where the nurse.docx
The assessment portion of the nursing process is where the nurse.docx
 
The assignment (3 – 4 pages)Analyze the history of the profession.docx
The assignment (3 – 4 pages)Analyze the history of the profession.docxThe assignment (3 – 4 pages)Analyze the history of the profession.docx
The assignment (3 – 4 pages)Analyze the history of the profession.docx
 
The Assignment (2–4 pages)Provide a transcript of what happen.docx
The Assignment (2–4 pages)Provide a transcript of what happen.docxThe Assignment (2–4 pages)Provide a transcript of what happen.docx
The Assignment (2–4 pages)Provide a transcript of what happen.docx
 
The articles about the 2011 horn of Africa famine note several dif.docx
The articles about the 2011 horn of Africa famine note several dif.docxThe articles about the 2011 horn of Africa famine note several dif.docx
The articles about the 2011 horn of Africa famine note several dif.docx
 
The Assignment (2–4 pages)Discuss something important you lea.docx
The Assignment (2–4 pages)Discuss something important you lea.docxThe Assignment (2–4 pages)Discuss something important you lea.docx
The Assignment (2–4 pages)Discuss something important you lea.docx
 
The Assignment (2–3 pages)Your submission should include the.docx
The Assignment (2–3 pages)Your submission should include the.docxThe Assignment (2–3 pages)Your submission should include the.docx
The Assignment (2–3 pages)Your submission should include the.docx
 
The assignment (2–3 pages)Explain the similarities and .docx
The assignment (2–3 pages)Explain the similarities and .docxThe assignment (2–3 pages)Explain the similarities and .docx
The assignment (2–3 pages)Explain the similarities and .docx
 
The assignment (2–3 pages)Identify the human services adminis.docx
The assignment (2–3 pages)Identify the human services adminis.docxThe assignment (2–3 pages)Identify the human services adminis.docx
The assignment (2–3 pages)Identify the human services adminis.docx
 
The Assignment (2–3 pages)Based on the program or policy ev.docx
The Assignment (2–3 pages)Based on the program or policy ev.docxThe Assignment (2–3 pages)Based on the program or policy ev.docx
The Assignment (2–3 pages)Based on the program or policy ev.docx
 
The Assignment (2–3 pages)Explain the effects of sexual tra.docx
The Assignment (2–3 pages)Explain the effects of sexual tra.docxThe Assignment (2–3 pages)Explain the effects of sexual tra.docx
The Assignment (2–3 pages)Explain the effects of sexual tra.docx
 
The article must be current to Law Enforcement or other Criminal.docx
The article must be current to Law Enforcement or other Criminal.docxThe article must be current to Law Enforcement or other Criminal.docx
The article must be current to Law Enforcement or other Criminal.docx
 
The assignment (1–2pages)Describe the diverse populatio.docx
The assignment (1–2pages)Describe the diverse populatio.docxThe assignment (1–2pages)Describe the diverse populatio.docx
The assignment (1–2pages)Describe the diverse populatio.docx
 

Recently uploaded

Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxsocialsciencegdgrohi
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxEyham Joco
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...M56BOOKSTORE PRODUCT/SERVICE
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...jaredbarbolino94
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitolTechU
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerunnathinaik
 

Recently uploaded (20)

Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptx
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptx
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developer
 

The assigment is overdue now. I will up the price I am willing to pa.docx

  • 1. The assigment is overdue now. I will up the price I am willing to pay to have it done. It must be completed by the latest on the 8th. However I would greatly preffer for it to be finished on the 7th. I will add $20 to the price if you can complete it by then. I need the files to run in Eclipse. Please upload them as such. See my file as an example. They must be coded in java. This is for a 200 level data structures class so please match that level accordingly. I need java Test cases and comments please. (see my example file) I have included part of the previous assigment so you can see what mine looks like and it also may have things you may need like map etc. Though I cannot guarantee all of it is working properly. (named example) ----- The Task Okay, we are finally going to finish off the Huffman application. Last week, we got to the point where we could build the tree and do some simple encoding and decoding. The problem with our technique is that we were converting text into Strings of 0s and 1s. Hopefully, the vast majority realized that this is the opposite of actual compression. Our goal was to reduce the number of bits required to encode a character. Instead, we blew it up, replacing one character with a whole String of them! Ouch. So, we are going to do some bit level work, and learn how to write binary data out to files and read it back in again. The second issue that we have is that once we have an encoded file, we don't have a good way to decode it without first having the
  • 2. original source file, which rather defeats the purpose of compressing the file in the first place. Thus, we need to store a copy of the tree in the coded file. Of course, we want to store the tree in a format we can read back out again, and also doesn't take up too much room... Background: Canonical form We would like our Huffman codes to be canonical . I gave you an algorithm for picking which character to add next to your Huffman tree that comes close to producing canonical codes, but, sadly, I have to admit it has a flaw. There is an edge case that it can never compensate for. So, we are going to have to do some more work to get it into the canonical form. The canonical form adds two rules to the way Huffman codes work. First, all codes of a given bit length have lexicographically consecutive values (i.e., not just in order, but immediately consecutive), in the same order as the symbols they represent, and second, shorter codes lexicographically precede longer ones. An example will make this a little clearer... Suppose we have some piece of text in which the characters A,B,C,and D appear, with the following frequencies [A:1, B:5, C:6, D:2]. We could put these into a Huffman tree and come out with the following codes: A 001 B 01 C 1 D 000 This is not in canonical form. The first rule is broken because A comes before D, but 000 should precede 001. The second rule is broken because C had a shorter code than B, but 01 precedes 1 lexicographically. Here is an alternate assignment of codes that
  • 3. does satisfy the rule: A 110 B 10 C 0 D 111 0 precedes 10, which precedes 11x, and 110 and 111 are lexicographically consecutive. The algorithm for deriving canonical codes is fairly straightforward, provided we start by knowing the lengths of the codes. The trick is to think of the codes as binary numbers. The first code, which is given to the lexicographically smallest symbol with the shortest code, is 0, padded out with 0s to be as long as the symbol's code. In our example, C has the shortest code (length 1), so its code is 0 (if C's code has been length three, the code would have been 000). We then increment the code (counting in binary), which will produce the lexicographically consecutive code. If the next symbol has a longer code, we pad the code with 0s to the right to match the code length (in other words, we perform a left shift or a multiply by 2). Thus, the next code would be 1, but B has a longer code length, so it gets the code 10. To move to A, we increment (11), and shift again to get 110. D has the same code length as A, so it gets 111. Why is this interesting? Well, it means that we can recover the entire tree starting only from knowledge about the length of the codes. So, when we want to store our tree in a file with our data, we just have to record the character followed by the length of its code. Cool, huh? Part one: Generate canonical codes [25 pts] We can keep all of the work that we did in the last assignment, but the tree that we produce is no longer the tree that we want to keep. Its sole purpose is to provide us with the initial code
  • 4. lengths for generating the canonical codes. Instead of traversing the tree and loading the reverse lookup into a map, you are going to traverse the tree and collect symbols and their code lengths, dumping them into a new priority queue as we go. I suggest tweaking your old wrapper class that held symbols and frequencies to be a more generic pairing of counts and symbols, so you can reuse it for symbols and code lengths (this is probably just some renaming to make it more general purpose). You will want to write a new Comparator that will return these items to you in order first by code length (shortest first) and then in lexicographic order (a to z). You should then write a new private method called buildTreeFromMap which takes in a PriorityQueue of your wrapper objects as an argument. In this method you will use the PriorityQueue to implement the above algorithm to build the Huffman tree (which the algorithm I provided just specifies the codes, you will want to build up into a tree that represents the given code words). The tree that results from this process is the one to save as an instance variable (for decode). Now is when you will build the Map that you need for encode (you should be able to reuse the code you had for building it before). The old buildTreeFromFile should obviously call buildTreeFromMap once it has built the code length map. Part two: File handling [40 pts] We can finally get to the actual application! The first step will be to encode the file. Start by making one additional tweak to buildFromFile that saves the File object in an instance variable. Write a new function called saveCompressedFile , which will take a single File
  • 5. object as an argument. This file will be the destination for the compressed file. This function will first write the tree representation to the destination file. Start by writing an integer that says how many character, code lengths pairs to expect (this tells the reader how many bytes of the file are consumed by the tree). Then write out each character followed by the length of its code. Following the tree, you can start writing the compressed data from the file. This works just like encode, walking character by character, except that you will want to write bits, rather than Strings holding 0s and 1s (we'll talk about this in class). You will then want to write the compliment to this. The difference here, however, is that we don't have the original source data to build the tree again. So I want you to write a second static factory method called newTreeFromCompressedFile . Like newTreeFromFile , this will create a new HuffmanTree object and then call a private instance method called buildFromCompressedFile , to which it passes the compressed file. This should read the tree description out of the file, dumping the symbols and code lengths into a priority queue as it reads. It should then call buildTreeFromMap to initialize the tree and the reverse lookup map. Finally, write a method called saveExpandedFile , which takes in a destination File and processes the original file, using the tree to decode the data. If you encounter errors in either compressing or decompressing with respect to unknown codes, throw a CharConversionException. A little help
  • 6. To help you get started, here is a skeleton of the HuffmanTree that includes som of the old functionality from the last homework: -- huffmanTree -- see attatched --- Java Tests needed The assignment info from the previous assignment is attatched. It explains how other things such as map are supposed to be built. Huffman tree skeleton is also attatched.