0% found this document useful (0 votes)
50 views

Assignment 7

The document discusses two questions related to implementing decoding processes and analyzing cricket match results using hashing. For the first question, the task is to decode an encrypted message using a substitution table generated from the positions of letters in a key string. For the second question, the task is to analyze results from a cricket tournament to determine teams that have never lost and those that lost only one match, storing the results in a 2D array using a hash table. Example inputs and outputs are provided.

Uploaded by

shivam sourav
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views

Assignment 7

The document discusses two questions related to implementing decoding processes and analyzing cricket match results using hashing. For the first question, the task is to decode an encrypted message using a substitution table generated from the positions of letters in a key string. For the second question, the task is to analyze results from a cricket tournament to determine teams that have never lost and those that lost only one match, storing the results in a 2D array using a hash table. Example inputs and outputs are provided.

Uploaded by

shivam sourav
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Algorithms Laboratory (CS29203)

Assignment 7: Hashing
Department of CSE, IIT Kharagpur
27th October 2022

Question-1 (50 points)


The Research and Analysis Wing (RAW) of India is working on a message encryption system to send confidential messages
secretly over the network. They are using two main components of the encryption system: a key and a message, which
represent a cipher key and a secret message, respectively. The steps to decode message are as follows:

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.

4. Spaces are transformed to themselves.

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"

Decoded message: "the five boxing wizards jump quickly"

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],[]]

You might also like