Graph+Theory


 * Graph Theory **

General Introduction
Graph theory is the study of graphs in mathematics and computer science. These kinds of graph have no relations to graphs that keep chart data. In this instance, it refers to a collection of vertices or nodes (dots) and a collection of edges (lines) that connect pairs of vertices. The size of the dots, the lengths of the lines, or whether the lines are straight or curved doesn't make a difference in this field of computer science.[[|2]]

Two dots can only be connected by one single line, it is illegal to draw another line connecting them.[[|2]] A graph can be directed so that its edges go from one vertex to another or undirected, meaning that the edges of the graph do not go in a particular direction. If some value had been assigned to the edges of a graph, then that graph is referred to as a weighted graph, otherwise it would be an unweighted graph.[[|1]]

**History**
The foundation of graph theory was first published in a paper written by Leonhard Euler in 1736, on the Seven Bridges of Konigsberg. Euler’s formula relating the number of edges, and vertices was generalized by Augustin-Louis Cauchy to be used to analyze tree graphs using differential calculus. This technique had many implications in chemistry which involved the enumeration of graphs. Cayley’s work on trees was linked with chemical compositions such as isomers. The first book on graph theory was written by Denes Konig in 1936. This allowed mathematicians, chemists, electrical engineers and social scientists to use the ideas of graph theory for their work.

BFS (Breadth-First Search)
Breadth-First Search is a graph search algorithm that begins at the root node and then proceeds onto all the neighboring nodes. Then those neighboring nodes would explore their unexplored neighbor, until it finds answer to the problem.[[|1]]

Breadth First Search By soetamrizky
media type="youtube" key="qBfzDxihJz4" height="315" width="420"

Depth-First Search
Depth-First Search is an algorithm that expands the first child node of the search tree and going deeper and deeper until no child node can be found or the goal node is found, then it backtracks and returns to the closest unexplored node.[[|1]] Demonstration of Depth First Search and Dijkstra algorithm []

Dijkstra's Algorithm
Because both Breath First Search and Depth first search have problems producing correct result in a weighted graph, Dijkstra's algorithm would be applied in that case. Dijkstra is an algorithm that takes the route with the lowest weight, so whenever there is more than one adjacent edges, it will always take the one with lowest weight and proceed from there. [[|1]] Note: Dijkstra's algorithm might fail if in the case of negative weights are used. Demonstration of Depth First Search and Dijkstra algorithm []

Bellman-Ford Algorithm
Dijkstra's algorithm is a faster way to find shortest path in a weighted graph, but if it would fail when negative weight is used, so Bellman-Ford Algorithm would be used in that case. Bellman-Ford is really similar to Dijkstra's algorithm in its structure, but instead of simply finding the smallest weight among adjacent ed ges, it relaxes(Relaxing an edge (u,v) means testing whether we can improve the shortest path to v found so far by going through u) an edge all edges |v|-1 time, v being the total number of edges. [[|1]]




 * Single Shortest Path in Dags**

