Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

If someone do completely correct, i will give %100 thumbs up and DON'T COPY AND PASTE MY CODE!! Key and Value are the elements in

If someone do completely correct, i will give %100 thumbs up and DON'T COPY AND PASTE MY CODE!!

Key and Value are the elements in the Hash Table, it is the basic topic in the HASH TABLE

image text in transcribed

public class HashST { private int N; // number of key-value pairs in the table private int M; // size of linear-probing table private Key[] keys; // the keys private Value[] vals; // the values public HashST() { this(16); } public HashST(int M) { this.M = M; keys = (Key[]) new Object[M]; vals = (Value[]) new Object[M]; } private void resize(int cap) { HashST t; t = new HashST(cap); for (int i = 0; i = M / 2) { resize(2 * M);} // double M (see text) int i; //uses empty spaces (marked by null) to terminate clusters of keys. If for (i = hash(key); keys[i] != null; i = (i + 1) % M) { if (keys[i].equals(key)) { vals[i] = val; return; } } keys[i] = key; vals[i] = val; N++; } public Value get(Key key) { for (int i = hash(key); keys[i] != null; i = (i + 1) % M) { if (keys[i].equals(key)) { return vals[i]; } } return null; } public void delete(Key key) { if (get(key) == null) {return;} int i = hash(key); while (!key.equals(keys[i])) { i = (i + 1) % M; } keys[i] = null; vals[i] = null; i = (i + 1) % M; while (keys[i] != null) { Key keyToRedo = keys[i]; Value valToRedo = vals[i]; keys[i] = null; vals[i] = null; N--; put(keyToRedo, valToRedo); i = (i + 1) % M; } N--; if (N > 0 && N == M / 8) resize(M / 2); } } 
public class SparseVector { // Implement Sparse Vector Class as an Hash Table // This provides constant time search and insertion private HashST st; // 1- constructor // 2- size // 3- put // 4- get public double dot(double[] that) { double sum = 0.0; // 5- USE: Object[] keys = st.keys(); // USE: get((int)keys[i]); return sum; } public static void show(double[] that){ for (int i = 0; i   Data Structures and Algorithms Hash Table Implementation of Sparse Vectors You are given the code for a linear probing hash table in HashST.java. Use this code to represent a sparse vector, where keys of HashST correspond to index of a sparse vector. The code for SparseVector is also given to you, but its constructor, size, put, get methods are missing. Also fill the missing parts of the dot-product method. 1. In the main method, create a sparse matrix as an array of SparseVector's. This sparse vector will have the same values as this matrix, 8 4 0 0 0 0 0 A-0 0 0 0 0 0 0 2. Write an array of type double r0.1 0.1 0.1 0.1 0. 0.25 0.25 3. Calulate and show the result of

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Pro Database Migration To Azure Data Modernization For The Enterprise

Authors: Kevin Kline, Denis McDowell, Dustin Dorsey, Matt Gordon

1st Edition

1484282299, 978-1484282298

More Books

Students also viewed these Databases questions