Decision Flashcards
Algorithm - definition
> An algorithm is a finite sequence of step-by-step instructions carried out to solve a problem.
Flow chart
> In a flow chart, the shape of each box tells you its function.
How can unordered lists be sorted?
- Bubble sort
- Quick sort
>Quick sort is quicker to implement than bubble sort except when e.g. only the largest item is out of place when putting them in ascending order.
Bubble sort
> In a bubble sort, you compare adjacent items in a list:
-if they are in order, leave them.
-if they are not in order, swap them.
-the list is in order when a pass is completed without any swaps.
0.5n(n-1) = (n-1) + (n-2) + … + 2 + 1.
Min passes = 1 (already in order)/
Max passes = n (if smallest item is at the end on the list).
Quick sort
> In a quick sort, you select a pivot then split the items into two sub-lists:
-one sub-list contains items less than the pivot.
-the other sub-list contains items greater than the pivot.
-you then select further pivots within each sub-list and repeat the process.
nlogn
The 3 bin-packing algorithms
- First-fit algorithm
- First-fit decreasing algorithm
- Full-bin packing algorithm
First-fit algorithm
> The first-fit algorithm works by considering items in the order they are given.
Quick to implement.
Not likely to lead to a good solution.
First-fit decreasing
> The first-fit decreasing algorithm requires the items to be in descending order before applying the algorithm.
Usually a good solution and easy to implement.
Not likely to lead to a good solution.
Full-bin packing
> Full-bin packing uses inspection to select items that will combine to full bins. Remaining items are packed using the first-fit algorithm.
Usually a good solution.
Difficult to do, especially when the numbers are plentiful or awkward.
Order of an algorithm
> The order of an algorithm can be described as a function of its size.
If an algorithm has order f(n), then increasing the size of the problem from n to m will increase the run time of the algorithm by a factor of approximately f(m) / f(n).
If the size of a problem is increased by some factor k then an algorithm of linear order will take approx. k times as long to complete, quadratic - k^2 etc.
Graph - description
> A graph consists of points (called vertices or nodes) which are connected by lines (edges or arcs).
Weighted graph/network
> If a graph has a number associated with each edge (usually called its weight), then the graph is known as a weighted graph or network.
Subgraph - definition
> A subgraph is a graph, each of whose vertices belongs to the original graph and each of whose edges belongs to the original graph.
It is part of the original graph.
Degree/valency/order of a vertex - definition
> The degree (or valency or order) of a vertex is the number of edges incident to it.
If the degree of a vertex is even, you say that it has even degree.
If the degree of a vertex is odd it has odd degree.
Walk - definition
> A walk is a route through a graph along edges from one vertex to the next.
Path - definition
> A path is a walk in which no vertex is visited more than once.
Trail - definition
> A trail is a walk in which no edge is visited more than once.
Cycle - definition
> A cycle is a walk in which the end vertex is the same as the start vertex and no other vertex is visited more than once.
Hamiltonian cycle - definition
> A Hamiltonian cycle is a cycle that includes every vertex.
Connected
> 2 vertices are connected if there is a path between them.
>A graph is connected if all its vertices are connected.
Loop - definition
> A loop is an edge that starts and finishes at the same vertex.
Simple graph - definition
> A simple graph is one in which there are no loops and there is at most one edge connecting any pair of vertices.
Directed graph - definition
> If the edges of a graph have a direction associated with them they are known as directed edges and the graph is known as a directed graph (or digraph).
Euler’s handshaking lemma
> In any undirected graph, the sum of the degrees of the vertices is equal to 2 x the number of edges.
As a consequence, the number of odd nodes must be even.
This result is called Euler’s handshaking lemma.
Any vertices of odd degree must therefore ‘pair up’.