Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Sam wants to leave a secret message for Kim. They share an office on different s

ID: 3661839 • Letter: S

Question

Sam wants to leave a secret message for Kim. They share an office on different shifts in the data backup and recovery division of the Umbrella Corporation. They will leave a post-it note in the top drawer of a filing cabinet they share if they want to give each other a secret message. Each can check when they arrive on their shift, however Malfoy can snoop on them and read the message that is left for each because the top drawer of the filling cabinet is unlocked. They decide to use a locking solution on the filing cabinet drawer. However, they only want one key each, and NOT the shared keys for the lock. Kim says why don’t they use two locks, but she cannot figure out how to lock the drawer without a hidden key to her lock and Sam’s lock put somewhere that Malfoy cannot find. If they drawer on the filing cabinet can accommodate two locks, how can this be solved? Write an algorithm that solves the problem with Kim and Sam only having one key to their respective lock, and there are no keys to the locks hidden from Malfoy. The algorithm should also solve the problem of communicating between Kim and Sam that one of them left a message for the other by virtue of using the locks and the single filing cabinet drawer.

Explanation / Answer

Good Wishes,

It is told that there are two locks say L1 and L2 and two two keys to the two locks respectively say K1 and K2 owned by samand kim respectively.

Now let us maintain this as a paried list and say it is stored in list LK

LK = { (L1,K1) , (L2,K2) }

It is said that the cabinet drawer is single filling which means that it can hold only one message at a time,

Let us use a stack to store this message, say the stack is msg

let variable 'top' represent the top position in stack msg.

initially top= -1 and when a message is in msg top = 0, which means full

Algorithm:

step 1: start

step 2: Accept key from user in lock L and store it in 'key'

step 3: If L=L1, then

check if LK(K1) = key

if true then goto step 5 else goto step 4

else if L = L2

check if LK( K2) = key

if true then goto step 5 else goto step 4

step 4: print message " lock not opened" and goto step 8

step 5: if top = -1, then

print "No new message"

else if top = 0

print the message in msg[0] and do top = -1

step 6: print "Do you want to enter message (Y/N)"

if user enters 'Y', then goto step 7

else goto step 8

step 7: Accept message from user and do top=0

And put the message in msg[0]

step 8: stop

Explaination:

I wrote the algorithm in its most simplest form that it is self explainatory. Even then let me explain for your convinence.

In step 1 I started

In step 2 I accepted the key from user and stored it in variable 'key' and checked into which lock the key was inserted and stored it in 'L'

In step 3 , used the lock-key pair to see if any match i.e.

if the lock in which the key is inserted is L1 then i checked to see if key is same as K1,

if true I went to step 5 else to step 4

similarly,

if the lock in which the key is inserted is L2 then i checked to see if key is same as K2,

if true I went to step 5 else to step 4

In step 4, it is sure that when the user reaches this step it means that either the key is an invalid one or the key is inserted into the wrong lock. whichever the cause might be i just prompted that the lock is not opened and did not mention the reason for security reasons and was then forwarded to step 8

In step 5, I first checked the value in top.

If top=-1, it means that the other person did not have any message for the user, hence was forwarded to step 6

else if top=0, it means the other person has a message for the user and the message in msg[0] is displayed to the user and forwarded to step 6

In step 6, I was trying to ask the user if he/she wants to put in a message to the other person

byasking "Do you want to insert a message(Y/N)"

If user inputs 'Y' , it means he want to insert a message, hence he/she is directed to step 7,

else if he/she inserts 'N' it means he/she has no message to insert and hence directed to step 8.

In step &, I am doing the insertion part

I am accepting the message from user and

then setting top to 0 and

then placing the message in msg[0] and then to step 8

In step 8, process is complete and hence stop.

Hope this is clear.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote