9. Algorithms and Programs Flashcards

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

What does the operator DIV do?

A

Finds the whole number of times a divisor can be divided into a number e.g. 11 DIV 2 = 5

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

What does the operator MOD do?

A

Finds the remainder when a divisor is divided into a number e.g. 11 DIV 2 = 1

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

What is an algorithm?

A

An algorithm is a set of organised steps or rules to solve a given problem

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

What is a Boolean?

A

A binary variable that can have two possible values, true or false

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

What is a string?

A

A data type used to represent a sequence of characters

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

What is an integer?

A

A whole number (positive or negative)

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

What is a real value?

A

Numbers including fractions and decimals

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

What is a character?

A

A letter, digit, space, punctuation mark or various other symbols

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

What is selection?

A

Determines which path a program takes when it is running e.g. if statements

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

What is a sequence?

A

The order in which instructions occur and are processed

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

What is repetition and what are the two types?

A

The repeated execution of a section of code when a program is running
- count controlled iteration: repeatedly executes a section of code a predetermined fixed amount of times
- condition controlled iteration: repeatedly executes a section of code until a condition is met/no longer met

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

What is a variable?

A

A named space in memory that can contain a single piece of data, which can change during the execution of a program.

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

What is a constant

A

A named space in memory that always contains the same value during program execution.

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

What is a variable scope?

A

It indicates the accessibility of a variable.

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

What is a local variable and what are its advantages?

A

A variable that only exists until the subroutine in which it was created ends.

advantages:
- subroutines with local variables can be reused in other programs
- easier to debug
- saves memory as it only takes up space when it is needed

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

What is a global variable and what are its advantages?

A

A variable that exists throughout the entire lifetime of a program’s execution.

advantages:
- can be used anywhere in the whole program
- makes maintenance easier as it only has to be declared once
- can be used for constants

17
Q

What is a subprogram and what are the two types?

A

A subprogram is a smaller program written within a larger one with the purpose of performing a specific task.

  1. Procedures
    A procedure performs a specific task and when it is done, the program continues where it left off.
  2. Functions
    Functions work the same way as procedures, but can manipulate data and return a result back to the main program.
18
Q

What are the benefits of using subprograms?

A
  • they are small in size so can be tested and debugged easily
  • can be saved as modules and reused in different programs
  • can be used repeatedly in a program and only be written out once
19
Q

What is a standard function and what are the benefits of using them?

A

A standard function is an in built, ready made function, e.g. print()

benefits:
- gone through rigorous testing so they work
- code optimised for maximum performance
- portable
- considerable amount of development time

20
Q

What is a parameter?

A

An item of data passed from one subroutine to another

21
Q

How does a binary search work?

A

A binary search takes the midpoint of a set of sorted data and compares it to the search value. If the search value is less than the midpoint, all data after the midpoint is eliminated, and if the search value is more than the midpoint, all data before the midpoint is eliminated. The midpoint of the new set of data is then found and the process is repeated until the midpoint equals the search data, or the end of the data is reached.

22
Q

How does a linear search work?

A

A linear search takes the first item in a set of data (does not have to be sorted) and compares it to the search value. If the search value is not equal to the item in the current position, then the search value is compared to the next piece of data in the list. This process is repeated until the search value equals the item in the current position, or until the end of the data is reached.

23
Q

What is abstraction in terms of computational thinking?

A

When a problem is simplified so that only the important and relevant details are considered.

24
Q

What is decomposition in terms of computational thinking?

A

When a large, complex problem is broken down into smaller, more easily solvable problems.

25
Q

What is a rogue value?

A

An unexpected value that will cause a loop to end

26
Q

What are self-documenting identifiers?

A

Variables with sensible names that immediately state their purpose in a program. They help other programmers working on the code to understand the purpose of the variable without extensive annotation.

27
Q

How does passing by reference work when passing parameters?

A

The memory address of the parameter is passed to the subroutine, rather than the actual value of the data. This may lead to unintended side effects, such as the value of the data being changed by the subroutine. This could unintentionally affect the value of the data in the main program as the value is shared between them.

28
Q

How does passing by value work when passing parameters?

A

A local copy of the data is created for the subroutine and passed to it. If the value is changed by the subroutine that receives it, the original data remains unchanged. This prevents the original data from being changed in the main program. The local copy of the data is then discarded later.

29
Q

What is compression?

A

Reducing the amount of file space that a file takes up.

30
Q

What is lossless compression?

A

When data is compressed without any data being lost.

31
Q

What is run-length encoding?

A

A form of lossless compression that replaces repeated data with a flag character, followed by the character itself and the number of times it is repeated.
E.g. BBBBBBBBB would become $B9

32
Q

What is Huffman encoding?

A

A form of lossless compression that assigns each character a unique code, with the most frequently used characters assigned the shortest code and the least frequently use characters assigned the longest code.

33
Q

What is lossy compression and how is it calculated?

A

When data is compressed by removing some of the data.

compression ratio = original file size / compressed file size

34
Q

What is dry running?

A

A way of determining the purpose of an algorithm by assigning values to the variables and doing any processing that takes place without translating it into code.

35
Q

What is a trace table?

A

A table to show the variable values when dry running an algorithm.

36
Q

How does a bubble sort work?

A

It sorts a list of items by comparing each item to the next and swapping them when necessary. The list will keep being passed through until no more swaps need to be made. As it is guaranteed each time that the largest element will be in its correct place after one pass, the last element does not need to be checked on the next pass and the number of comparisons can be reduced by one on each pass. This method of sorting is inefficient as it is the slowest and performs poorly on large amounts of data.

37
Q

How does an insertion sort work?

A

Items in a list are grouped into two: sorted and unsorted. With each pass through the list, an item from the unsorted sublist is compared with all items in the sorted list until it is inserted into the correct position. Passes are continually made until no items remain in the unsorted sublist. With each pass made, the number of comparisons decreases by one. The first out of order item is copied into a temporary variable as items are shifted to the right to make room in the sorted sublist, meaning the item would be lost if it were not copied into a variable.

38
Q

How do bubble sorts and insertion sorts compare?

A

They both pass through the list a similar amount of times, however an insertion sort usually involves fewer comparisons per pass, meaning insertion sorts are generally quicker to execute than bubble sorts, especially on large sets of data.