Updated PDAssignment6
Updated PDAssignment6
ASSG<Number><ROLLNO><FIRST-NAME>.zip
(Example: ASSG6_ B240123CS_NEEMA.zip). DO NOT add any other files (like temporary f
iles, input files, etc.) except your source code, into the zip archive.
• The source codes of each question must be named as
ASSG<Number><ROLLNO><PROGRAM-NUMBER>.c
(For example: ASSG6_ B240123CS_1.c).
Standard of Conduct
• Violation of academic integrity will be severely penalized. Each student is expected to
adhere to high standards of ethical conduct, especially those related to cheating and
plagiarism. Any submitted work MUST BE an individual effort. Any academic dishonesty will
result in zero marks in the corresponding exam or evaluation and will be reported to the
department council for record keeping and for permission to assign F grade in the course.
The department policy on academic integrity can be found at:
http://cse.nitc.ac.in/sites/default/files/Academic-Integrity new.pdf.
General Instructions
• Programs should be written in C language.
• Check your programs with sufficiently large values of inputs within the range as specified
in the question.
• Global and/or static variables should not be used in your program.
Sample Output 1:
700 50 85 92 -1 -1 76
0
3
-1
Sample Input 2:
54
21 22 23 24
2
23
25
Processing:
● 21 % 5 = 1 → Insert at index 1
● 22 % 5 = 2 → Insert at index 2
● 23 % 5 = 3 → Insert at index 3
● 24 % 5 = 4 → Insert at index 4
Final Hash Table:
-1 21 22 23 24
Sample Output 2:
-1 21 22 23 24
3
-1
Sample Input 3:
10 6
12 22 32 42 52 62
3
32
52
100
Processing:
● 12 % 10 = 2 → Insert at index 2
● 22 % 10 = 2 (Collision) → Try 3 → Insert at index 3
● 32 % 10 = 2 (Collision) → Try 3 (Collision) → Try 4 → Insert at index 4
● 42 % 10 = 2 (Collision) → Try 3 (Collision) → Try 4 (Collision) → Try 5 → Insert at index 5
● 52 % 10 = 2 (Collision) → Try 3 (Collision) → Try 4 (Collision) → Try 5 (Collision) → Try 6 →
Insert at index 6
● 62 % 10 = 2 (Collision) → Try 3 (Collision) → Try 4 (Collision) → Try 5 (Collision) → Try 6
(Collision) → Try 7 → Insert at index 7
Final Hash Table:
-1 -1 12 22 32 42 52 62 -1 -1
Sample Output 3:
-1 -1 12 22 32 42 52 62 -1 -1
4
6
-1
Sample Input 4:
85
15 25 35 45 55
3
25
55
75
Processing:
● 15 % 8 = 7 → Insert at index 7
● 25 % 8 = 1 → Insert at index 1
● 35 % 8 = 3 → Insert at index 3
● 45 % 8 = 5 → Insert at index 5
● 55 % 8 = 7 (Collision) → Try 0 → Insert at index 0
Final Hash Table:
55 25 -1 35 -1 45 -1 15
Sample Output 4:
55 25 -1 35 -1 45 -1 15
1
0
-1
Sample Input 5:
63
10 20 30
3
10
30
40
Processing:
● 10 % 6 = 4 → Insert at index 4
● 20 % 6 = 2 → Insert at index 2
● 30 % 6 = 0 → Insert at index 0
Final Hash Table:
30 -1 20 -1 10 -1
Sample Output 5:
30 -1 20 -1 10 -1
4
0
-1
Input Specification
1. The first line contains an integer N (number of operations).
2. The next N lines contain operations of the following format:
○ "INSERT X": Insert key X into the hash table.
○ "SEARCH X": Search for key X and print "1" or "-1".
○ "DELETE X": Delete key X from the hash table.
3. The hash table size is predefined and must be a prime number.
Output Specification
● For "SEARCH X" operation, print"1" if X is present in the table, otherwise "-1" if X is not in
the table.
● For "DELETE X", if X exists in the hash table, it should be removed. Otherwise, do nothing.
Sample Input 1:
6
INSERT 10
INSERT 20
SEARCH 10
SEARCH 15
DELETE 10
SEARCH 10
Sample Output 1:
1
-1
-1
Sample Input 2:
5
INSERT 5
INSERT 15
SEARCH 5
DELETE 5
SEARCH 5
Sample Output 2:
1
-1
Output Specification:
● Delete <key>: deletes the key from the hash table and prints the location if found otherwise, print
“NOT FOUND”
● Search <key>: Search the given <key> in hash table prints its location if found; otherwise, print
-1.
● Display: Prints the current state of the hash table with E and D, indicating that empty slots and
deleted slots where there is no key in the slots.
● Exit: command terminates the execution of the program.
Sample Input 1:
10 7
Insert 25
Insert 35
Insert 15
Insert 45
Insert 55
Display
Search 35
Delete 35
Search 35
Display
Exit
Sample Output 1:
Index: 0 1 2 3 4 5 6 7 8 9
Keys: E 15 35 E E 25 55 E E 45
2
2
-1
Index: 0 1 2 3 4 5 6 7 8 9
Keys: E 15 D E E 25 55 E E 45
Sample Input 2:
10 8
Sample Output 2:
gcd(10, 8) not equal to 1
Sample Input 1:
5
INSERT 123 "Data Structures in Practice" "John Doe" 2020
INSERT 125 "Algorithms Unlocked" "Jane Smith" 2018
SEARCH 123
SEARCH 999
DELETE 125
DELETE 125
SEARCH 125
Sample Output 1:
Data Structures in Practice, John Doe, 2020
-1
1
-1
-1
5. Menu driven program (Open addressing: Linear, Quadratic, and Double hashing)
Problem:
A college has a Library Management System that uses a hash table to store and manage book records.
Each book record consists of a unique ISBN (13-digit number) and the book title (string). The system
should support three collision resolution techniques: Linear Probing, Quadratic Probing, and Double
Hashing. The user can select the collision resolution method at the start of the program. The system
should allow the user to add books, search for books, delete books, and display the current state of the
hash table.
Input Specification:
● The first line choose the method for handling collision.
● Thesecond line contains the size of the hash table with respect to the method chosen above.
The program accepts a command (a string) which is the operation to be performed (in capital letters),
followed by optional arguments depending on the command. The commands and their formats are as
follows:
1. Add Book:
○ ADD <ISBN> “<title>”: Adds a book with the given <ISBN> (13-digit unique integer)
and “<title>” (string of 30 characters) into the hash table.
■ Example: ADD 9783161484100 "The Great Gatsby"
2. Search Book:
○ SEARCH <ISBN>: Searches for the book with the given <ISBN>.
■ Example: SEARCH 9783161484100
3. Delete Book:
○ DELETE <ISBN>: Deletes the book with the given <ISBN> from the hash table.
■ Example: DELETE 9783161484100
4. Display Hash Table:
○ DISPLAY: Displays the current state of the hash table, showing the index, ISBN, and title
for each occupied slot.
■ Example: DISPLAY
5. Exit:
○ EXIT: Terminates the program.
■ Example: EXIT
Each command should be entered on a new line.
Output Specification:
The program will output results as follows:
1. Add Books
○ Print output: "1" for successful insertion. Otherwise, output -1.
2. Search Book:
○ Print ISBN, title if the book is found. Otherwise, print -1.
3. Delete Book:
○ Print 1if the book is successfully deleted. Otherwise, print -1.
4. Display Hash Table:
○ Output: Displays the current state of the hash table, showing the index, ISBN, and title for
each occupied slot.
5. Exit: Terminate the Program.
SAMPLE INPUT 1:
SAMPLE OUTPUT 1:
1
1
9783161484100, The Great Gatsby
Index 0: (None, None)
Index 1: (9783161484100, The Great Gatsby)
Index 2: (9780451524935, 1984)
SAMPLE INPUT 2:
1
1
1
-1
Index 0: (None, None)
Index 1: (None, None)
Index 2: (9780451524935, 1984)
SAMPLE INPUT 3:
SAMPLE OUTPUT 3:
1
1
1
9780141439518, Pride and Prejudice
Index 0: (9780141439518, Pride and Prejudice)
Index 1: (9783161484100, The Great Gatsby)
Index 2: (9780451524935, 1984)
Input Specifications:
● First line: Prompt the user to enter the number of buckets to create in the hash table (for example,
5, 10, etc.).
● Operations are listed below:
○ Insert <ID> <NAME>: A unique student ID (e.g., 101, 202, etc.) and a string
representing the student’s name (e.g., "JohnDoe").
○ Search <ID>: Search for the student's ID in the hash table or not.
○ Delete <ID>: Deleting the student’s record if the ID is found.
○ Display: Displays the current status of the records in the Hash Table
○ Exit : Terminating the program.
Output Specifications:
● Insert: No need for display after insert operation.
● Search: Print ID, Name if the record is found in the respective DLL of the bucket. Otherwise,
print -1.
● Delete: Print the ID, Name of the record is it is deleted. Otherwise, print -1.
● Display: List all buckets in the hash table. Each bucket should display all the (ID, Name) pairs
stored in that bucket. Print E if a bucket is empty.
Sample Input 1:
Enter the number of buckets:
5
Insert 101 JohnDoe
Insert 104 Kendy
Insert 106 Bob
Insert 221 Alice
Insert 112 Eve
Display
Search 104
Delete 104
Search 104
Display
Exit
Sample Output 1:
Index 0: E
Index 1: 221 Alice 106 Bob 101 JohnDoe
Index 2: 112 Eve
Index 3: E
Index 4: 104 Kendy
104 Kendy
-1
Index 0: E
Index 1: 221 Alice 106 Bob 101 JohnDoe
Index 2: 112 Eve
Index 3: E
Index 4: E
Input Specification:
○ At the start, prompt the user for the number of buckets in the hash table (e.g., 5, 10, etc.).
○ Show a menu with five options:
■ Insert
■ Search
■ Delete
■ Display
■ Exit
○ For Insert, the user inputs:
■ A unique integer representing the license plate number (e.g., 1234).
■ A string representing the owner’s name (e.g., "Alice").
○ For Search or Delete, the user inputs the license plate number they want to look up or
remove.
Output Specifications:
○ Print a success message when an insert is successful, or an error message if the license
plate number already exists in the system.
○ Print an appropriate message when searching:
■ “Registration found: (plate_number, owner_name)” if it exists. “No registration
found for plate_number” if it does not exist.
○ When deleting a registration:
■ Print a success message if the record is found and removed, or “No registration
found for plate_number” if not found.
○ The Display operation should print the contents of all buckets. Each bucket can list all
(plate_number, owner_name) pairs, reflecting the use of separate chaining.
○ The program terminates on choosing Exit, optionally printing a closing message.
Sample Testcase 1:
Sample Output 1: