Flashcards in Algorithms Deck (43)

Loading flashcards...

1

## binary search precondition

### the list needs to be sorted

2

## Insertion sort

### works by dividing a list into two groups: sorted and unsorted. Elements are inserted one by one into their correct position in the sorted section.

3

## linear search

### starts at the beginning of a list and checks each item in turn until the desired item is found

4

## Binary search

### divides a list in two each time until the item being searched for is found

5

## Four sorting algorithms

### Bubble, Insertion, Quick, Merge

6

## Insertion sort words

###
Make the first item in the list the sorted list. The remaining items are the unsorted list.

While there are items in the unsorted list take the first item of the unsorted list.

While there is an item to the left of it which is smaller than itself swap with that item. End while.

The sorted list is now one item bigger.

End while

7

## Merge sort

### splits a list of size n into n lists of size 1. Each pair of lists are merged together in order until there is only one list of size n.

8

## Why does merge split down into unit lists

### because a list of length one is sorted

9

## Merge algorithm

###
1. If the sub-list is 1 in length, then that sub-list has been fully sorted

2. If the list is more than 1 in length, then divide the unsorted list into roughly two parts. (An odd numbered length list can't be divided equally in two)

3. Keep dividing the sub-lists until each one is only 1 item in length.

4. Now merge the sub-lists back into a list twice their size, at the same time sorting each items into order

5. Keep merging the sub-lists until the full list is complete once again.

10

## Quick sort algorithm

###
REPEAT:

1. Pick a pivot

2. sort the items either side of the pivot

3. make the items either side of the pivot a sublist

Until length of sublist= 1

11

## Quick sort

### The basic idea is to keep splitting a list into two smaller lists, sort those lists using the same quick-sort rules, then split the sub-lists and sort again, until there are only lists of 1 item or less left.

12

## Where can the pivot be applied

### The pivot can be applied to any item in the unsorted list.

13

## advantages bubble

### - simple

14

## disadvantages bubble

### - long time to run

15

## advantages insertion

###
- Simple to code

- Good performance with small lists

- memory efficient

- good with sequential data

16

## disadvantages insertion

###
- poor performance with larger lists

- not as quick as merge/quick sort

17

## disadvantages quick

###
- difficult to implement

- if a bad pivot is picked the runtime is slow

- worst case efficiency is bad

18

## advantages quick

###
- very efficient

- no additional storage required/ less stack memory

19

## advantages merge

###
- Good for sorting slow access data

- Good for sorting sequential data

- if there are two equal values then positions are conserved, which is quicker

20

## disadvantages merge

###
- It needs twice then length of memory space than the list

- If recursion is used, it used twice the stack memory as a quick-sort

- quick sort is faster

21

## advantages Linear search

###
- Good Performance

- List does not need to be ordered

- Not affected by insertions and deletions

22

## disadvantages linear search

### - May be too slow over large lists

23

## advantages binary search

###
- Works well with larger lists

- Quicker

24

## disadvantages binary search

###
- Small lists simpler to use linear search

- Cannot deal with unordered lists

25

## Shortest path algorithms

### Dijkstras and A*

26

## Dijkstras table columns

### visited, vertex, shortest distance from start node, previous vertex

27

## What are all the shortest distances filled with at the beginning (Dijkstras)

### infinity, except for the vertex your measuring from which is zero

28

## A*

### A variation of Dijkstras that uses a heuristic to try and get the correct solution sooner

29

## A* table

### visited, vertex, shortest distance from start node, heuristic distance, sum, previous vertex

30