Sorting Algorithms and Big O notation Flashcards
Big O notation
This is a special notation for classifying algorithms based on how their computational times grows as their input size grows
Time Complexity
How much time they need to solve a given problem
Space Complexity
The amount of resource e.g. memory they require
Factorial
The permutation of a set of objects simply means the number of ways you can arrange those objects
Function maps one set of values to another
Nothing more than mapping of one set of inputs onto a set of outputs, one element of the input set always relates to one element of the output
Key terms for Function
- Domain: All the possible inputs of a function f
- Range: Set of all outputs of f
- Codomain: All the possible values that may be output from a function f
Serial Array big o notation
Adding items to a serial array and a list is constant time complexity - O(1)
Linear Search
Linear time complexity is O(n) at worst case scenario and if directly to an element of an array O(1)
Sequential array
adding items to a sequential array is time complexity O(n)
Sorted array
uses binary search, halves the set of numbers with each selection, therefore is time complexity O(log n)
Stack or Queue
Pushing and popping from stacks or queues O(1), searching through a stack / queue is O(n)
Hashing
Hashing is 0(1) to insert and find assuming item isn’t a synonym otherwise it is O(n) to find an item in the overflow, constant time complexity is much better
Linked List
Searching in a linked list is O(n), inserting/ deleting items from a linked list is O(1)
Binary tree insertion
binary tree insertion and searching is O(log n). Traversal is O(n)
Bubble and Insertion sort, and quick sort
They use a nested loop and they use O(n^2)