Students
Teachers & SchoolsStudents
Teachers & SchoolsAPCS: Standard Data Structures Drill 1, Problem 3. Which of the following is the best postcondition for the fillArray method?
AP | AP Computer Science |
AP Computer Science | Standard Data Structures |
Computer Science | AP Computer Science |
Language | English Language |
Standard Operations and Algorithms | Operations on data structures |
Test Prep | AP Computer Science |
method has the following preconditions our is a valid in
terrain declared with a specified length greater than or equal
to one Are that bar well which of the following
is the best post condition for the pillory method And
here the potential answers we're thinking we're thinking and if
we stop now we're thinking again okay free and post
conditions are like promises we make to ourselves almost like
new year's resolutions except we actually wind up keeping In
the case of the phil ary method we're working with
the precondition that r is a valid array of imagers
with a length greater than or equal to one let's
walk through the method to see what it actually does
well first line hear gives us an imager named flynn
which is the length of the array we're going to
be filling The next line starts up for life the
three parameters were set up to create emitter i as
the counter starting at zero and specifies that lupul run
until ice less than len becomes false and iterated I
buy one each time The looks like the code within
the loop itself visits the array of whichever position i
is at the time and fills that position's content with
again number that eyes that though position zero in the
array will contain the number zero position four will contain
the number four and so on Get it let's Look
at the potential answers option a this one says that
our is an imager array of length twenty Well no
the hillary method is written in such a way that
it'll fill an array of whatever size we specified Option
b says our is an imager array of a length
thread a ventricle the one and each value equals its
index Hey that sounds exactly like what we're making better
check the other cells What option c says is technically
true but it's less specific than option b and that
it doesn't say anything about the values being the indices
though it's not our best choice option d again with
the twenty thing no option a is pretty similar to
be except that the arrays and unspecified size that's not
true erase sizes definitely greater than zero because the loops
generator starts at zero and aloof runs until the generator
is equal to or greater than our yeah software pirate
joke we've beaten to death If we specified we wanted
in a ray the sides of negative three for example
aside from being impossible the four loop wouldn't run it
all because the generator is already greater than our and
no array would be generated Not only that but our
precondition already specified The array of length is greater than
or equal to one so nuts to that Our answer's 00:02:57.115 --> [endTime] Definitely B no not r it's b