Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

Java Data Structures Cheat Sheet

by Ieternalleo via cheatography.com/45716/cs/13401/

Array Linked List Hash Map

Defi​‐ - Stores data elements based on an Defi​‐ - Stores data with nodes that point to Defi​‐ - Stores data with key value pairs. -
nit​io‐ sequen​tial, most commonly 0 based, nit​io‐ other nodes. - Nodes, at its most basic nit​io‐ Hash functi​ons accept a key and
n index. - Based on [tuple​s] n it has one datum and one reference n return an output unique only to that
(​htt​p:/​/en.wi​kip​edi​a.o​rg/​wik​i/T​uple) from (another node). - A linked list _chains_ specific key. - This is known as
set theory. - They are one of the nodes together by pointing one node's hash​ing, which is the concept that an
oldest, most commonly used data reference towards another node. input and an output have a one-to-one
struct​ures. corres​pon​dence to map inform​ation. -
Deta​i - Designed to optimize insertion and
Deta​i - Optimal for indexing; bad at deletion, slow at indexing and Hash functions return a unique
ls
ls searching, inserting, and deleting searching. - Doubly linked list has address in memory for that data.
(except at the end). - Linear arrays, or nodes that reference the previous Deta​i - Designed to optimize searching,
one dimens​ional arrays, are the most node. - Circ​ularly linked list is simple ls insertion, and deletion. - Hash
basic. - Are static in size, meaning that linked list whose tail, the last node, collis​ions are when a hash function
they are declared with a fixed size. - references the head, the first node. - returns the same output for two distinct
Dynamic arrays are like one inputs. - All hash functions have this
Stack, commonly implem​ented with
dimens​ional arrays, but have reserved problem. - This is often
linked lists but can be made from
space for additional elements. - If a accomm​odated for by having the hash
arrays too. - Stacks are last in, first
dynamic array is full, it copies it's tables be very large. - Hashes are
out (LIFO) data struct​ures. - Made with
contents to a larger array. - Two important for associ​ative arrays and
a linked list by having the head be the
dimens​ional arrays have x and y database indexing.
only place for insertion and removal. -
indices like a grid or nested arrays. Queu​es, too can be implem​ented with Big- - Indexing: Hash Tables: O(1) -
Big- - Indexing: Linear array: O(1), Dynamic a linked list or an array. - Queues are a O Search: Hash Tables: O(1) - Insertion:
O array: O(1) - Search: Linear array: O(n), first in, first out (FIFO) data structure. effici​ Hash Tables: O(1)
effici​ Dynamic array: O(n) - Optimized - Made with a doubly linked list that ency
ency Search: Linear array: O(log n), only removes from head and adds to
Dynamic array: O(log n) - Insertion: tail. Binary Tree
Linear array: n/a Dynamic array: O(n)
Big- - Indexing: Linked Lists: O(n) - Search:
Defi​ - Is a tree like data structure where
O Linked Lists: O(n) - Optimized Search:
nit​i every node has at most two children. -
effici​ Linked Lists: O(n) - Insertion: Linked
on There is one left and right child node.
ency Lists: O(1)

By Ieternalleo Published 6th November, 2017. Sponsored by ApolloPad.com


cheatography.com/ieternalleo/ Last updated 6th November, 2017. Everyone has a novel in them. Finish Yours!
Page 1 of 3. https://apollopad.com
Java Data Structures Cheat Sheet
by Ieternalleo via cheatography.com/45716/cs/13401/

Binary Tree (cont) Search Basics Depth First Search (cont)

