3.1 Fundamentals Of Algorithms Flashcards

1
Q

Algorithm definition:

A

= sequence of steps followed to complete a task

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

Decomposition definition:

A

= breaking complex problem down into smaller sub-problems & solving each one individually

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

Abstraction definition:

A

= removing unnecessary detail from a problem (picking out important bits)

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

Two ways to write an algorithm:

A
  • pseudo-code

- flowcharts

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

Pseudo-code purpose & advantages:

A

= clearly shows an algorithms steps without the finer details

  • quick to write
  • easy to understand
  • easily converted into any programming language
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Pseudo-code signs:

A

Assigning a variable: _

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

Flowchart commands

A

Oval = start/stop
Parallelogram = outputs/inputs
Rectangle = processes (instructions/calculations)
Diamond = decision
Rectangle with added vertical lines = subroutine
Arrow = shows direction

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

Types of flowcharts

A
  • sequences (Straight from start to end)
  • iteration (Contains a loop, allows tasks to be repeated)
  • selections (Multiple ways from start to stop, includes decision)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Types of search algorithms:

A

= to find items in a list

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

Binary search

A

1) find middle item in ordered list
2) if this is the item you’re looking for, stop
3) if not, compare middle term with desired item (if it comes before the middle term, get rid of 2nd half of list, if it comes after, get rid of 1st half)
4) repeat steps 1-3 until the desired item is found
(Divide-and-conquer algorithm)

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

Advantages & disadvantages of binary search:

A

+
Faster/more efficient on large datasets

-
Dataset must be sorted(ordered) before

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

Linear search:

A

1) check first item in dataset
2) if this is the item you are looking for, stop
3) if not look a next item in list
4) repeat steps 2-3 until desired item found, or every item checked

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

Advantages & disadvantages of linear search

A

+
Very easy to implement (simple)
List doesn’t need to be sorted/ordered (used on any type of list)

  • Slow/not efficient on long lists
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Types of sort algorithms:

A

= sorts lists into numerical/alphabetical order

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

Bubble sort:

A

1) look at first 2 items in list
2) if in right order, don’t do anything, if in wrong order, swap them
3) move onto next pair of items
4) repeat steps 2-3 until end of list = 1 pass
5) repeat steps 1-4 until no swaps in a pas (include last pass with 0 swaps)

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

Advantages & disadvantages of bubble sort

A

+
Simple algorithm, easily implemented on computer
Efficient to check if list is already in order
Doesn’t use much memory

-
Inefficient = slow for large lists

17
Q

Merge sort

A

1) split list in half (into sub-lists) until all lists only contain 1 item
2) merge pairs of sub-lists, sorting items into right order each time
3) repeat step 2 until merged all sub-lists together

18
Q

Advantages & disadvantages of merge sort

A

+
More efficient/quicker (than bubble) for large lists but similar for small lists
Very consistent running time regardless of how ordered original list is

  • Even if list is already sorted, will still go through whole process
    Uses more memory (creates additional lists)