Skip to content

Kahnurd/Algorithms-Lab11

Repository files navigation

To run the code, run main in Huffingman.java then some prompts will come up in the console to ask for inputs

Task 1

Encodings : a: 10 b: 00 c: 111 d: 110 e: 011 f: 010

Task 2

In huffingman.java

Task 3

English.txt is the input englishEncoding.txt is the output (Letters with corresponding binary)

Task 4

I stole text from: https://learnenglishteens.britishcouncil.org/blogs/books/reading-fun-english

Orignial Text:

When I was at primary school, summers holidays meant football with friends, countless PlayStation1 (wow I feel old...) sessions and more importantly no homework. Yet admittedly there was one thing I always feared…the book project. For those of you that don’t know what it is, it is a scheme to encourage young people to read, which involves finishing five books during the two months of holidays. Although it wasn’t obligatory, my sister was an avid reader and keen participator, so I was somewhat forced into it to by my parents. At the time of choosing the books I had a rather basic checklist; pictures, very few pages and a large font. Nevertheless, receiving the certificate on completion, which would stand proudly on the table for the first two weeks of term, helped motivate me to start enjoy reading. Now I can safely say that it is a hobby of mine. So, if you also enjoy reading, why not use a hobby to help you learn English?

Okay, so firstly it’s important to choose a book which is the right level for you. This is extremely important. If you are just starting out with English, don’t try to read a 600 page classic novel! Not only may you fall into a coma through boredom but something too difficult will make you feel negative about your own level. The more you read at your level the better you will get, and one day, you will be ready for something more challenging!

Secondly, although having a dictionary at hand to look up words which appear a lot is useful, I would recommend trying not to translate word by word. You will soon get bored of looking through the dictionary and you may end up wanting to throw it out the window! This is more serious if you’re using an online dictionary…Go into the process accepting that you are not going to understand every word. It will often be the case that the words you don’t recognise will be uncommon words that you will never use in your life…hence not as important to learn! Look up the words that you think are important to understand the text or follow the story. This is important, so as to stop the process from becoming boring. If you do learn a new word, as with any new vocabulary, try to use it in a sentence. This will make it more likely that you will remember it in the future.

Finally, perseverance is key. Although at first it may seem that reading has become a chore, you will soon get into the story and you will end up not being able to put the book down! The feeling of finishing a book in a different language is very satisfying. If you finish one, however, don’t stop there! The more you read the more vocabulary you will learn and the more you will start to become familiar with sentence structures and common phrases.

I hope the next time you pick up a book it will be in English!

PS. Picking it up and putting it back on the shelf doesn’t count…

Encoded text :