Deta​i - Designed to optimize searching and Deta​i - Optimal for searching a tree that is
ls sorting. - A dege​nerate tree is an ls deeper than it is wide. - Uses a stack
unbalanced tree, which if entirely one- Breadth First Search to push nodes onto. - Because a stack
sided is a essent​ially a linked list. - is LIFO it does not need to keep track
Defi​‐ - An algorithm that searches a tree (or
They are comparably simple to of the nodes pointers and is therefore
nit​io‐ graph) by searching levels of the tree
implement than other data struct​ures. - less memory intensive than breadth
n first, starting at the root. - It finds every
Used to make binary search trees. - A first search. - Once it cannot go further
node on the same level, most often
binary tree that uses comparable keys left it begins evaluating the stack.
moving left to right. - While doing this it
to assign which direction a child is. - tracks the children nodes of the nodes Big- - Search: Depth First Search: O(|E| +
Left child has a key smaller than it's on the current level. - When finished O |V|) - E is number of edges - V is
parent node. - Right child has a key examining a level it moves to the left effici​ number of vertices
greater than it's parent node. - There most node on the next level. - The ency
can be no duplicate node. - Because of bottom​-right most node is evaluated
the above it is more likely to be used as last (the node that is deepest and is
Breadth First Search Vs. Depth First Search
a data structure than a binary tree. An farthest right of it's level).
AVL Tree is a balanced binary search - The simple answer to this question is that it
Deta​i - Optimal for searching a tree that is
tree. -The process for inserting or depends on the size and shape of the tree.
ls wider than it is deep. - Uses a queue to
deleting is the same as in a - For wide, shallow trees use Breadth First
store inform​ation about the tree while it
regula​r(u​nba​lanced) BST, except you Search
traverses a tree. - Because it uses a
have to rebalance after each operation. - For deep, narrow trees use Depth First
queue it is more memory intensive than
A node in an AVL tree is balanced if its Search
depth first search. - The queue uses
balance factor is either -1,0, or 1
more memory because it needs to
Big- - Indexing: Binary Search Tree: O(log Nuances:
stores pointers
O n) - Search: Binary Search Tree: O(log - Because BFS uses queues to store
Big- - Search: Breadth First Search: O(|E| +
effici​ n) - Insertion: Binary Search Tree: inform​ation about the nodes and its children, it
O |V|) - E is number of edges - V is
ency O(log n) could use more memory than is available on
effici​ number of vertices
ency your computer. (But you probably won't have
The balance factor of a node is the height of
to worry about this.)
its right subtree minus the height of its left
- If using a DFS on a tree that is very deep you
subtree Depth First Search
might go unnece​ssarily deep in the search. See
Defi​ - An algorithm that searches a tree (or [xkcd]​(ht​tp:​//x​kcd.co​m/761/) for more
nit​i graph) by searching depth of the tree inform​ation.
on first, starting at the root. - It traverses left - Breadth First Search tends to be a looping
down a tree until it cannot go further. - algorithm.
Once it reaches the end of a branch it - Depth First Search tends to be a recursive
traverses back up trying the right child algorithm.
of nodes on that branch, and if possible
left from the right children. - When Efficient Sorting Basics
finished examining a branch it moves to
the node right of the root then tries to go
left on all it's children until it reaches the
bottom. - The right most node is
evaluated last (the node that is right of
all it's ancest​ors).

By Ieternalleo Published 6th November, 2017. Sponsored by ApolloPad.com


cheatography.com/ieternalleo/ Last updated 6th November, 2017. Everyone has a novel in them. Finish Yours!
Page 2 of 3. https://apollopad.com
Java Data Structures Cheat Sheet
by Ieternalleo via cheatography.com/45716/cs/13401/

Merge Sort Quicksort (cont) Merge Sort vs. QuickSort

Defi​‐ - A comparison based sorting algorithm Deta​i - While it has the same Big O as (or - Quicksort is likely faster in practice.
nit​io‐ - Divides entire dataset into groups of ls worse in some cases) many other - Merge Sort divides the set into the smallest
n at most two. - Compares each number sorting algorithms it is often faster in possible groups immedi​ately then recons​tructs
one at a time, moving the smallest practice than many other sorting the increm​entally as it sorts the groupings.
number to left of the pair. - Once all algori​thms, such as merge sort. - Know - Quicksort contin​ually divides the set by the
pairs sorted it then compares left most that it halves the data set by the average, until the set is recurs​ively sorted.
elements of the two leftmost pairs average contin​uously until all the
creating a sorted group of four with the inform​ation is sorted. Heap Sort
smallest numbers on the left and the Big- - Best Case Sort: Merge Sort: O(n) -
largest ones on the right. - This process Defini​tio Sorts using a complete binary Tree.
O Average Case Sort: Merge Sort: O(n
is repeated until there is only one set. n:
effici​ log n) - Worst Case Sort: Merge Sort:
Deta​i - This is one of the most basic sorting O(n^2) Details: Arra​yList can be used to store a
ency
ls algori​thms. - Know that it divides all the Heap
data into as small possible sets then For a node of i:
Bubble Sort
compares them. -Left child: 2i+1
Defi​‐ - A comparison based sorting algorithm -Right child: 2i+2
Big- - Best Case Sort: Merge Sort: O(n) -
Average Case Sort: Merge Sort: O(n nit​io‐ - It iterates left to right comparing every -Parent: (i - 1)/2
O
log n) - Worst Case Sort: Merge Sort: n couplet, moving the smaller element to
effici​ Big-O: O(nlogn)
O(n log n) the left. - It repeats this process until it
ency
no longer moves and element to the
left.
Quicksort
Deta​i - While it is very simple to implement, it
Defi​ - A comparison based sorting algorithm - ls is the least efficient of these three
nit​i Divides entire dataset in half by selecting sorting methods. - Know that it moves
on the average element and putting all one space to the right comparing two
smaller elements to the left of the elements at a time and moving the
average. - It repeats this process on the smaller on to left.
left side until it is comparing only two
Big- - Best Case Sort: Merge Sort: O(n) -
elements at which point the left side is
O Average Case Sort: Merge Sort: O(n2)
sorted. - When the left side is finished - Worst Case Sort: Merge Sort: O(n2)
effici​
sorting it performs the same operation
ency
on the right side. - Computer
archit​ecture favors the quicksort
process.

By Ieternalleo Published 6th November, 2017. Sponsored by ApolloPad.com


cheatography.com/ieternalleo/ Last updated 6th November, 2017. Everyone has a novel in them. Finish Yours!
Page 3 of 3. https://apollopad.com

You might also like