Python
zip
A function that allows us to combine two (or more) lists as inputs and returns an object that contains a list of pairs. Each pair contains one element from each of the inputs. Printing this object directly will only return the location of memory, so make sure to print(list(zipped_variable_name)) if you want to print the new list.
Merge Sort
A list is split into individual lists, these are then combined (2 lists at a time).
.index()
A method that returns the given index of the argument given index_of_element = my_list.index(element)
module
A module is a collection of Python declarations intended broadly to be used as a tool. Often referred to as "libraries" or "packages"
queue
A queue is a data structure which contains an ordered set of data. Queues provide three methods for interaction: Enqueue - adds data to the "back" or end of the queue Dequeue - provides and removes data from the "front" or beginning of the queue Peek - reveals data from the "front" of the queue without removing it can be implemented using linked lists or arrays bounded queues have a limited size and therefore can have a queue overflow First In First Out structure
Bubble Sort Algorithm
A sorting algorithm that makes multiple passes through the list from front to back, each time exchanging pairs of entries that are out of order. If the element on the left is greater than the one on the right it swaps. The result is a list from lowest to highest. Run time of O(n^2)
separate chaining
A strategy to deal with hash collisions. Is mapping each array index points to some other data structure such as a linked list, another hash map, etc
super()
A way of overriding a parent class' method by adding logic or functionality to that method, without rewriting it when we simply override it
exception
An Exception is a class that inherits from Python's Exception class.
dictionary
An unordered set of key: value pairs.
probing
Finding a new open array index in a fixed pattern until an empty index is found
adjacency list
Graph representation where each vertex has a list of all the vertices it shares an edge with.
adjacency matrix
Graph representation where vertices are both the rows and the columns. Each cell represents a possible edge. 1 means an edge, 0 means no edge in weighted graphs the number in the matrix represents the weight of the path
Inheritance
In object-oriented programming, inheritance enables new objects to take on the properties of existing objects. A class that is used as the basis for inheritance is called a parent class, superclass, or base class. A class that inherits from a superclass is called a child class, subclass or derived class
Binary Search
Looking for an item in an already sorted list by eliminating large portions of the data on each comparison. Since each step we cut the list in half we get O(log N)
constructors
Methods that are used to prepare an object being instantiated
len()
Returns the number of elements in that list
list comprehension
Shorthand notation for for loops new_list = [#expression#for statement#conditional]
.pop()
The .pop() method will take an item off of the end of a list: my_list = [1, 4, 10, 15] number = my_list.pop() #number is now 15
nodes
The basic building block for many computer sciene data structures. An individual node contains data and links to other nodes, or null if its the end of a node path
Big Omega
The best case runtime of the program
edge
The connection in a graph between two vertices.
Asymptotic Notation
The notation we use to demonstrate how a programs runtime by looking at how many instructions the program has to do. It is done this way since computers all have different processing speed
Big Theta
The runtime of the program, usually used if the runtime is the same in every case
Big O
The worst case runtime of the program
open addressing
Uses probes to find an open location to store data.
min-heap
a binary tree with two qualities: 1) the child node is always a greater value than the parent node 2) the root is the minimum value of the dataset
max-heap
a binary tree with two qualities: 1) the child node is always a lesser value than the parent node 2) the root is the maximum value of the dataset
cycle
a completed path in a directed graph where you start and end at the same vertex
hash map
a complex data structure that is: Built on top of an array using a special indexing system. A key-value storage with fast assignments and lookup. A table that represents a map from a set of keys to a set of values.
stack
a data structure which contains an ordered set of data. Stacks provide three methods for interaction: Push - adds data to the "top" of the stack Pop - returns and removes data from the "top" of the stack Peek - returns data from the "top" of the stack without removing it can have a limited size is First In Last Out
recursive function
a function that calls itself
type()
a function that returns the type of datatype its argument is
range
a function that takes a single input, and generates numbers starting at 0 and ending at the number before the input. So, if we want the numbers from 0 through 9, we use range(10) because 10 is 1 greater than 9:
hash function
a function that takes a string or some type of data and returns an array index
sorted()
a function used to create a new list that is the sorted version of the list passed threw it new_sorted_list = sorted(my_list)
directed graph
a graph where an edge has a direction associated with it
weighted graph
a graph where the pathways(edges) are weighted in some way, distance, steepness, etc. Useful for algorithms in finding the shortest path
Linear Search
a method for finding a target value within a list. It sequentially checks each element of the list for the target value until a match is found or until all the elements have been searched. Best case is its the first element O(1), worst case is last or no element O(N), avg is O(N/2) = > O(N)
.lower()
a method that returns the string with all lowercase characters.
.upper()
a method that returns the string with all uppercase characters.
.title()
a method that returns the string with the first letter of each word capitalized
.format()
a method that takes variables as an argument and includes them in the string that it is run on. You include {} marks as placeholders for where those variables will be imported.
.count()
a method used on lists that counts the number of cells that match the argument you pass it
.sort()
a method used on lists that sorts your list alphabetically or numerically
.append()
a method used to add a single element to a list.
.update()
a method used to add multiple key:value pairs to a dictionary
.join()
a method used to join a list of strings together. the delimiter goes before the method, and the list is the argument passed into the method
.strip()
a method used to removes all whitespace from both sides of a string. you can also pass something in it as an argument that will be stripped instead
.replace()
a method used to replace something with something else in a string
.find()
a method used to search for a string within a string and return the first index value of where the string is
.split()
a method used to split strings wherever the argument passed through it is found, defaults to spaces
(__repr__)
a method we can use to tell Python what we want the string representation of the class to be. __repr__ can only have one parameter, self, and must return a string. stands for string represenetation
vertex
a node in a graph
parent
a node which references other nodes
leaf
a node with no children
root
a node with no parent. one per tree
heap
a non-linear data structure used to maintain a maximum or minimum value in a dataset. min heap- heap where top(root) value is the smallest value max heap - heap where top(root) value is the largest value often used for priority queues
graphs
a nonlinear data structure made up of vertices(nodes of data) and edges(the pathways between the nodes). the edges have varying pathways of connection the vertex-edge relationship usually represented in two ways: 1) adjacency list 2)adjacency matrix
path
a sequence of one or more edges between verticies
Quicksort
a sorting technique that moves elements around a pivot and recursively sorts the elements to the left and the right of the pivot
class
a template for a data type. It describes the kinds of information that class will hold and how a programmer will interact with that data.
binary tree
a tree in which each node has at most two children. Further constraints make a binary search tree: Left child values must be lesser than their parent. Right child values must be greater than their parent.
linked lists
a type of data structure in computer science. It is made up of nodes, starting with a start node and ending with an end node. since the nodes use links to denote the next node in the sequence, the data does not need to be saved sequentially. Common operations on a linked list may include: adding nodes removing nodes finding a node traversing (or travelling through) the linked list
Try-Except Statement
a type of statement that runs the 'try' part and if there is no error continues past the 'except' part; however, if there is an error it jumps to the except section and runs that code
Radix Sort
an O(n*k) search algorithm where K = keylength. Stable. Sorts input into bins based on the lowest digit; then combines bins in order and sorts on the next highest digit & so forth.
object
an instance of a class
list
an ordered set of objects; can be strings, numbers, or even other lists!
growing a list
can be done by both .append() or + [list_object1. list_object2]
slicing
creating a section from a list. done with : notation select 1st to 4th elements = [0:3] or [:3] selecting elements after 4th =[3:] last 3 elements = [:-3]
object-oriented programming
designing a program by discovering objects, their properties, and their relationships
how to create an empty list in python
empty_list = []
nested loop syntax
for <inner_lists> in <outer_list>: for <elements> in <inner_list>: <action>
for loop syntax
for <temporary variable> in <list variable>: <action> for <temporary variable> in range(<number of times we want repeated>): <action>
module syntax
from module_name import object_name
dir()
function to investigate an object's attributes at runtime
methods
functions that are defined as part of a class
while loop syntax
index = 0 while index < len(<list>): print(<list>[index]) index += 1
.items()
it returns a dict_list object. Each element of the dict_list returned by .items() is a tuple consisting of: (key,value)
continue
keyword to move to the index to the next value in the list, without executing the code in the rest of the for loop.
break
keyword to stop your for loop and proceed to next line outside of loop
How to select last item in a list
last_element = list[-1]
dictionary syntax
menu = {"oatmeal": 3, "avocado toast": 6, "carrot juice": 5, "blueberry muffin": 2} KEY : VALUE
init constructor (__init__)
method is used to initialize a newly created object. It is called every time the class is instantiated.
.keys()
method that returns a dict_keys object for all keys in the dictionary.
.values()
method that returns a dict_values object (just like a dict_keys object but for values!) with all of the values in the dictionary.
.get()
method to search for a value instead of the my_dict[key] notation we have been using. If the key you are trying to .get() does not exist, it will return None by default:
add a key syntax
my_dict["new_key"] = "new_value"
.append() syntax
my_list.append(new_list_element)
child
node referenced by other nodes
sibling
nodes which have the same parent
map
relating two pieces of information, in which every key that is used can only have one single value
combining lists into dictionary
students = {key:value for key, value in zip(names, heights)}
level
the height or depth of the tree.
Try-Except Statement syntax
try: raises_value_error() except ValueError: print("You raised a ValueError!")
polymorphism
using the same syntax to do different things. For instance, "+" can do several different things such as addition, combining strings, or growing a list
heapify up
when adding new data to the heap, the data is swapped with the parental nodes of the heap until the qualities of the heap remain true
adjacent
when an edge exists between two vertices
heapify down
when removing data(the root) from the heap, the new root is the bottom rightmost node and then is swapped with children nodes until the qualities of the heap remain true. if the node has two children that are both lesser values it swaps with the more less value
hash collision
when two (or more) keys hash to same slot common solutions: saving keys seperate chaining open addressing