Question: 4. Block Uh Oh (20 points) Dr. I Lai has a son in preschool, and she wants to spell out words to him with alphabet
4. Block Uh Oh (20 points) Dr. I Lai has a son in preschool, and she wants to spell out words to him with alphabet blocks by picking up one block at a time to show to him. However, somehow every block is covered in BabySlime, so they are very hard to pick up unless they are in the ACME Block Washer. Unfortunately, the washer has only 5 spots. Picking up a block from the table costs one Happiness Point every time. Picking up a block from the washer is free! Dr. Lai would to spell out her favorite song, "ALGORITHMS ARE THE BESTEST BEST BEST YEAH", with a minimal number of BabySlime interactions (so as many letters pulled out of the block washer as possible). Note: Letters can be swapped into the block washer, but putting a new block into the washer requires getting it from the table, which costs a happiness point. (a) Design an optimal Greedy Algorithm for placing blocks in the block holder. What is the cost in happiness points? (b) Generalize your algorithm to k blocks in the holder and a string of size k. (e) Can you use a greedy algorithm if you don't know the entire sequence ahead of time
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
