D1 Flashcards
Bubble Sort
Purpose
Sorts a list into ascending or descending order
[n]
The integer value of
Round to the nearest whole number
Bubble Sort
Algorithm
- Starting at the beginning of the list compare adjacent values
- if they are in order leave them
- if not swap them - When you get to the end of the list repeat step one, each repetition of step one is called a pass
- When a pass has been completed without any swaps the list is in order
Quick Sort
Purpose
Sorts a list into ascending or descending order
Quick Sort
Algorithm
- Select the middle value as a pivot by circling it
- Write out the items that are lower than the pivot in the order they appear in the list before the pivot
- Write down the pivot in a square as a fixed value
- Write down the remaining items that would come after the pivot in the order that they appear in the list
- Each side of the pivot(s) is now treated as a separate sub lists
- For each sub list repeat steps 1-5
- Stop when all items are fixed values, in a square
Binary Search
Purpose
To find an item in an ordered list
Binary Search
Algorithm
T is the value you are looking for
m is the value from the list
n is the number of items left in the list
- m = [n+1 / 2]th value
- -if m=T item is found, end
- if mT discard m and all items before it
- Repeat steps 1 to 2 until T is found or the list is exhausted
Bin Packing
Purpose
Fitting items into a space
Bin Packing
First Fit Algorithm
- Take the items in the order given
2. Place each item in the first bin that it will fit in starting from bin 1 each time
Bin Packing
First Fit Decreasing Algorithm
- Reorder the items so that they are in descending order, biggest first
- Apply the first fit algorithm to the new list
Bin Packing
Full Bin Packing Algorithm
- Pack the first bins with any combinations of items that will completely fill a bin
- Pack any remaining items using the first fit algorithm (not decreasing) using the original order given
Graph
Definition
A graph consists of vertices/nodes connected by edges/arcs
Simple Graph
Definition
Contains no loops
No more than one edge between each pair of vertices
Weighted Graph
Definition
A graph that has a number or distance associated with each edge
Su graph
Definition
A part of a bigger graph
Degree / Valency / Order
Definition
The degree/valency/order of a vertex is the number of edges incident to it
Connected
Definition
Two vertices are connected if there is a path between them
Path
Definition
A finite sequence of edges such that the end vertex of one edge in the sequence is the start vertex if the next edge in the sequence
No vertex is repeated
Walk
Definition
A path in which you are permitted to repeat vertices
Cycle / Circuit
Definition
A closed path, the end vertex of the last edge is the start vertex of the first edge
Loop
Definition
An edge that starts and finishes at the same vertex
Digraph
Definition
A graph that has directions associated with its edges
Tree
Definition
A connected graph with no cycles
Spanning Tree
Definition
A spanning tree of a graph, G, is a su graph which includes all of the vertices in G and is also a tree
Minimum Spanning Tree
Definition
The minimum spanning tree of a graph, G, is the spanning tree of smallest weight that includes all of the vertices in G