AP Computer Science 3.5 Standard Data Structures
Recommendation
Want a study guide too?
AP Computer Science: Standard Data Structures Drill 3, Problem 5. The resulting array from this code snippet has which of the following shapes?
AP | AP Computer Science |
AP Computer Science | Standard Data Structures |
Computer Science | AP Computer Science |
Language | English Language |
Program Analysis | Program correctness |
Test Prep | AP Computer Science |
Transcript
this code snippet has which of the following shapes And
here your potential answers Where rectangles circles Okay here we
go Nothing pushes a person's brain to the breaking point
Quite like the street magic of rubik's cubes and multidimensional
raised well looks like this code uses the first two
lines to create a two dimensional array of length ten
and twelve hollywood squares on mars Then a loop is
created and something gets added each cycle Well well look
at that lube or in depth in a second But
let's take a moment to see if we can knock
out some potential answers based on that information alone Option
a says the resulting array would look like a square
being that we've created two arrays with length of ten
and twelve there's No way it's going to be a
perfect square option B says we're creating a rectangle Well
maybe We'll hang on to be for now a better
shot he says we'll be creating a circle Well that
doesn't seem very likely because the four loop only increases
some factor in value probably widening the shape forever We'll
see that second circle It obviously need to come back
down to zero toe Drop the second half All right
let's put sea into the no pile All right d
a triangle Well totally possible If the shape is increasing
in size with every generation that loop things might end
up looking like a right triangle Thank you paige Rhys
We'll need to walk through the code To be sure
though e none of the above Well let's find out
Okay we've got our two dimensional array called multi with
length of ten and twelve Then loop begins with the
generator i at zero and runs until eyes no longer
lessen the length of the multi array which is ten
At least in terms of the first given dimension From
that we can predict the code within louisville Run ten
times One's inside It'll take the multi raise second mention
it Whatever I currently and zero on the first cycle
and create a new imager at the position of zero
plus one no one Then it'll cycle again with i
increased by one and again and again and again we
could keep going but it looks like we're just getting
a right triangle just to double check Let's open our
interpreter and add this line to loop so we can
visualize what's being constructed system out print line a raise
to string multi eye all right that'll print to the
console in string form Whatever the content of multi at
the eye dimension is and you're goes and yep that's
pretty triangle e and a right triangle e is that
the ideas are answer and we didn't even have to
try Is that hard Hi sorry we'll try to do 00:02:42.11 --> [endTime] better He's going forward there yeah