Assignment 7
Assignment 7
Assignment 7: Hashing
Department of CSE, IIT Kharagpur
27th October 2022
1. The first appearance of all 26 lowercase English letters in the key are used as the order of the substitution table.
2. The substitution table is aligned with the regular English alphabet.
3. Each letter in message is then substituted using the table.
For example, consider the following key and message as: key = “the quick brown fox jumps over the lazy dog”, message =
“vkbs bs t suepuv”. First, we build the substitution table as follows, which is obtained by taking the first appearance of each
letter in key:
t h e q u i c k b r o w n f x j m p s v l a z y d g
a b c d e f g h i j k l m n o p q r s t u v w x y z
Then we take the corresponding characters in message and output this. So the message “vkbs bs t suepuv” is decoded to
“this is a secret” using the table.
Your task is to implement the decoding process using the idea of hash table. You may consider the input key and message
as strings, and output the message as another string.
Example:
key = "eljuxhpwnyrdgtqkviszcfmabo"
message = "zwx hnfx lqantp mnoeius ycgk vcnjrdb"
1
Question-2 (50 points)
A cricket tournament KPL (Kharagpur Premier League) is going on in the Tata Sports Complex at IIT campus. There are
many participating teams in the tournament, and each team is given a unique integer id number. There are n number of
matches that are already played. The results on the matches are stored as n pairs of winning and defeated team ids. For
example, the following is a valid list of pairs: [[1,3],[3,6],[5,6],[5,7]]. This means in the first match team #1 won and team #3
lost, in the second match team #3 won and team #6 lost, and so on. Now our task is to determine which teams have never
lost in the tournament so far, and which teams have lost exactly one match. In this example, teams 1, 5 have never lost any
game, and teams 3, 7 have lost exactly one match.
Your task is to write a program to solve this problem. Take the input in a 2D array, and store the results in another
2D array that contains the teams that have never lost in the tournament so far, and the teams that have lost exactly one
match. You must use the idea of hash table in the implementation. Hint: store the unique winner teams in an array, and
the loser teams with their corresponding number of defeats in a hash table first. Then traverse these lists for further processing.
Example 1:
Input: [[1,3],[2,3],[3,6],[5,6],[5,7],[4,5],[4,8],[4,9],[10,4],[10,9]]
Output: [[1,2,10],[4,5,7,8]]
Example 2:
Input: [[2,3],[1,3],[5,4],[6,4]]
Output: [[1,2,5,6],[]]