111000001101110101100111000111110011111000111001100011000100111111000101101 1001010110011110111011110110010101001001010010111000100100111101111011100 10111111110110110010100101111111010000001011101110100010110011111110111101 111000110000000110010110001100011101010111100101011110101010101000011101 01110011001111001111011111101101100100011110001100110110101110001101111000 1100001010110111110111011110110111100101110011001110011011010100111111010 1011101001110110000111100010011110011101100000011111010000111011011011010 11010011110101001011111000110110000100011101101011000111110111010011100 00000001110111111011011010000011011100001111100011111001110110100110000011 1100101000100110011111110111100011111011011001001010111111100001110111000 00110111011001101110101000111110011000110101000100011010110000010111011000 000001111011001011110100101101101110101010000001111110001011111011010000 010001110101101111000111000001111110001100000110010011100000110010011111 10010101100110110100101100011010111010010111101010101000111100100011101101 11010101010100010011100101111011110011110101100011011000011111110111111000 00111100010110011110010100100001101111010100000111001001011100101011001001 00111100101000100001011100010000011101100110111010100011100110111010101000 1100101000100000001101100011100011010100111011010000001110011101001010011 1101111011100101111111101101100111111110100000111101010100010000111100000 11100011111001101000011011011001110111000010011110001101100010110101001 1011011001110010010000111000111000111110011111101011110100001100101111000 011111110111011100011111010101110100011011011101011100111111000000110001011 1100111001111100011011000100111011100111000111110011001110101001011111000 001111110000010111011000010110111011111001010000110111000000001101101100 10110101001101101111001111110000111010000100111110000000011011000110001001 01111010010101011001111011101100111001010001000000011011101100110111010100011 100111000011111110111111110001111000001101110001011001111100111000101101011 001101101011010001111101110010010001110011100010110000101010000111001010000 01110001011010010101111100011100111110010001110011111101010111111111101 11111000001000110010111011010000101001101000001110000000011011111010111001 10011000011010110111100010000110010100010000000110110101101110000001100 00101110001011111100001111011010010111101010011110011110101100011001101 101011100000111100010110011111000110101010111011011110010001111101010111 11100110001101010101011111101101101110110100000011011000111110110011101 01100101110110000000011011001011100100010010000001110001101111000011011 0100011100111010010100001110000100100110111110111100101110111010011101000 110001000011110000110100101100011011001000111110000000111010010001001101 10110110000111111101111100101000100101011011110001100010111111101010011111 00101011111011011011001111110110100000111111000110000011001001111100111101 101100101100101101110100101010011100101001110011101110000101101101110101010 11111110110011101011101001000100110110110110000111111101111100101000100 111000001110110110101101000010101001011111100111101101100101100101101000 11010011011111011110011011011101010101110101111111000101001110100010011101 110010010011110101000111111101101100111010010111001000100100011101101101 110000010011100010011110011101100000011111010000000110101011001111011101 1001011111110110011011101010001111100000111100010110011110010010000011011 1000110000100001100011101011010000011111010010111011000101101110101010000 0011110010011100100101101000101000010000110100101111101101101110001001111001 11011000000111110100001100001011011011101010101111100001101000100010101001 000100100011111000000110010100010011010101000011100011000000011011101000100 1110111001001001110111110110100000001000101101000110110000111111101111111 11100111110010001101011111011111100110011100010111010110101000001111101 10101101000110110101110110110101001111110110110110111010101000101111111101 11101110010100001101111101011110101001111100000111000110101010001000011 101100110110000111011111010100110110001010000100111010100101100000111100 10100010000011011101101111100001010010111000101101010111010001110001100 111011110101001111101000110111011011101010100010101101111101101001100100 11110001100010000011111110110011010101000010110111010101010001101111000 10101110101101000001111101000001101101001110110000111011011101010101000 0111111101111111000101101110101010100011101011010000011111010000011011101100 011000000011100010110111010101011100011001110111101001000110001111101010111 11011010011101111111101101101101110101010111000110011101111011011000111000 011111110111101101001011101100010011101010010110000011110010100010001001 11011000011010110011111111101111010111010001001100101000100100101101011 110110101011111101101101111111101000001111010101000100001100111111010000 11001010001001111101111100010110001100110110101111100010110111110000011 11111010101110001101111011101110101000110101011100111100011011000101111001 11100000111100010110011111111100111100101111111000111111101110100011001001 010101001011001010101011101110011100011010101011101101111000011010111101 0100101001011101010111000100010110111001010001001010110100000011010001000 111110101001111011111000011111000110110001011110110010110111100011011000 1011110110111010101011100011001110111101100111011101101000100011000101100 1101100001110111110100101111011101110101000111100101000100000001110001101 01010001000011000001101110111110001011000110011011010111110001011011111 101010111101101110101010010011111101101011101010111010101110011110001111 10100001100101000100000110100000111000110111100011000001101010100000000011 01111100011001010101111101111000000001111001001110010010100111011000011 100101110001100110101010100111000010110110111010101010000110101010011100 10100010011111010110110101110111001010011101111100010110001100110110101111 10001011010010011011100101000011010000011011111001100011010101101110011001 111101011010110111110010001100101000100000001111110001011011101010101111 100001110101101000001001101110010100010000011010101010101011101110001001 00011111010101110110100000111000101101111000110110001011111000001110001100 11101111011101001010000111010101100011000001101101011111110010110000011 11110000000011011111000110110001011110011011011101010101011111011010000 10000110101111010010010101100100101111100011001110111101101100011010101010 01011110101001010011101101011100011011000101111001000001111110001011011101 01010111000110011101111011010011010000011100001010100101111001010101101 110101010100011101110000101011001101110100101101110101101000111110011100 0100111100111011000000111110100000001101111010111111100010101110111011101 01000110101011100100000110111110001101100010111100100000111111000101101 110101010000001111001010010001111111000011110001001111001110110000001111 10100000001101010101010101110111000100100011111010101110000011011000011 01000101000011011000001011101111011110111011110000000011011100100011011000 10110100000111100100111001001110001001111001110110000001111101000010011101 111110010001101100100011011110010000011011111001100011010101101110011001 001011000110101001101100011010111101010011100101000100101100110110001100 1010001001100001011011011101010101011111011110101111111000101011111010011 11100011100011011000101111111100111100011000000011111110101011011010011 11100001000011010101111111011000101011101111110001011010001000101101000 11010101010010111100000110010101111100101110100000111010010110110000011 110010011110001100111011110101001111101000110111100000010011101100001111101 11000100011011111011011010000011111100010110111010101011100011001110111101 10000110100101101001101100011100011000001100101000000110110010101010000 01010100001100101110010101111111011110110110111100101110001001011010000 011100011111010010110111100100101000110111011011111111010000011110101010 0010000111111000001011100100010010001100000010011111101101100101101101001 0000011111100010000111111101111100101000100001111111001101100011010111101 01001011111101011001111011000011101101110101010111000110011101111011001 1101110110100010001100011001010000110100000110111001000110110001011011111 10101011110110111010101011100011001110111101011101010111010101110011010 11010001011000111100101000100111110110011101011000110111100101010000000 0011011101100110111010100011101111101111000101000000110110010101101111101 11001010001001101001010010111001010110010010011110010100010011111011001101 110101000111100101011111011111000010100101011100001110100001110111111010 0010001010111100100011110010010100000111000101101100111110001100100100101 101101110010100010011000010110110111010101000101110010101100100100111101 1010011001111011110000110100000111000101111101101000010010001101111001000 00110111000011000001101101001110110000111011011101010101000011111110111 000001101101001110110000110100001101010111111101100010101110111111000101101 10110111010101011100011001110111101111010111111100010101111101010111000 0011011010011101100001110110111010101011100011001110111101100100011111000 00000011011011000110101111010100101100101111101001110011101110011111000 111000110000000111001011101000001110100101101110010001000010100101100001010 1000011100111111010101110101111010100101001110110101110010011100011111001 011100111000011110111100101100000110111010011010001010000000110001001011 1011011101010101110011100010110100011010101110011111101100110111010100011 1100000111000110011101111011011000111100101001110100010011101110010010011 11100110011110011100010110100011110010100010011000000101011100111111010 101111110010101000000011001010001001100000101100111101011010001111011010 000001101110010011011111010010110111110101110011010000010111101010101010 000

