Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8485429
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T20:38:36+00:00 2026-06-10T20:38:36+00:00

I have an assignment that I am working on, and I can’t get a

  • 0

I have an assignment that I am working on, and I can’t get a hold of the professor to get clarity on something. The idea is that we are writing an anagram solver, using a given set of words, that we store in 3 different dictionary classes: Linear, Binary, and Hash.

So we read in the words from a textfile, and for the first 2 dictionary objects(linear and binary), we store the words as an ArrayList…easy enough.

But for the HashDictionary, he want’s us to store the words in a HashTable. I’m just not sure what the values are going to be for the HashTable, or why you would do that. The instructions say we store the words in a Hashtable for quick retrieval, but I just don’t get what the point of that is. Makes sense to store words in an arraylist, but I’m just not sure of how key/value pairing helps with a dictionary.

Maybe i’m not giving enough details, but I figured maybe someone would have seen something like this and its obvious to them.

Each of our classes has a contains method, that returns a boolean representing whether or not a word passed in is in the dictionary, so the linear does a linear search of the arraylist, the binary does a binary search of the arraylist, and I’m not sure about the hash….

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T20:38:38+00:00Added an answer on June 10, 2026 at 8:38 pm

    The difference is speed. Both methods work, but the hash table is fast.

    When you use an ArrayList, or any sort of List, to find an element, you must inspect each list item, one by one, until you find the desired word. If the word isn’t there, you’ve looped through the entire list.

    When you use a HashTable, you perform some “magic” on the word you are looking up known as calculating the word’s hash. Using that hash value, instead of looping through a list of values, you can immediately deduce where to find your word – or, if your word doesn’t exist in the hash, that your word isn’t there.

    I’ve oversimplified here, but that’s the general idea. You can find another question here with a variety of explanations on how a hash table works.

    Here is a small code snippet utilizing a HashMap.

    // We will map our words to their definitions; word is the key, definition is the value
    Map<String, String> dictionary = new HashMap<String, String>();
    map.put("hello","A common salutation");
    map.put("chicken","A delightful vessel for protein");
    
    // Later ...
    map.get("chicken"); // Returns "A delightful vessel for protein"; 
    

    The problem you describe asks that you use a HashMap as the basis for a dictionary that fulfills three requirements:

    • Adding a word to the dictionary
    • Removing a word from the dictionary
    • Checking if a word is in the dictionary

    It seems counter-intuitive to use a map, which stores a key and a value, since all you really want to is store just a key (or just a value). However, as I described above, a HashMap makes it extremely quick to find the value associated with a key. Similarly, it makes it extremely quick to see if the HashMap knows about a key at all. We can leverage this quality by storing each of the dictionary words as a key in the HashMap, and associating it with a garbage value (since we don’t care about it), such as null.

    You can see how to fulfill the three requirements, as follows.

    Map<String, Object> map = new HashMap<String, Object>();
    // Add a word
    map.put('word', null);
    
    // Remove a word
    map.remove('word');
    
    // Check for the presence of a word
    map.containsKey('word');
    

    I don’t want to overload you with information, but the requirements we have here align with a data structure known as a Set. In Java, a commonly used Set is the HashSet, which is almost exactly what you are implementing with this bit of your homework assignment. (In fact, if this weren’t a homework assignment explicitly instructing you to use a HashMap, I’d recommend you instead use a HashSet.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on a short java assignment that I have been set. The
I am working on an assignment with polymorphism and have followed online tutorials that
I'm working on an assignment that is telling me to assume that I have
I have an assignment that wants me to write an ternary search algorithm and
I have an assignment that simulates a dice game. As part of the program,
I have quite a large XSL document for an assignment that does a number
My assignment requires that I have an ER diagram that shows the dependencies between
For a school assignment I have to create a C++ program that will create
For an assignment in college, we have to make a script in Perl that
I am working on a C++ assignment for class that wants me to overload

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.