Computational Constructs Flashcards

1
Q

What does declarative programming focus on?

A

Defining what a program should achieve rather than defining the method of achieving the desired output

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

What does Imperative Programs define?

A

Exactly the steps that a computer will execute to achieve a specific result

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

What do programs in Prolog consist of?

A

Facts and Rules

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

What is a knowledge base?

A

Combination of the facts and rules in prolog

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

What is Recursion?

A

A programming technique where a sub-program repeatedly calls itself

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

In what type of programming languages is recursion used?

A

Declarative and Imperative Programming Styles

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

What is passing by reference?

A

Passing the real copy of the parameter, changes to this parameter will be proper changes

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

What is passing by value?

A

Any changes to the parameter will not be carried onto the real value

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

Write the pseudocode for the Fibonacci sequence

A
def Fibonacci(n):
If n < 2:
return n
else 
return Fibonacci(n-1) + Fibonacci(n-2)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Give some advantages of recursion

A
  • It is a unique way of implementing a variable number of nested
    loops.
  • Prevents repeating of code
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Give some disadvantages of recursion

A
  • Recursion uses more memory than iteration and looping
  • Recursive methods will often throw a Stack Overflow Exception error
    when processing big sets of data
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What are the operations that can performed on a sequential file?

A
  • Write data
  • Read data
  • Append
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is a sequential file identified by?

A

Identified by a path and a filename

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

Describe a sequential file

A
  • Identified by a path and a filename
  • Reading from the beginning
  • Cannot be written and read to at the same time
  • If file does not exist, must be created first
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is the difference between append and read/write functions for sequential file?

A

Append allows data to be added to the file without it being read into memory first

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

Write pseudocode for writing (a set of string values)to a new sequential text
file from an array

A
Procedure writeFile(name):
DECLARE myFile INITIALLY "N://myFile.txt"
CREATE myFile
OPEN myFile
FOR counter FROM 0 to End of Array DO
SEND names[counter] to myFile
END FOR
CLOSE myFile
END Procedure
17
Q

Write pseudocode for reading (a set of string values) from a sequential text file into
an array

A
PROCEDURE ReadFile(name)
DECLARE myFile INITIALLY "N://myFile.txt"
OPEN myFile
FOR counter FROM 0 to End of File DO
Receive names[counter] from myFile
END FOR
CLOSE myFile
END PROCEDURE
18
Q

Describe a random file

A

A file which stores data in a way which allows it to be retrieved from any place in the file without needing to read through the entire file
Data is indexed in a way which allows each item to be uniquely identified

19
Q

What are random files frequently used to store?

A

Records

20
Q

Give three advantages to random files?

A
  • Fast access to data since position of any item can be calculated from it’s index
  • Data items can be accessed individually instead of having to read the entire file
  • Random files can be read and written to simultaneously