1: Algorithms & Graph Theory Flashcards
Bubble Sort Algorithm (1:2, 3)
- Start at the beginning of the working list and move from left to right, comparing adjacent items
a) If they are in order, leave them
b) If they aren’t in order, swap them - When you get to the end of the working list, the last item will be in its final position. Remove this item from the working list
- If you have made some swaps in the last pass, repeat steps 1 & 2
- When a pass is completed without any swaps, the list is in order
Quick Sort Algorithm (6)
- Choose item at the midpoint of the list to be the first pivot
- Write down all the items that are less than the pivot, keeping their order in a sub-list
- Write down the pivot
- Write down the remaining items in a sub-list
- Repeat steps 1 to 4 for each sub-list
- When all the items have been chosen as pivots, stop
First-Fit Algorithm (2)
- Take the items in the given order
2. Pack each item in the first available bin that can take it, starting from bin 1 each time
First-Fit Algorithm +/- (2)
+ Quick and easy to implement
- Not likely to lead to a good solution
First-Fit Decreasing Algorithm (2)
- Sort the items into descending order
2. Apply the first-fit algorithm on the reordered list
First-Fit Decreasing Algorithm +/- (3)
+ Usually get a fairly good solution
+ Quick and easy to implement
- May not get an optimal solution
Full-Bin Method (2)
- Use inspection to find combinations of items that will fill a bin and pack these items first
- Pack any remaining items using the first-fit algorithm
Full-Bin Method +/- (2)
+ Usually get a good solution
- Difficult to do, especially when the numbers are plentiful and awkward
Vertex / Node
Point on a graph
Edge / Arc
Line segment joining two vertices
Weight
Number associated with an edge
Weighted Graph / Network
Graph with weighted edges
Vertex Set
List of vertices
Edge Set
List of edges
Subgraph
Part of an original graph, all of whose vertices and edges belong to the original graph
Degree / Valency / Order
Number of edges incident to a vertex
Even / Odd Degree
Even / odd number of edges incident to a vertex
Walk
Route through a graph along the edges from one vertex to the next
Path
Walk in which no vertex is visited more than once
Trail
Walk in which no edge is visited more than once
Cycle
Walk in which the end vertex is the same as the start vertex and no other vertex is visited more than once
Hamiltonian Cycle
Cycle that includes every vertex
Connected Vertices
Two vertices are connected if there is a path between them
Connected Graph
A graph is connected if all of its vertices are connected
Loop
Edge that starts and finishes at the same vertex
Simple Graph
Graph in which there are no loops and there is, at most, one edge joining any pair of vertices
Directed Edge
An edge with a direction associated with it
Digraph
Graph with directed edges (a.k.a., directed graph)
Euler’s Handshaking Lemma (2)
- In any undirected graph, the sum of the degrees of the vertices = 2 x the number of edges
- Thus, in any undirected graph, there is an even number of odd vertices
Tree
Connected graph with no cycles
Spanning Tree
Subgraph, which contains all the vertices of the original graph and is a tree
Complete Graph
Graph in which every vertex is joined, by a single edge, to every other vertex (notation: K_n where n is number of vertices)
Isomorphic Graphs
Graphs which show the same information but may be drawn differently
Planar Graph
Graph that can be drawn in a plane such that no two edges meet except at a vertex
Planarity Algorithm (5, 1:4))
- Identify a Hamiltonian cycle
- Draw a polygon with vertices labelled to mach the ones in the Hamiltonian cycle
- Draw edges inside the polygon to match the edges of the original graph not already represented by the polygon
- Make a list of all edges inside the polygon
- Choose any unlabelled edge in the list and label it ‘I’. If all edges are now labelled, the graph is planar
- Look at any unlabelled edges that cross the edge(s) just labelled:
- If there are none, go back to step 5
- If any of these edges cross each other, the graph is non-planar
- If none of these edges cross each other, give them the opposite label to the edge(s) just labelled
- If all edges are now labelled, the graph is planar. Otherwise, go back to the start of step 6
Algorithm
A finite sequence of step-by-step instructions carried out to solve a problem
Eulerian Graph
Connected graph, whose vertices are all even. It contains an Eulerian cycle
Eulerian Cycle
Cycle, that includes every edge exactly once
Semi-Eulerian Graph
Connected graph with exactly two odd vertices. It contains a trail, that includes every edge but starts and finishes at different vertices