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 6738471
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:22:22+00:00 2026-05-26T11:22:22+00:00

So, here is the actual question (it’s for a homework): A hashtable is data

  • 0

So, here is the actual question (it’s for a homework):

A hashtable is data structure that allows access and manipulation of the date at constant time (O(1)). The hashtable array must be initialized to null during the creation of the hashtable in order to identify the empty cells. In most cases, the time penalty is enormous especially considering that most cells will never be read. We ask of you that you implement a hashtable that bypasses this problem at the price of a heavier insertion, but still at constant time. For the purpose of this homework and to simplify your work, we suppose that you can’t delete elements in this hashtable.

In the archive of this homework you will find the interface of an hashtable that you need to fill. You can use the function hashcode() from java as a hash function. You will have to use the Vector data structure from Java in order to bypass the initialization and you have to find by yourself how to do so. You can only insert elements at the end of the vector so that the complexity is still O(1).

Here are some facts to consider:

  • In a hashtable containing integers, the table contains numeric values (but they don’t make any sense).

  • In a stack, you cannot access elements over the highest element, but you know for sure that all the values are valid. Furthermore, you know the index of the highest element.

Use those facts to bypass the initialization of the hashtable. The table must use linear probing to resolve collisions.

Also, here is the interface that I need to implement for this homework:

public interface NoInitHashTable<E>
{
    public void insert(E e);
    public boolean contains(E e);

    public void rehash();
    public int nextPrime(int n);
    public boolean isPrime(int n);
}

I have already implemented nextPrime and isPrime (I don’t think they are different from a normal hashtable). The three other I need to figure out.

I thought a lot about it and discussed it with my teammate but I really can’t find anything. I only need to know the basic principle of how to implement it, I can handle the coding.

tl;dr I need to implement an array hashtable that works without initializing the array to null at the start. The insertion must be done in constant time. I only need to know the basic principle of how to do that.

  • 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-05-26T11:22:22+00:00Added an answer on May 26, 2026 at 11:22 am

    I think I have seen this in a book as exercise with answer at the back, but I can’t remember which book or where. It is generally relevant to the question of why we usually concentrate on the time a program takes rather than the space – a program that runs efficiently in time shouldn’t need huge amounts of space.

    Here is some pseudo-code that checks if a cell in the hash table is valid. I will leave the job of altering the data structures it defines to make another cell in the hash table valid as a remaining exercise for the reader.

    // each cell here is for a cell at the same offset in the
    // hash table
    int numValidWhenFirstSetValid[SIZE];
    int numValidSoFar = 0; // initialise only this
    // Only cells 0..numValidSoFar-1 here are valid.
    int validOffsetsInOrderSeen[SIZE];
    
    boolean isValid(int offsetInArray)
    {
      int supposedWhenFirstValid =
       numValidWhenFirstSetValid[offsetInArray]
      if supposedWhenFirstValid >= numValidSoFar)
      {
        return false;
      }
      if supposedWhenFirstValid < 0)
      {
        return false;
      }
      if (validOffsetsInOrderSeen[supposedWhenFirstValid] !=
        offsetInArray)
      {
        return false;
     }
     return true;
    }
    

    Edit – this is exercise 24 in section 2.2.6 of Knuth Vol 1. The provided answer references exercise 2.12 of “The Design And Analysis of Computer Programs” by Aho, Hopcraft, and Ullman. You can avoid any accusation of plaigarism in your answer by referencing the source of the question you were asked 🙂

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

Sidebar

Related Questions

The actual question is a little more complex than that, so here goes. I
Before I get to my question/problem, here is the basic structure of my application:
I have this homework question: Assume a Database table has 0 records at time
Im making an asynchronous call from a class to another. Here is my actual
I know I'm missing something here. In the XSLT transformation below, the actual result
Here's a basic regex technique that I've never managed to remember. Let's say I'm
Here is the issue I am having: I have a large query that needs
Here's my scenario - I have an SSIS job that depends on another prior
Here's a coding problem for those that like this kind of thing. Let's see
Here is the scenario: I'm writing an app that will watch for any changes

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.