CS 202, Fall 2017 Homework #4 Balanced Search Trees and Hashing Due Date: December 18, 2017

Similar documents
CS 202, Fall 2017 Homework #3 Heaps and AVL Trees

CS 202 Fundamental Structures of Computer Science II

Programming Standards: You must conform to good programming/documentation standards. Some specifics:

PROBLEM 1 : (And the winner is...(12 points)) Assume you are considering the implementation of a priority queue that will always give you the smallest

Homework 3 Grade Database Management Due Date

CS3114 (Fall 2013) PROGRAMMING ASSIGNMENT #2 Due Tuesday, October 11:00 PM for 100 points Due Monday, October 11:00 PM for 10 point bonus

Homework 2 (by Ao Zeng) Solutions Due: Friday Sept 28, 11:59pm

King Abdulaziz University Faculty of Computing and Information Technology Computer Science Department

Data Structure and Algorithm Homework #3 Due: 1:20pm, Thursday, May 16, 2017 TA === Homework submission instructions ===

CSE 332 Autumn 2013: Midterm Exam (closed book, closed notes, no calculators)

We don t have much time, so we don t teach them [students]; we acquaint them with things that they can learn. Charles E. Leiserson

CSE 332 Spring 2013: Midterm Exam (closed book, closed notes, no calculators)

Part 1: Written Questions (60 marks):

Introduction to Programming II Winter, 2015 Assignment 5 (Saturday, April 4, 2015: 23:59:59)

6.1 Skip List, Binary Search Tree

CS 104 (Spring 2014) Final Exam 05/09/2014

CSE 332 Spring 2014: Midterm Exam (closed book, closed notes, no calculators)

CISC 3130 Data Structures Spring 2018

a f b e c d Figure 1 Figure 2 Figure 3

CSE 332 Winter 2015: Midterm Exam (closed book, closed notes, no calculators)

5. Hashing. 5.1 General Idea. 5.2 Hash Function. 5.3 Separate Chaining. 5.4 Open Addressing. 5.5 Rehashing. 5.6 Extendible Hashing. 5.

IMPORTANT: Circle the last two letters of your class account:

CS261: HOMEWORK 2 Due 04/13/2012, at 2pm

Com S 227 Assignment Submission HOWTO

CS301 All Current Final Term Paper Subjective 2013 Solved with refernces

3. When you process a largest recent earthquake query, you should print out:

CSCE 210/2201 Data Structures and Algorithms. Prof. Amr Goneid. Fall 2018

You must include this cover sheet. Either type up the assignment using theory5.tex, or print out this PDF.

Prefix Trees Tables in Practice

CS Fall 2018 Homework Assignment 3 Due: 23:59, Dec 26, 2018

COSC 2007 Data Structures II Final Exam. Part 1: multiple choice (1 mark each, total 30 marks, circle the correct answer)

! Determine if a number is odd or even. ! Determine if a number/character is in a range. - 1 to 10 (inclusive) - between a and z (inclusive)

Data Structure and Algorithm Homework #3 Due: 2:20pm, Tuesday, April 9, 2013 TA === Homework submission instructions ===

CMSC 201 Fall 2016 Homework 6 Functions

Homework 1 Due Monday April 24, 2017, 11 PM

CS 241 Data Organization using C

Final Examination CSE 100 UCSD (Practice)

15-122: Principles of Imperative Computation, Spring 2013

Jim Lambers ENERGY 211 / CME 211 Autumn Quarter Programming Project 2

COMP251: Algorithms and Data Structures. Jérôme Waldispühl School of Computer Science McGill University

Programming in OOP/C++

CSE 373 Autumn 2012: Midterm #2 (closed book, closed notes, NO calculators allowed)

CS ) PROGRAMMING ASSIGNMENT 11:00 PM 11:00 PM

Problem assignment 1 Due: Tuesday, September 12, 2017

UNIT III BALANCED SEARCH TREES AND INDEXING

CS251-SE1. Midterm 2. Tuesday 11/1 8:00pm 9:00pm. There are 16 multiple-choice questions and 6 essay questions.

