Comp Exam paper 1 Flashcards
What is meant by recursion?
A recursive route is one that is defined in terms of itself
How do stacks work?
They store items and follow a last in first out (LIFO) rule. (Like taking from a stack of plates). Used to stored actions so they can be undone.
What does pushing the stack do?
Used to add items to the stack. Pushes the top position of the stack up and adds the item to the stack.
What does popping the stack do?
Used to remove elements from the stack. Moves the top of the counter down and removes the item.
What function has a constant time?
f= O(n^0)
f=O(1)
What function has a logarithmic time?
f= O(log n) : The Binary search
List is split into half with one rejected
f = O(n log n) : Merge sort
What function has a linear time?
f= O(n) : Linear Search
Checks each element of the list individually
What function has a polynomial time?
f= O(n^2) : Bubble sort- swaps item if one is bigger
What function has exponential time?
f= O(2^n) : Fibonacci
What function has factorial time?
f= O(n!) : Travelling salesman problem
What are intractable problems?
Problems that can be solved by a computer, but not in a reasonable amount of time when there are large inputs. (Less than polynomial time)
What is an heuristic approach?
A guessed solution can be checked in polynomial time. Problem becomes tractable.
What is the halting problem?
An unsolvable problem which asks whether it is possible to create a program which takes another program as an input and determines whether it will halt or loop infinitely.
How should you compare Algorithms?
Time complexity: How long it takes to complete a task with a given input
Space complexity: How much memory an algorithm needs to complete a task with a given input
Order of growth: How quickly the complexity grows with growth in input size
What is the proof of the halting problem?
def(g): If halts(g): loop_forever() If halts(g) is true, g will call loop forever and will never halt. If halts(g) is false, g will halt as it doesn’t call loop forever. This is a contradiction.