• Shuffle
    Toggle On
    Toggle Off
  • Alphabetize
    Toggle On
    Toggle Off
  • Front First
    Toggle On
    Toggle Off
  • Both Sides
    Toggle On
    Toggle Off
  • Read
    Toggle On
    Toggle Off
Reading...
Front

Card Range To Study

through

image

Play button

image

Play button

image

Progress

1/28

Click to flip

Use LEFT and RIGHT arrow keys to navigate between flashcards;

Use UP and DOWN arrow keys to flip the card;

H to show hint;

A reads text to speech;

28 Cards in this Set

  • Front
  • Back
  • 3rd side (hint)

Merge sort time complexity

O(n log n) in every case. Always divides the array into two halves and then merges the arrays in linear time.

Divides the array in half until down to a single unit, then merges them all.

Merge sort space complexity

O(n) it requires an equal amount of extra space as the original list, so it's not recommended for large unsorted lists.

Bubble sort space complexity

O(1) because it only requires a single additional unit for the temp variable.

Anonymous Array

An array in Java created by a keyword new with an array initializer.

Ragged Array

A degenerate matrix where rows have different numbers of column elements. Visualized as jagged. An array of arrays where the first is two elements, another is three, another is one, etc.

Big O Definition

Denotes "fewer than or the same as" <expression> iterations. The set of functions that grow slower than or the same as the rate of expansion. Described the worst case run time of the function

Big Omega Definition

Denotes "more than or the same as" <expression> iterations. The set of functions that grow faster than or the same as the rate of expansion.

Big Theta

Denotes "the same as" <expression> iterations. Consists of all the functions that lie in both Big O and Big Omega.

Little O

Denotes "fewer than" <expression> iterations.

Little Omega

Denotes "more than" <expression> iterations.

Predicate

A predicate is a function that returns true or false. It is generally used to make a decision about an action to take.


someMethod(..., (Unity Engineer. Color c) => c== Color.white,...) ;

Bubble Sort Definition

Sorts N elements. It compares all elements one by one and sorts them based on their values. Each iteration through the smaller elements bubble up toward the front of the array.


It compares two numbers and if they are out of order, it swaps them before moving in to the next two numbers.

Determine When To Stop Sorting


(Bubble Sort)

Use a flag. If no swaps were made for the entire iteration, then the array is sorted and you can stop.

Bubble Sort Time Complexity

Best: O(n) when already sorted.



Worst and Average: O(n^2)


because every item must be compared against nearly every item. (n-1)+(n-2)+...+1 = n(n-1)/2 = n^2

Insertion Sort Definition

Sorts the array by shifting elements one by one. We have a sorted section and an unsorted section. We start at position 2 and compare it to the numbers before it, then put the number in the correct position. The sorted section is thus always in order.

Insertion Sort Stats

Stable


Adaptive


Efficient for small sets, inefficient for large sets.


Better Rohan selection or bubble sort.

Stable Definition

A stable sort does not change the relative order of the elements with equal keys. If R and S have the same key, but R came before S in the original list, a stable sort keeps R before S in the sorted list.

Adaptive Definition

If the sort takes advantage of the presortedness of the input. A presented array may make a sort linear time instead of quadratic.

Insertion Sort Time Complexity

Best Case: O(n) when array is sorted.



Average and Worst Case: O(n^2). Because each item must be compared with nearly every other item in order to find the correct location.

Static Variable / Class Variables

Only one instance of the variable, at the class level. Usually as you create new instances of the class, each instance gets its own copy of the variable. If however you wanted to keep track of total books you could have a static variable. Referenced by



ClassName.variableName instead of using the instance name.



Book.totalBooks += 1 instead of


MobyDick.totalBooks += 1

Static Method / Class Method

Often used to access static variables, but they cannot access instance variables since they are part of the class, not of the specific instance.


ClassName. methodName() ;

Constants

Static final VARIABLENAME


The values of a final variable cannot change.


Constant names are all caps.


They cannot be reassigned.


If it is a primitive or string then at compile time the compiler actually replaces every instance of the variable with the value.

Java Default Initialization

Boolean false


Byte 0


Int 0


Char \u0000


Double 0.0d


Object reference null

this()

Used in constructors, it must be the first thing. It's used to call other constructors. The code after this() will execute after the invoked constructor completes.

Super()

Used in the constructor. Must be the first thing in it. Used to call the constructor of the Super class. Almost always used with arguments since the default constructor is always called anyway unless you specifically use this() or a super with arguments.

In place sorting algorithms

Quicksort


Heapsort

What is in place sorting?

It does not mean you can't create additional variables. It means you can't create a copy of the input. No copy of array to move the sorted array into.



It works directly on its input which means the original is destroyed.

Prototype Pattern

You create a prototype interface that contains a clone method.



You extend it into concrete classes that employ the clone method to clone themselves.



If object creation is slow or compute heavy (reading lots of data from database for example) it is faster to copy an object already created.



You can clone an object just by knowing its base type.