Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
387 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
NAME = aula | ||
SHELL = bash | ||
PWD = $(shell pwd) | ||
|
||
all: text clean | ||
|
||
clean: | ||
rm -f *.{acn,acr,alg,aux,bbl,blg,fls,glg,glo,gls,glsdefs,hd,idx,ilg,ind,ins,ist,log,loa,loe,lof,lot,mw,nav,out,sbl,snm,sym,toc,vrb,xdy,fdb_latexmk,gz} | ||
|
||
text: | ||
# Works on El Captain | ||
# "/Library/TeX/texbin/pdflatex" -synctex=1 -interaction=nonstopmode --shell-escape $(NAME).tex | ||
"/Library/TeX/texbin/xelatex" -synctex=1 -interaction=nonstopmode --shell-escape $(NAME).tex | ||
#"/Library/TeX/texbin/bibtex" $(NAME).aux | ||
"/Library/TeX/texbin/xelatex" -synctex=1 -interaction=nonstopmode --shell-escape $(NAME).tex | ||
"/Library/TeX/texbin/xelatex" -synctex=1 -interaction=nonstopmode --shell-escape $(NAME).tex | ||
#test -e $(NAME).pdf && mv $(NAME).pdf 03-MVC.pdf |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
\documentclass{beamer} | ||
|
||
\usepackage{amsthm} | ||
\usepackage[utf8]{inputenc} | ||
\usepackage[T1]{fontenc} | ||
\usepackage[brazil]{babel} | ||
\usepackage[export]{adjustbox} | ||
\usepackage{listings} | ||
\usepackage{fontspec} | ||
\usepackage{color} | ||
|
||
\definecolor{pblue}{rgb}{0.13,0.13,1} | ||
\definecolor{pgreen}{rgb}{0,0.5,0} | ||
\definecolor{pred}{rgb}{0.9,0,0} | ||
\definecolor{pgrey}{rgb}{0.46,0.45,0.48} | ||
|
||
\lstset{language=Java, | ||
showspaces=false, | ||
showtabs=false, | ||
breaklines=true, | ||
showstringspaces=false, | ||
breakatwhitespace=true, | ||
commentstyle=\color{pgreen}, | ||
keywordstyle=\color{pblue}, | ||
stringstyle=\color{pred}, | ||
basicstyle=\ttfamily, | ||
} | ||
|
||
|
||
\usetheme{Madrid} | ||
\usecolortheme{beetle} | ||
\usefonttheme{professionalfonts} | ||
|
||
\setmainfont{Oswald} | ||
|
||
\lstset{basicstyle=\ttfamily,breaklines=true} | ||
\beamertemplatenavigationsymbolsempty | ||
|
||
\begin{document} | ||
|
||
\selectlanguage{brazil} | ||
\title[QuickSort]{QuickSort} | ||
\author{Prof. Andrey Masiero} | ||
|
||
\begin{frame}[plain,noframenumbering] | ||
\titlepage | ||
\end{frame} | ||
|
||
\begin{frame}[plain,noframenumbering] | ||
\frametitle{Agenda} | ||
\tableofcontents | ||
\end{frame} | ||
|
||
\section{QuickSort} | ||
|
||
\begin{frame} | ||
\frametitle{QuickSort} | ||
\begin{itemize}[<+->] | ||
\item Assim como o MergeSort, é um algoritmo que tem base no paradigma de divisão e conquista; | ||
\item Só que utiliza a técnica de maneira contrária. Trabalho pesado é feito antes das chamadas recursivas; | ||
\item Dado uma sequência S: | ||
\begin{itemize} | ||
\item Aplica a técnica de divisão e conquista, fazendo subsequências de S; | ||
\item Aplica a recursão ordenando cada subsequência; | ||
\item Por fim, combina as subsquências ordenadas através de uma concatenação simples. | ||
\end{itemize} | ||
\end{itemize} | ||
\end{frame} | ||
|
||
|
||
\begin{frame} | ||
\frametitle{QuickSort} | ||
Os três passos do algoritmo: | ||
\begin{itemize}[<+->] | ||
\item Dividir: se S tiver pelo menos dois elementos, escolhe-se um elemento $x$ de S, chamado de \emph{pivô}. Uma opção é escolher $x$ como o último elemento de S. Os demais elementos de S são removidos, e colocados em três sequências: | ||
\begin{itemize} | ||
\item L: elementos de S menores que $x$; | ||
\item E: elementos de S iguais a $x$; | ||
\item G: elementos de S maiores que $x$. | ||
\end{itemize} | ||
\item Recursão: Ordena as sequências de L e G, recursivamente; | ||
\item Conquista: Uni os elementos de S em ordem, a partir de L, passando por E e finalizando com G. | ||
\end{itemize} | ||
\end{frame} | ||
|
||
\begin{frame} | ||
\frametitle{QuickSort} | ||
\begin{figure} | ||
\centering | ||
\includegraphics[scale=0.5]{images/esquema-visual.png} | ||
\caption{Goodrich e Tamassia, 2013} | ||
\end{figure} | ||
\end{frame} | ||
|
||
\begin{frame} | ||
\frametitle{QuickSort} | ||
\begin{itemize}[<+->] | ||
\item Assim como o MergeSort, o QuickSort pode ser visualizado com uma árvore binária recursiva; | ||
\item A altura da árvore do QuickSort é no pior caso linear; | ||
\item O pior caso ocorre quando a sequência consiste em n elementos distintos e já ordenada. | ||
\end{itemize} | ||
\end{frame} | ||
|
||
\begin{frame} | ||
\frametitle{QuickSort} | ||
\begin{figure} | ||
\centering | ||
\includegraphics[scale=0.5]{images/ida.png} | ||
\caption{Goodrich e Tamassia, 2013} | ||
\end{figure} | ||
\end{frame} | ||
|
||
\begin{frame} | ||
\frametitle{QuickSort} | ||
\begin{figure} | ||
\centering | ||
\includegraphics[scale=0.5]{images/vinda.png} | ||
\caption{Goodrich e Tamassia, 2013} | ||
\end{figure} | ||
\end{frame} | ||
|
||
|
||
\begin{frame} | ||
\frametitle{Algoritmo de Ordenação} | ||
\centering | ||
\lstinputlisting[language=Java]{src/sort.java} | ||
\end{frame} | ||
|
||
\begin{frame} | ||
\frametitle{Método Divide} | ||
\centering | ||
\lstinputlisting[language=Java]{src/divide.java} | ||
\end{frame} | ||
|
||
\section{Exercícios} | ||
|
||
\begin{frame} | ||
\frametitle{Exercícios} | ||
|
||
\begin{enumerate} | ||
\item Implemente o QuickSort. | ||
\item Teste os algoritmos em um programa principal, com o seguintes vetores: | ||
\begin{enumerate} | ||
\item 42, 21, 37, 75, 98, 11, 50, 63 | ||
\item 88, 15, 27, 55, 44, 38 | ||
\item 12, 81, 75, 37, 47, 25, 34 | ||
\item 48, 11, 88, 33, 57, 12, 18, 87, 54, 8 | ||
\end{enumerate} | ||
\end{enumerate} | ||
\end{frame} | ||
|
||
\section{Referências} | ||
|
||
\begin{frame} | ||
\frametitle{Referências Bibliográficas} | ||
\begin{enumerate} | ||
\item Cormen, Thomas H., Charles E. Leiserson, Ronald L. Rivest, and Clifford Stein. ``Introduction to algorithms second edition.'' (2001). | ||
\item Goodrich, Michael T. and Tamassia, Roberto. ``Estrutura de Dados e Algoritmos em Java.'' Porto Alegre, Ed. Bookman 5 (2013). | ||
\item Ascencio, Ana Fernanda Gomes, and Graziela Santos de Araújo. ``Estruturas de Dados: algoritmos, análise da complexidade e implementações em JAVA e C/C++.'' São Paulo: Perarson Prentice Halt 3 (2010). | ||
\end{enumerate} | ||
\end{frame} | ||
|
||
\end{document} |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
public int divide(int X[], int inicio, int fim) { | ||
int pivot = X[inicio]; | ||
int postPivot = inicio; | ||
for (int i = inicio + 1; i <= fim; i++) { | ||
if(X[i] < pivot) { | ||
X[postPivot] = X[i]; | ||
X[i] = X[postPivot + 1]; | ||
postPivot++; | ||
} | ||
} | ||
X[postPivot] = pivot; | ||
return postPivot; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
public void sort(int X[], int inicio, int fim) { | ||
if (inicio < fim) { | ||
int pivot = this.divide(X, inicio, fim); | ||
this.sort(X, inicio, pivot - 1); | ||
this.sort(X, pivot + 1, fim); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
aula_08/src/com/andreymasiero/aulas/algoritmos/MergeSort.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.andreymasiero.aulas.algoritmos; | ||
|
||
public class MergeSort { | ||
|
||
public void sort(int X[], int inicio, int fim) { | ||
|
||
if (inicio < fim) { | ||
|
||
int meio = (inicio + fim) / 2; | ||
this.sort(X, inicio, meio); | ||
this.sort(X, meio + 1, fim); | ||
this.merge(X, inicio, meio, fim); | ||
|
||
} | ||
|
||
} | ||
|
||
private void merge(int X[], int inicio, int meio, int fim) { | ||
|
||
int i, esquerda, direita; | ||
int aux[] = new int[X.length]; | ||
|
||
for (i = inicio; i <= fim; i++) aux[i] = X[i]; | ||
|
||
esquerda = inicio; | ||
direita = meio + 1; | ||
i = inicio; | ||
|
||
while (esquerda <= meio && direita <= fim) { | ||
if (aux[esquerda] <= aux[direita]) X[i++] = aux[esquerda++]; | ||
else X[i++] = aux[direita++]; | ||
} | ||
|
||
while (esquerda <= meio) X[i++] = aux[esquerda++]; | ||
} | ||
|
||
} |
26 changes: 26 additions & 0 deletions
26
aula_08/src/com/andreymasiero/aulas/algoritmos/QuickSort.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.andreymasiero.aulas.algoritmos; | ||
|
||
public class QuickSort { | ||
|
||
public void sort(int X[], int inicio, int fim) { | ||
if (inicio < fim) { | ||
int pivot = this.divide(X, inicio, fim); | ||
this.sort(X, inicio, pivot - 1); | ||
this.sort(X, pivot + 1, fim); | ||
} | ||
} | ||
|
||
public int divide(int X[], int inicio, int fim) { | ||
int pivot = X[inicio]; | ||
int postPivot = inicio; | ||
for (int i = inicio + 1; i <= fim; i++) { | ||
if(X[i] < pivot) { | ||
X[postPivot] = X[i]; | ||
X[i] = X[postPivot + 1]; | ||
postPivot++; | ||
} | ||
} | ||
X[postPivot] = pivot; | ||
return postPivot; | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
aula_08/src/com/andreymasiero/aulas/algoritmos/Recursion.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.andreymasiero.aulas.algoritmos; | ||
|
||
|
||
public class Recursion { | ||
|
||
public static int fatorialNonRecursive(int n) { | ||
int result = 1; | ||
for (int i = result; i <= n; i++) { | ||
result *= i; | ||
} | ||
return result; | ||
} | ||
|
||
public static int fatorialRecursive(int n) { | ||
if (n == 0) | ||
return 1; | ||
|
||
return n * fatorialRecursive(n - 1); | ||
} | ||
|
||
public static int fibonacciNonRecursive(int n) { | ||
int f = -1; | ||
int fibMenos1 = 1; | ||
int fibMenos2 = 0; | ||
for (int i = 3; i <= n; i++) { | ||
f = fibMenos1 + fibMenos2; | ||
fibMenos2 = fibMenos1; | ||
fibMenos1 = f; | ||
} | ||
return f; | ||
} | ||
|
||
public static int fibonacciRescursive(int n) { | ||
if (n == 0 || n == 1) return 0; | ||
if (n == 2) return 1; | ||
return fibonacciRescursive(n - 2) + fibonacciRescursive(n - 1); | ||
} | ||
|
||
} |
29 changes: 29 additions & 0 deletions
29
aula_08/src/com/andreymasiero/aulas/algoritmos/Search.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.andreymasiero.aulas.algoritmos; | ||
|
||
public class Search { | ||
|
||
public static int sequentialSearch(int[] data, int value) { | ||
for (int i = 0; i < data.length; i++) { | ||
if (data[i] == value) { | ||
return i; | ||
} | ||
} | ||
return -1; | ||
} | ||
|
||
public static int binarySearch(int[] data, int value) { | ||
int begin = 0; | ||
int end = data.length - 1; | ||
|
||
while (begin < end) { | ||
int middle = (begin + end) / 2; | ||
if (data[middle] > value) | ||
end = middle - 1; | ||
else if (data[middle] < value) | ||
begin = middle + 1; | ||
else | ||
return middle; | ||
} | ||
return -1; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.andreymasiero.aulas.algoritmos; | ||
|
||
public class Sort { | ||
|
||
public static void bubblesort (int[] data) { | ||
for (int i = 0; i < data.length; i++) | ||
for (int j = 0; j < data.length - 1; j++) | ||
if (data[j] > data[j + 1]) | ||
swap(data, j, j + 1); | ||
} | ||
|
||
public static void selectionSort (int[] data) { | ||
for (int i = 0; i < data.length; i++) { | ||
int sindex = i; | ||
for (int j = i + 1; j < data.length; j++) | ||
if (data[j] < data[sindex]) sindex = j; | ||
swap(data, i, sindex); | ||
} | ||
} | ||
|
||
public static void insertionSort (int[] data) { | ||
for (int i = 0; i < data.length; i++) { | ||
int x = data[i]; | ||
for (int j = i - 1; j >= 0 && data[j] > x; j--) { | ||
data[j + 1] = data[j]; | ||
data[j] = x; | ||
} | ||
|
||
} | ||
} | ||
|
||
public static void swap(int[] d, int a, int b) { | ||
int aux = d[a]; | ||
d[a] = d[b]; | ||
d[b] = aux; | ||
} | ||
} |
Oops, something went wrong.