首页 > 其他分享 >CRICOS Data Structures and AlgorithmsHash Tables

CRICOS Data Structures and AlgorithmsHash Tables

时间:2024-10-08 14:00:19浏览次数:8  
标签:Tables hash Data will probing table Structures your

Data Structures and AlgorithmsHash Tables

Page 1 of 3CRICOS Provide Code: 00301J 

Note:

  • hashArray stores the key, value and state (used, free, or previously-used)of every hashEntry.We must store both the key and value since we need to check hashArrayto tell if there is a collision and we should keep probing until we find theright key.
  • put(), hasKey() and get() must take the passed-in key and call hash() toconvert the key into an integer. This integer is then used as the index forhashArray.Java Students: If you use a private inner class for DSAHashEntry, thenput(DSAHashEntry will need to be private, otherwise it will be public.
  • There are many hash functions in existence, but all hash functions mustbe repeatable (i.e., the same key will always give the same index). A goodhash function is fast and will distribute keys evenly inside hashArray.

Hash Tables

Updated: 21st July, 2023

Aims

  • To implement a hash table.
  • To make the above hash table automatically resize.
  • To save the hash table and reload it from a file.

Before the Practical

  • Read this practical sheet fully before starting.

Activities

  1. Hash Table ImplementationFollowing the lecture slides as a guide, Create DSAHashTable class and a companionlass called DSAHashEntry to implement a hash table with a simple hash function. Useinear probing first since it’s easier to think about, then convert to double-hashing.Assume the keys arestrings and the values are Objects.Data Structures and AlgorithmsHash Tables

Page 2 of 3CRICOS Provide Code: 00301J

Note:

  • Of course, the latter depends on the distribution of the keys as well, so it’snot easy to say what a good hash function will be without knowing thekeys.For the purpose of this practical, just use one of the hash functions fromthe lecture notes.
  • Use linear probing or double-hashing to handle collisions when inserting.
  • hasKey(), get() and remove() will need to use the same approach sincethey also need to find the right item.t’s probably a good idea to try make a private find() method that doesthe probing for these three functions and returns the index to use. Use theDSAHashEntry state to tell you when to stop probing.
  • Be aware that remove() with probing methods adds the代 写Data Structures and AlgorithmsHash Tables  problem that itcan break probing unless additional measures are taken.In particular, say we added Key1, then Key2 which collides withKey1, so we linearly probe and add Key2 to thenext entry.If we remove Key1, later attempts to get Key2 will fail because Key2maps to where Key1 used to be.Since it is now null, probing will abort and imply that Key2 doesn’texist.The solution is to use the state filed in DSAHashEntry that trackswhether the entry has been used before or not.
  1. Resizing a Hash Table

Modify your DSAHashTable to allow it to resize. There are various ways to determinewhen to and how to resize a hash table.The simplest way to determine when is to set an upper and lower threshold valuefor the load factor. When the number of elements is outside of this, the put() or

remove() methods should call resize(size) automatically.

  • Remember, this will be computationally expensive (what is it it in Big-O?), so it isimportant not to set the threshold too low. Also, collisions occur more frequentlyat higher load factors, thus it is equally important to not set the threshold toohigh. Do some research to find "good" values.

A simple way to resize is to create a new array, then iterate over hashArray (ignoringunused and previously used slots) and re-hashing (using put().

  • To select a suitable size for the new array, you can either use a "look up" table ofsuitable primes or re-calculate a new prime after doubling/halving the previoussize.Test your resize functionality with a small hash table size, just so you know it will

work when you increase the size of the table.Data Structures and AlgorithmsHash TablesPage 3 of 3CRICOS Provide Code: 00301J

  1. File I/OTo truly test your hash table implementation, you will need a large dataset. Read inthe RandomNames7000.csv as input to insert values into your hash table. There are someduplicates in the file, so your program should beable to handle them.It is alsouseful to be able to save the hash table. The save order is not important,

o just iterate through the keys and values in the order they are stored in the hash

table and write it to a .csv.

Submission Deliverable

  • Your code are due 2 weeks from your current tutorial session.You will demonstrate your work to your tutors during that sessionIf you have completed the practical earlier, you can demonstrate your workduring the next session
  • You must submit your code and any test data that you have been using electronically via Blackboard under the Assessments section before your demonstration.Java students, please do not submit the *.class files

Marking Guide

Your submission will be marked as follows:

  • [6] Your DSAHashTable and DSAHashEntry are implemented correctly.
  • [4] Your hash function is well thought out and properly implemented.This means that it meets at least the first three criteria of a good hash function andyou can argue that it at least partially meets the last.
  • [5] Your hash table resizes as you put and remove hash entries.
  • [5] You can read in and save .csv files.

End of Worksheet

标签:Tables,hash,Data,will,probing,table,Structures,your
From: https://www.cnblogs.com/comp9313/p/18450901

相关文章

  • GUI图形界面 无代码开发 原理 - 属性标识链 | uiotos致敬amis、nodered、appsmith、co
    低代码饱受争议。也有例外:后端NodeRed,前端Amis。整体还是诟病为主:简单业务可以,复杂的是扯淡,不论前后端。这是一贯的认知。在GUI方面,UIOTOS发明的嵌套技术,为复杂前端的无代码开发,开辟了一条新的思路。往期文章:可视化拖拉拽?过时了!组态零代码,不能做复杂前端?嵌套原理一复杂交互......
  • 组态也能开发WEB前端 | uiotos致敬amis、nodered、appsmith、codewave、goview、datar
    WEB组态开发SCADA、HMI画面、大屏可视化,还比较常见。比如下面: UIOTOS组态示例那么常规WEB前端功能,组态能否一并做了呢?比如下面这种: UIOTOS前端示例答案是可以的!UIOTOS支持页面无限嵌套,能实现原型即应用。现在就以一个具体小示例介绍如何实现的。效果如下所示,初......
  • divide by zero encountered in log10 my_vmin=np.log10(data['PValue'].min())
     sm=plt.cm.ScalarMappable(cmap='viridis',norm=plt.Normalize(vmin=np.log10(data['PValue'].min()),vmax=np.log10(data['PValue'].max()))) C:\Python310\lib\site-packages\pandas\core\arraylike.py:397:RuntimeWarning:d......
  • 在K8S中,kube-proxy ipvs和 iptables 有何异同?
    在Kubernetes(K8s)中,kube-proxy是负责服务发现和负载均衡的关键组件,它支持多种代理模式,其中IPVS和iptables是两种常用的模式。以下是kube-proxy在IPVS和iptables模式下的异同点:1.相同点服务发现和负载均衡:IPVS和iptables模式都用于实现Kubernetes中的服务发现和负载均衡功能。......
  • 在K8S中,kube-proxy iptables原理是什么?
    在Kubernetes中,kube-proxy使用不同模式来实现其功能,其中iptables模式是早期广泛使用的模式之一。下面详细介绍kube-proxy使用iptables模式的基本原理。1.iptables原理概述iptables是Linux内核的一部分,用于定义网络封包过滤规则。它是一个用户空间的应用程序,用来设......
  • iptables一句话修复安全漏洞
    iptables一句话修复安全漏洞原创 龚诗嘉 运维前沿  2024年08月30日08:20 辽宁 听全文  iptables一句话安全修复漏洞安全漏洞对于开发和运维人员来说总是灾难,而且总是来的猝不及防CVE-2022-22947GET /actuator/gateway/routes HTTP/1.1Host: 127.0.0.1:......
  • 连接Mysql时出现的“no database selected”错误该如何解决?
    遇到“nodatabaseselected”错误通常是因为在尝试执行SQL查询时没有明确指定要使用的数据库。以下是解决这个问题的步骤:确认连接时已选择数据库在连接数据库之后,确保已经选择了具体的数据库。例如,在MySQL中,可以使用 USE<database_name>; 语句来选择一个数据库。USE......
  • winforms基本操作-将datagridview内容保存为excel文件
    这里记录一下将winforms展示的datagridview,导出或保存为excel文件。这里说一下环境、版本信息:win系统:win11框架:winforms依赖:Microsoft.Office.Interop.Excel.net:8.0.401.netframework:4.8DataGridView对象为dataGridView1,然后添加一个按钮,绑定事件btnConfirm即可。priva......
  • Databinding(kotlin)
    简单使用(只作为view获取)build.gradle.kts配置android{dataBinding{enable=true}}activity注入//setContentView(R.layout.activity_main)valbinding:ActivityMainBinding=DataBindingUtil.setContentView(this,R.layout.activity_main......
  • FIT5147 Data Exploration and Visualisation
    MonashUniversityFIT5147DataExplorationandVisualisationSemester2,2024ProgrammingExercise3:D3(5%)ProgrammingExercise3:D3Pleasecarefullyreviewalltherequirementsbelowtoensureyouhaveagoodunderstandingofwhatisrequiredforyo......