Algorithms and definitions Flashcards

1
Q

What is an algorithm?

A

An algorithm is a finite sequence of step-by-step instructions carried out to solve a problem.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Describe the bubble sort algorithm.

A

In a bubble sort, you can compare adjacent items in a list.
The algorithm is;
1) Start at the beginning of the working list and move from left to right comparing adjacent items.
•If they are in order leave them.
•If they aren’t in order, leave them.
2) When you get to the end of the working list, the last item will be in its final position. This item is then no longer in the working list.
If you have made some swaps in the last pass, repeat step 1.
When a pass is completed without any swaps, every item is in its final position and the list is in order.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Describe the quick sort algorithm.

A

In a quick sort algorithm, you select a pivot, then split the items into two sub-lists.
The algorithm is;
1) Choose the item at the midpoint of the list to be the first pivot.
2) Write down all the items that are less than the pivot, keeping their order, in a sub-list.
3) Write down the pivot.
4) Write down the remaining items, those greater than the pivot) in a sub-list.
5) Apply steps 1 to 4 to each sub-list.
6) When all items have been chosen as pivots, stop.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is a pass?

A

Going from the start to the end of the working list. The length of the working list reduces by 1 with each pass.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Going from the start to the end of the working list. The length of the working list reduces by 1 with each pass.

A

The first-fit algorithm works by considering items in the order they are given.
The algorithm is;
1) Take the items in the order given.
2) Place each item in the first available bin that can take it. Start from bin 1 each time.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Describe the first-fit decreasing algorithm.

A

The first-fit decreasing algorithm requires the items to be in descending order before applying the algorithm.
The algorithm is;
1) Sort the items so that they are in descending order.
2) Apply the first-fit algorithm to the reordered list.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Describe the full-bin packing algorithm.

A

Full-bin packing uses inspection to select items that will combine to fill bins. Remaining items are packed using the first-fit algorithm.
The algorithm is;
1) Use observation to find combinations of items that will fill a bin. Pack these items first.
2) Any remaining items are packed using the first-fit algorithm.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Describe the first-fit algorithm.

A

The first-fit algorithm works by considering items in the order they are given.
The algorithm is;
1) Take the items in the order given.
2) Place each item in the first available bin that can take it. Start from bin 1 each time.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the order of a bubble sort?

A

½𝑛(𝑛-1) or ½𝑛²-½𝑛. The bubble sort algorithm is said to have a quadratic order.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is a vertex?

A

A vertex is a point on a graph. Vertices are sometimes called nodes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is an edge?

A

An edge is a line segment joining vertices. Edges are sometimes called arcs.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is the vertex set?

A

The list of vertices comprising a graph.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is a subgraph?

A

A graph, each of whose vertices belongs to the original graph and each of whose edges belong to the original graph.
It is simply a part of the original graph.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is the degree of a vertex?

A

The degree or valency or order of a vertex is the number of edges incident. If the degree of a vertex is even, it is said to have even degree.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is a walk?

A

A route through the graph along edges from one vertex to the next.
OR
A walk in a network is a finite sequence of edges such that the end vertex of one edge is the start vertex of the next.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is a path?

A

A path is a walk in which no vertex is visited more than once.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What is a trail?

A

A trail is a walk in which no edge is visited more than once.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What is a cycle?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

What is a Hamiltonian cycle?

A

A Hamiltonian cycle is a cycle that includes every vertex.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

What does it mean for two vertices to be connected?

A

Two vertices are connected if there is a path between them.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

What does it mean for a graph to be connected?

A

A graph is connected if all its vertices are connected.

22
Q

What is a loop?

A

A loop is an edge that starts and ends at the same vertex.

23
Q

What does it mean for a graph to be simple?

A

A simple graph is one in which there are no loops and there is at most one edge connecting any pair of vertices.

24
Q

What is a directed edge?

A

If an edge of a graph has a direction associated with it, it is known as a directed edge and the graph is known as a directed graph, often abbreviated to a digraph.

25
Q

