Question: Problem 2: 2. There are m doors numbered 1 to m which are all initially closed. Your goal is to open them by pressing n


Problem 2: 2. There are m doors numbered 1 to m which are all initially closed. Your goal is to open them by pressing n switches numbered from 1 to n in an order of your choice. The behavior of the switches is described by an n xm matrix M. When switch i is pressed door j behaves as follows: If the (i, j)th entry, Mij, is 1, door j opens no matter whether it was open or closed before. - If the (i, j)th entry, Mij, is -1, door j closes no matter whether it was open or closed before. - If the (i, j)th entry, Mij, is 0, door j remains at its previous state (open or closed). In this problem, you will design a greedy algorithm for determining an order to press the switches assuming such an order exists. Each switch must be pressed exactly once. Your algorithm is given the matrix M as input. Example Suppose there are m = 5 doors and n = 3 switches with matrix M shown on the right. The optimal way to open all doors is to press switches in the order 2,3,1. - Initially: (Closed, Closed, Closed, Closed, Closed) NAAA - After 2: (Open, Open, Open, Closed, Closed) Switch 0 1 1 1 0 Switch 1 1 1 0 -1 - After 3: (Open, Closed, Open, Closed, Open) - Finally: (Open, Open, Open, Open, Open) Switch 0 -1 0 0 1 (b) Now consider a general instance with n switches and m doors. Assume that all the doors can open by pressing the switches in some order. State a greedy rule for determining which of the n switches should be pressed last. (c) Briefly prove the correctness of your greedy rule. That is, show that if there exists an ordering of switches for opening all doors, then there exists one where the switch you chose in part (b) is pressed last. Problem 2: 2. There are m doors numbered 1 to m which are all initially closed. Your goal is to open them by pressing n switches numbered from 1 to n in an order of your choice. The behavior of the switches is described by an n xm matrix M. When switch i is pressed door j behaves as follows: If the (i, j)th entry, Mij, is 1, door j opens no matter whether it was open or closed before. - If the (i, j)th entry, Mij, is -1, door j closes no matter whether it was open or closed before. - If the (i, j)th entry, Mij, is 0, door j remains at its previous state (open or closed). In this problem, you will design a greedy algorithm for determining an order to press the switches assuming such an order exists. Each switch must be pressed exactly once. Your algorithm is given the matrix M as input. Example Suppose there are m = 5 doors and n = 3 switches with matrix M shown on the right. The optimal way to open all doors is to press switches in the order 2,3,1. - Initially: (Closed, Closed, Closed, Closed, Closed) NAAA - After 2: (Open, Open, Open, Closed, Closed) Switch 0 1 1 1 0 Switch 1 1 1 0 -1 - After 3: (Open, Closed, Open, Closed, Open) - Finally: (Open, Open, Open, Open, Open) Switch 0 -1 0 0 1 (b) Now consider a general instance with n switches and m doors. Assume that all the doors can open by pressing the switches in some order. State a greedy rule for determining which of the n switches should be pressed last. (c) Briefly prove the correctness of your greedy rule. That is, show that if there exists an ordering of switches for opening all doors, then there exists one where the switch you chose in part (b) is pressed last
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
