ShmoopTube

Where Monty Python meets your 10th grade teacher.

Search Thousands of Shmoop Videos

AP Computer Science 2.5 Standard Algorithms 176 Views


Share It!


Description:

In this computer science drill question, figure out which implementation will copy one array over to another.

Language:
English Language

Transcript

00:00

Thank you We sneak And here's your shmoop du jour

00:05

brought to you by people who can say the alphabet

00:07

backwards either they're extremely smart they know how to integrate

00:11

backwards through an array or they've just done a lot

00:13

of sobriety tests and you don't want to go there

00:17

All right Which of the following implementation successfully copies over

00:21

array my alf to a realist alphabet All right And

00:26

here your potential answers brought to you by the romans

00:32

Okay option one uses a for each loop which will

00:35

cycle once for each element in an array In this

00:39

case for each string in the array my alf will

00:42

add the content of that element to the array list

00:45

alphabet and the loop will in as soon as we've

00:48

reached the end of my alf that's about as simple

00:51

as it gets and it will totally work all right

00:54

Option two option two creates an iterated that begins at

00:57

zero And while the current element of my health is

01:01

not equal to z where it'll add that particular value

01:06

to alphabet add one to the generator and do it

01:08

all over again Do that to me one more time

01:13

Great hold when the wild statement finally does find a

01:16

value equal to z it'll end the loop and travel

01:19

down to the next statement adding the current value of

01:21

my alf meaning z we just found the alphabet so

01:25

option two fits the bill to woo hoo wiseguys will

01:29

have already noticed that none of the possible answers are

01:31

all three options work and think we're totally done here

01:33

but because we're also smart and uptight about things we're

01:37

going to not just assume the answer is d all

01:39

right so let's just check out option three and be

01:41

sure it doesn't work looks decent on first glance right

01:45

Well standard looking loop something niggling with the array list

01:47

Nothing obviously a miss Ah wait we can't use that

01:51

alphabet dot set call on indices that don't exist yet

01:55

remember our ray list alphabet is totally empty all set

01:58

replaces elements that already existe with other elements We need

02:01

to use an ad call instead and if we're being

02:04

nitpicky Well that four loop set up is saying well

02:08

i is less than alphabet dot size and that would

02:11

have to be changed to the size of alphabet at

02:13

this stage would be zero so the loop would never

02:16

run in all changing that terminator parameter to while i

02:20

is less than my health dot length it would allow

02:22

the loop to run the full twenty six Anyway we're 00:02:26.018 --> [endTime] done Wait Okay we're leaving we're leaving

Related Videos

AP Computer Science 1.4 Standard Algorithms
200 Views

AP Computer Science 1.4 Standard Algorithms. How many times will mystery be called for mystery(n) for n > 1?

AP Computer Science 4.2 Standard Algorithms
191 Views

AP Computer Science 4.2 Standard Algorithms. What kind of algorithm is the following?

AP Computer Science 1.2 GridWorld Case Study and APIs
493 Views

AP Computer Science 1.2 GridWorld Case Study and APIs. What is the direction of the actor?

AP Computer Science 2.3 Classes and Objects
191 Views

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
204 Views

AP Computer Science 3.4 Inheritance, Abstraction, and Polymorphism. Which of the following will satisfy the conditional if statement for boo, str,...