Programming:theory Flashcards

1
Q

Describe the halting problem

A

Determining, given a program and input, whether or not the program will halt
{determining if a program will halt without running the program for a particular input}

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

Why can’t the halting problem be simulated with a turning machine?

A

The halting problem is non-computable, a program cannot be written that determines whether a given algorithm will halt for a specified input.

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

What are the components of a turing machine?

A

-infinite tape
-read/write head
-control unit
-finite set of states
-transition rules
-set of accepting/ halting states

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

What is a UTM?

A

Universal turing machine

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

What is a UTM?

A

-UTMs can simulate the behaviour of any other turing machine, and so can compute any computable sequence.
-Can act as an interpreter, taking data, programs or any other turing machine as an input

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

Why are UTMs more powerful than any other computer?

A

Because it has an infinite amount of memory/tape

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

What is an advantage of using constants?

A

-speed increases when run
-easier to read and maintain
-values only need to be assigned

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

Define a global variable

A

A variable that can be referenced/accessed from any point in the program.

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

Define a local variable

A

Can only be referenced/accessed within the subroutine it is defined in

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

What is an advantage of local variable usage?

A

-avoids redundant memory usage, as variable value is no longer stored once subroutine is finished executing

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

define the term record

A

A collection of fields, each of which could have a
different data type. You can think of a record as a row
from a table

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

define a pointer or reference

A

A way of storing memory addresses

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

what are the key features of an array?

A

-finite
-indexed
-same data type

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

what are user defined data types?

A

derived from existing data types in order to create a customised data structure

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

why are meaningful identifier names important?

A

-easier for others to understand
-means maintenance is easier
-collaborative programming is easier

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

What is a constant?

A

a variable that once defined, does not change its value

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

what is the python function for returning the length of a value?

A

len()

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

what is the python function for determining the position of a specified character?

A

rfind()
index = string_variablename.rfind(character)

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

what is the python function for returning a substring of a given string?

A

stringvariablename[startindex:endindex]
- negative index represents the last x values in a string
-stringvariablename[-5:] returns the last five values of a string
-stringvariablename[0:-4] returns all characters except the last 4

20
Q

what is the python function for converting values into a float?

A

float()

21
Q

what is the python function for generating random numbers?

A

random.randint(a,b) (inclusive)

22
Q

what does exception handling consist of?

A

a catch block which runs in the event of an error

23
Q

What is a subroutine?

A

A named block of code design to perform a frequently used specific function

24
Q

What is an advantage of using subroutines?

A

-Avoids repetition
-code is more compact and easier to read

25
Q

What is the difference between a function and a procedure?

A

A function must return a value, whereas a procedure does not have to.

26
Q

what is the purpose of a parameter?

A

holds pieces of information to be passed to subroutines that are needed to run the process.

27
Q

What is the difference between a parameter and an argument?

A

-an argument is the actual value that is passed
-a parameter is used to hold the argument

28
Q

Define a local variable

A

a variable that can only be accessed/referenced in the subroutine within which it was instantiated

29
Q

How are stack frames used during subroutine calling?

A

If a subroutine is called within another subroutine, nesting occurs. the current process taking place is pushed onto the call stack in its current state before the second subroutine is run.

30
Q

what does a recursive subroutine consist of?

A

a base case and a general case

31
Q

What are the benefits and drawbacks of using a recursive algorithm?

A

-more concise
-less memory efficient
-less easy to program

32
Q

what are the four basic structures of the structured approach?

A

assignment, sequence, selection and iteration

33
Q

define encapsulation

A

combining methods and procedures into a single object

34
Q

what is the result of inheritance??

A

a class inherits the attributes and methods of a parent class, while still having it’s own attributes and methods (overwriting)

35
Q

describe the term polymorphism

A

-when objects are processed differently based on their class

36
Q

describe the idea of overriding in classes

A

when an inheriting class has a method of the same name with a different process or implementation

37
Q

which kind of association is the weaker kind?

A

aggregation association

38
Q

define aggregation association

A

it will still exist if the containing object is destroyed

39
Q

define composition association

A

if the containing object is destroyed, the object associated via composition association will also be destroyed

40
Q

positives of using object oriented programming?

A

-clear structure in programs
-development and testing is easier
-portions of code can be divided among developers
-sections of code can be reused using methods like inheritance

41
Q

what are the three design principles of object oriented programming?

A

-encapsulate what varies
-favour composition over inheritance
-program to interfaces not implementation

42
Q

how is inheritance displayed in class diagrams?

A

an arrow pointing from the child to the parent class

42
Q

describe the design principle of ‘encapsulate what varies’

A

any requirements that a likely to change in the future should be encapsulated in class for ease of access

42
Q

describe the reason for the design concept of favouring composition over inheritance

A

-composition is a more flexible relationship, though not always suitable

43
Q

what symbol represents aggregation association in class diagrams?

A

hollow diamond

44
Q

what symbol represents composition association in class diagrams?

A

a solid diamond

45
Q

what are the symbols for public private or protected in class diagrams?

A

= protected

+ = public
- = private
# = protected