U2a - Programming Basics Flashcards

1
Q

Define data type

A

The kind of values that can be used in a data item.

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

Name 5 data types

A

Integer, float/real, character, string, boolean

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

Define arithmetic operator

A

A symbol that will perform an operation on numbers e.g. +, -

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

What do constants look like?

A

They’re typically shown in uppercase and the words are separated with an underscore, eg. MIN_AGE
This is known as snake case.

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

Why declare a constant instead of a variable?

A

This prevents the value from being changed accidentally by a part of a code. It shows a programmer that the value should stay the same throughout the program.

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

Can a constant ever change its value?

A

A constant cannot be changed when the program is running. However, a constant can be changed by a programmer before the program is compiled or translated.

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

What is used to convert data types? (AKA Casting)

A

Functions

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

Why should you use comments in your programs? (3)

A
  • To describe the purpose of the program
  • To state the author of the program
  • To explain what the code does
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Define sequence

A

Statements are executed one by one in the order they are written

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

Define selection

A

An IF statement is a selection statement. The next statement to be executed depends on whether the condition being tested is True or False

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

Comparison operators

A

= equal to
=/ not equal to
> greater than
< less than

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

Define iteration

A

Iteration means repetition of a section of code

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

Three types of iteration statement

A
  • FOR..ENDFOR
  • WHILE…ENDWHILE
  • REPEAT…UNTIL
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

When would you use a for loop

A

When you want to execute the loop a specific number of times

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

When would you use a while loop

A

When you want to execute the loop while a certain condition is true

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

When would you use a repeat until loop

A

When you want to execute the loop until a certain condition is true

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

Define an array

A

A data structure that allows you to hold many items of data which is referenced by one identifier

18
Q

Do all items of data in the array have to be the same data type?

A

Yes

19
Q

How would you find an array’s length?

A

LEN(array)

20
Q

How would you add red to an array?

A

array[index e.g. 0]

21
Q

Which out of lists and arrays have a fixed length?

A

Arrays

22
Q

How can you add more items to an array?

A

You would need to create a new larger array and copy the items across

23
Q

How does a linear search work?

A

Each item is examined in sequence until the item is found or the end of the list is reached.

24
Q

How does a bubble sort work?

A
  • Each item in a list is compared to the one next to it, and if it is greater, they swap places
  • At the end of one pass through the list, the largest item is at the end of the list
  • This is repeated until the items are sorted
25
Q

What is a record?

A

A data structure consisting of a number of fields which can all be of different types

26
Q

What is a field (records)?

A

A field is a single item of data in a record

27
Q

What is instantiation?

A

New instances of a record structure being made

28
Q

Define algorithm

A

A set of instructions for solving a problem or completing a task

29
Q

Define abstraction

A

Removing unnecessary detail from a problem so that you can focus on the essentials

30
Q

Define decomposition

A

Breaking down a large problem into smaller sub-problems. Then the sub-problems can be broken down further until each small task is manageable.

31
Q

Advantages of decomposition (2)

A
  • The problem becomes easier to solve when it consists of a number of small subtasks or modules
  • Some modules may be reusable in other programs, saving development time
32
Q

Define variable

A

A location in memory in which you can temporarily store text or numbers

33
Q

Define real

A

A number with a decimal point

34
Q

Define string

A

One or more characters enclosed in quote marks

35
Q

How does a binary search work?

A

The size of the list is approximately halved each time an item is examined. ROUND DOWN when even number of choices.

36
Q

What is the condition of a binary search?

A

The list has to be sorted. If it isn’t, it isn’t possible to do a binary search. A linear search may be carried out instead.

37
Q

How to merge sort

A
  • Divide the unsorted list into n sublists, each containing one element
  • Repeatedly merge two sublists at a time to produce new sorted sublists until there is only one sublist remaining. This is the sorted list
38
Q

Which is more efficient, merge sort or bubble sort

A

Merge sort because it’s much quicker

39
Q

Disadvantage of bubble sort

A

It’s slow and inefficient for more than a few items - a list of n item takes roughly n^2 comparisons

40
Q

Disadvantage of merge sort

A

The merge sort requires more memory to store the sublists, and with a very large number of items this can be a disadvantage