1/52
Looks like no tags are added yet.
encapsulation
bundling of data and methods within a class
accessibility
public - everywhere
private - same class
protected - same package and subclasses
overriding
child provides new implementation of a method that was defined in the parent class
dynamic binding
method executed is determined at runtime by object type
Arithmetic Exception cause
divide by zero
Null Pointer Exception cause
using null reference
Array Index Out Of Bounds Exception cause
invalid array index
Number format Exception cause
invalid string to number conversion
IO Exception cause
file IO problems
recursion
method calls itself to solve smaller version of the same problem, must include base case and a recursive call
Stack Overflow Error cause
missing base case in recursion
lists
ordered collection allowing duplicates, maintains insertion order
ArrayList
resizable, fast random access, less memory
LinkedList
stores elements as connected nodes, slow random access, fast insertion/deletion at beginning or middle, more memory
time complexity of access and insertion/deletion of ArrayList and LinkedList
ArrayList - access O(1), insertion/deletion O(n)
LinkedList - access O(n), insertion/deletion O(1)
stack and its common functions
last in first out
push() - inserts element at top
pop() - removes top element
queue and its common functions
first in first out, implemented by classes such as LinkedList, ArrayDeque, and PriorityQueue
peek() - views the top
poll() - removes the top
priority queue
processes based on priority not insertion order
set
stores unique elements, O(n) insertion
sets lookup and ordering
HashSet - O(1) av and O(n) worst lookup, no ordering
LinkedHashSet - O(1) av and O(n) worst lookup, insertion order
TreeSet - O(log n) lookup, sorted order
map
stores data in key value pairs, O(n) insertion
maps lookup and ordering
HashMap - O(1) av and O(n) worst lookup, no order
LinkedHashMap - O(1) av and O(n) worst lookup, insertion order
TreeMap - O(log n) lookup, sorted order
time complexity of loop dividing by two or doubling
O(log n)
insertion and bubble sort time complexity
best O(n), av and worst O(n²)
quick sort time complexity
best and av O(n log n), worst O(n²)
merge and heap sort time complexity
best, av and worst O(n log n)
insertion sort
mark first element as sorted
starting at index 1, compare element with elements to the left until finding one smaller
repeat until sorted
bubble sort
start at first element and compare it to the next, swap if first is greater
continue for all adjacent elements in array to complete one pass, now last element is sorted
continue until a pass with no swaps
quick sort
pick a pivot and put all numbers smaller on left and all larger on right by going left to right
then swap the pivot to the correct location
repeat for left and right groups until sorted
merge sort
divide list into halves until single elements remain
sort back upward until list is sorted by combining the halves
heap sort
move largest element to the end and repeat until sorted
to create tree work backwards, completely filling in each level until moving to the next
stable sorts
insertion, bubble, and merge
insertion in binary search tree
start at root, go left or right depending on the value and insert when a null position is found
deletion in binary search tree (3 cases)
no children - just delete
one child - delete and move child to replace it
two children - find smallest value in right subtree and replace node that is being deleted
insertion/deletion in BST time complexity
best and av O(log n), worst O(n)
inorder traversal
left, root, right (ascending order in BST)
preorder traversal
root, left, right
post order traversal
left, right, root
AVL tree
self balancing binary search tree
AVL balance factor
= height left subtree - height right subtree
time complexity in AVL tree
insert/search/delete O(log n), rotation O(1)
hash table
stores values
hash function
maps key to an index
hash collision
hash function produces same table index for 2 keys
linear probing
checks consecutive slots
quadratic probing
jumps by increasing square values
double hashing
reduces collisions and most clustering
getDegree(#)
look at all points that have # in either spot, then how many unique neighbors there are (other number in points)
sum of vertex degrees
n(n-1)
number of edges
n(n-1) / 2
left bitwise shift
num1 × 2^num2
right bitwise shift
num1 / 2^num2