This algorithm is used to solve shortest path problem in a directed graph, the idea is to topologically(scheduling a sequence of vertices d sort the vertices of the graph and relaxes the edge according to the order given by the sort.[[|1]]



Floyd-Warshall Algorithm
The Floyd-Warshall Algorithm is an example of dynamic programming; it compares all possible paths through the path between each pair of vertices. It is used to find shortest path and to find transitive closure ( if R is the relation on nodes "has an edge leading to" then the transitive closure of R is the relation "has a path of zero or more edges to")[[|3]] of a relation.[[|1]]



Prim's Algorithm
There might be several spanning trees in a weighted graph, Prim's Algorithm would often be used in that case to figure out the Minimum Spanning Tree (spanning tree with the lowest total cost (weight)). The Prim's Algorithm works by growing a new Minimum S Panning Tree from the current spanning tree. It does that by adding the nearest (lowest weight) vertex and the edge connecting the nearest (lowest weight) vertex to the new Minimum Spanning Tree.[[|1]]



Prim's Algorithm by Andrewhickson666
media type="youtube" key="BtGuZ-rrUeY" height="315" width="420"

Kruskal's Algorithm
Kruskal's Algorithm generates Minimum Spanning Trees using an edge-based approach .The basic idea of Kruskal's algorithm is to grow an Minimum Spanning Tree from a forest of spanning trees.[[|1]]

Kruskal by GreenfordMaths
media type="youtube" key="OWfeZ9uDhdw" height="315" width="420"

**Graph-theoretic data structures**
These are data structures used to store graphs in a computer system. Theoretically, storing graphs can be done by using a list or matrix structure. List structures are often preferred for sparse graphs as they have smaller memory requirements. Matrix structures on the other hand provide faster access for some applications but can consume huge amounts of memory.[[|1]]


 * The most common types are: **


 * Adjacency list ** – Vertices are stored as arrays, and every vertex stores a list of adjacent vertices. This data structure allows the storage of additional data on the vertices.


 * Incidence list ** – Vertices and edges are stored as arrays. Each vertex stores its incident edges, and each edge stores its incident vertices. This data structure allows the storage of additional data on vertices and edges.


 * Adjacency matrix ** – A two-dimensional matrix, in which the rows represent source vertices and columns represent destination vertices. Data on edges and vertices must be stored externally. Only the cost for one edge can be stored between each pair of vertices.


 * <span style="font-family: 'Arial','sans-serif';">Incidence matrix **<span style="font-family: 'Arial','sans-serif';"> – A two-dimensional Boolean matrix, in which the rows represent the vertices and columns represent the edges. The entries indicate whether the vertex at a row is incident to the edge at a column.

<span style="font-family: 'Arial','sans-serif';">Adjacency lists or matrixes are most commonly used for undirected graph problems, such as shortest path problems and most other route problems and Incidence lists or matrixes are commonly used for directed graph problems.

**Applications in real life**
The field of graph theory can be applicable to many other fields such as biochemistry, engineering and operation researches. The reason why graph theory can be so applicable is because the point of Graph theory is to find the shortest/ most efficient way to solve a question. Graph theory is considered the bridge between mathematics and science, being used to improve fields such as finding the strands in DNA or improving system security and using less memory. It should be noted Graph Theory is all around everyday life and is helping every individual without one knowing it. [[|5]]

Biochemistry
In biochemistry, DNA strands with hundreds of strand may have conflicts between strands. A conflict in DNA strands are when the same sequences are the same, so they are not needed in analysis between two species difference. An example to demonstrate this is by comparing the strands of two humans. The biochemist will want to study the difference between the two humans, while the similarities are possibly what make us human. A biochemist may need to remove a minimal amount of strands that would still give the same result but enough so that all conflicts are resolved. By removal the strands that are not needed, we are able to get the difference between the two DNA and find out how the difference can be used to determine the characteristic and nature of the sequence. This is known as

Single Nucleotide Polymorphism.[[|5]]



Computer Network Security
In computer security, a computer security programmer tries to find the optimal strategy in setting up a network, with a minimal amount of connection to the internet, but with enough computers connected to one another so they all are still connect to the network and router. This problem is called minimal vertex cover, and is useful to know for both hackers and computer networking because if the security is optimal, it can hinder a worm from crawling through the network quickly or for a hacker, to find the most optimized strategy to get through to every computer. The diagram below is a simple diagram that shows an optimal solution so that the worm must crawl through every route to infect all the computers. [[|5]]



Timetabling
In many places, a timetabling program is very important because it is necessary to create schedules that most people would be satisfied of. An example of this is a high school, where the students pick their optimal courses. This would require graph theory to find the most satisfying solutions to the student. For example, a grade 12 would have higher weights (priority) over grade 9 because they would need to classes to graduate, while grade 9 will have weights when it comes with mandatory courses. Using Dijkstra algorithm (weights with recursive for optimal strategy) and matrices/arrays, a computer will find the optimal solution for schedules for all the students in the class. Below is a computer finding the most optimal strategy of what courses should be done after one another for a professor so that he can teach the most course in two semesters.[[|5]]



Map Creating and Global Positioning System
In map theory, there is a famous rule of thumb that optimal/easy to read map should only have 4 colours and no 2 of the same colour should be used to shade adjacent regions. With graph theory and given 4 colours, a computer can solve for the optimal solution of how to colour the map. An example of this is below. Another application of graph theory is GPS. In order for GPS to find the directions you want to go to, a computer must solve the shortest path from your point to point A. For example, if you want to find your way to the mall, a computer may first find every way to get there, and then using traffic, stop signs, stop light, and terrain to consider your optimal path using weights.[[|5]]



Knight's Tours
In graph theory, a classic and famous problem is the Knight's Tour. The problem requires a computer solve for a knight to have been on every single spot of the chessboard starting at any point, but can only land on the each square only once and the knight may only move in the chess L shape. This problem has been explored many times, and is useful for chess players to use their knights to its full potential. Below is a computer that solves the 8x8 chessboard Knight's Tour. [[|5]]



Other applications
There are many more applications to graph theory. Anything that can be mapped or requires mapping can use graph theory to find optimal solutions when there are one are more vertices. In fact, anything that involves movements in paths and limited amount of some sort of items (such as data, water, money), can be solved optimally with graph theory. Here is a small list of applicable things in real life.[[|6]]


 * <span style="line-height: normal; mso-list: l0 level1 lfo1; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; tab-stops: list 36.0pt;">bits on the internet
 * <span style="line-height: normal; mso-list: l0 level1 lfo1; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; tab-stops: list 36.0pt;">trucks on roads
 * <span style="line-height: normal; mso-list: l0 level1 lfo1; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; tab-stops: list 36.0pt;">current and voltage in electrical networks
 * <span style="line-height: normal; mso-list: l0 level1 lfo1; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; tab-stops: list 36.0pt;">fluids in pipelines
 * <span style="line-height: normal; mso-list: l0 level1 lfo1; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; tab-stops: list 36.0pt;">goods being moved between places
 * <span style="line-height: normal; mso-list: l0 level1 lfo1; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; tab-stops: list 36.0pt;">money flowing through an economy

Source
1.Graph Theory for Dummies[| http://sharafat.shaiekh.com/guides/Graph_Theory_for_Dummies.pdf] 2.Graphs and Graph Theory [] 3.Transitive Closure [] 4. Demonstration of Depth First Search and Dijkstra algorithm [] or the file is here for download. *NOTE* Hit Run again to solve the maze 5. Applications of Graph Theory [] 6. Graph Theory [] <span style="display: block; height: 1px; left: -40px; overflow-x: hidden; overflow-y: hidden; position: absolute; top: 4913px; width: 1px;">http://www.greenfoot.org/scenarios/4900

Floyd-Warshall Algorithm
<span style="display: block; height: 1px; left: -40px; overflow: hidden; position: absolute; top: 12277.5px; width: 1px;">The Floyd-Warshall Algorithm is an example of dynamic programming; it compares all possible paths through the path between each pair of vertices. It is used to find shortest path and to find transitive closure ( if R is the relation on nodes "has an edge leading to" then the transitive closure of R is the relation "has a path of zero or more edges to")[[|3]] of a relation.[[|1]]