AS Flashcards
How do you carry out a bubble sort?
Start at the first element of the list. Then compare the adjacent element to the right, if they’re in the wrong order then swap them. Then compare elements 2 and 3 and swap if needed. Continue this process of comparing and swapping until all the list is sorted
How do you carry out a quick sort?
Start at the middle element in the list (right-hand one if there is no middle) and mark it as a pivot by underlining. Then retaining the order of elements put everything left of the pivot to its left and everything greater than to the right. Then box the pivot. Next pick a pivot for each of the sublists we have made using the same middle method and repeat until the list is sorted so everything has been a pivot or every sublist has length 1.
What is the formula for working out the time of the algorithm?
T = f(m)/f(n) x t where f(x) is the order of the algorithm so polynomial gives f(x) = x^n or logarithmic gives f(x) = log(x)
What is a graph?
A diagram consisting of nodes which can be connected by edges that may have weights on them
What is Eulers handshaking lemma?
Σ deg(V) = 2 #edges
What is a path?
A finite sequence of edges connecting vertices such that one vertex appears only once in the path
What is a trail?
A finite sequence of edges such that no edge is visited more than once
What is a hamiltonian cycle?
A closed path that passes through every vertex only once and starts and ends at the same node
What is a tree?
A connected graph with no cycles
What is a spanning tree?
It is a subgraph which includes all the vertices and is also a tree
What is K_n?
It is a complete graph of n nodes where every node connects to every other node and so will have exactly n(n-1)/2 arcs
What is kruskals?
A minimum spanning tree algorithm that lists all of the arcs in order of ascending weights and then adds each arc to the MST so long as it doesn’t make a cycle and at the end we should have an MST. We MUST list the rejects so list all the arcs and tick or cross them to indicate a selection or a rejection.
What is prims?
Another minimum spanning tree algorithm in which we start at a given node, look at every arc connecting to that node and pick the one with the lowest cost. We then do this and look at every arc connecting to the now two nodes we have in our MST and select the one with the lowest cost that doesn’t make a cycle. We MUST NOT list the rejects so only list the arcs
that are selected.
https://algorithm-visualizer.org/greedy/prims-minimum-spanning-tree
How do we do Prims on a matrix and what is the total number of comparisons?
Given the matrix we cross out the row of the start vertex and label it number 1 above. Then look at the lowest cost arc for the labelled columns and circle it. Then add this arc to the MST and cross out the rest of the row and number the node we crossed out. Continue this until all rows are crossed out and the circled entries will give you the arcs we need for the MST. The total comparisons is (n^3 - 7n + 6)/6
What is a semi-Eulerian graph?
A connected graph with strictly one pair of odd nodes