Algorithms Flashcards
What is time complexity of an algorithm?
A measure of how long it takes an algorithm to run based on the size of the input.
What is Big-O notation for?
Showing the time complexity of an algorithm, used in the form O(f(n)) where n is the input size.
What are the search algorithms covered?
Linear search, binary search and binary tree search.
How does linear search work?
By going through an array in order to find the wanted element.
How does binary search work?
By starting in the middle of a sorted list and ignoring the half of the list that is all greater or less than the desired value.
What is the time complexity of a linear search?
O(n).
What is the time complexity of a binary search?
O(log n).
What is a binary tree search?
Same as a binary search but a tree is used instead of a list.
What are the sorting algorithms covered?
Bubble, insertion, merge and quick sort.
What is bubble sort?
A sorting algorithm where you run through the list of items comparing values and moving the larger one up the list so that after each run the largest value is at the top of the list.
What is insertion sort?
A sorting algorithm where items are moved from an unsorted array to a sorted array one item at a time.
How does merge sort work?
The list is split into lots of sub-lists starting at length 1 which are sorted as they are joined together.
What is the time complexity of bubble sort?
O(n^2).
What is the time complexity of insertion sort?
O(n^2).
What is the time complexity of merge sort?
O(n log(n)).