2 Problem Set 5
Problem 5-3. [10 points] Short-Circuitry
Star-crossed androids Romie-0 and Julie-8 are planning an engagement party and want to invite all their
robotic friends. Unfortunately, many pairs of their friends can’t be in the same room without short-circuiting.
Romie-0 has an idea to throw two parties instead: inviting some friends to the first party, and the rest to the
second. Ideally, everyone would get invited to a party, but nobody would go to the same party as someone
that would make them short-circuit. Julie-8 points out to Romie-0 that this might not be possible, for
example if they have three friends who all make each other short-circuit. Given the n short-circuiting pairs
of friends, describe an O(n)-time algorithm to determine whether Romie-0 and Julie-8 can invite all of their
friends to two peaceful parties, without anyone short-circuiting.
Problem 5-4. [10 points] Ancient Avenue
The ancient kingdom of Pesomotamia was a fertile land near the Euphris and Tigrates rivers. Newly-
discovered clay tablets show a map of the kingdom on an n × n square grid, with each square either:
• part of a river, labeled as
’euphris’ or ’tigrates’; or
• not part of a river, labeled with a string: the name of the farmer who owned the square plot of land.
The tablets accompanying the map state that ancient merchants built a trade route connecting the two
rivers: a path along edges of the grid from some grid intersection adjacent to a
’euphris’ square to a grid
intersection adjacent to a
’tigrates’ square. The tablets also state that the route:
• did not use any edge between two squares owned by the same farmer (so as not to trample crops); and
• was the shortest such path between the rivers (assume a shortest such path is unique).
Given the labeled map, describe an O(n
2
)-time algorithm to determine path of the ancient trade route.
Problem 5-5. [15 points] Statum Quest
Liza Pover is a hero on a quest for free pizza in the Statum Center, a large labyrinth with some of the best free
food in the entire Technological Institute of Mathachusetts. Many unsuspecting victims
1
have ventured into
the labyrinth in search of free food, but few have escaped victorious. Luckily, Liza has downloaded a map
from b
plansc.tim.edu consisting of locations L (including rooms, hallways, staircases, and elevators
2
)
and doors D which connect pairs of locations. One location e ∈ L is marked as the entrance/exit: Liza’s
path must begin and end here. A subset Π ⊂ L of locations each contain a free pizza. Liza’s goal is to enter
the maze, grab one pizza, and leave as quickly as possible.
Each door d = (`
1
, `
2
) connects two locations `
1
and `
2
and may be one-way (can be traversed only from
`
1
to `
2
) or two-way (can be traversed in either direction). In addition, each door d may require card access
to one of the four Statum Center labs — See-Sail, TOPS, S3C
3
, and DSW
4
. A card-access door of type
t ∈ {SeeSail, TOPS, S3C, DPW} can only be traversed after Liza acquires the matching key card, where the
key card of type t is in a known location `
t
.
Describe an O(|L| + |D|)-time algorithm to find a viable path from e to e that collects at least one pizza
from Π (and possibly some of the key cards along the way to open some doors), and minimizes the number
of times that Liza has to walk through a door.
1
Formerly known as freshmen
2
We model an entire elevator column as one location, with a door to each floor location it can access
3
Super Secret Spider Consortium
4
Department of Speechlore and Wisdomlove