What Are Two Desirable Properties of A Hash Function?: Homework Week 4 Set, Hash and Map [PDF]

  • 0 0 0
  • Gefällt Ihnen dieses papier und der download? Sie können Ihre eigene PDF-Datei in wenigen Minuten kostenlos online veröffentlichen! Anmelden
Datei wird geladen, bitte warten...
Zitiervorschau

Homework week 4 Set, Hash and Map 1.

What are two desirable properties of a hash function? Trả lời

2.

-

Tính toán nhanh

-

Giảm thiểu sự trùng lặp(va chạm)

Draw the 11-entry hash that results from using the hash function h(i) = (2i+5) mod 11 to hash keys 12, 44, 13, 88, 23, 94, 11, 39, 20, 16, 5. a)

Assume collisions are handled by chaining.

b)

3.

Assume collisions are handled by linear probing.

Draw the 17-entry hash that results from using the hash function h(i) = (i+3) mod 17 to hash keys 1, 3, 18, 8, 23, 35, 11, 36, 20, 16. c)

Assume collisions are handled by chaining.

d)

4.

Assume collisions are handled by linear probing.

A student has following information: ● ID: An unique integer number ● Name: a string of at most 100 characters ● Class: a string of at most 30 characters Your task is to write a program to manage students for your university with follow operations: ● Insert (ID, Name, Class): Insert a student into the list ● Delete (ID): Delete student ID from the list ● Infor (ID): Return the Name and Class of student ID separated by a comma. If the student is not exist, return string ‘NA,NA’ Input: Operations come from keyboard. Each operation is in one line.

Output: Write to the screen the results from calling infor(ID) operations. Example Keyboard Insert(1,Tuan,K61CS) Insert(2,Vinh,K43C) Infor(3) Infor(2) Delete(2) Infor(2)

Screen NA,NA Vinh,K43C NA,NA

#include  #include  #include  using namespace std; struct Student{     string Name;     string Class;     Student(string Name_, string Class_) {         Name = Name_;         Class = Class_;     } }; map  mymap; void Insert(int ID_, string Name_, string Class_) {     Student n(Name_, Class_);     mymap.insert({ID_, n}); } void Delete(int ID_) {     mymap.erase(ID_); } void Info(int ID_) {     map::iterator it = mymap.find(ID_);     if (it == mymap.end()) {         cout