unit 6- algorithms Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

A computer game is written in a high-level programming language.
(a) State why the computer needs to translate the code before it is executed

A

interpreter translates code into machine code, instruction by instruction - the CPU executes each instruction before the interpreter moves on to translate the next instruction. Interpreted code will show an error as soon as it hits a problem, so it is easier to debug than compiled code.

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

Describe the difference between how a compiler and an interpreter would translate the
code.

A

Interpreter translates just one statement of the program at a time into machine code. Compiler scans the entire program and translates the whole of it into machine code at once

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

what is a constant in programming

A

Data values that stay the same every time a program is executed are known as constants

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

what is a binary search ?

A

It works by repeatedly dividing in half the portion of the list that could contain the item, until you’ve narrowed down the possible locations to just one.

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

how does a linear search work

A

Starting at the beginning of the data set, each item of data is examined until a match is made. Once the item is found, the search ends.

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

what is a bubble sort ?

A

each item is compared with the one on the right and swapped if larger. at the end of the first pass the largest item is last.

an example: ( 15 , 9,7, 6 )
the first pass (9,7,6,15)
the second pass ( 7,6,9,15)
the third pass ( 6,7,9,15)

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

what is an insertion sort ?

A

the algorithm sorts one data at a time.

its similar to how you wold sort a deck of cards

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

here is a list 9,5,4,15

use and describe the method of an insertion sort

A

first you compare 9 and 5 9 is bigger so you swap them
list is now 5,9,4,15
you now compare 4 to the first two sets of data its the smallest so therefor goes first.
list is now 4,5,9,15

you then compare 15 but 15 is the highest so stays at the back

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

here is a list 9,5,4,15

use the bubble sort to sort the list

A
first pass (5,4,9,15) 
second pass (4,5,9,15)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the method of a merge sort ?

A

Divide the unsorted list in two
Continue to divide these lists into two until there is just one item in each list
Now merge each list back until there is only one list remaining – which will be the fully sorted list

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

What are the method of a merge sort ?

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

Pros and cons of linear search

A

Easier to understand than binary and works on any list

Can be inefficent when looking at longer lists

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

Pros and cons of binary search

A

More efficent with longer lists

Harder to understand and only works on sorted lists

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

Pros and cons of a merge sort ?

A

More efficent than bubble and instertion with longer lists

Uses more memory

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

Pros and cons of bubble

A

Easier to understand

Inefficent in longer litsts

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

Pros and cons of insertion sort

A

Easy to understand

Time consuming and ineffective with longer lists

17
Q

What is decomposition

A

Breaking a large problem into smaller more manageable ones

18
Q

What is abstaction

A

Removing the unnecessary detail from a problem to leave only the important parts