We've learned many different types of sorts such as selection, merge, quick etc. Each sort is efficient for different types of data structures. For example, insertion sort is extremely efficient for data structures which are already sorted in ascending order, but terribly inefficient for data which is sorted in descending order. We've also learned about time complexity which is usually expressed using big O notation which excludes coefficients and lower order terms. For example, if the time required by an algorithm on all inputs of size n is at most 5n3+3n, the time complexity would be express as O(n^3). Time complexity is usually estimated by counting the number of steps which is taken by the algorithm.
Wednesday, 2 April 2014
Weel 7: Recursion
Recursion is a method in computer science in which a function calls itself in order to solve a problem. This contrasts the method which we have most often used to far which is iteration. While iteration does steps over a certain amount of time, recursion will keep calling the function itself until it hits the "base case". Although it's a somewhat complicated, recursion appears to be extremely useful as it can write some iterative codes in much less lines or in some cases, there are problems in which only recursion can solve.
Subscribe to:
Posts (Atom)