summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--graph/graph.tex3
-rw-r--r--java/java.tex4
-rw-r--r--math/factor.cpp2
-rw-r--r--sonstiges/sonstiges.tex15
-rw-r--r--string/kmp.cpp5
-rw-r--r--string/levenshtein.cpp12
-rw-r--r--string/string.tex3
-rw-r--r--tcr.pdfbin208094 -> 212442 bytes
-rw-r--r--toDo.txt3
9 files changed, 37 insertions, 10 deletions
diff --git a/graph/graph.tex b/graph/graph.tex
index 6c4b1e8..d4bf9d5 100644
--- a/graph/graph.tex
+++ b/graph/graph.tex
@@ -20,6 +20,7 @@ Kürzestes Pfade in Graphen mit negativen Kanten. Erkennt negative Zyklen.
\subsubsection{\textsc{Floyd-Warshall}-Algorithmus}
Alle kürzesten Pfade im Graphen.
\lstinputlisting{graph/floydWarshall.cpp}
+\textsc{Floyd-Warshall} findet auch negative Kreise. Es existiert genau dann ein negativer Kreis, wenn \lstinline{dist[i][i] < 0} ist.
\subsection{Strongly Connected Components (\textsc{Tarjans}-Algorithmus)}
\lstinputlisting{graph/scc.cpp}
@@ -66,7 +67,7 @@ Finde die maximale Anzahl Pfade von $s$ nach $t$, die keinen Knoten teilen.
\item Der maximale Fluss entspricht der unterschiedlichen Pfade ohne gemeinsame Knoten.
\end{enumerate}
-\subsection{Maximal Cardinatlity Bipartite Mathcing}
+\subsection{Maximal Cardinatlity Bipartite Matching}\label{kuhn}
\lstinputlisting{graph/maxCarBiMatch.cpp}
\subsection{TSP}
diff --git a/java/java.tex b/java/java.tex
index e8e132c..d9c3a75 100644
--- a/java/java.tex
+++ b/java/java.tex
@@ -28,7 +28,7 @@ Hier ein kleiner überblick über die Methoden der Klasse BigInteger:
//Returns this +,*,/,- val
BigInteger add(BigInteger val), multiply(BigInteger val), divide(BigInteger val), substract(BigInteger val)
-//Returns this\(^e\)
+//Returns this^e
BigInteger pow(BigInteger e)
//Bit-Operations
@@ -37,7 +37,7 @@ BigInteger and(BigInteger val), or(BigInteger val), xor(BigInteger val), not(),
//Returns the greatest common divisor of abs(this) and abs(val)
BigInteger gcd(BigInteger val)
-//Returns this mod m, this\(^{-1}\) mod m, this\(^e\) mod m
+//Returns this mod m, this^-1 mod m, this^e mod m
BigInteger mod(BigInteger m), modInverse(BigInteger m), modPow(BigInteger e, BigInteger m)
//Returns the next number that is greater than this and that is probably a prime.
diff --git a/math/factor.cpp b/math/factor.cpp
index 0e5d7d8..0cbca33 100644
--- a/math/factor.cpp
+++ b/math/factor.cpp
@@ -12,7 +12,7 @@ vector<int> factorize(ll n) {
factor.push_back(primes[pos]);
}
else pos++;
- if(primes[pos]*primes[pos] > n) break;
+ if(primes[pos]*primes[pos] > num) break;
}
if(num != 1) factor.push_back(num);
return factor;
diff --git a/sonstiges/sonstiges.tex b/sonstiges/sonstiges.tex
index 255af6a..694aaf7 100644
--- a/sonstiges/sonstiges.tex
+++ b/sonstiges/sonstiges.tex
@@ -32,3 +32,18 @@ $n$ Personen im Kreis, jeder $k$-te wird erschossen.
\lstinputlisting{sonstiges/josephusK.cpp}
\end{description}
\textbf{Beachte bei der Ausgabe, dass die Personen im ersten Fall von $1, \ldots, n$ nummeriert sind, im zweiten Fall von $0, \ldots, n-1$!}
+
+\subsection{Gemischtes}
+\begin{itemize}[itemsep=5mm]
+ \item \emph{\textsc{Johnsons} Reweighting Algorithmus:} Füge neue Quelle \lstinline{S} hinzu, mit Kanten mit Gewicht 0 zu allen Knoten. Nutze \textsc{Bellmann-Ford} zum Betsimmen der Entfernungen \lstinline{d[i]} von \lstinline{S} zu allen anderen Knoten. Stoppe, wenn es negative Zyklen gibt. Sonst ändere die gewichte von allen Kanten \lstinline{(u,v)} im ursprünglichen Graphen zu \lstinline{d[u]+w[u,v]-d[v]}. Dann sind alle Kantengewichte nichtnegativ, \textsc{Dijkstra} kann angewendet werden.
+ \item Für ein System von Differenzbeschränkungen: Ändere alle Bedingungen in die Form $a-b \leq c$. Für jede Bedingung füge eine Kante \lstinline{(b,a)} mit Gweicht \lstinline{c} ein. Füge Quelle \lstinline{s} hinzu, mit Kanten zu allen Knoten mit Gewicht 0. Nutze \textsc{Bellmann-Ford}, um die kürzesten Pfade von \lstinline{s} aus zu finden. \lstinline{d[v]} ist mögliche Lösung für \lstinline{v}.
+ \item Min-Weight-Vertex-Cover im bipartiten Graph: Partitioniere in \lstinline{A, B} und füge Kanten \lstinline{s -> A} mit Gewicht \lstinline{w(A)} und Kanten \lstinline{B -> t} mit Gewicht \lstinline{w(B)} hinzu. Füge Kanten mit Kapazität $\infty$ von \lstinline{A} nach \lstinline{B} hinzu, wo im originalen Graphen Kanten waren. Max-Flow ist die Lösung.\newline
+ Im Residualgraphen:
+ \begin{itemize}
+ \item Das Vertex-Cover sind die Knoten inzident zu den Brücken. \emph{oder}
+ \item Die Knoten in \lstinline{A}, die \emph{nicht} von \lstinline{s} erreichber sind und die Knoten in \lstinline{B}, die von \lstinline{erreichber} sind.
+ \end{itemize}
+ \item Allgemeiner Graph: Das Komplement eines Vertex-Cover ist ein Independent Set. $\Rightarrow$ Max Weight Independent Set ist Komplement von Min Weight Vertex Cover.
+ \item Bipartiter Graph: Min Cover (kleinste Menge Knoten, die alle Kanten berühren) = Max Matching.
+ \item Bipartites Matching mit Gewichten auf linken Knoten. Minimiere Matchinggewicht. Lösung: Sortiere Knoten links aufsteigend nach Gewicht, danach nutze normlen Algorithmus (\textsc{Kuhn}, Seite \pageref{kuhn})
+\end{itemize}
diff --git a/string/kmp.cpp b/string/kmp.cpp
index f7c3630..6844975 100644
--- a/string/kmp.cpp
+++ b/string/kmp.cpp
@@ -1,8 +1,3 @@
-#include <iostream>
-#include <vector>
-
-using namespace std;
-
//Preprocessing Substring sub for KMP-Search
vector<int> kmp_preprocessing(string& sub) {
vector<int> b(sub.size() + 1);
diff --git a/string/levenshtein.cpp b/string/levenshtein.cpp
new file mode 100644
index 0000000..d1980f8
--- /dev/null
+++ b/string/levenshtein.cpp
@@ -0,0 +1,12 @@
+int levenshtein(string& s1, string& s2) {
+ int len1 = s1.size(), len2 = s2.size();
+ vector<int> col(len2 + 1), prevCol(len2 + 1);
+ for (int i = 0; i < len2 + 1; i++) prevCol[i] = i;
+ for (int i = 0; i < len1; i++) {
+ col[0] = i + 1;
+ for (int j = 0; j < len2; j++)
+ col[j+1] = min(min(prevCol[j+1] + 1, col[j] + 1), prevCol[j] + (s1[i]==s2[j] ? 0 : 1));
+ col.swap(prevCol);
+ }
+ return prevCol[len2];
+} \ No newline at end of file
diff --git a/string/string.tex b/string/string.tex
index 61385fc..0fddb86 100644
--- a/string/string.tex
+++ b/string/string.tex
@@ -3,6 +3,9 @@
\subsection{\textsc{Knuth-Morris-Pratt}-Algorithmus}
\lstinputlisting{string/kmp.cpp}
+\subsection{\textsc{Levenshtein}-Distanz}
+\lstinputlisting{string/levenshtein.cpp}
+
\subsection{Trie}
\lstinputlisting{string/trie.cpp}
diff --git a/tcr.pdf b/tcr.pdf
index b315d9b..045dc9e 100644
--- a/tcr.pdf
+++ b/tcr.pdf
Binary files differ
diff --git a/toDo.txt b/toDo.txt
index e623188..53691db 100644
--- a/toDo.txt
+++ b/toDo.txt
@@ -1,2 +1,3 @@
-- bitonic tsp
+- kondensierter Graph
- min cost max flow
+- dijkstra mit variablen startknoten \ No newline at end of file