abstract data type
used for indexing data points
data structure made of nodes and pointers
explores levels in order
every node in a level should be visited before going to next level
starts at root, ends at leaves
total number of nodes in the longest path from the root to a leaf
if no node, height is 0
if 1 node, height is 1
length of the longest path from the root to a leaf
if no node, height is -1
if 1 node, height is 0
a self-balancing BST
difference between the height of the left and right subtree cannot be more than 1 for all node (balanced)
1.) All empty trees are also AVL trees
2.) If T is a non-empty BST with TL and TR as its left and right subtrees, then T is an AVL tree iff:
TL and TR are also AVL trees
|hL - hR| <= 1
height of the left subtree minus the height of the right subtree
hL - hR or hR - hL
an abstract data type
must be a complete binary tree
all values stored in the subtree of a given node are less than or equal to the value stored in the node
root stores highest value of any given subtree
all values stored in the subtree of a given node are greater than or equal to the value stored in that node
root stores the smallest value of any given subtree
elements are inserted in order of arrival
element with highest priority is processed/removed first
each element of V
AKA point, node
each element of E
AKA link
number of vertices (cardinality of V)
denoted by |V|
cardinality of E
denoted by |E|
each vertex adjacent to a given vertex is listed
space: O(|V| + |E|)
takes O(|V|) time to check if vertex u is adjacent to vertex v
|V| x |V| binary matrix
A(u,v) = 1 if (u,v) is an edge, else it equals 0
space: O( |V|^2 )
O(1) time to check if vertex u is adjacent to vertex v
(|V|) time to list all neighbors
a tree that spans undirected and connected graph G and is a subgraph of G
includes every vertex of G and every edge in the tree belongs to G
simple, intuitive algorithm used in optimization problems
tries to find overall optimal way to solve entire problem
builds spanning tree by adding edges one by one into growing spanning tree
follows greedy approach → finds an edge with least weight and adds it to tree
keeps track of vertices already included in MST
picks vertices with minimum key value to add to MST and updates key value of all adjacent vertices
Given an array of n numbers, sort the array in n steps
Steps
Scan the entire array and find smallest element
Swap smallest element with element at index i
Increment i
Repeat until i = n
Using divide and conquer, break down the array and sort each part
Then, merge the pieces back together
runtime complexity:
adding a record: O(1)
deleting a record: O(n)
searching for a record: O(n)
runtime complexity:
adding a record: O(n)
deleting a record: O(n)
searching for a record: O(logn) → binary search
runtime complexity:
adding a record: O(logn)
deleting a record: O(logn)
searching for a record: O(logn)
runtime complexity:
adding a record: O(1)
deleting a record: O(1)
searching for a record: O(1)
special type of array
each record has own exclusive cell → large array
pro: O(1) time complexity for everythin
con: space complexity is huge
a mathematical calculation that maps the search key to an index in a hash table
time complexity for calculating: O(1)
a way to access a table/array in constant time
uses a hash function and collision resolution scheme
when a hash function maps 2+ search keys into the same location in a hash table
h(key1) = h(key2)
only select a few digits instead of whole integer
ex: h(4324494421) = 432
pro: fast and easy to calculate
con: does not distribute randomly
adds digits of the integer together
ex: h(123456789) = 1+2+3+4+5+6+7+8+9 = 45
can add in different ways for hash tables of diff sizes:
ex: h(123456789) = 123+456+789 = 1368
uses prime number for table size to reduce collisions
h(x) = x mod (tableSize)
ex: h(123456789) = 123456789 mod 31 = 2