COS 212 Hashing and Data Structures
10 Questions
5 Views

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to Lesson

Podcast

Play an AI-generated podcast conversation about this lesson

Questions and Answers

What is the optimal condition for division hashing to work best?

  • T = large prime number (correct)
  • T = odd number
  • T = small prime number
  • T = even number

What is the purpose of folding in hash functions?

  • To compress the key
  • To encrypt the key
  • To reduce variability of hash codes
  • To increase variability of hash codes (correct)

In shift folding, how are the parts of the key combined?

  • Using addition (correct)
  • Using subtraction
  • Using division
  • Using multiplication

What is the advantage of the mid-square function?

<p>It uses the entire key (A)</p> Signup and view all the answers

Why can hash functions be combined?

<p>To produce more variation in the hash values (A)</p> Signup and view all the answers

How are strings hashed?

<p>By using ASCII codes (C)</p> Signup and view all the answers

What is the range of ASCII codes used for hashing?

<p>0 - 127 (C)</p> Signup and view all the answers

What is the purpose of the hash function in the code snippet?

<p>To calculate the hash value of the string (A)</p> Signup and view all the answers

What operation is used to combine the ASCII codes in the hash function?

<p>Addition (B)</p> Signup and view all the answers

What is the result of the hash function in the code snippet?

<p>The hash value modulo table size (D)</p> Signup and view all the answers

Study Notes

Hashing

  • Average and worst-case complexity of searching, inserting, and deleting in unsorted arrays, sorted arrays, unsorted linked lists, sorted linked lists, skip lists, binary search trees (BST), and B-Trees.

Hash Functions

  • Basic idea: save items in a key-indexed table where the index is a function of the key.
  • Properties of a good hash function:
    • Easy to compute
    • Each index is equally likely to be generated for each key
    • A perfect hash function assigns a unique index to each key

Types of Hash Functions

Extraction

  • Use a selection of digits as the key
  • Choose the part of the key that is least likely to repeat

Division Hashing

  • Hash function: hash(K) = K % T where T is the size of the hash table
  • Works best when T is a large prime number
  • Alternatively: hash(K) = (K % p) % T where p is a prime number greater than T

Folding

  • Designed to increase variability of hash codes
  • Split the key into equal parts and combine them using a simple operation like addition
  • Apply division hashing to restrict the index to the desired range
  • Examples: shift folding and boundary folding

Mid-Square Function

  • Square the key
  • Use the middle section of a desired length as the hash value
  • Advantage: the entire key is used, producing more variation
  • Can be combined with other hash functions like folding

Hashing Strings

  • Use ASCII codes to hash strings
  • Methods:
    • Concatenate ASCII codes and apply division hashing
    • Add ASCII values and apply division hashing

Studying That Suits You

Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

Quiz Team

Description

This quiz covers the concepts of hashing, data structures, and their complexities in terms of search, insert, and delete operations. Learn about the average and worst-case scenarios for unsorted arrays, sorted arrays, linked lists, skip lists, BST, and B-Trees.

More Like This

Hashing in Computer Science
10 questions
Hashing in Data Structures
12 questions
Hashing and Heaps: Week 9
16 questions

Hashing and Heaps: Week 9

EntrancingKansasCity avatar
EntrancingKansasCity
Use Quizgecko on...
Browser
Browser