1.9 Algorithms and Programming Flashcards

1
Q

What is an algorithm?

A

A series of steps (sequence) to solve a specific problem.

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

State 3 methods of defining algorithms.

A
  1. Flowcharts
  2. Pseudocode
  3. Structured english
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is pseudocode? (2)

A
  1. A method of writing code without using syntax of any particular language.
  2. Shows the structure of a solution.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is structured English?

A

A cross between pseudocode and written English.

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

What is a variable?

A

A named space in the memory that contains a single piece of data.

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

What is a constant?

A

The same as a variable except the data
cannot be changed in the program.

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

Name 3 techniques to make code readable.

A
  1. Indenting the code
  2. Writing annotations to explain the code to programmers
  3. Using appropriate identifiers
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

State 2 types of a variable.

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

What is a local variable? (2)

A
  1. Only exists until the subroutine in which it was created ends.
  2. Only visible in that subroutine.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is a global variable?

A

Exists throughout the program and can be read/ written from any subroutine.

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

What is a parameter?

A

It is an item of data that is passed from one subroutine to another

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

What are the two ways of passing a parameter?

A
  1. Passing by value.
  2. Passing by reference
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is passing by value? (2)

A
  1. A copy of a value passed from one subroutine to another.
  2. The original value cannot be changed by the subroutine that receives it
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is passing by reference? (2)

A
  1. An actual variable is passed from one subroutine to another
  2. The original value can be changed by the subroutine that receives the variable
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is difference between 5 DIV 3 and 5 MOD 3?

A

5 DIV 3 = 1 i.e. integer division

5 MOD 3=2 i.e. remainder after division

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

What is sorting?

A

Placing data into a specified order .e.g. alphabetical, numerical or other

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

State 2 sorts.

A
  1. Bubble sort
  2. Insertion sort
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

How does Bubble Sort work? (4)

A
  1. A pass is made through the data, comparing each value with the following one, and swapping if necessary.
  2. It compares the 1st with 2nd, 2nd with 3rd and so on.
  3. When it has worked to the end it has completed one pass.
  4. A number of passes is made until the data is in order/ no swaps
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

When is Bubble sort most appropriate to use?

A

Works best on smaller, nearly sorted data.

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

How does Insertion Sort work? (4)

A
  1. Takes an element out the data and compared with a sorted list
  2. Items in the sorted list are moved up/ down to enable new items to be added in the correct place.
  3. It initially assumes only the first number is in the correct order.
  4. With each pass the number of items assumed correct increases by one.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

When does insertion sort works best?

A

Works best on small, jumbled up files.

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

What is searching?

A

Locating an item in a data structure

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

Name two types of searches.

A
  1. Linear search
  2. Binary search
24
Q

How does a linear search work?

A

Starts at one end of a data structure and examines every element in order until the item is found.

25
Q

When is a linear search faster? (2)

A
  1. Number of items to search is small.
  2. The item to search is one of the first data items in the list
26
Q

How does a binary search work? (4)

A
  1. Start at middle & check if value to be found is larger or smaller than the current value.
  2. If larger, discard smaller values. If smaller,
    discard larger values.
  3. Search in the middle of the selected data and repeat step 1. This eliminates half the data with every pass.
  4. Continue until the number is found or there is no more data to search.
27
Q

When is binary search faster?

A

Good on large sorted sets of data

28
Q

What is Top-Down Design?

A

Breaking down a problem into smaller problems, and smaller problems into smaller problems until the problems are simple and can be solved easily.

29
Q

What is a sequence?

A

Lines of code that are executed one after another in the order in which they are written.

30
Q

What is a selection?

A

One path through the code will be selected if a condition is met. An example of selection code is IF.

31
Q

What is repetition?

A

Code that is executed more than once. Example: For, While, loop.

32
Q

What is count?

A

An integer that keeps track of how many times a code has been run.

33
Q

What is a Rogue Value? (2)

A
  1. An invalid value to represent a special case.
  2. Often used as an exit condition from a loop
34
Q

What is modular programming?

A

The splitting up of a large piece of code into smaller chunks (modules) of code that perform a specific task.

35
Q

State 4 advantages of using modular programming.

A
  1. Different modules can be allocated to different programmers.
  2. Programmers with different skills are given tasks appropriately.
  3. Modules can be designed separately and tested separately.
  4. Modules can be reused reducing risk of bugs.
36
Q

What is a subroutine?

A

It is a piece of code that performs a specific task.

37
Q

What is a function?

A

Code that must return a value.

38
Q

What is compression?

A

Making a file occupy less space on a disk.

39
Q

State 4 advantages of using compression.

A
  1. Can transfer files faster
  2. Means that the disk has more space and can hold more files.
  3. Faster reading and writing of a file.

4 Helpful for streaming and downloading files

40
Q

State 2 disadvantages of using compression.

A
  1. Can result in lower quality of files.
  2. You may lose information that can’t be recovered.
41
Q

State 2 types of compression.

A
  1. Lossy
  2. Lossless
42
Q

What is lossy compression?

A

Removing data to decrease the file size.

43
Q

What is Lossless compression? (2)

A
  1. Shrinks the whole file while keeping all of the quality.
  2. Works by finding repeated patterns and compressing those patterns.
44
Q

What is lossless compression based on?

A

The LZ compression method developed by Lempel and Ziv.

45
Q

State 2 advantages of lossless compression,

A
  1. The file can be restored to its original quality.
  2. The file can be compressed up to 50% without losing quality.
46
Q

State 2 disadvantages of lossless compression.

A
  1. A lossless compressed file is not as small as a lossy compressed file
  2. Does not work well with random data as it is dependent on patterns in data
47
Q

What is run- length encoding? (2)

A
  1. Compressing clusters of number. E.g. pictures with lots of the same color.
  2. A form of lossless compression
48
Q

Give an example of run- length encoding.

A

Original: 0000 0000 0000 1111 1000 0000
Compressed: 12(0); 5(1); 7(0)

49
Q

Why is testing used?

A

To verify that a program is bug free.

50
Q

List 5 standard tests on data entry (E.g. input an integer between 1-10).

A
  1. Normal data (5)
  2. Extreme data (1,10)
  3. Invalid data (0,11)
  4. Data type (hello)
  5. Missing data ()
51
Q

Why is normal data used?

A

To see if the program processes normal data.

52
Q

Why is extreme data used?

A

While valid it is as invalid as possible.

53
Q

Why is invalid data used?

A

Should not work even if close to valid number.

54
Q

Why is data type used?

A

Testing to see if an error message appears.

55
Q

Why is missing data used?

A

To check the code doesn’t crash when data is missing.