Embed presentation
Download to read offline

![{
Integer index = hash.get(x);
if (index == null)
return;
hash.remove(x);
int size = arr.size();
Integer last = arr.get(size-1);
Collections.swap(arr, index, size-1);
arr.remove(size-1);
hash.put(last, index);
}
int getRandom()
{
Random rand = new Random();
int index = rand.nextInt(arr.size());
return arr.get(index);
}
Integer search(int x)
{
return hash.get(x);
}
}
class Main
{
public static void main (String[] args)
{
Dynamic ds = new Dynamic();
ds.add(10);
ds.add(20);
ds.add(30);
ds.add(40);
System.out.println(ds.search(30));
ds.remove(20);
ds.add(50);
System.out.println(ds.search(50));
System.out.println(ds.getRandom());
}
}](https://image.slidesharecdn.com/usingjava-codeadynamiclinearquotienthashingdatastructurethat-230204014145-152ddcbd/85/Using-Java-code-a-dynamic-Linear-Quotient-Hashing-data-structure-that-docx-2-320.jpg)

The document provides a Java implementation of a dynamic linear quotient hashing data structure. It includes methods for basic operations such as fetching, deleting, updating, and inserting elements, while also tracking performance metrics like search length, loading factor, pseudo loading factor, and density. The code illustrates the functionality through the main method, demonstrating the addition and removal of elements from the data structure.

![{
Integer index = hash.get(x);
if (index == null)
return;
hash.remove(x);
int size = arr.size();
Integer last = arr.get(size-1);
Collections.swap(arr, index, size-1);
arr.remove(size-1);
hash.put(last, index);
}
int getRandom()
{
Random rand = new Random();
int index = rand.nextInt(arr.size());
return arr.get(index);
}
Integer search(int x)
{
return hash.get(x);
}
}
class Main
{
public static void main (String[] args)
{
Dynamic ds = new Dynamic();
ds.add(10);
ds.add(20);
ds.add(30);
ds.add(40);
System.out.println(ds.search(30));
ds.remove(20);
ds.add(50);
System.out.println(ds.search(50));
System.out.println(ds.getRandom());
}
}](https://image.slidesharecdn.com/usingjava-codeadynamiclinearquotienthashingdatastructurethat-230204014145-152ddcbd/85/Using-Java-code-a-dynamic-Linear-Quotient-Hashing-data-structure-that-docx-2-320.jpg)
