2150_a4.pdf - COMP2150 Assignment 4 Winter 2016 Due April 8...

Info icon This preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
COMP2150 Assignment 4 Winter 2016 1 Due: April 8, 2016, before 11:59 pm. Notes Please follow both the "Programming Standards" and "Assignment Guidelines" for all work you submit. Programming standards 1-25 are in effect. Hand-in will be via the UMLearn Dropbox facility. Make sure you leave enough time before the deadline to ensure your hand-in works properly. The assignments are submitted using UMLearn’s time (not the time on your computer). Assignments that are late will be marked according to the late policy in the ROASS. All assignments in this course carry an equal weight. Assignment 4: Hash Tables in Ruby The assignment has two parts. Each part is worth half of the total marks for the assignment. Part 1: Hash Table Data Structure Description Create a class called HashTable that implements a hash table in ruby. The class should work as follows: 1. When initialized, the HashTable should be given a size as a parameter. The HashTable will create an array of that size as a private field. When adding or searching for an element in the HashTable, the position of the element in the table will be its hash code modulo the length of the array. 2. The HashTable should use separate chaining. If there is a collision between two elements based on their hash code, the HashTable should place both elements in a linked list of elements at the array position. The order of elements in the linked list at a position is not important. 3. The HashTable should implement the following public methods: a. add(x): takes a Hashable object x and adds it to the HashTable in the appropriate position (see below for information on the Hashable class). The method returns nil. b. get(x): takes a Hashable object x and returns the first occurrence of x in the hash table. If the element does not exist, the method should raise an error. c. remove(x): takes a Hashable object and deletes one occurrence of x in the hash table. If the element does not exist, the method should leave the table unchanged. The method should return a boolean that indicates whether an element was removed or not. d. contains?(x): takes a Hashable object x and determines if it is in the hash table. Returns a boolean value.
Image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
COMP2150 Assignment 4 Winter 2016 2 e. isEmpty?(): returns a boolean value determining whether the hash table is empty or not.
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern