Component 2.2 - Algorithms And Programming Constructs Flashcards

1
Q

What is an algorithm?

A

An algorithm is a set of instructions that can be used to solve a given problem

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

What two things must the instructions of an algorithm be?

A
  • clear

- in the correct order to produce the solution

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

Algorithms are a ___ for writing a computer program to ___

A

Starting point, solve the given problem

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

What programming language should an algorithm be presented in?

A

Algorithms should be presented in a way that it can be used in different programming languages. It should NOT be in computer code

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

What is pseudo code?

A

Pseudo code is a way of writing instructions in plain english

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

What is a flowchart?

A

A flowchart is a diagram showing the instructions to be carried out in the order they should be carried out

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

What 3 things must a good algorithm be?

A
  • Be finite - must not never end trying to solve a problem
  • have well defined instruction (each step must be clear)
  • be effective (it should give the correct result/solution)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What does a rounded rectangle mean in a flowchart?

A

Start/stop

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

What does a diamond mean in a flowchart?

A

Decision

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

What does a parallelogram mean in a flowchart?

A

Input/Output

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

What does a rectangle mean in a flowchart?

A

Operation

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

What does a circle mean in a flowchart?

A

Connector

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

What does a rectangle with two lines near each end mean in a flowchart?

A

Store/call subroutine

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

What are the three basic constructs used to design algorithms?

A

Sequence, selection and iteration

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

What is the sequence construct of an algorithm?

A

Algorithms consist of a series of instructions in a specific order. It is the sequence in which instructions must be carried out for the algorithm to work.

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

What happens if the sequence if an algorithm is not right?

A

Computers can only follow instructions in the order they are given, if the sequence is not right the computer will still follow the order they are given in

17
Q

What is the selection construct of an algorithm?

A

A selection instruction is one where a decision must be made. This is the times in which an instruction in an algorithm may give different options

18
Q

What is the iteration construct of an algorithm?

A

Sometimes an algorithm will need a series of steps to be carried out more than once. This is called iteration, often referred to as a loop in a program. (E.g. for next loop)

19
Q

When will you use a loop with a count or rouge value?

A

You would use this when you do not know how many times you will need the instructions in the loop to be used

20
Q

How does a count value loop work?

A

Count records the-number of times a process is carried out and when it reaches the required number the loop terminates

21
Q

What is a rogue value?

A

A rogue value is a value that falls outside the range of possible values for the data that is being processed

22
Q

How does a rogue galue loop work?

A

If there is a loop asking for inputs, storing them as var which must be positive, you could input -1 for var which will end the loop (following your code)

23
Q

What does a sorting algorithm do?

A

A sorting algorithm will put items in a list into a particular order, alphabetic or numeric

24
Q

What is merge sort?

A

Merge sort is a sorting technique based on the idea of ‘divide and conquer’

25
Q

How is the idea of ‘divide and conquer’ presented in merge sort?

A

Merge sort first divides the list into two equal halves then combines them in a sorted list

26
Q

How does the merge sort algorithm work?

A

Th merge sort algorithm divides lists into two equal halves, then splits the halves into halves and so on until on,y single items are left. It then combines them in the same way they were divided but in order.

27
Q

What is bubble sort?

A

Bubble sort is a simple sorting algorithm based on the comparison of adjacent data items, swapping them if they are in the wrong order

28
Q

What is the disadvantage of bubble sort?

A

It is not suitable for large data sets

29
Q

How does bubble aort work?

A

1) Bubble sort starts by comparing the first two items in a List
2) If the first is smaller than the second it swaps them
3) It then moves onto items 2 and three and does the same
4) It keeps repeating steps 1-3 doing items 2,3 then 3,4 then 4,5 and so on
5) Once it reaches the end of the list it loops over and over again until, no swaps have been done
6) As no swaps means a sorted list

30
Q

What is linear search?

A

Linear search is a very simple searching algorithm

31
Q

How does linear search work?

A

Each item in the data set is compared with the search condition in sequence till the item is found or the end of the data set is reached. (Basically if you want to find 20, it goes through a list looking at each item one by one comparing it to 20, if it matches it has found it is successful, if it reaches the end of the list it has failed (item does not exist))

32
Q

How can the efficiency of a search be measured?

A

You can measure the efficiency of a search by considering the number of comparisons that are made before the required item is found

33
Q

Why is linear search inefficient?

A

Linear search may have to go through almost the whole list till items are found since items in the list are not ordered. It also has to go through the whole list to decide that an item doesn’t exist

34
Q

What needs to be done for a search to be more efficient?

A

For a search to be more efficient, it is necessary to sort the data into order first

35
Q

How does binary search work?

A

1) Firstly the list being searched is sorted
2) The search starts comparing the item requested to the item at the mid point
3) - If the item at the midpoint matches the search item it has been found
- If the item in the midpoint is greater than the search item all items to the right can be discarded (as they are greater)
- Opposite if it is less than
4) This process is repeated on the remaining data till the required item is found, or all items have been discarded

36
Q

If binary search calculates the midpoint with a decimal place (e.g. 6.5) what item number is taken as the midpoint?

A

The midpoint is taken as the integer part of the result (6)