Decoded text :

wheniwasatprimaryschoolsummersholidaysmeantfootballwithfriendscountle ssplaystationwowifeeloldsessionsandmoreimportantlynohomeworkyetadmitt edlytherewasonethingialwaysfearedthebookprojectforthoseofyouthatdontk nowwhatitisitisaschemetoencourageyoungpeopletoreadwhichinvolvesfinish ingfivebooksduringthetwomonthsofholidaysalthoughitwasntobligatorymysi sterwasanavidreaderandkeenparticipatorsoiwassomewhatforcedintoittobym yparentsatthetimeofchoosingthebooksihadaratherbasicchecklistpicturesv eryfewpagesandalargefontneverthelessreceivingthecertificateoncompleti onwhichwouldstandproudlyonthetableforthefirsttwoweeksoftermhelpedmoti vatemetostartenjoyreadingnowicansafelysaythatitisahobbyofminesoifyoua lsoenjoyreadingwhynotuseahobbytohelpyoulearnenglishokaysofirstlyitsim portanttochooseabookwhichistherightlevelforyouthisisextremelyimportan tifyouarejuststartingoutwithenglishdonttrytoreadapageclassicnovelnoto nlymayyoufallintoacomathroughboredombutsomethingtoodifficultwillmakey oufeelnegativeaboutyourownlevelthemoreyoureadatyourlevelthebetteryouw illgetandonedayyouwillbereadyforsomethingmorechallengingsecondlyaltho ughhavingadictionaryathandtolookupwordswhichappearalotisusefuliwouldr ecommendtryingnottotranslatewordbywordyouwillsoongetboredoflookingthr oughthedictionaryandyoumayendupwantingtothrowitoutthewindowthisismore seriousifyoureusinganonlinedictionarygointotheprocessacceptingthatyou arenotgoingtounderstandeveryworditwilloftenbethecasethatthewordsyoudo ntrecognisewillbeuncommonwordsthatyouwillneveruseinyourlifehencenotas importanttolearnlookupthewordsthatyouthinkareimportanttounderstandthe textorfollowthestorythisisimportantsoastostoptheprocessfrombecomingbo ringifyoudolearnanewwordaswithanynewvocabularytrytouseitinasentenceth iswillmakeitmorelikelythatyouwillrememberitinthefuturefinallypersever anceiskeyalthoughatfirstitmayseemthatreadinghasbecomeachoreyouwillsoo ngetintothestoryandyouwillendupnotbeingabletoputthebookdownthefeeling offinishingabookinadifferentlanguageisverysatisfyingifyoufinishonehow everdontstoptherethemoreyoureadthemorevocabularyyouwilllearnandthemor eyouwillstarttobecomefamiliarwithsentencestructuresandcommonphrasesih opethenexttimeyoupickupabookitwillbeinenglishpspickingitupandputtingi tbackontheshelfdoesntcount

