Optimisation + Other Algorithms Flashcards
(35 cards)
What is an optimisation algorithm?
An algorithm that finds the best possible solution to the problem proposed.
What is an example of an optimisation algorithm?
Dijkstra’s Shortest Path (DSP)
What does DSP do?
Calculates the shortest distance between a starting node to all other nodes in the graph
What is the efficiency of DSP?
O(n2)
What are the uses of DSP?
- Shortest path between two locations in a transport network
- Telephone and computer network planning
- Network routing / packet switching
In what terms can algorithms be classified as?
- Time complexity
- Space required
for a given size of dataset
What is Big O notation
Used to describe time complexity of of algorithms, based on worst case scenario for that algorithm for a given dataset of size n
Convenient way to compare efficiency of algorithms and determine how well an algorithm will scale
What is a tractable algorithm?
An algorithm that can be solved within polynomial time: O(nk)
What are all the time complexities?
- Constant complexity: O(1)
- Logarithmic Complexity: O(logn)
- Linear Complexity: O(n)
- Polynomial Complexity: O(nk)
- Exponential Complexity: O(xn)
- (Factorial Complexity: O(n!) )
What is an intractable algorithm?
An algorithm that does not have a solution within polynomial time so is not practical for anything other than small n.
What are the properties of an algorithm with constant complexity?
- Time Taken is constant so is independent of size of the dataset
- As n increases the time taken stays the same
What are some examples of algorithms with a constant complexity?
- Accessing an index in an array
- Looking up a value in a hash table (assuming no collisions)
- Popping from a stack or dequeueing from a queue
What are the properties of an algorithm with logarithmic complexity?
- Time taken increases logarithmically with respect to the size of the database
- The size of the problem set is halved after each iteration or recursive call
What are some examples of algorithms with a logarithmic time complexity?
- Binary Search
- Merge Sort
What are the features of an algorithm with a linear time complexity?
Time taken increases proportionally with the size of the dataset
What are some examples of algorithms with a linear time complexity?
- Linear Search
- Traversing a linked list
What are the properties of an algorithm with a polynomial complexity?
- Time taken increases exponentially with the size of the dataset
- At the limit of the tractability
What are some examples of algorithms with a polynomial time complexity?
- Bubble Sort
- Dijkstra’s shortest path
What are the properties of an algorithm with exponential complexity?
- Time taken increases exponentially with size of dataset
- Intractable
What are some examples of algorithms with an exponential time complexity?
- Brute force password cracking
- Travelling Salesman Problem
What are the number of different permutations for a set with size n?
n!
How to identify O(1)
No iteration or number of steps doesn’t depend on n
How to identify O(n)
Single iteration that depends on n
How to identify O(nk)
Nested iteration where each iterative structure depends on n and k is the iterative depth