Computational Constructs Flashcards
What does declarative programming focus on?
Defining what a program should achieve rather than defining the method of achieving the desired output
What does Imperative Programs define?
Exactly the steps that a computer will execute to achieve a specific result
What do programs in Prolog consist of?
Facts and Rules
What is a knowledge base?
Combination of the facts and rules in prolog
What is Recursion?
A programming technique where a sub-program repeatedly calls itself
In what type of programming languages is recursion used?
Declarative and Imperative Programming Styles
What is passing by reference?
Passing the real copy of the parameter, changes to this parameter will be proper changes
What is passing by value?
Any changes to the parameter will not be carried onto the real value
Write the pseudocode for the Fibonacci sequence
def Fibonacci(n): If n < 2: return n else return Fibonacci(n-1) + Fibonacci(n-2)
Give some advantages of recursion
- It is a unique way of implementing a variable number of nested
loops. - Prevents repeating of code
Give some disadvantages of recursion
- Recursion uses more memory than iteration and looping
- Recursive methods will often throw a Stack Overflow Exception error
when processing big sets of data
What are the operations that can performed on a sequential file?
- Write data
- Read data
- Append
What is a sequential file identified by?
Identified by a path and a filename
Describe a sequential file
- 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
What is the difference between append and read/write functions for sequential file?
Append allows data to be added to the file without it being read into memory first