\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{malandro123} \pdfinfo{ /Title (computacao-2.pdf) /Creator (Cheatography) /Author (malandro123) /Subject (Computação 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}{A3A3A3} \definecolor{LightBackground}{HTML}{F3F3F3} \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{Computação 2 Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{malandro123} via \textcolor{DarkBackground}{\uline{cheatography.com/23628/cs/5543/}}} \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}malandro123 \\ \uline{cheatography.com/malandro123} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Published 27th October, 2015.\\ Updated 9th May, 2016.\\ 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*}{2} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Tipos de Busca}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Busca Sequencial} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{Busca Binária} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Arvore de Busca Binária} \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{Hash} \tn % Row Count 4 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Busca Sequencial}} \tn \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{Compara a chave com cada item na array ou lista, até encontrar um item de dado cujo valor é igual o valor da chave.% Row Count 3 (+ 3) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Busca Sequencial - Code}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{for (i=0; i\textless{}n; i++) \newline if (A{[}i{]}==x) \newline return(i); /{\emph{chave encontrada}}/ \newline return(-1); /{\emph{chave não encontrada}}/} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Algoritmo de busca seqüencial em um vetor A, com N posições (0 até N-1), sendo x a chave procurada} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Busca Sequencial - Code c/ Sentinela}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{A{[}N{]}=x; \newline for(i=0; x!=A{[}i{]}; i++); \newline if (i\textless{}n) return(i); /{\emph{chave encontrada}}/ \newline else return(-1); /{\emph{sentinela encontrado}}/} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Busca Binária - Code}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Bin-Search(collection c, low, high, k) \newline int mid; \newline if low \textgreater{} high \newline then return NIL; \newline mid = (high+low)/2; \newline if k = key{[}mid{]} \newline then return key{[}mid{]}; \newline else if k \textless{} key{[}mid{]} \newline then return Bin\_search(c, low, mid-1, k); \newline else return Bin\_search(c, mid+1, high, k);} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Busca Binária - Complexidade}} \tn \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{O(log(n)), pois cada comparação reduz o número de possíveis candidatos por um fator de 2.% Row Count 2 (+ 2) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Árvore Binária de Busca - Busca Geral Recursivo}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Tree-Search(x, k) \newline if x = NIL or k = key{[}x{]} \newline then return x \newline if k \textless{} key{[}x{]} \newline then return Tree-Search(left{[}x{]}, k) \newline else return Tree-Search(right{[}x{]}, k)} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Árvore Binária de Busca - Busca Geral Iterativo}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Iterative-Tree-Search(x, k) \newline while x ≠ NIL and k ≠ key{[}x{]} \newline do if k \textless{} key{[}x{]} \newline then x ← left{[}x{]} \newline else x ← right{[}x{]} \newline return x} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Árvore Binária de Busca - Busca do Valor Minimo}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Tree-Minimum(x) \newline while left{[}x{]} ≠ NIL \newline do x ← left{[}x{]} \newline return x} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Árvore Binária de Busca - Busca do Valor Maximo}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Tree-Maximum(x) \newline while right{[}x{]} ≠ NIL \newline do x ← right{[}x{]} \newline return x} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Algoritmo de Busca do Valor Sucessor}} \tn \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{O sucessor do nó x é o nó com o menor chave maior que key{[}x{]}. \newline % Row Count 2 (+ 2) Case 1: Se a subarvore direita do nó x não for vazio, então, o sucessor do x é o nó mais esquerdo na subarvore direita; \newline % Row Count 5 (+ 3) Case 2: Se a subarvore direita do nó x for vazio, o sucessor do x (se x é um filho esquerdo) é o antecessor de nível mais baixa ou é o antecessor de nível mais baixa , cujo filho esquerdo também é antecessor do x (se x é um filho \newline % Row Count 10 (+ 5) direito) .% Row Count 11 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Algoritmo de Busca do Valor Sucessor}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Tree-Successor(x) \newline if right{[}x{]} ≠ NIL \newline then return Tree-Minimum(right{[}x{]}) \newline y ← p{[}x{]} \newline while y ≠ NIL and x = right{[}p{[}x{]}{]} \newline do x ← y \newline y ← p{[}y{]} \newline return y} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Algoritmo de Inserção}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Tree-Insert(T, z) \newline y ← NIL \newline x ← root{[}T{]} \newline while x ≠ NIL \newline do y ← x \newline if key{[}z{]} \textless{} key{[}x{]} \newline then x ← left{[}x{]} \newline else x ← right{[}x{]} \newline p{[}z{]} ← y \newline if y = NIL \newline then root{[}T{]} ← z \newline else if key{[}z{]} \textless{} key{[}x{]} \newline then left{[}y{]} ← z \newline else right{[}y{]} ← z} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Algoritmo de Remoção}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Tree-Delete(T, z) \newline if left{[}z{]} = NIL ou right{[}z{]} = NIL \newline then y ← z \newline else y ← Tree-Successor(z) \newline if left{[}y{]} ≠ NIL \newline then x ← left{[}y{]} \newline else x ← right{[}y{]} \newline if x ≠ NIL \newline then p{[}y{]} ← p{[}x{]} \newline if p{[}y{]} = NIL \newline then root{[}T{]} ← x \newline else if y =left{[}p{[}y{]}{]} \newline then left{[}p{[}y{]}{]} ← x \newline else right{[}p{[}y{]}{]} ← x \newline if y ≠ z \newline then key{[}z{]} ← key{[}y{]} \newline return y} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Folha 1}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{} \tn % Row Count 0 (+ 0) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Ver Note}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{\#include \textless{}stdio.h\textgreater{} \newline \#include \textless{}stdlib.h\textgreater{} \newline \newline int main() \newline \{ \newline int conj1,conj2,conj3,n1,n2,n3,i,k1,k2,k3,soma1,soma2,soma3,mediageral; \newline float media1,media2,media3; \newline \newline printf("Insira o numero de valores para serem somados no conjunto 1: \textbackslash{}n"); \newline scanf("\%d", \&n1); \newline soma1=0; \newline for(i=0;i\textless{}n1;i++)\{ \newline printf("insira os valores: \textbackslash{}n"); \newline scanf("\%d",\&k1); \newline soma1=k1+soma1; \newline \} \newline media1= (float) soma1/n1; \newline \newline printf("A média do conjunto 1 é: \%f\textbackslash{}n", media1); \newline printf("Insira o numero de valores para serem somados no conjunto 2: \textbackslash{}n"); \newline scanf("\%d", \&n2); \newline soma2=0; \newline for(i=0;i\textless{}n2;i++)\{ \newline printf("insira os valores: \textbackslash{}n"); \newline scanf("\%d",\&k2); \newline soma2=k2+soma2; \newline \} \newline media2= (float)soma2/n2; \newline \newline printf("A média do conjunto 1 é: \%f\textbackslash{}n", media2); \newline \newline \newline \newline printf("Insira o numero de valores para serem somados no conjunto 3: \textbackslash{}n"); \newline scanf("\%d", \&n3); \newline soma3=0; \newline for(i=0;i\textless{}n3;i++)\{ \newline printf("insira os valores: \textbackslash{}n"); \newline scanf("\%d",\&k3); \newline soma3=k3+soma3; \newline \} \newline media3= (float)soma3/n3; \newline \newline printf("A média do conjunto 3 é: \%f\textbackslash{}n", media3); \newline \newline mediageral= \seqsplit{(float)(media1+media2+media3)/3;} \newline \newline printf ("A média final gerada dos três conjuntos é: \%f\textbackslash{}n",mediageral);} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Exercício 2.7.1. Escrever um programa C, sem utilizar funções, que \newline a) Leia três conjuntos de n números reais digitados pelo usuário (n pode ser diferente para cada conjunto)} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Ver Note 2}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{\#include \textless{}stdio.h\textgreater{} \newline \#include \textless{}stdlib.h\textgreater{} \newline \newline float conjunto(void)\{ \newline int i,n,k; \newline float soma,media; \newline \newline printf("Insira o numero de valores para serem somados no conjunto: \textbackslash{}n"); \newline scanf("\%d", \&n); \newline soma=0; \newline for(i=0;i\textless{}n;i++)\{ \newline printf("insira os valores: \textbackslash{}n"); \newline scanf("\%d",\&k); \newline soma=k+soma; \newline \} \newline media= (float) soma/n; \newline return (media) \newline \newline \} \newline \newline int main()\{ \newline \newline \newline float media1,media2,media3, mediageral; \newline media1=conjunto (); \newline media2=conjunto (); \newline media3=conjunto (); \newline printf("A média do conjunto 1 é: \%f\textbackslash{}n", media1); \newline \newline printf("A média do conjunto 2 é: \%f\textbackslash{}n", media2); \newline \newline printf("A média do conjunto 3 é: \%f\textbackslash{}n", media3); \newline \newline mediageral= \seqsplit{(media1+media2+media3)/3.0;} \newline \newline printf ("A média final gerada dos três conjuntos é: \%f\textbackslash{}n",mediageral);} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{b) Imprima a média e o desvio padrão de cada um dos três conjuntos;} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Questao 4}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{int soma (int valor)\{ \newline int aux; \newline if (valor == -1 || valor == 1)\{ \newline valor = -1; \newline \} \newline else\{ \newline valor = ((-2*valor) +1) + soma(valor-1); \newline \} \newline \newline return valor; \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Escreve uma função recursiva para calcular a seuinte soma: -1-3-5-7-...-(2N-1)} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}