Task 6

Average from task 5: 4.217600000000001 From task 4: 9527/2266 = 4.2043248014121800529567519858782

Smaller example:

Plaintext: The experimental results we achieved are close to the results we wished to achieve. We were told that all 3 compounds were within 20-50% composition within the unknown mixture and none of our calculated percent compositions were outside of that margin. The percent composition of our KCl was 45.05%, a little larger than desired; the percent of our SiO2 was 29.54% very close to what was desired; the percent of our CaCO3 was 23.14%, a little smaller than desired. Our total percent composition added up to roughly 97.73%, meaning that we had an error of 2.27%, not as bad as it could be but something we strive on getting closer to perfection. Possible sources of error include not heating the flask with KCl fully to evaporation, resulting in a larger percent composition of KCl than desired. In the guide on how to properly evaporate, we are told to turn down the heat slightly just before all liquid is evaporated and to remove the flask before splattering our melting of the material occurs.

Encryption: 00000110110110100010101110010111000110001001011101000011111110110000111001 01010111010001001111000011111101011001111000110100000111011111111000011 010111110111011001011000110100000110111000011100101010111010001001111000 01111100011001001001101110111000110111110101100111100011010000011111000 0111110000111000011000110111101101110000011111100011111110111101010111101 01001111001110101010101010111100111100001110000111110001100000001111001010 010111101010011110011101100111000001100110110101110001100000001111001010 00000110110101010100100011101011011110001010010011100010001010000010101000 011111110101011110101101101001111010010111010101010000101111111110101011 0101011101111100001110111111001011100001011011101000001011110101001111001 110110011100000110011011010100111100001110000111101010100001001110010111 01111010010100000111111000010011111100000100110010100000011011111001011 100001011011101000001011110101001111001110110011100000110011011010110100101 11010101010000100011010111110111100011111001111111101110000000011101011 11101111110000010001110000000011111110101011101110011100100001110111000 001101111100101110000101101110100001101001011101010101000100111001101111000 111110010100000111000101101010111110111011001011000110111100000111111000 1110001111100110111011100111001000011101110000011011111001011100001011011 10100001101001011101010101000010111111010111101111000111110011111111011100 00000011101011100101001111111101111010111000000001111111010101110111001 1100100001110111110101010100000011010001111111011110010111000010110111010 000010111101010011110011101100111000001100110110101111101111011101110111 01010111001000110110001101010100010000111110110110101001011111110101100 101000100000001111110001110000110011111110111111110100111000100011011000 110100101101011010001111100110110011111011111111001110000001011110101010 111011011110110001110110001010000100111010100101100000111100101000100111000 011100100010001100010000011110110100010001100000011001010001000101111101 1101100101110000001101111001011100000101011010110001100110110101110011101 10011001110010110011101011100111010101010000101101110011101001010111000 100011011000110010100101111101010101011101110101101000001101111110001100 1010001000000011011001011110111111001010001111100011000000011010001101011 111010010101010111011110110110100011010110100001111111001110110001111000 11001101101010000111001010101110100011001010001001100101011111110111111000 001000111000111001011100001011011101000001011110101001111001110110011100 000110011011010110100101010001101011111010000011111110101011101110011100 10000111011111001010000001101100100010101100101110111101101000111101111000 000110111100110001101111001011100011101101101011010000111111100111011000 111100001111100001111111000011000110111101101110001101000010101000101010111 11011110001010000001101100110111111000100111101110000100001100011101101101 010001000101010010001011000110010111011000011111111101111011110111000100010110 010101100101111100100101101000011111110011101100011110000111011111111010 101110001101100001101001110101000001100000110110010111101111110010100011 10110001100101110110000111001111001111011111000000011100011001010001001101 010101000010010111110100011001010001001101001010000011011010011111000011 10001100111111101110101011010110101010001001

