Ap Exam Csa Crunch Sheet
Ap Exam Csa Crunch Sheet
6 13 17 20 31
Insertion Sort Unit 10: Recursion public static int factorial(int num){
20 31 6 17 13 if(num >= 1)
return num * factorial(num - 1);
Current index looks A recursive method calls itself, and each call has its own local else
“backwards” 20 31 6 17 13 variables. Remember to include a BASE CASE! return 1;
through the array to }
find where it should 6 20 31 17 13
Step 1: Assign the low index to 0 and the high index to the highest index. ∎ Written recursively
Binary Search
Step 2: While the lowest index is less than or equal to the highest index, find the middle index.
∎ Don't need to know the code
Merge Sort
be inserted at. Step 3: If you find the value of the number at the middle index, return it.
Elements are shifted 6 17 20 31 13 Otherwise, check to see if that value is higher than the middle element. ∎ Fast on large datasets
from the point of If it is, look through the higher part of the array by making your low index ∎ Breaks down an array into
equal to the middle index. single arrays; rebuilds the arrays
insertion. 6 13 17 20 31 Otherwise, look through the lower half of the array by switching the high
index to the midpoint.
into a single sorted array
Downloaded by Cerise Tsoi (tsoicerise@gmail.com)
lOMoARcPSD|33456997
a superclass (whatever type the object is DECLARED as, that • child class (subclass) – the class that is doing the inheriting. It inherits access to the object instance
method needs to be in that class or a parent of that class) at variables and methods in the parent class. Private instance variables still have to be called with accessor.
compile time. The program will not compile if this is not satisfied. Private methods are not inherited.
• When the program runs, the method that runs is determined from
what the object was CREATED as. • overridden method – A child class can have the same method signature (method name and parameter list)
as a parent class. Since methods are executed starting with the class that created the object (think: what
TechTool t2 = new LapTop(); constructor did I use?), that method will be called instead of the inherited parent method, so the child method
t2.toString(); overrides the parent method.
This will check to make sure that toString() is in the • overloaded method – At least two methods with the same name but different parameter lists. The parameter
TechTool class. If it is, it will compile. Then, when the program lists can differ by the number of parameters and/or the types.
is executed, it will look in the LapTop class first for the public static double area(int side)
toString() method and run it if it find it there. public static double area(int length, int width)
Object Superclass: All classes in Java extend the Object class.
//returns a String describing the object //returns true if this object is equal to another
//default implementation: ClassName@MemoryAddress //default implementation only checks for reference equality
public String toString() public boolean equals(Object other)