Draw a diagram of an empty circular queue and describe it to the reader.

CS 1803 Pair Homework 4 Greedy Scheduler (Part I) Due: Wednesday, September 29th, before 6 PM Out of 100 points

Binary Search Trees Treesort

CSCE 210/2201 Data Structures and Algorithms. Prof. Amr Goneid

Department of Computer Science. COS 122 Operating Systems. Practical 3. Due: 22:00 PM

CISC-235* Test #3 March 19, 2018

CS 61B Summer 2005 (Porter) Midterm 2 July 21, SOLUTIONS. Do not open until told to begin

APJ ABDUL KALAM TECHNOLOGICAL UNIVERSITY THIRD SEMESTER B.TECH DEGREE EXAMINATION, JULY 2017 CS205: DATA STRUCTURES (CS, IT)

CS 2150 Final Exam, Spring 2018 Page 1 of 10 UVa userid:

CS 374 Fall 2014 Homework 2 Due Tuesday, September 16, 2014 at noon

CMPE 4003 Formal Languages & Automata Theory Project Due May 15, 2010.

Data Structure and Algorithm Homework #2 Due: 2:00pm, Thursday, March 29, 2012 TA

CPSC 331 Term Test #2 March 26, 2007

Hash table basics. ate à. à à mod à 83

On my honor I affirm that I have neither given nor received inappropriate aid in the completion of this exercise.

Hash Tables. CS 311 Data Structures and Algorithms Lecture Slides. Wednesday, April 22, Glenn G. Chappell

CIS 190: C/C++ Programming. Lecture 12 Student Choice

CSE548, AMS542: Analysis of Algorithms, Fall 2012 Date: October 16. In-Class Midterm. ( 11:35 AM 12:50 PM : 75 Minutes )

CSC2100-Data Structures

Hash table basics mod 83 ate. ate

Course Review. Cpt S 223 Fall 2009

Homework 1 CS161 Computer Security, Spring 2008 Assigned 2/4/08 Due 2/13/08

Assignment 4. Overview. Prof. Stewart Weiss. CSci 335 Software Design and Analysis III Assignment 4

CISC 3130 Data Structures Fall 2018

UNIVERSITY OF WATERLOO DEPARTMENT OF ELECTRICAL AND COMPUTER ENGINEERING E&CE 250 ALGORITHMS AND DATA STRUCTURES

Instructions. Definitions. Name: CMSC 341 Fall Question Points I. /12 II. /30 III. /10 IV. /12 V. /12 VI. /12 VII.

CS302 Data Structures using C++

CSE 332, Spring 2010, Midterm Examination 30 April 2010

Practice Midterm Exam Solutions

UNIVERSITY OF WATERLOO DEPARTMENT OF ELECTRICAL AND COMPUTER ENGINEERING ECE 250 ALGORITHMS AND DATA STRUCTURES

CS 2316 Individual Homework 4 Greedy Scheduler (Part I) Due: Wednesday, September 18th, before 11:55 PM Out of 100 points

CS503 Advanced Programming I CS305 Computer Algorithms I

CSE 100 Advanced Data Structures

Data Structure. A way to store and organize data in order to support efficient insertions, queries, searches, updates, and deletions.

CS Homework 2 p. 1. CS Homework 2

INFO1x05 Tutorial 09

list<t>::const_iterator it1 = lst.begin(); // points to first element list<t>::const_iterator it2 = lst.begin(); // points to second element it2++;

Duration: 90 minutes. Page 1 of 14 Q2: /13 Q3: /13 TOTAL: /38. Bonus /1

Homework 9: Stock Search Android App with Facebook Post A Mobile Phone Exercise

CMPSCI 187 / Spring 2015 Sorting Kata

CS2223: Algorithms D- Term, Homework I. Teams: To be done individually. Due date: 03/27/2015 (1:50 PM) Submission: Electronic submission only

CIT 590 Homework 5 HTML Resumes

Contact No office hours, but is checked multiple times daily. - Specific questions/issues, particularly conceptual

During the first 2 weeks of class, all students in the course will take an in-lab programming exam. This is the Exam in Programming Proficiency.

