AP® Computer Science—Semester B
Code this.
- Course Length: 18 weeks
- Course Type: AP
Schools and Districts: We offer customized programs that won't break the bank. Get a quote.
This course has been approved by the College Board, which indicates that the syllabus "has demonstrated that it meets or exceeds the curricular expectations colleges and universities have for your subject." Please contact sales@shmoop.com if you would like to add this course to your official record of AP course offerings.
It has also been granted a-g certification, which means it has met the rigorous iNACOL Standards for Quality Online Courses and will now be honored as part of the requirements for admission into the University of California system.
After a semester of 1337 hacking, you might think you know computers—but you do know you know computers? Any time you're sitting in your IDE, coding away your own version of Samantha and you hit a
NullPointerException
, what is there to help you figure out what's going on?
…Besides Java's extensive API. (Let's face it, those explanations are almost as unreadable as the code itself. )
Sure, you could try to hack around the problem, but the more variables and conditionals throw in, the less your code looks like code, and the more it starts to look like spaghetti.
Stick with us and you'll learn everything you'll need to know about making code that's designed instead of just built. By going more thoroughly into
- recursion
- sorting algorithms
- object-oriented programming
- software engineering strategies
you'll get your fill of all the ways code should be built. We'll even throw in a slew of programming assignments so that you can go straight from learning about merge and insertion sort to actually programming them on your own—spaghetti stain cleaner not included.
PS: This is a two-semester course and you're looking at Semester B. Trying to find the place where you learn about for loops and methods? Head on over to Semester A.
AP® is a trademark registered and/or owned by the College Board, which was not involved in the production of, and does not endorse, this product.
Unit Breakdown
7 AP® Computer Science—Semester B - The World of Recursion
From factorials to fractals, we'll be diving into the world of recursion, binary trees, and file systems. Stack overflows come free of charge.
8 AP® Computer Science—Semester B - It Takes All Sorts
Sometimes the only thing you can do with an unruly list is sort it. But to sort it, you're going to need to know some of the most popular algorithms, like merge, insertion, selection, and Quicksort. You've got an as-sort-ment of algorithms to pick from (…yeah, we groaned at that one, too).
9 AP® Computer Science—Semester B - Orienting All the Objects
Now that you know so much more about programming than you did before, we're heading back to the land of object-oriented programming, which happens to be Java's home town. Don't worry: we'll stop it before it tries to take you on a tour of its Great Aunt Betsy's favorite Laundromat.
10 AP® Computer Science—Semester B - In Defense of Software Engineering: A Coder's Manifesto
If programming alone wasn't cutting it for you, don't worry: we're talking about working on projects with others in this unit. We'll talk about all the rules of the road for coding together. Except body odor. That's a personal conversation you'll have to have without us.
11 AP® Computer Science—Semester B - Putting the AP in AP CS
Reviewing for the AP Exam's so important that we're giving you an entire unit to do it. Don't worry: we'll guide you through all the material you need to know. Instead of being the scenic route, though, you'll be on the 30-Minutes-or-Less tour. It might be terrible for tours of national museums, but it's great for rehashing CS concepts you're rusty on.
Sample Lesson - Introduction
Lesson 7.03: Identifying the Cases Lab
(Source)
One of the toughest parts of learning recursion is knowing where to get the base and recursive cases. It's like baseball players trying to find home plate. If
- the plate wasn't a different shape
- players weren't taught the rules of the game
they would just keep running until they…well, ran out of steam (probably).
Or out of innings.
For those who aren't into America's Favorite Pastime, do you remember learning how to read? That's a huge hurdle for most people. We bet you remember when street signs looked like they were in an alien language.
No? Just us?
Regardless of your sports preferences or planetary origins, you probably read without thinking now—going from one word to the next, connecting the sentence as a whole as if it isn't even a thing.
Stop for just a sec and think about what you're actually doing. You identify each letter, and attach it to a sound. You string those sounds together to make words, which each have their own meaning. In the bigger picture, you understand a sentence, this collection of words combining to make a complicated idea. Even further, you piece together a paragraph, a page, even an entire book.
Whoa.
Think about the last book you read. Do you remember the sentences in it? How about the words or letters? With the exception of a really great quote, it isn't likely. Yet somehow, you can tell your friend what happened in your favorite book. Even if you don't read a lot, you can apply all of these same things to the last movie or TV show you watched. Once you understand the underlying process, piecing together the greater whole is a breeze.
Even if a couple of scenes and lines get lost along the way.
Learning to think in a programming language is just like that process. You're learning your letters, your words, and how to make sentences. There are times now where you can step back and make abstract sense out of the groups of sentences you put together. Base cases, recursive cases, and infinite recursion are fundamental to making that abstract thought into something tangible.
Pretty soon, you'll be creating "essay-length paragraphs" in your IDE like a pro.
Sample Lesson - Reading
Reading 7.7.03: Reading the Recursion
You'll do all kinds of reading recursive methods today, Shmooper, but before you do, you need to know more about how to read recursive methods.
Remember that book you had all the way back in Semester A? It was called Introduction to Programming with Java: A Problem Solving Approach, written by John and Raymond Dean, remember? Is it near you? If not, go run and get it.
We'll wait.
Once you've got it, turn to page 477 and read through till you hit Figure 11.4 on 479. It's going to explain a great way of following recursive methods using a trace.
You might remember traces from the unit on loops, and…they're pretty much the same(-ish). Loops and recursion are pretty similar, but the key difference here is that you'll need an entire table to follow something recursive.
Whew.
That's pretty organized, but you'll need to be organized to follow a recursive method. If you label out each call to the method in a column and write in the values of the different variables, it's going to be pretty clear how the numbers change.
Now that we're on the topic of loops, though, go ahead and read through Section 11.4 on pages 480 – 484. It's going to go through all the important components that let you convert between loops and recursion.
Like we said, loops and recursive methods are very similar. Depending on the recursion, you can convert between loops—which overtly iterate through items—and recursive methods—which do the same thing, just implicitly. You'll see what we mean when you read it, though.
Take notes on
- how you should set up the table to trace a recursive method.
- converting between recursion and loops.
You'll need those skills right…about…
Now.
Sample Lesson - Activity
Activity 7.03: Reverse the Recurse
You've already looked at how to identify base and recursive cases, but let's do a bit of a recap. To keep from infinite recursion (and…um, making sure it runs at all) you need to find
- the base case, which ends the recursion. Unlike the recursive case, this is the one that just returns a value up the call stack, promising the end to the method. Sometimes it does something before returning—but never after. If it did, that would be like trying to make a method do something after it's already returned. That just doesn't work. There's always at least one base case. If there wasn't one, the fun wouldn't stop. By fun, we mean nightmarish infinite recursion.
- the recursive case, which is the star of the show. This calls the method again, usually with a different value that's closer to your overall goal case (read: base case). Sometimes it performs other actions before or after calling itself again. That's because calling itself can happen anywhere before the recursive case itself returns. We always have at least one recursive case involved in recursion. (Cough, cough: recursive, recursion…don't know, they sound kinda related. Just throwing that out there.)
- early-exit cases, which are generally used to catch inputs that could make the method run infinitely—or not at all. Humans write code, after all, so don't be surprised if they put in a -39 when you were expecting a positive number. (Ugh, humans, are we right?) These early-exit cases help you handle things gracefully and return a reasonable value. Sometimes, the recursive and base cases cover all possibilities, so you might not need an early-exit case. It just depends.
Then there's this little thing called infinite recursion (maybe you've heard us mention it once or twice?). When the method calls itself without ever stopping, we're in hot water. That's going to happen any time we don't hit a base case or there's a way that you can't reach the base case. Thankfully, as you know, Java sends you an error message, but because recursion has so little written-out code, it's hard to debug those lines.
Here's a concrete example of infinite recursion: if the base case checks whether the argument is less than a certain value, you don't want the recursive case to start higher than that value and go up. In that case, the method would be stuck in an infinite loop calling the method with larger and larger numbers.
Comprehension Check Rubric - 40 Points
- Course Length: 18 weeks
- Course Type: AP
Schools and Districts: We offer customized programs that won't break the bank. Get a quote.