...

/

Getting Ready: Jigsaw Puzzle

Getting Ready: Jigsaw Puzzle

Understand the jigsaw puzzle problem and learn the questions to simplify this problem.

Problem definition

A jigsaw puzzle is a picture divided into irregularly shaped pieces that can be assembled to form a complete picture. It has a fixed number of pieces that can only fit together in exactly one way. We can solve the jigsaw puzzle by aligning the pieces so that they fit together and also create a coherent picture.

Expectations from the interviewee

Although the jigsaw problem is a simpler design problem asked in interviews, the interviewer still has some expectations. The following provides an overview of what the interviewer wants to hear you discuss in more detail during the interview.

The puzzle board

You may want to ask the interviewer more about the kind of jigsaw puzzle. You can ask the following questions:

  • What does a jigsaw puzzle look like? Is there a picture or a pattern on the puzzle?

  • What type of shape does our board have? Is it rectangular, circular, or any other shape?

The puzzle pieces

It is important to clarify the requirements for a single piece of the puzzle, as it is a key feature of the problem. You can ask the following questions:

  • What kind of shape do the puzzle pieces have? How many sides does a piece have?

  • How do the pieces fit together?

  • Will all the pieces of a jigsaw puzzle be unique?

Design approach

We are going to design this jigsaw puzzle using the bottom-up design approach. For this, we will follow the steps below:

  • Identify and design the smallest components first, like the puzzle edges of a piece.

  • Use these small components to design bigger components, for example, the puzzle piece.

  • Repeat the steps above until we design the whole system, i.e., the puzzle board.

Design pattern 

During an interview, discussing the design patterns that a Jigsaw puzzle falls under is always a good practice. Stating the design patterns gives the interviewer a positive impression and shows that the interviewee is well-versed in the advanced concepts of object-oriented design.

Try to answer the following question. If you are not familiar with design patterns, don’t worry! You can learn about them by asking, “Define design patterns.”

Which design pattern(s) should be used to design a jigsaw puzzle? Please elaborate on your choice(s).

Note: The jigsaw puzzle design problem is fairly simple, so we don’t need to create the use case, sequence, and activity diagrams. The requirements defined for this problem are unsuitable for these diagrams.

Let’s explore the requirements of the jigsaw puzzle problem in the next lesson.