What is a tree?

A

What is a tree?

26
Q

What is a spanning tree?

A

A spanning tree is a subgraph which includes all the original graph’s vertices and is also a tree.

27
Q

What is a complete graph?

A

A complete graph is a graph in which every vertex is directly connected by a single edge to each of the other vertices.
The complete graph of 𝑛 vertices is written Kₙ.

28
Q

What is an isomorphic graph?

A

An isomorphic graphs are graphs that show the same information but may be drawn differently.

29
Q

What is an adjacency matrix?

A

Each entry in an adjacency matrix describes the number of arcs joining the corresponding vertices.

30
Q

What is a distance matrix?

A

A matrix associated with a weighted graph, in a distance matrix, the entries represent the weight of each arc, not the number of arcs.

31
Q

What is a planar graph?

A

A planar graph is one that can be drawn in a plane such that no two edges meet except at vertices.

32
Q

A planar graph is one that can be drawn in a plane such that no two edges meet except at vertices.

A

The planarity algorithm can be applied to graphs that containing a Hamiltonian cycle.
The algorithm is as follows:
1) Identify a Hamiltonian cycle.
2) Draw a polygon with vertices labelled to match the ones in the Hamiltonian cycle.
3) Draw edges inside the polygon to match the edges of the original graph not already represented by the polygon itself.
4) Make a list of all edges inside the polygon, in any order.
5) Choose any unlabelled edge and label it ‘I’. If all edges are now labelled then the graph is planar.
6) Look at any unlabelled edges that cross the edge(s) just labelled:
•If there are none, then go back to step 5.
•If any of these edges cross each other, then 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.

33
Q

What is a minimum spanning tree?

A

Sometimes called a minimum connector, a minimum spanning tree is a spanning tree of a weighted graph such that the total length of its arcs (edges) is as small as possible.

34
Q

What is Kruskal’s algorithm?

A

Kruskal’s algorithm can be used to find a minimum spanning tree:
1) Sort all the arcs (edges) into ascending order of weight.
2) Select the arc of the least weight to start the tree.
3) Consider the next arc of least weight.
• If it would form a cycle with the arcs already selected, reject it.
•If it doesn’t form a cycle, add it to the tree.
•If there is a choice of equal arcs, consider each in turn.
4) Repeat step 3 until all vertices are connected.

35
Q

What is Prim’s algorithm.

A

Prim’s algorithm can be used to find a minimum spanning tree:
1) Choose any vertex to start the tree.
2) Select an arc of least weight that joins a vertex already in the tree to a vertex not yet in the tree.
•If there is a choice of arcs of equal weight, choose any of them.
3) Repeat step 2 until all the vertices are connected.

36
Q

What is the difference between Kruskal’s and Prim’s algorithm?

A

Prim’s algorithm considers vertices, whereas Kruskal’s algorithm considers edges.

37
Q

How would you apply Prim’s algorithm to a distance matrix?

A

The distance matrix form of Prim’s algorithm is:
1) Choose any vertex to start the tree.
2) Delete the row in the matrix for the chosen vertex.
3) Number the column in the matrix for the chosen vertex.
4) Put a ring round the lowest undeleted entry in the numbered columns.
•If there is an equal choice, choose randomly.
5) The ringed entry becomes the next arc to be added to the tree.
6) Repeat steps 2-5 until all rows have been deleted.

38
Q

What is Dijkstra’s algorithm?

A

Dijkstra’s algorithm can be used to find the shortest path from S to T through a network:
1) Label the start vertex, S, with the final label, 0.
2) Record a working value at every working value at every vertex, Y, that is directly connected to the vertex that has just received it’s final label, X.
•Working value at Y= final label at X+weight of arc XY.
•If there is already a working value at Y it is only replaced if the new value is smaller.
•Once a vertex has received a final label, it is not revisited and its working values are no longer considered.
3) Look at the working values at all vertices without final labels. Select the smallest working value. This now becomes the final label at that vertex. (If two vertices have the same smallest working value, either may be given its final label first).
4) Repeat steps 2 and 3 until the destination vertex T receives its final label.
5) To find the shortest path, trace back from T to S. Given that B already lies on the route, include arc AB whenever: final label of B-final label of A=weight of arc AB.
You can also use Dijkstra’s algorithm to find the shortest route between the start vertex and any other vertex with a final label, this also works for networks with directed arcs, they must be treated like one way roads.

