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