Topic 4: Computational Thinking and Programming Flashcards

1
Q

Describe the characteristics of the linear search (sequential search) algorithm.

A

Simple, takes at most n comparisons on a list of length n, does not required the list to be ordered.

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

Construct pseudocode for the linear search/sequential search algorithm.

A

See image.

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

Describe the characteristics of the binary search algorithm.

A

Only works on sorted arrays, relies on divide and conquer strategy, half of the elements are eliminated at each step, much more efficient than linear search for large arrays, requires at most log(n) comparisons on an array of size n.

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

Construct pseudocode for the binary search algorithm.

A

See image.

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

Describe the characteristics of the bubble sort algorithm.

A

A simple sorting algorithm that steps through the array, compares adjacent elements and swaps them if they are out of order. Makes repeated passes through the array until no swaps are made and the array is sorted. Slow and impractical for most cases.

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

Construct pseudocode for the bubble sort algorithm.

A

See image.

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

Describe the characteristics of the selection sort algorithm.

A

A simple and inefficient sorting algorithm, divides the array into a sorted subarray and an unsorted subarray. It finds the smallest element in the unsorted subarray and swaps it with the first element in the unsorted subarray, putting it in sorted order. Now the sorted subarray is one element larger and the unsorted one element smaller. This is repeated until the sorted subarray is the entire array.

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

Construct pseudocode for the selection sort algorithm.

A

See image.

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

Outline the standard operations on a collection (like an array or list).

A

addItem(): used to add an item to the collection (like using items.append(value) in Python).
getNext(): returns the first item in a collection when it is first called, will then return subsequent items when it is called again.
resetNext(): restarts iteration through the collection. When getNext() is called after resetNext() it will return the first element of the collection again.
hasNext(): Returns true if there are remaining elements in the collection that have not yet been accessed durign the current iteration (through calling getNext()).
isEmpty(): Returns true if the collection contains no elements, and returns false otherwise.

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

Suggest two design considerations that could be made to an algorithm that would make it more efficient.

A

The algorithm could use loops;
To remove the necessity to process extra lines of code;
Use of arrays/data structures;
So data can be stored/re-used/re-entered;
Use of flags;
To stop a search routine when an item has been found so that all elements don’t have to be searched;

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

State the fundamental operations of a computer.

A

Add, compare, retrieve, and store data. Complex operations are composed of combinations of a large amount of these simple operations.

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

Distinguish between fundamental and compound operations of a computer.

A

Compound operations involve multiple fundamental operations. For example, a program that finds the maximum of four numbers would have to use multiple fundamental operations to read, compare and store these numbers.

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

Explain the essential features of a computer language.

A

Has fixed vocabulary, unambiguous meaning, consistent grammar and syntax.

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

Explain the need for higher level languages.

A

Computer programs have grown sufficiently complex that writing all programs in machine code (code using the fundamental operations that can run directly on the device) becomes too tedious and difficult. Higher level languages were developed to be much easier to use and closer to natural language, however programs written in them need to be translated to machine code before they can be executed.

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

Outline the need for a translation process from a higher level language to machine executable code.

A

(The program written in HLL must be translated into machine code) so that the computer can execute the program; as the computer only understands machine language / as code written in HLL can only be understood by humans and cannot be interpreted by the computers (which work in binary);

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

Define the term variable

A

Variables define areas in memory in which values (data) are stored;
Variables are unique identifiers that retrieve values from the memory addresses at which they are stored;
Variables are the names one gives to computer memory locations which are used to store values in a computer program;
The value of a variable can be changed during the execution of the program.

17
Q

Define the term constant.

A

Similar to a variable, but its value can not be changed during the execution of the program.

18
Q

Define the term operator.

A

Used to manipulate data, can be arithmetic, relational, logical, e.g. “+”, “*”, “>”, “<=”, “and”, “or”

19
Q

Define the term array.

A

A ordered list of fixed size of elements of the same data type.

20
Q

Define the term object.

A

Comprised of data and methods. Methods are operations that can be performed by the object that can use or modify its data.

21
Q

Define the operators mod and div

A

div is the integer part of the quotient (e.g. 22 div 3 = 7)
mod is the “modulo operator” that calculates the remainder of a division (e.g. 22 mod 3 = 1 since 1 is the remainder of 22 divided by 3)