Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Given a wall and a position, write a function to return how many neighbors the brick at that position has. The position within the wall

Given a wall and a position, write a function to return how many neighbors the brick at that position has.

The position within the wall is given from the top-left and may fall anywhere within a brick (not necessarily at the start).

For example, in the wall below:

- the brick at (0, 2) has four neighbors.

- the brick at (2, 6) has seven neighbors.

- the brick at (4, 2) has six neighbors.

- the brick at (5, 6) has three neighbors.

- the brick at (5, 7) has two neighbors.

+---+---+---+---+---+---+---+---+---+

| (7) | 1 | 1 |

+---+---+---+---+---+---+---+---+---+

| 5 | 1 | 1 | 2 |

+---+---+---+---+---+---+---+---+---+

| 3 | (4) | 1 | 1 |

+---+---+---+---+---+---+---+---+---+

| 1 | 1 | 1 | 1 | 3 | 2 |

+---+---+---+---+---+---+---+---+---+

| 1 | (2) | 1 | 3 | 2 |

+---+---+---+---+---+---+---+---+---+

| 1 | 1 | 1 | 1 | (3) | (2) |

+---+---+---+---+---+---+---+---+---+

brick_wall_7 = [

[7,1,1],

[5,1,1,2],

[3,4,1,1],

[1,1,1,1,3,2],

[1,2,1,3,2],

[1,1,1,1,3,2]

]

brick_wall_8 = [

[1,1,1,1,1,1,1,1],

[1,1,1,1,1,1,1,1],

[1,1,1,1,1,1,1,1]

]

brick_wall_9 = [

[1,5,1]

]

brick_wall_10 = [

[3],

[3]

]

analyze_brick(brick_wall_7, 0, 2) => 4

analyze_brick(brick_wall_7, 2, 6) => 7

analyze_brick(brick_wall_7, 4, 2) => 6

analyze_brick(brick_wall_7, 5, 6) => 3

analyze_brick(brick_wall_7, 5, 7) => 2

Additional test cases using some of the walls from the previous question:

analyze_brick(brick_wall_8, 1, 1) => 4

analyze_brick(brick_wall_9, 0, 4) => 2

analyze_brick(brick_wall_10, 0, 2)=> 1

Complexity analysis variables:

n: number of bricks in the wall

w: wall width

h: wall height (in layers)

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

Database Theory Icdt 99 7th International Conference Jerusalem Israel January 10 12 1999 Proceedings Lncs 1540

Authors: Catriel Beeri ,Peter Buneman

1st Edition

3540654526, 978-3540654520

More Books

Students also viewed these Databases questions