Preparing your scribe

Lecture 23: Priority Queues, Part 2 10:00 AM, Mar 19, 2018

Cpt S 223 Fall Cpt S 223. School of EECS, WSU

Curves & Splines. Assignment #3. Overview & Objectives. Due Dates. CPSC 453 Fall 2018 University of Calgary

be able to read, understand, and modify a program written by someone else utilize the Java Swing classes to implement a GUI

pl98a: Project February 17, 1998 The goal of this exercise is to write a program named plmath, which is a helper to the

CS 2704 Project 2: Elevator Simulation Fall 1999

Syllabus CS 301: Data Structures Spring 2015

University of Toronto Department of Electrical and Computer Engineering. Midterm Examination. ECE 345 Algorithms and Data Structures Fall 2012

Data Structure and Algorithm Homework #1 Due: 1:20pm, Tuesday, March 21, 2017 TA === Homework submission instructions ===

Transcription:

CS 202, Fall 2017 Homework #4 Balanced Search Trees and Hashing Due Date: December 18, 2017 Important Notes Please do not start the assignment before reading these notes. Before 23:55, December 18, upload your solutions in a single ZIP archive using Moodle submission form. Name the file as studentid.zip. Your ZIP archive should contain the following files: hw4.pdf, the file containing the answers to Questions 1, 2 and 3, Person.h, Person.cpp, PersonHashing.h, PersonHashing.cpp, Friendship.h, Friendship.cpp, FriendshipHashing.h, FriendshipHashing.cpp, main.cpp files which contain the C++ source codes, and the Makefile. Do not forget to put your name, student id, and section number in all of these files. Well comment your implementation. Add a header as in Listing 1 to the beginning of each file: Listing 1: Header style /** * Title : Balanced Search Trees and Hashing * Author : Name Surname * ID: 21000000 * Section : 0 * Assignment : 4 * Description : description of your code */ Do not put any unnecessary files such as the auxiliary files generated from your favorite IDE. Be careful to avoid using any OS dependent utilities. You should prepare the answers of Questions 1, 2 and 3 using a word processor (in other words, do not submit images of handwritten answers). 1

Although you may use any platform or any operating system to implement your algorithms and obtain your experimental results, your code should work in a Linux environment (specifically using the g++ compiler). We will compile your programs with the g++ compiler and test your codes in a Linux environment. Thus, you may lose significant amount of points if your C++ code does not compile or execute in a Linux environment. This homework will be graded by your TA, Hasan Balcı. Thus, please contact him directly for any homework related questions. Attention: For this assignment, you are allowed to use the codes given in our textbook and/or our lecture slides. However, you ARE NOT ALLOWED to use any codes from other sources (including the codes given in other textbooks, found on the Internet, belonging to your classmates, etc.). Furthermore, you ARE NOT ALLOWED to use any data structure or algorithm related function from the C++ standard template library (STL). Do not forget that plagiarism and cheating will be heavily punished. Please do the homework yourself. Question 1 10 points Use the exact algorithms discussed in class to answer the following parts: (a) [5 points] 26 3 23 32 42 49 2 6 12 20 25 30 36 38 43 44 45 52 Figure 1: 2-3-4 tree Draw an equivalent red-black tree of the 2-3-4 tree in Figure 1. Clearly indicate red and black nodes. (b) [5 points] Draw the resulting 2-3-4 tree after inserting 34 into the original 2-3-4 tree in Figure 1. Page 2

Question 2 10 points (a) [3 points] What is the maximum number of keys that a 2-3 tree of height h can hold? (b) [3 points] If you start with an empty 2-3-4 tree and insert the letters in English alphabet A, B, C, D,... in alphabetical order, the first time the tree would grow to height 2 would be after inserting D. After inserting which letter would the tree grow to height 3 for the first time? (c) [2 points] Assuming you have a red-black tree with n elements, how fast can you sort those elements using the tree? (d) [2 points] Is every subtree of a red-black tree also a red-black tree? Explain your answer with one sentence. Question 3 10 points Fill in the below table appropriately by giving expected times without providing any explanations in big-o notation for each operation. You may assume that hashing uses separate chaining. Data Structure insert ismember unsorted array red-black tree hashing priority queue using a heap sorted linked list Question 4 70 points In this part, you will use hash tables to implement a simple social network application. Remember that insertion, deletion, and retrieval operations are to run in expected constant time for hash tables. Your program will accept a sequence of commands of the following forms as input, one command to a line: P <name> Create a person record of the specified name. You may assume that no two people have the same name. Page 3