39
Q

Describe Floyd’s algorithm.

A

Floyd’s algorithm can be used to find the shortest path between every pair of vertices in a network:
1) Complete an initial distance table for the network. If there is no direct route from one vertex to another, label the distance with the infinity symbol.
2) Complete an initial route table by making every entry in the first column the same as the label at the top of the first column, making every entry in the second column the same as the label at the top of the second column and so on.
3) In the first iteration, copy the first row and the first column values of the distance table into a new table. Lightly shade these values.
4) Consider each unshaded position in turn. Compare the value in this position in the previous table with the sum of the corresponding shaded values.
If X+Y≥Z then copy Z into the new table.
If X+Y

40
Q

What is an Eulerian graph?

A

An Eulerian graph or network is one which contains a trail that includes every edge and starts and finishes at the same vertex. This trail is called an Eulerian circuit, often called an Eulerian cycle. Any connected graph whose vertices are all even is Eulerian.

41
Q

What is a semi-Eulerian graph?

A

A semi-Eulerian graph or network is one which contains a trail that includes every edge but starts and finishes at different vertices. Any connected graph with exactly two odd vertices is semi-Eulerian.

42
Q

What is the route inspection algorithm?

A

The route inspection algorithm, or Chinese postman algorithm, can be used to find the shortest route in a network that traverses every arc at least once and returns to its starting point.
•If all the vertices in the network have even degree, then the length of the shortest route will be equal to the total weight of the network.
If a network has exactly two odd vertices, then the length of the shortest route will be equal to the total weight of the network, plus the length of the shortest path between the two odd vertices.
The algorithm:
1) Identify any vertices with odd degree.
2) Consider all possible complete pairings of these vertices.
3) Select the complete pairing that has the least sum.
4) Add a repeat of the arcs indicated by this pairing to the network.

43
Q

What is a tour?

A

A tour is a walk which visits each vertex, returning to its starting vertex.

44
Q

What are decision variables in linear programming?

A

The numbers of each thing that can be varied. The variables will be the ‘letters’ in the inequalities and objective function.

45
Q

What are constraints in linear programming?

A

The things that prevent you from making or using an infinite number of each of the variables.
Each constraint will give rise to one inequality.

46
Q

What is a feasible solution in linear programming?

A

If you find values for the decision variables that satisfy each constraint you have a feasible solution

47
Q

What is a feasible region in linear programming?

A

In graphical linear programming, the region that contains all the feasible solutions is called the feasible region.

48
Q

What is an optimal solution in linear programming?

A

The feasible solution that meets the objective.

There may be multiple.

49
Q

What is the process to formulate a problem as a linear programming problem?

A

1) Define the decision variables
2) State the objective (maximise or minimise, together with an objective function)
Write the constraints as inequalities.

50
Q

How would you represent a feasible region graphically?

A

The feasible region is the region of the graph that satisfies all of the constraints of the linear programming problem. Shade out all areas that do not satisfy all of the constraints

51
Q

How would you find a maximum or minimum point of a feasible region using the objective line method (or ruler method).

A

To get the objective line, draw a line between the points y=coefficient of x and x=coefficient of y or a multiple.
To find the maximum, draw a line parallel to the objective line with the highest possible y intercept such that it still passes touches the feasible region, this is the maximum point.
For the minimum, aim instead for the lowest possible y intercept, with the same constraints.

52
Q

How would you find an optimal point using the vertex testing method?

A

1) Find first the coordinates of each vertex of the feasible region.
2) Evaluate the objective function at each of these points.
3) Select the vertex that gives the optimal value of the objective function.