Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

There is already a listed solution however I don't understand it. Presumably the answer is a dynamic programming solution. Billy, a 7-year-old kid, is let

There is already a listed solution however I don't understand it. Presumably the answer is a dynamic programming solution. Billy, a 7-year-old kid, is let loose in a park, which is an N-by-N grid of cells (x, y) [N] [N]. His starting location is the Southwest corner (x, y) = (1, 1). He takes a walk in the park, always moving from a square to an adjacent square in one of the four cardinal directions. He never leaves the park, and never visits the same square twice. Eventually he ends up napping somewhere in the park. We are given the N-by-N matrix A, whose entries are A[i, j] = if Billy never visits cell (i, j), A[i, j] = if Billy visited cell (i, j) and departed upwards (North direction); A[i, j] = if Billy visited cell (i, j) and departed in the leftwards direction; similarly for , ; A[i, j] = BILLY if Billy is napping in cell (i, j). As one example, A[1, 1] will contain an arrow indicating the first step Billy took after entering the park (unless he stopped to nap immediately). Give an algorithm that makes only O(N) queries to the matrix A, and locates Billy. Partial credit for O(N log N).

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

How To Build A Million Dollar Database

Authors: Michelle Bergquist

1st Edition

0615246842, 978-0615246840

More Books

Students also viewed these Databases questions