ShmoopTube
Where Monty Python meets your 10th grade teacher.
Search Thousands of Shmoop Videos
AP Computer Science Videos 110 videos
AP Computer Science: Classes and Objects Drill 1, Problem 1. Which of the following is a correct {/* Implementation */} for the isInsect method?
AP Computer Science 1.1 Inheritance, Abstraction, and Polymorphism. Which of the following are correct?
AP Computer Science 1.1 Program Development. The situation in the video is an example of which of the following?
AP Computer Science 3.2 Standard Data Structures 180 Views
Share It!
Description:
AP Computer Science 3.2 Standard Data Structures. Which of the following methods successfully add an element to the array?
Transcript
- 00:00
Sorry And here's your shmoop du jour brought to you
- 00:05
by a ray list looking for an array You khun
- 00:08
dynamically resize it's a ray of hope want want which
- 00:13
of the following methods successfully add an element to an
- 00:15
array signs this crap over here that's Fine that code
Full Transcript
- 00:19
Over here you looked in and here your potential answers
- 00:24
Okay here we go The purpose of this question seems
- 00:27
to remind us of the difference between a plane all
- 00:29
arrays and a ray lists they work the same way
- 00:32
in a lot of respects but one of the biggest
- 00:34
difference is the ability to dynamically resize array list While
- 00:38
old school razor stuck with the side they're given forever
- 00:42
this question featured in a ray list things would be
- 00:44
over with pretty quickly Add to an array list we
- 00:47
could just call the ad method toe add a value
- 00:49
to it whenever we'd like no sweat but this question
- 00:52
is asking us to do the impossible Add values to
- 00:55
a regular array can't be done unless we're a little
- 00:59
sneaky like option one so check this out option one
- 01:02
takes it upon itself to create a new array that's
- 01:05
one size larger Then it loops over the older ray
- 01:08
grabbing his values and adding them to the new array
- 01:11
once the loop finishes it adds the imager called lm
- 01:15
which would be the imager provided with the method call
- 01:17
to the end and returns the fresh new array very
- 01:21
slick option one could be a used car salesman option
- 01:24
Two seems simple enough thie idea seems to be to
- 01:26
place the contents of the imager elem at the index
- 01:30
corresponding to the total length of the array What this
- 01:33
method is attempting is almost clever if only it worked
- 01:37
Because all array indexes begin counting at zero the total
- 01:40
length of an array does not correspond directly to the
- 01:43
index values they're one off if you hadn't array with
- 01:46
the length of five which is to say five total
- 01:48
elements in it the array would be index from zero
- 01:51
to four if you had a twelve element array zero
- 01:54
to eleven and so on so this method is trying
- 01:56
to provide a value for an array member who's index
- 01:59
doesn't exist and will always be just one position out
- 02:03
of reach You know what that's like in life story
- 02:07
option two will keep throwing an array index out of
- 02:09
bounds exception until the end of time So totally not
- 02:12
gonna work and option three looks nice and simple That
- 02:15
ad function looks very handy except that yeah again this
- 02:19
isn't an array list ad calls like this one won't
- 02:23
do a single thing for our array here that makes
- 02:26
our answer A option One only like climbing over the
- 02:29
fence when the gate was wide open Option one made
- 02:31
it possible for us to do way more work than
- 02:34
necessary to achieve something that could have been done more 00:02:36.78 --> [endTime] easily Another way Well want want
Related Videos
AP Computer Science 1.2 GridWorld Case Study and APIs. What is the direction of the actor?
AP Computer Science 1.4 Standard Algorithms. How many times will mystery be called for mystery(n) for n > 1?
AP Computer Science 2.3 Classes and Objects. Which of the following is correct implementation of the Country class?
AP Computer Science 3.4 Inheritance, Abstraction, and Polymorphism. Which of the following will satisfy the conditional if statement for boo, str,...
AP Computer Science 4.2 Standard Algorithms. What kind of algorithm is the following?