Decryption: theexperimentalresultsweachievedareclosetotheresultswewishedtoachieve weweretoldthatallcompoundswerewithincompositionwithintheunknownmixtur eandnoneofourcalculatedpercentcompositionswereoutsideofthatmarginthep ercentcompositionofourkclwasalittlelargerthandesiredthepercentofoursi owasveryclosetowhatwasdesiredthepercentofourcacowasalittlesmallerthan desiredourtotalpercentcompositionaddeduptoroughlymeaningthatwehadaner rorofnotasbadasitcouldbebutsomethingwestriveongettingclosertoperfecti onpossiblesourcesoferrorincludenotheatingtheflaskwithkclfullytoevapor ationresultinginalargerpercentcompositionofkclthandesiredintheguideon howtoproperlyevaporatewearetoldtoturndowntheheatslightlyjustbeforeall liquidisevaporatedandtoremovetheflaskbeforesplatteringourmeltingofthe materialoccurs

Average from task 5: 4.217600000000001 Average from this test: 3288/784 = 4.193877551020408163265306122449

Even smaller example:

Plaintext: The potassium iodide disassociates into its ions in the solution, so we have aqueous potassium (K+) and iodide (I-).

Encryption: 00000110111110011101000111110011001110001010010011100110110111110010111 01110111110010011111100110011101010111100111100001110011100101000011011100 00010011100110110101001110010100000011011100111011110101010000110011011010 100111011110000110011111101000001111110100010110010100111101010101001111001 110100011111001100111000101001001010001111111010101111100110110111110010111 0111100

Decryption:

thepotassiumiodidedisassociatesintoitsionsinthesolutionsowehaveaqueou spotassiumkandiodidei

Average from task 5: 4.217600000000001 Average from this test: 3288/784 = 4.1868131868131868131868131868132

Sample with a lot of Z's

Plaintext: Zorro, who's real name is Zachory, Zigzagged around a zinc zookeeper holding a zillion zebrafish

Encryption: 0100010111110110001000110111100000111101100110000111111111011010111101001 01111001001010001011111110101100111101100010110101000101111100001000100010111 111100100001000111011111111000110101010101010111111101000101111100101001011 010001011111011101010001101101111100101110000011110111101101111100101000100 111101000101111100111011110111001101101001000101110111011001000111100101 110010010011

Decryption: zorrowhosrealnameiszachoryzigzaggedaroundazinczookeeperholdingazillio nzebrafish

Average from task 5: 4.217600000000001 Average from this test: 389/80 = 4.8625

Conclusion

As far as I can tell, the theoretical average seems to be pretty accurate to the practical average. Even with different sample sizes, it stays fairly accurate. However, when looking at a sentence with a lot of Z's (The most uncommon letter) the average did change a little bit. None of the tests show any drastic change in the average lengths, so the theoretical average is fairly accurate to practical uses.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages