C) Programming Paradigms Flashcards

1
Q

What are some data types?

A
  • Boolean: true or false
  • character: a single item e.g. a letter or a number
  • float: a decimal number
  • integer: a whole number
  • string: one or more characters
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Why are constants useful?

A

They protect from the value being accidentally changed and they can make a program easier to read and maintain.

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

What is the difference between declaring and defining a variable?

A

Declaring a variable is creating it, whereas defining a variable is setting/changing it.

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

Why is it important to give variables meaningful names?

A
  • more readable
  • easier to maintain
  • easier to debug
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are some common naming conventions?

A
  • camelCase
  • snake_case
  • PascalCase
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is a reserved word?

A

A set of words that cannot be used as identifiers, including instructions of the programming language.

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

What is the difference between local and global variables?

A

These are known as the scope of a variable, which refers to what parts of the program can access the data stored by the variable. Global variables are accessible throughout the entire code, whereas local variables are only accessible within the function they are declared in.

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

Why is it better to use local variables in a function rather than global?

A

They are more efficient as they only take up memory when the subprogram is running. They also increase code security as the values can only be accessed and altered within specific sections of the code.

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

What are the standard arithmetic operators?

A
    • adds one value to another
    • subtracts one value from another
  • / divides one value by another
    • multiplies one value by another
  • % returns the remainder of dividing one value by another
  • DIV (integer division) divides one value by another, ignoring any remainder
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is a relational operator and what are the standard relational operators.

A

They allow us to compare values and return either true or false.
- == returns true if both values are the same
- != returns true if both values are not the same
- = sets the value of a variable
- > returns true if a value is greater than another
- < returns true if a value is less than another
- >= returns true if a value is greater than or equal to another
- <= returns true if a value is less than or equal to another

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

What is a logical operator and what are the standard logical operators?

A

Allow multiple relational operators to eb combined for more complex expression.
- AND returns true if both conditions together are true
- OR returns true if either condition (or both) is true
- NOT returns true if the condition is false and vise versa

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

What is a function?

A

A named section of code that performs a set task when called. they are used to make code more readable, maintainable and reusable.

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

What is a library and what are their advantages/disadvantages?

A

A collection of predefined code that can be used in programs.
adv:
- saves time
- code in libraries have been extensively tested
disadv:
- you are relying on code someone else has produced

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

What are some common built-in arithmetic functions?

A
  • random number generation
  • generating a range of numbers
  • rounding numeric values
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What are some common built-in string handling functions?

A
  • returning the length of a string
  • extracting characters from a string
  • returning substrings
  • concatenation (joins two or more strings together)
  • conversion (strings to arithmetic values)
  • truncation (trims a string to a specified length)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What are some common built-in general purpose functions?

A
  • input/output
  • file handling
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What are some functions of file handling and the modes of files?

A

functions:
- open opens a file for reading or writing
- close closes a file so that other programs can use it
- read reads data from a file into RAM
- write writes data from RAM to a file

modes:
- read allows data to be read from the file but not changed
- write allows data to be written to a file overwriting previous content
- append adds new data to the end of the file, leaving previous data unchanged

18
Q

What is validation and why is it important?

A

Checks that data input into a system meets a series of requirements. It is only as good as the criteria used. It ensures code is secure and can prevent cybercriminals from doing serious damage.

19
Q

What is verification?

A

Checks that no errors have been introduced when data is input.

20
Q

What are the types of validation check?

A
  1. Data type check: checks that data is the correct type
  2. Range check: checks that data is within a set range
  3. Length check: checks that the number of characters in a string is within the predefined range
  4. Presence check: checks whether data is present or not
  5. Format check: checks whether data is in a predefined format e.g. dd/mm/yy for dates
  6. Spelling check: checks whether words can be found within a predefined dictionary
  7. Constraints check: rules than an input must meet
  8. Check digits: a character that is calculated based on the value of a specified piece of data using an algorithm. If the character is different from the stored value, it is invalid.
21
Q

What are some post-check actions?

A

Error handling allows software to manage invalid or unusual inputs.
Error reporting provides useful information to inform users of what is correct, or to help a programmer debug their code

22
Q

What are the three basic control structures?

A
  1. Sequence: when instructions run one after another
  2. Selection: when a program can branch into different sequences depending on the condition
  3. Iteration: when a part of a program loops until a condition is met, or sometimes forever
23
Q

What is the difference between pre-condition and post-condition loops and what are some examples?

A

A pre-condition loop is when the condition determining if the loop will run takes place at the beginning of the loop e.g. for loops and while loops. A post-condition loops is when the condition determining if the loop will run takes place at the end of the loop e.g. repeat… until loops.

24
Q

What are some examples of data structures?

A
  • array
  • list
  • record
  • set
25
Q

What is an array and what are their advantages and disadvantages?

A

They store multiple values of the same type of data.

adv:
- efficient
- high performance
- easy to implement/understand

disadv:
- inflexible as they are fixed and limited to only one type of data

26
Q

What is a list and what are their advantages and disadvantages?

A

They are like an array but can store multiple different types of data.

adv:
- flexible as they are dynamic and can store different data types
- efficient use of available memory
- quick reordering of stored values as only pointers need to be changed

disadv:
- slower than arrays
- can be complex to implement

27
Q

What is a record?

A

An ordered collection of elements in which each element is called a field. Each field has a name and a data type.

28
Q

What is a set?

A

Data that is grouped according to ownership of different sets. They allow us to organise and filter data very quickly.

29
Q

What is a bubble sort?

A

A sorting algorithm that compares each adjacent value in a list and swaps them if necessary. It continually passes through the list until no more swaps are made, at which point it is sorted.

30
Q

What is an insertion sort?

A

A sorting algorithm that compares each value with the value to its left and moves it left until it is in the correct position. This algorithm sorts through data in one pass.

31
Q

What is a quick sort?

A

An algorithm that uses an element of a list as the pivot and splits the list into two sublists. The elements higher than the pivot go in one sublist and elements lower than the pivot go in the other sublist. These sublists are then quick sorted until each sublist only has one element. These sublists are then combined to create one ordered list.

32
Q

What are the advantages and disadvantages of a bubble sort?

A

Adv:
- simple, easy to understand and implement

Disadv:
- inefficient, takes a long time to complete if the data is in reverse order

33
Q

What are the advantages and disadvantages of an insertion sort?

A

Adv:
- simple, easy to understand and implement
- doesn’t require lots of additional memory to run

Disadv:
- inefficient, takes a long time to complete for large quantities of data

34
Q

What is a linear search?

A

An algorithm that compares elements in a list one at a time with the search data until a match is found.

35
Q

What is a binary search?

A

An algorithm that takes the middle element of a list and compares it with the search data. If it is not a match, it then determines whether the search data is higher or lower in value than the element and will binary search data on either side of the middle element accordingly.

36
Q

What are the advantages/disadvantages of a linear search?

A

Adv:
- simple, easy to understand and implement
- doesn’t require data to be sorted
- quick for small data sets

Disadv:
- inefficient, can be slow for large data sets

37
Q

What are the advantages/disadvantages of a binary search?

A

Adv:
- efficient, tends to be quicker than a linear search

Disadv:
- data must be sorted in advance

38
Q

What is a count occurrence?

A

Works like a linear search but instead of ending when the search data is found, it counts every time the search data occurs. Unless the data is sorted, it must run through the entire data set.

39
Q

What is recursion?

A

When a function calls itself

40
Q

What is a stack?

A

A LIFO data structure in which only the top item of data can be added (pushed) or removed (popped) from the stack.

41
Q

What is a queue?

A

A FIFO data structure in which data can only be added (enqueued) to the tail of the queue and can only be removed (dequeued) from the head of the queue. This ensures fair access to resources.