| 
  • If you are citizen of an European Union member nation, you may not use this service unless you are at least 16 years old.

  • You already know Dokkio is an AI-powered assistant to organize & manage your digital files & messages. Very soon, Dokkio will support Outlook as well as One Drive. Check it out today!

View
 

Module 8 -  Hashing Part 1

Page history last edited by Dr. Ron Eaglin 7 years, 11 months ago

  Module 8 -  Hashing (and compression) Part 1

 

The topic of hashing is quite easy Topic - Hashing Techniques - if you have done anything as simple as putting socks in one drawer and underwear in another, well you've exercised the principle of hashing. Put similar items in bins so they can be found more easily.

 

Assignment

 

If you look at some compression techniques (such as LZW Compression https://en.wikipedia.org/wiki/Lempel%E2%80%93Ziv%E2%80%93Welch ) they make use of the concept of hashing techniques to compress files. We are going to do something similar. Consider the phrase

 

To be or not to be, that is the question.

 

Even though it does not make much sense to do this as the phrase is short. We are going to create bins for each word, and record the position of the instances of the words in the proper bins. So write a program that first has a series of bins

 

to

be

or

not

etc....

 

Because the word to occurs in positions 1 and 5, the bin for the word to will contain 1 and 5

 

to: 1 5

be: 2 6

or: 3

 

Write an program that will take the phrase, create bins for each word, and then record the instance position of each word in the bin. It will then output each bin (word) and the locations of the word in the phrase. So if the input was;

 

I want what I want and I know what I want.

 

The output would be;

 

I: 1 4 7 10

want: 2 5 11

what: 3 9

and: 6

know: 8

 

I have created a JSFiddle Shell to get you started that is here - http://jsfiddle.net/reaglin/rm96Luws/ 

 

Assignment Grading - I am going to look at your code to see if you constructed a decent Hash with bins to perform this. You can use an array, Lists, or Queues or combinations of these to hold the information. For example you could keep the bins in an array and each bin could be a list. A working system is worth 5 points and a design that uses the structures you have used to date makes it worth another 5. 

 

Quiz ( Quiz Submission Instructions )

 

Do quiz http://geeksquiz.com/data-structure/hash/ 

 

Previous: Module 7 - Sorting Part 1

Next: Module 9 - Indexes

 

Comments (0)

You don't have permission to comment on this page.