F <name1> <name2> Record that the two specified people are friends. U <name1> <name2> Record that the two specified people are no longer friends. L <name> Print out the friends of the specified person. Q <name1> <name2> Check whether the two people are friends. If so, print Yes ; if not, print No. X terminate the program. For instance, this is one possible input: P Ali P Veli P Ahmet P Mehmet F Ali Veli F Ahmet Mehmet F Mehmet Ali F Mehmet Veli L Mehmet L Veli U Mehmet Ahmet L Mehmet Q Ali Veli Q Ahmet Mehmet X and this is the corresponding output: Veli Ali Ahmet Mehmet Ali Veli Ali Yes No You must Define Person class which has at least two fields; one field for the name and one field for the linked list of friends. Page 4

Store the friends of each person in a linked list, not in an array. The list must be a list of Person objects, not a list of their names, as strings. Define PersonHashing class that creates a hash table which indexes each Person object by using the name field as key. This hash table implementation will use separate chaining and table size will be 11. The hash function will be h(x) = (sum of the ASCII codes of each letter in the name) mod (table size). Define Friendship class which has at least three fields. First field is for the friendship name. The friendship name will be the concatenation of the names of two people in the friendship in alphabetical order. For example, the friendship name of "Veli" and "Ali" will be "AliVeli". The second field will be a pointer to the node corresponding to Ali in the linked list of Veli s friends, and the third field will be a pointer to the node for Veli in the linked list of Ali s friends. Define FriendshipHashing class that creates a hash table which indexes each Friendship object by using the friendship name field as key. This hash table implementation will use quadratic probing and table size will be 71. The hash function will be h(x) = (sum of the ASCII codes of each letter in the friendship name) mod (table size). Executing commands To execute a P command, create a Person object for the name, and save it in the PersonHashing hash table by using the name as key. To execute an F command: Find two Person objects in the PersonHashing hash table. Add each person to the front of the linked list of the friends of the other person. Construct the friendship name by using two names. Create a Friendship object for the friendship name. Connect the first pointer to the node corresponding to the second name in the linked list of first name s friends, and connect the second pointer to the node corresponding to the first name in the linked list of second name s friends. Save this Friendship object to the FriendshipHashing hash table by using the friendship name as key. To execute a U command: Construct the friendship name by using two names. Page 5

Find the Friendship object in the FriendshipHashing hash table by using friendship name as key. Find two Person objects by using the appropriate pointers and delete both person from each other s friend list. Delete the Friendship object from FriendshipHashing hash table. To execute an L command, find the Person object in the PersonHashing hash table, and loop through the list of friends. To execute a Q command, construct the friendship name by using two names and look it up in the Friendship hash table by using the friendship name as key. Input/Output You may assume that the input is correctly formatted. That is: Each line consists of a command character P, F, U, L, Q, or X followed by a blank followed by one or two names separated by a blank. A name is a sequence of alphabetic characters. Any name mentioned in an F, U, L, or Q command has been already created by a P command. The sequence of commands ends with X. What, if anything, you want to do about invalid inputs is up to you. However, the program should do the right thing under the following circumstances: A person friends or unfriends himself. In this case, the program should do nothing; it should not add the person to his own list of friends. A person unfriends someone who is not a friend. In that case, the program should do nothing. The program must take its input from a text file named input.txt in the same directory as the program. At the end, write a basic Makefile which compiles all your code and creates an executable file named hw4. Check out these tutorials for writing a simple make file: tutorial 1, tutorial 2. Please make sure that your Makefile works properly, otherwise you will not get any points from Question 4. Page 6