Answered step by step
Verified Expert Solution
Question
1 Approved Answer
CS 2 1 2 4 Data Structures Assignment 3 - Recursion Program Description Jethro and Cletus are quarantined at home and bored. They spend most
CS Data Structures
Assignment Recursion Program
Description
Jethro and Cletus are quarantined at home and bored. They spend most of their day sitting
at their computer monitor working or browsing the internet in their small apartment. Out of
boredom Jethro begins counting the number of steps needed to reach each location in their
small apartment. After seeing that taking different paths from their computer to their coffee
maker yields different numbers of steps a question dawns on them. They want to know what
is the fewest number of steps needed to reach all of the locations in their small apartment
starting from their computer.
Fortunately, Jethro is quite skilled at ASCII art. So they model their room with ASCII
characters. A space can be moved through. An asterisk is a wall or furniture that
cannot be traversed no climbing over furniture! Going up down, left, right one space
takes exactly one step well assume no diagonal movements for that sake of simplicity For
example, here is a possible model of their room:
A
Assume that is the upper lefthand corner. For the sake of simplicity you can assume
the apartment is enclosed in characters and that the location of Jethros computer has
been marked with an A
Jethro is still new to programming and wants to hire you to write the program to label all
of the locations in their apartment with the minimum number of steps needed to reach
them. To keep with the ASCII art theme youll use the letters AZ Such that:
A is steps
B is step
C is steps
Y is steps
Z is or more steps
Heres some example rooms:
Example :
Base room:
A
Room after algorithm:
ABC
D
GFE
We cant pass through the symbols
Example :
Base room:
A
Room after algorithm:
BABCDEFGHIJK
CBCDFGHIJKL
DCDEGHIJKLM
EDHIJKLMN
FEFGHIJKLMNO
GFGHIOP
HGHIJRQPQ
Example :
Base room:
A
Room after algorithm:
DCBABCDEFGHIJKLMNOPQRSTUVWXYZZZZ
We dont count past Z since Jethro has a pretty small apartment
Example :
Base room:
A
Room after algorithm:
ABCDE
EF
FG
GH
KJIHI
Unreachable areas should remain unchanged
Part Programming: points
Write a brute force recursive program to solve the problem described above in paintRoom.c
Hint : This program will take fewer lines of code than previous one but youll need to
think about and test them carefully. For reference, my recP aintRoom only had lines of
code in it
Hint : From any given space, you need to try to continue moving up down, left, and right
ie recursive calls
Hint : Your algorithm can move into a but upon recognizing it as an obstacle, it should
return from that call.
Hint : It may help to track the distance traveled so far from the starting A character.
Hint : Only updating locations that contain a wont be enough. Sometimes youll need
to update a location you previously visited and labeled.
Hint : chars can be treated like small valued integers. In particular, it may be helpful to
use operations like and with your chars.
Part Runtime: points
What is the runtime complexity of your algorithm? There are multiple reasonable answers
and the answer depends on your code so you should also justify your reasoning in order
to receive credit.
Deliverables:
Your program solution should be submitted as paintRoomcalso submit any additional
files you created to solve this problem Your solutions to part should be submitted as a
text file txtpdf or doc
Upload these files to Blackboard under Assignment Do not zip your files.
To receive full credit, your code must compile and execute. You should use valgrind to ensure
that you do not have any memory leaks.Part Programming: points
Write a brute force recursive program to solve the problem described above in paintRoom.c
Hint : This program will take fewer lines of code than previous one but youll need to
think about and test them carefully. For reference, my recP aintRoom only had lines of
code in it
Hint : From any given space, you need to try to continue moving up down, left, and right
ie recursive calls
Hint : Your algorithm can move into a but upon recognizing it as an obstacle, it should
return from that call.
Hint : It may help to track the distance traveled so far from the starting A character.
Hint : Only updating locations that contain a wont be enough. Sometimes youll need
to update a location you previously visited and labeled.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started