ShmoopTube

Where Monty Python meets your 10th grade teacher.

Search Thousands of Shmoop Videos


AP Computer Science Videos 112 videos

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 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 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?

See All

AP Computer Science 1.5 Standard Data Structures 174 Views


Share It!


Description:

AP Computer Science 1.5 Standard Data Structures. Which of the following is a correct iterative implementation?

Language:
English Language

Transcript

00:00

Thank you We sneak And here's your shmoop twos you're

00:05

brought to you by the power of two dirt bikes

00:10

now close All right which of the following is a

00:12

correct iterated implementations right here your potential answers And why

00:19

would i miss you Power raise candy bar Okay well

00:26

there are a number of ways to populate an array

00:29

and the two most obvious are sequential and iterated implementations

00:33

Well sequential is exactly as it sounds going right down

00:36

the line manually giving values to each array element one

00:39

by one that's what's happening in answer e And because

00:43

we're in the market for an illiterate of solution rather

00:45

than sequential we can throw e out right away because

00:49

the values we're going to be filling the array with

00:52

are all mathematically related powers of two which are practically

00:56

blood relatives or like a really close biker gang we

00:59

could pretty easily is an illiterate of implementation Here We'll

01:03

just need a simple loop that travels down the array

01:05

via its indices and at each stop multiplies have value

01:09

by two and copies that product to the array before

01:12

moving on Well let's see if any of the remaining

01:14

loops fit the bill Option a looks good Really good

01:18

Luke runs without errors but it doesn't do right in

01:21

terms of the problem given which is to fill the

01:24

array with the first ten powers of two starting with

01:26

two So this option starts with one instead All right

01:30

Well in fact he has the same problem By the

01:34

way b is an interesting luke but makes a textbook

01:36

mistake on the very first line It fails to take

01:39

into account the old array index begins at zero thing

01:43

The energy er i being used as an inter reiter

01:46

should started zero because in a raise indexing scheme starts

01:50

at zero not one run This bit of code and

01:53

index zero would get skipped over So no good but

01:56

just leave c which is our answer It heroically starts

01:59

it's iterated zero and the first value power at two

02:04

While eyes less than the total length of the array

02:06

it'll go through loop that changes the current array element

02:09

to the value of power Cia network Change the value

02:13

of power to be itself times two and increases the

02:16

value of the it aerator by one and that's the

02:18

whole hot well

Related Videos

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 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 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,...

AP Computer Science 4.2 Standard Algorithms
191 Views

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