\documentclass[10pt,a4paper]{article} % Packages \usepackage{fancyhdr} % For header and footer \usepackage{multicol} % Allows multicols in tables \usepackage{tabularx} % Intelligent column widths \usepackage{tabulary} % Used in header and footer \usepackage{hhline} % Border under tables \usepackage{graphicx} % For images \usepackage{xcolor} % For hex colours %\usepackage[utf8x]{inputenc} % For unicode character support \usepackage[T1]{fontenc} % Without this we get weird character replacements \usepackage{colortbl} % For coloured tables \usepackage{setspace} % For line height \usepackage{lastpage} % Needed for total page number \usepackage{seqsplit} % Splits long words. %\usepackage{opensans} % Can't make this work so far. Shame. Would be lovely. \usepackage[normalem]{ulem} % For underlining links % Most of the following are not required for the majority % of cheat sheets but are needed for some symbol support. \usepackage{amsmath} % Symbols \usepackage{MnSymbol} % Symbols \usepackage{wasysym} % Symbols %\usepackage[english,german,french,spanish,italian]{babel} % Languages % Document Info \author{Paloma} \pdfinfo{ /Title (computer-science-midterm-2.pdf) /Creator (Cheatography) /Author (Paloma) /Subject (Computer Science Midterm 2 Cheat Sheet) } % Lengths and widths \addtolength{\textwidth}{6cm} \addtolength{\textheight}{-1cm} \addtolength{\hoffset}{-3cm} \addtolength{\voffset}{-2cm} \setlength{\tabcolsep}{0.2cm} % Space between columns \setlength{\headsep}{-12pt} % Reduce space between header and content \setlength{\headheight}{85pt} % If less, LaTeX automatically increases it \renewcommand{\footrulewidth}{0pt} % Remove footer line \renewcommand{\headrulewidth}{0pt} % Remove header line \renewcommand{\seqinsert}{\ifmmode\allowbreak\else\-\fi} % Hyphens in seqsplit % This two commands together give roughly % the right line height in the tables \renewcommand{\arraystretch}{1.3} \onehalfspacing % Commands \newcommand{\SetRowColor}[1]{\noalign{\gdef\RowColorName{#1}}\rowcolor{\RowColorName}} % Shortcut for row colour \newcommand{\mymulticolumn}[3]{\multicolumn{#1}{>{\columncolor{\RowColorName}}#2}{#3}} % For coloured multi-cols \newcolumntype{x}[1]{>{\raggedright}p{#1}} % New column types for ragged-right paragraph columns \newcommand{\tn}{\tabularnewline} % Required as custom column type in use % Font and Colours \definecolor{HeadBackground}{HTML}{333333} \definecolor{FootBackground}{HTML}{666666} \definecolor{TextColor}{HTML}{333333} \definecolor{DarkBackground}{HTML}{00BCC9} \definecolor{LightBackground}{HTML}{EFFAFB} \renewcommand{\familydefault}{\sfdefault} \color{TextColor} % Header and Footer \pagestyle{fancy} \fancyhead{} % Set header to blank \fancyfoot{} % Set footer to blank \fancyhead[L]{ \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{C} \SetRowColor{DarkBackground} \vspace{-7pt} {\parbox{\dimexpr\textwidth-2\fboxsep\relax}{\noindent \hspace*{-6pt}\includegraphics[width=5.8cm]{/web/www.cheatography.com/public/images/cheatography_logo.pdf}} } \end{tabulary} \columnbreak \begin{tabulary}{11cm}{L} \vspace{-2pt}\large{\bf{\textcolor{DarkBackground}{\textrm{Computer Science Midterm 2 Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{Paloma} via \textcolor{DarkBackground}{\uline{cheatography.com/55343/cs/15271/}}} \end{tabulary} \end{multicols}} \fancyfoot[L]{ \footnotesize \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{LL} \SetRowColor{FootBackground} \mymulticolumn{2}{p{5.377cm}}{\bf\textcolor{white}{Cheatographer}} \\ \vspace{-2pt}Paloma \\ \uline{cheatography.com/paloma} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Published 30th April, 2018.\\ Updated 30th April, 2018.\\ Page {\thepage} of \pageref{LastPage}. \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Sponsor}} \\ \SetRowColor{white} \vspace{-5pt} %\includegraphics[width=48px,height=48px]{dave.jpeg} Measure your website readability!\\ www.readability-score.com \end{tabulary} \end{multicols}} \begin{document} \raggedright \raggedcolumns % Set font size to small. Switch to any value % from this page to resize cheat sheet text: % www.emerson.emory.edu/services/latex/latex_169.html \footnotesize % Small font. \begin{multicols*}{3} \begin{tabularx}{5.377cm}{x{2.88351 cm} x{1.00694 cm} p{0.68655 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{5.377cm}}{\bf\textcolor{white}{Some Helpful Big Oh Analysis}} \tn % Row 0 \SetRowColor{LightBackground} Expansion & \seqsplit{Summation} & Big Oh \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} 1+2+3+4+....+ N & \seqsplit{N(N+1)/2} & O(N\textasciicircum{}2) \tn % Row Count 3 (+ 1) % Row 2 \SetRowColor{LightBackground} N+N+N+....+N & N*N & O(N\textasciicircum{}2) \tn % Row Count 4 (+ 1) % Row 3 \SetRowColor{white} \seqsplit{N+N+N+....+N+....+N+....+N} & 3N*N & O(N\textasciicircum{}2) \tn % Row Count 6 (+ 2) % Row 4 \SetRowColor{LightBackground} 1+2+4+....+ & 2\textasciicircum{}(N+1)-1 & O(2\textasciicircum{}N) \tn % Row Count 8 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}---} \SetRowColor{LightBackground} \mymulticolumn{3}{x{5.377cm}}{2\textasciicircum{}10 = 1024 \textasciitilde{}\textasciitilde{} 1000 \newline O- notation is an upper bound so N is O(N) but it is also O(N\textasciicircum{}2)} \tn \hhline{>{\arrayrulecolor{DarkBackground}}---} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Order of Growth Classifications}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{5.377cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/paloma_1522035265_Screen Shot 2018-03-25 at 11.32.22 PM.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Usually, nested for loops have a big O(N\textasciicircum{}2) because each of them runs n times. However, sometimes they can run less than n times. \newline \newline for (int i =0; i\textless{}N; i++) -{}-{}-\textgreater{} N times \newline for (int j =1; j\textless{}n; j - j{\emph{2) \newline \newline Big O is n}} log n times} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Big Oh Complexity}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{5.377cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/paloma_1522332887_Screen Shot 2018-03-29 at 10.14.02 AM.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Common Data Structure Operations}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{5.377cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/paloma_1522332934_Screen Shot 2018-03-29 at 10.14.12 AM.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.74195 cm} x{3.23505 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Arrays vs ArrayLists}} \tn % Row 0 \SetRowColor{LightBackground} Arrays & ArrayLists \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} They have a fixed size & Size can change \tn % Row Count 3 (+ 2) % Row 2 \SetRowColor{LightBackground} Much faster to add to & Adding to an arraylist is usually N \tn % Row Count 5 (+ 2) % Row 3 \SetRowColor{white} & But when you reach the max, the computer doubles the limit every time you hit the limit so it takes O(N) times -{}-\textgreater{} This is why it takes longer \tn % Row Count 11 (+ 6) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Circular Linked Lists}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{5.377cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/paloma_1522635682_Screen Shot 2018-04-01 at 10.20.31 PM.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Binary Search Tree}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{5.377cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/paloma_1522636383_Screen Shot 2018-04-01 at 10.29.39 PM.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{- Each node has a value \newline - Nodes with the values less than their parent are in the left \newline -Nodes with values greater than their parent are in the right subtree \newline - If equal, choose a side and stay consistent \newline - Insert from top of binary search tree and move down} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Binary Tree Insertion}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{5.377cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/paloma_1522642303_Screen Shot 2018-04-02 at 12.11.01 AM.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Appending Lists}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{5.377cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/paloma_1522675224_Screen Shot 2018-04-02 at 9.19.52 AM.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{BSTS to Lists}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{5.377cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/paloma_1522675007_Screen Shot 2018-04-02 at 9.16.22 AM.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{-{\bf{Trees:}} are nodes with two pointers \newline -{\bf{Doubly linked lists:}} also nodes with two pointers (allows for constant time access with one pointing to front and one pointing to back)} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Complete Binary Tree}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{- Every non leaf node has two children \newline % Row Count 1 (+ 1) - All the leaves are at the same level \newline % Row Count 2 (+ 1) - There are 2\textasciicircum{}N\textasciicircum{} -1 or O(2\textasciicircum{}N\textasciicircum{}) nodes with N levels \newline % Row Count 4 (+ 2) - There are 2\textasciicircum{}N-1\textasciicircum{} leaves with n levels% Row Count 5 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Priority Queues}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{5.377cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/paloma_1522639616_Screen Shot 2018-04-01 at 11.26.42 PM.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{- Minimum is first out \newline -Poll means remove the minimum each time \newline -List {[}0{]} will be smallest \newline -List {[}1{]} is smallest of all the ones that remain \newline -While a queue is first in first out, a priority queue is minium out first \newline -Shortest path} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Heaps}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{- Heap is an array-based implementation of a binary tree used for implementing priority queues and supports: insert, findMin, and deleteMin \newline % Row Count 3 (+ 3) -Using array minimizes storage (no explicit pointers) , faster too because children are locatd by index/position in array \newline % Row Count 6 (+ 3) Deletion: remove root and replace with right most child and then bubble down filling left to right \newline % Row Count 8 (+ 2) -{\bf{Properties:}} \newline % Row Count 9 (+ 1) - {\bf{shape:}} tree filled at all levels (except perhaps last) and filled in left-to-right (complete binary tree \newline % Row Count 12 (+ 3) - {\bf{value:}} each node has value smaller than both children \newline % Row Count 14 (+ 2) {\bf{Min Heap:}} \newline % Row Count 15 (+ 1) - Minimal element is at root, index 1 \newline % Row Count 16 (+ 1) -Maximal element has to be a leaf, because can't be greater than child \newline % Row Count 18 (+ 2) -Complexity of finding maximal elements, half nodes are trees -{}-\textgreater{} O(n/2) so O(n) \newline % Row Count 20 (+ 2) - Second smallest element must be one level below root% Row Count 22 (+ 2) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Using An Array For a Heap}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{5.377cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/paloma_1522684604_Screen Shot 2018-04-02 at 11.56.30 AM.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{- Store node values in array starting at index 1 \newline - For node with index k: \newline - {\bf{left child:}} index 2{\emph{k \newline -{\bf{right child:}} index 2}}k +1 \newline - {\bf{parent:}} index k/2} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Adding Values to Heap}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{5.377cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/paloma_1522684800_Screen Shot 2018-04-02 at 11.59.45 AM.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{- To maintain heap shape, must add new value in left-to-right order of last level \newline - This could violate heap property \newline - move value "up" if too small \newline - Change places with parent if heap property is violated and stop when parent is smaller and stop when root is reached \newline -Pull parent down} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Heap Add Implementation}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{5.377cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/paloma_1522684902_Screen Shot 2018-04-02 at 12.00.44 PM.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Tries}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{- Tries support add, contains, delete in O(w) time for words of length w \newline % Row Count 2 (+ 2) - Each node in a trie has a subtrie for every valid letter than can follow \newline % Row Count 4 (+ 2) -% Row Count 5 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Priority Queue Implementations}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{5.377cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/paloma_1522685029_Screen Shot 2018-04-02 at 12.03.01 PM.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Operations: O(log n) \newline add - add element to last spot and bubble up \newline remove/poll - remove root.min and take last element and bubble down} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Graphs Vocabulary}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{- A collection of vertices and edges \newline % Row Count 1 (+ 1) - Edge connections two vertices \newline % Row Count 2 (+ 1) - Direction can be imported, directed edge, directed graph \newline % Row Count 4 (+ 2) - Edge may have associated weight/cost \newline % Row Count 5 (+ 1) - A vertex sequence is a path where vk and vk+1 are connected by an edge \newline % Row Count 7 (+ 2) - If some vertex is repeated, the path is a cycle \newline % Row Count 9 (+ 2) - A graph is connected if there is a path between any pair of vertices \newline % Row Count 11 (+ 2) -Articulation Point breaks graph in two% Row Count 12 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Graphs DFS}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{5.377cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/paloma_1525015482_Screen Shot 2018-04-29 at 11.24.26 AM.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Envision each vertex as a room \newline Go into a room, mark the room, choose an unused door, exit \newline Don't go into room you've already been in-{}-\textgreater{} explore every vertex one time \newline qu is where we're going, visited is where we've been} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Adjacency Lists and Matrix}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{5.377cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/paloma_1525017331_Screen Shot 2018-04-29 at 11.53.47 AM.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Adjacency List: V+E spaces \newline Adjacency Matrix: V*E} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Sorting}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{5.377cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/paloma_1525018564_Screen Shot 2018-04-29 at 12.09.32 PM.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Creating Adjacency Matrix}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{public int howLong(String {[}{]} connects, String {[}{]} costs)\{ \newline int {[}{]} {[}{]} adjMatrix = new int {[}connects.length{]}{[}connects.length{]}' \newline for (int i =0; i\textless{}connects.length; i++)\{ \newline String {[}{]} edges - connects{[}i{[}.split(" "); \newline String {[}{]} weights = costs{[}i{]}.split(" "); \newline for (int j =0; j\textless{}edges.length; j++)\{ \newline adjMatrix{[}i{]}{[}Integer.partseInt(edges{[}j{]})) = Integer.parseInt(weights{[}j{]});} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.4885 cm} x{2.4885 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Analysis: Empirical vs. Mathematical}} \tn % Row 0 \SetRowColor{LightBackground} Empirical Analysis & Mathematical Analysis \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} Measure running times, plot, and fit curve & Analyze algorithm to estimate \# ops as a function of input size \tn % Row Count 6 (+ 4) % Row 2 \SetRowColor{LightBackground} Easy to perform experiments & May require advanced mathematics \tn % Row Count 8 (+ 2) % Row 3 \SetRowColor{white} Model useful for predicting, but not for explaining & Model useful for predicting and explaining \tn % Row Count 11 (+ 3) % Row 4 \SetRowColor{LightBackground} & Mathematical analysis is independent of a particular machine or compiler; applies to machines not yet built. \tn % Row Count 17 (+ 6) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Comparators}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{5.377cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/paloma_1522036669_Screen Shot 2018-02-22 at 12.26.32 PM.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Comparators}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{- Can't always access comparable method (implements .compareTo and uses Collections.sort and Arrays.sort) \newline % Row Count 3 (+ 3) -Sometimes must implement comparators in which you pass two objects \newline % Row Count 5 (+ 2) - Must implement .compare(T a, T b) \newline % Row Count 6 (+ 1) - Return \textless{}0 when a\textless{}b \newline % Row Count 7 (+ 1) - Return ==0 when a ==b \newline % Row Count 8 (+ 1) Return \textgreater{}0 when a\textgreater{}b% Row Count 9 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Comparator Example}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{5.377cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/paloma_1522801826_Screen Shot 2018-04-03 at 8.28.49 PM.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Comparator Example}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{5.377cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/paloma_1522801617_Screen Shot 2018-04-03 at 8.26.28 PM.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{p{0.62655 cm} x{1.21133 cm} x{1.16956 cm} x{1.16956 cm} } \SetRowColor{DarkBackground} \mymulticolumn{4}{x{5.377cm}}{\bf\textcolor{white}{Linked List vs. ArrayList}} \tn % Row 0 \SetRowColor{LightBackground} & Linked List & ArrayList & Both \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} & Separate elements in memory that all have pointers to each other & A collection of elements in order in memory & Collection of elements \tn % Row Count 7 (+ 6) % Row 2 \SetRowColor{LightBackground} & & & Add, remove, for loops, sort themselves, clear \tn % Row Count 12 (+ 5) % Row 3 \SetRowColor{white} \seqsplit{Remove} First \seqsplit{Element:} & N Time because you don't have to shift something when it is in the front of the list & N\textasciicircum{}2 Time because everything stores \seqsplit{sequentially} so when you take something out you have to shift everything by 1 & \tn % Row Count 23 (+ 11) % Row 4 \SetRowColor{LightBackground} \seqsplit{Remove} \seqsplit{Middle} Index & Has a higher \seqsplit{coefficient} and thus is slower: To get there takes time but to remove it is \seqsplit{instantaneous} :O(N) & Faster: To get to middle element is \seqsplit{instantanenous} but to remove it you have to shift it: O(N) & \tn % Row Count 33 (+ 10) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{5.377cm}{p{0.62655 cm} x{1.21133 cm} x{1.16956 cm} x{1.16956 cm} } \SetRowColor{DarkBackground} \mymulticolumn{4}{x{5.377cm}}{\bf\textcolor{white}{Linked List vs. ArrayList (cont)}} \tn % Row 5 \SetRowColor{LightBackground} & Best for \seqsplit{adding/removing} front & Best for \seqsplit{adding/removing} something from \seqsplit{back/middle} & \tn % Row Count 5 (+ 5) \hhline{>{\arrayrulecolor{DarkBackground}}----} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Trees}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{5.377cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/paloma_1522639172_Screen Shot 2018-04-01 at 11.19.00 PM.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{If you have N nodes, height is asking how many times you can divide by 2 -{}-\textgreater{} expressed as the log base 2 of n \newline Good search tree is height is log n \newline Bad search tree is n \newline Balanced if left and right subtrees are height balanced and left and right heights differ by at most 1} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Autocomplete}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{-{\bf{BruteAutocomplete:}} stores data as a Term array and finds the top k matches by iterating through the array and pushes all terms starting with the prefix into a max priority queue sorted by weight and returns the top k terms from that priority queue \newline % Row Count 6 (+ 6) - not compared by weight and o organization \newline % Row Count 7 (+ 1) -topMatches: O(n+mlogm) \newline % Row Count 8 (+ 1) - topMatch: O(n) \newline % Row Count 9 (+ 1) -{\bf{Improving BruteAutocomplete:}} \newline % Row Count 10 (+ 1) - had to iterate through every single term in the array because it did not know where the terms starting with the prefix were located aka array was unsorted. \newline % Row Count 14 (+ 4) - If we sort the array lexicographically, then all the terms with the same prefix will be adjacent (Sorting takes O(n log n) \newline % Row Count 17 (+ 3) - {\bf{Term:}} encapsulates a word/term and its corresponding weight \newline % Row Count 19 (+ 2) -{\bf{BinarySearchAutocomplete:}} finds Terms with a given prefix by performing a binary search on a sorted array of Terms \newline % Row Count 22 (+ 3) -{\bf{TrieAutocomplete:}} finds Terms with a given prefix by building a trie to store the Terms. To be efficient should only look at words whos maxsubtree weight is greater than the minimum% Row Count 26 (+ 4) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Autocomplete: Term class}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{- The term class encapsulates a comparable word weight pair \newline % Row Count 2 (+ 2) - {\bf{WeightOrder:}} sorts in ascending weight order \newline % Row Count 4 (+ 2) -{\bf{ReverseWeightOrder:}} sorts in descending weight order \newline % Row Count 6 (+ 2) -{\bf{PrefixOrder:}} which sorts by the first r characters \newline % Row Count 8 (+ 2) -If one or both words are shorter than r, we just use normal lexicographical sorting \newline % Row Count 10 (+ 2) - compare method must take O(r)% Row Count 11 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Autocomplete: Binary Search}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{- Find all the range of all the terms comparator considers equal to key \newline % Row Count 2 (+ 2) - Quickly return the first and last index respectively of an element in the input array which the comparator considers to be equal to key \newline % Row Count 5 (+ 3) - We specify the first and last index because there could be multiple Terms in which the comparator consider to be equal to key \newline % Row Count 8 (+ 3) - Collections.binary search does not guarantee first index of terms that match key, it gives an index% Row Count 11 (+ 3) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Autocomplete: Tries}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{- To completely eliminate terms which don't start with prefix, store in trie \newline % Row Count 2 (+ 2) - Navigate to the node representing the string. The trie rooted at this node only contains nodes starting with this trie \newline % Row Count 5 (+ 3) - No matter how many words are in our trie, navigating this node takes the same amount of time% Row Count 7 (+ 2) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.78503 cm} x{0.96117 cm} x{1.8308 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{5.377cm}}{\bf\textcolor{white}{Autocomplete: Big-Oh}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{Class}} & {\bf{TopMatch}} & {\bf{TopMatches}} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \seqsplit{BruteAutocomplete} & O(n) & O(mlogm + n) \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} \seqsplit{BinarySearchAutocomplete} & \seqsplit{O(log(n)} + m) & O(log(n) + (m + k)log(k)) \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} \seqsplit{TrieAutocomplete} & O(w) & O(w) \tn % Row Count 8 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}---} \SetRowColor{LightBackground} \mymulticolumn{3}{x{5.377cm}}{n: number of terms in total \newline m: number of terms that match the prefix \newline k: desired number of terms \newline w: number of letters in the word} \tn \hhline{>{\arrayrulecolor{DarkBackground}}---} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Common Recurrences and Their Solutions}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{5.377cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/paloma_1522713797_Screen Shot 2018-04-02 at 8.02.39 PM.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Huffman: Compressing}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{5.377cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/paloma_1525014655_Screen Shot 2018-04-29 at 11.10.04 AM.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Huffman: Decompressing}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{5.377cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/paloma_1525014680_Screen Shot 2018-04-29 at 11.10.11 AM.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Graphs BFS}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{5.377cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/paloma_1525015810_Screen Shot 2018-04-29 at 11.27.51 AM.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Visit everything that is one away, then everything that is two away... \newline Used to find shortest distance \newline takes a lot of space -{}-\textgreater{} B\textasciicircum{}d} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Bacon Number}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{Good Center - Has the most people closest to them \newline % Row Count 1 (+ 1) Chooses the best path, lowest number of edges \newline % Row Count 2 (+ 1) {\bf{Actor Actor Representation}}//Vertices: actors or actresses//Edges: Two actors are adjacent (joined by a graph edge) if and only if they appear in the same movie \newline % Row Count 6 (+ 4) {\bf{ Movie Movie Representation}}// Vertices: Movies//Edges: Two movies are adjacent if they share a cast member \newline % Row Count 9 (+ 3) {\bf{ Actor Movie Representation}}//Vertices: Actors, actresses, and movies// Edges: An actor is connected to a movie if he or she appeared in that movie% Row Count 12 (+ 3) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{1. Most vertices: Actor to movie \newline a. All of the vertices you had in actor to actor and all vertices in movie \newline to movie \newline 2. Most edges: Actor to Actor} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Erdos Number Part 2}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{5.377cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/paloma_1525018540_Screen Shot 2018-04-29 at 12.14.47 PM.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Stacks}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{LIFO% Row Count 1 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Queue}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{FIFO% Row Count 1 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Recursion}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{Efficient sorting algorithms are usually recursive \newline % Row Count 2 (+ 2) {\bf{Base Case:}} does not make a recursive call \newline % Row Count 3 (+ 1) {\bf{For Linked Lists:}} Base case is always empty list or singular node/Recursive calls make progress toward base case (list.next as argument)% Row Count 6 (+ 3) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Percolation Overview}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{- System percolates if top and bottom are connected by open sites \newline % Row Count 2 (+ 2) - Given a NxN grid, where each is site is open with probability p*, what is the probability that the system percolates? \newline % Row Count 5 (+ 3) - if p\textgreater{}p*, system most likely percolates \newline % Row Count 6 (+ 1) - if p\textless{} p*, system does not percolate \newline % Row Count 7 (+ 1) -All simulations, whether using PercolationDFS, PercolationDFSFast, or Percolation UF with any implementation of union-find will be at least O(N\textasciicircum{}2\textasciicircum{}) \newline % Row Count 10 (+ 3) - {\bf{Finding the threshold}} \newline % Row Count 11 (+ 1) - Initialize NxN grid of sites as blocked \newline % Row Count 12 (+ 1) - Randomly open sites until system percolates \newline % Row Count 13 (+ 1) - Percentage of pen sites gives an approximation of p* \newline % Row Count 15 (+ 2) {\bf{How do you get random cells to open and not open same shell more than once:}} \newline % Row Count 17 (+ 2) - Make points out of the cells \newline % Row Count 18 (+ 1) - Shuffle them gets a random ordering of all the point where each one \newline % Row Count 20 (+ 2) occurs once time \newline % Row Count 21 (+ 1) - Go through and repeatedly open each% Row Count 22 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Percolation Solution 1: Depth First Search}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{- Try searching from all of the open spots on the top row \newline % Row Count 2 (+ 2) - Search from all legal adjacent spots you have not visited \newline % Row Count 4 (+ 2) - Recurse until you can't search any further or have reached the bottom row \newline % Row Count 6 (+ 2) - Try all the legal adjacent spots (what makes it recursive is that we do the \newline % Row Count 8 (+ 2) same problem but at a different place) \newline % Row Count 9 (+ 1) - Base Cases: \newline % Row Count 10 (+ 1) - Out of bounds \newline % Row Count 11 (+ 1) - Blocked \newline % Row Count 12 (+ 1) - Already full/visited \newline % Row Count 13 (+ 1) PercolationDFS sets each grid cell to OPEN and runs a DFS from each open cell in the top (index-zero) row to mark the cells reachable from them as FULL. In the new model PercolationDFSFast, you'll make this implementation more efficient by only checking the cell being opened to see if it results in more FULL cells, rather than checking every cell reachable from the top row. \newline % Row Count 21 (+ 8) -Percolation DFS and DFSFast run in O(N) because it iterates through only the bottom row to check if it is full% Row Count 24 (+ 3) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Percolation DFSFast}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{- {\bf{Why is this an Improvement}}: An improvement because we don't have to search from the top: \newline % Row Count 2 (+ 2) - Don't have to start from the top and go down \newline % Row Count 3 (+ 1) - For the cells that are adjacent, now search from that spot \newline % Row Count 5 (+ 2) - If one of my neighbors is full, I am full \newline % Row Count 6 (+ 1) -Don't have to redfs things you've already seen \newline % Row Count 7 (+ 1) {\bf{Methodology:}} \newline % Row Count 8 (+ 1) Percolation DFS Fast \newline % Row Count 9 (+ 1) 1. Create a grid \newline % Row Count 10 (+ 1) 2. Set them all to blocked \newline % Row Count 11 (+ 1) 3. Protected void updateOnOpen \newline % Row Count 12 (+ 1) 4. Clear everything from being full \newline % Row Count 13 (+ 1) 5. Dfs checks base cases \newline % Row Count 14 (+ 1) a. If not in bounds, return \newline % Row Count 15 (+ 1) b. If cell is full or not open, return \newline % Row Count 16 (+ 1) Otherwise try all neighbors recursively% Row Count 17 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Percolation Solution 2: Union- Find}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{- Create an object for each site (each cell) (Vtop as N*N, Vbottom as N\textasciicircum{}2 +1) \newline % Row Count 2 (+ 2) - Percolates if vtop is connected to vbottom \newline % Row Count 3 (+ 1) - One call that you have to make -{}-\textgreater{} union find \newline % Row Count 5 (+ 2) - For every cell, give it an index \newline % Row Count 6 (+ 1) - Becomes problematic when n is too long \newline % Row Count 7 (+ 1) {\bf{QuickUWPC:}} \newline % Row Count 8 (+ 1) - Look at ultimate parent making path short to find parent at constant time \newline % Row Count 10 (+ 2) - Run time is O(1) because we simply check if vtop and vbottom are in the same set \newline % Row Count 12 (+ 2) -IUnionFInd.find is called from both connected and union to find sets that p and q belong to% Row Count 14 (+ 2) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Percolation Method Score Board}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{5.377cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/paloma_1522631219_Screen Shot 2018-04-01 at 9.04.16 PM.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Tree Traversals InOrder}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{5.377cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/paloma_1522675751_Screen Shot 2018-04-02 at 9.28.19 AM.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Visit left sub-tree, process root, visit right subtree \newline Increasing order \newline - Follow path and In order is when you do outline and you hit it the second time} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Tree Traversals PreOrder}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{5.377cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/paloma_1522675945_Screen Shot 2018-04-02 at 9.32.09 AM.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Process root, then visit left subtree, then visit right subtree \newline Good for reading/writing trees \newline - When you follow the outline and preorder is just when you hit it for the first time} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Tree Traversals: PostOrder}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{5.377cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/paloma_1522676114_Screen Shot 2018-04-02 at 9.34.58 AM.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Visit left subtree, right subtree, process root \newline Good for deleting trees \newline When you follow the outline and postorder is when you hit it going up} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Recursion with ListNodes in return statement}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{public ListNode\textless{}Integer\textgreater{} convertRec (ListNode\textless{}String\textgreater{} list): \newline if (list == null) return null; \newline return new ListNode\textless{}Integer\textgreater{} (list.info.length, convertRev(list.next);} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Doubly Linked Lists}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{List Node first = new ListNode \textless{}"cherry", null, null\textgreater{}; \newline List Node fig = new ListNode \textless{}"fig", first, null\textgreater{}; \newline List Node mango = new ListNode \textless{}"mango", fig, null\textgreater{}; \newline first.right = fig; \newline fig.right = mango;} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Data Compression}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{Types: \newline % Row Count 1 (+ 1) Lossless: Can recover exact data \newline % Row Count 2 (+ 1) Lossy: Can recover approximate data \newline % Row Count 3 (+ 1) - Use when you don't care, photos can't tell the difference, can compress it \newline % Row Count 5 (+ 2) more% Row Count 6 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Bytes}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{5.377cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/paloma_1525010830_Screen Shot 2018-04-29 at 10.03.10 AM.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Huffman: Text Compression}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{In the trie, 0 is left, 1 is right \newline % Row Count 1 (+ 1) Make the ones that occur most often the shortest path \newline % Row Count 3 (+ 2) Ones that rarely occur can be long \newline % Row Count 4 (+ 1) Ones that never occur can be as long as we want \newline % Row Count 5 (+ 1) Look at it 8 bits at a time \newline % Row Count 6 (+ 1) Building: Combine minimally weighted trees -{}-\textgreater{} Greedy \newline % Row Count 8 (+ 2) Bad Huffman Tree: when different character occurs once \newline % Row Count 10 (+ 2) Good Hufman Tree: One character occurs multiple times% Row Count 12 (+ 2) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Alphabet size and run time and compression rate: \newline - Alphabet size has a big impact on run time because alph size tell syou how big the tree will be \newline - The number of leaves is equal to the size of your allphabet, so you have 2\textasciicircum{}k nodes in your tree \newline - Amount of compression is frequency that it occurs \newline ○ 256 characters that occur the same amount of time is bad compression \newline ○ Huffman takes advantage of the fact that some characters occur more often than others} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Creating Huffman Tree}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{5.377cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/paloma_1525013071_Screen Shot 2018-04-29 at 10.43.40 AM.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Huffman: TreeTighten APT}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{5.377cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/megphibbs_1525017767_Screen Shot 2018-04-29 at 12.01.24 PM.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Big Oh for Huffman Encodings}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{5.377cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/paloma_1525013299_Screen Shot 2018-04-29 at 10.45.19 AM.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Read in tree data: O(k) \newline Decode bit string with tree: O(n)} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Actor Actor Graph}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{5.377cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/paloma_1525016642_Screen Shot 2018-04-29 at 11.43.39 AM.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Movie Movie Graph}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{5.377cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/paloma_1525016670_Screen Shot 2018-04-29 at 11.44.05 AM.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Actor Movie Graph}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{5.377cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/paloma_1525016697_Screen Shot 2018-04-29 at 11.44.33 AM.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{DFS Recursion}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{5.377cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/paloma_1525017809_Screen Shot 2018-04-29 at 12.02.45 PM.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Erdos Number Part 1}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{5.377cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/paloma_1525018517_Screen Shot 2018-04-29 at 12.14.38 PM.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Creating Adjacency Matrix}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{public int howLong(String {[}{]} connects, String {[}{]} costs)\{ \newline int {[}{]} {[}{]} adjMatrix = new int {[}connects.length{]}{[}connects.length{]}' \newline for (int i =0; i\textless{}connects.length; i++)\{ \newline String {[}{]} edges - connects{[}i{[}.split(" "); \newline String {[}{]} weights = costs{[}i{]}.split(" "); \newline for (int j =0; j\textless{}edges.length; j++)\{ \newline adjMatrix{[}i{]}{[}Integer.partseInt(edges{[}j{]})) = Integer.parseInt(weights{[}j{]});} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}