Theory of Computation Flashcards
What is an algorithm?
An algorithm is a sequence of unambiguous instructions for solving a problem for obtaining a required output for any legitimate input in a finite amount of time.
What is assignment?
Assignment is the process of giving a value to a variable or constant.
What is sequence?
Sequence is the name given to instructions that follow on from one another.
What is selection?
Selection is the process of choosing an action to take based on the result of a comparison of values.
What is iteration?
Iteration is the process of repeating an operation. For and While loops
What is abstraction?
Abstraction is the name given to the process of emitting unnecessary details from a problem. When a solving a problem, abstraction can be used to simplify the problem which can in turn make finding a solution easier.
Two types of abstraction
Representational and Generalisation
What is representational abstraction?
A representation of a problem arrived at by removing unnecessary details from the problem.
What is abstraction by generalisation?
A grouping by common characteristics to arrive at a hierarchical relationship of the ‘is a king of’ type.
What is information hiding?
Information hiding is defined s the process of hiding all details of an object that do not contribute to its essential characteristics.
Pros of information hiding
- allows different objects to have identical interfaces
- sharing of an interface means that objects do not have to be retrained when changing from using one object to using another
- it means that the user needs to have no knowledge of the object’s internal design
- the internal design can be kept secret
- changes are made easier because changes are local to modules
What is procedural abstraction?
Procedural abstraction involves breaking down a complex model into a series of reusable procedures. The actual values used in a computation are abstracted away and a computational method is achieved.
What is a procedure?
A procedure is a small section of a program that performs a specific task.
What is a function?
A function is a small section of a program that performs a specific task that can be used repeatedly throughout a program, but the task is usually a calculation. Functions perform the task and return a value to the main program.
What is functional abstraction?
Procedural abstraction results in a procedure. Abstracting further disregards the particular method of a procedure and results in just a function.
What is data abstraction?
In data abstraction, specific details of how data is actually represented are abstracted away, allowing new kinds of data structure to be created from previously defined data structures. Data abstractions forms the basis of abstract data types
What is problem abstraction?
In problem abstraction, details are removed from a problem until it is represented in a way that is solvable. This works because a simplified problem is often similar to a problem that has already been solved, meaning that a solution for the problem can be found.
What is decomposition?
When using decomposition, a problem is divided into a series of smaller sub-problems. These smaller problems can be solved individually or further divided until all parts of the original problem have been solved.
What is composition?
When dealing with a complex problem, composition can be used to combine procedures to form a larger system. Composition is used in abstract data types, where a complex abstract data type is formed for smaller and simpler data types.
What is automation?
Automation is the process of putting abstractions of real world phenomena into action to solve problems. Automation is achieved by creating algorithms which are later implemented in code, implementing models in data structures and finally executing the code on the data structures.
What is the computational complexity of an algorithm?
The way to think about efficiency is to think about the “cost” of the algorithm. The algorithm that can solve the problem for the lowest cost could then be declared the better algorithm. In general, the amount for resources (or cost) that an algorithm requires in order to return that expected result is called computational complexity. This has two sections: time and space. The time complexity of an algorithm indicates how fast the algorithm runs. The space complexity of an algorithm indicates how much memory the algorithm needs.
Big O notation
Simplified analysis of an algorithm’s efficiency. It refers to the complexity in terms of input size, N
Orders of complexities
Constant time: independent of input size N: O(1)
linear time: O(N)
quadratic time: O(N^2)
Exponential time
The amount of time taken to complete an algorithm will double with every additional item. O(2^n)
Polynomial time
Polynomial time often arises when nested loops are used, for example in a number of sorting algorithms.: O(n^2)
Linear time
Linear time usually arises from algorithms which go through data step by step. If you have a data structure with n elements and you through it step by step, you end up with linear time complexity. O(n)
Logarithmic time
Logarithmic time arises when an algorithm is designed in such a way that the execution time does not increase as fast as the input size.- 0(log n)
Constant time
The amount of time taken to complete an algorithm is independent from the number of elements inputted
Time complexity of initialising a grid size with empty cells?
O(n^2)
Time complexity of the CheckForMatchWithPattern
O(n^2*m), where n is the Gridsize and m is the num of allowed patterns. This is because the method iterates over each cell of the grid in O(n^2) and checks against each allowed pattern
Time complexity of the GetSymbolFromUser method
O(k), k number of times the user enters an invalid symbol
Time complexity of the DisplayPuzzle
O(n^2); the method iterates through each cell in the grid to print the symbols and creates horizontal lines for each row
Time complexity of AddToNotAllowedSymbols
O(1), since it is in constant time
Explain the purpose of the Puzzle class.
The puzzle class represents the entire puzzle grid. It contains methods for initializing the grid, checking for matches with a given pattern, getting user input, creating horizontal lines for display, and displaying the puzzle
Describe the process and purpose of initializing the grid in the Puzzle class.
The grid is initialized to create an empty puzzle of size GridSize x GridSize. This involves creating and storing instances of the Cell class in a list representing the grid. Each cell starts as empty, and the grid setup allows for easy access and manipulation of individual cells.