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?

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
What is the difference between a function and a procedure?
A function must return a value, whereas a procedure does not have to.
26
what is the purpose of a parameter?
holds pieces of information to be passed to subroutines that are needed to run the process.
27
What is the difference between a parameter and an argument?
-an argument is the actual value that is passed -a parameter is used to hold the argument
28
Define a local variable
a variable that can only be accessed/referenced in the subroutine within which it was instantiated
29
How are stack frames used during subroutine calling?
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
what does a recursive subroutine consist of?
a base case and a general case
31
What are the benefits and drawbacks of using a recursive algorithm?
-more concise -less memory efficient -less easy to program
32
what are the four basic structures of the structured approach?
assignment, sequence, selection and iteration
33
define encapsulation
combining methods and procedures into a single object
34
what is the result of inheritance??
a class inherits the attributes and methods of a parent class, while still having it's own attributes and methods (overwriting)
35
describe the term polymorphism
-when objects are processed differently based on their class
36
describe the idea of overriding in classes
when an inheriting class has a method of the same name with a different process or implementation
37
which kind of association is the weaker kind?
aggregation association
38
define aggregation association
it will still exist if the containing object is destroyed
39
define composition association
if the containing object is destroyed, the object associated via composition association will also be destroyed
40
positives of using object oriented programming?
-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
what are the three design principles of object oriented programming?
-encapsulate what varies -favour composition over inheritance -program to interfaces not implementation
42
how is inheritance displayed in class diagrams?
an arrow pointing from the child to the parent class
42
describe the design principle of 'encapsulate what varies'
any requirements that a likely to change in the future should be encapsulated in class for ease of access
42
describe the reason for the design concept of favouring composition over inheritance
-composition is a more flexible relationship, though not always suitable
43
what symbol represents aggregation association in class diagrams?
hollow diamond
44
what symbol represents composition association in class diagrams?
a solid diamond
45
what are the symbols for public private or protected in class diagrams?
# = protected + = public - = private # = protected