Cyril moment Mid-term
Quick sort method
1.Rearrange 2.Recurse
Merge sort method
1.Recurse 2.Rearrange
Circular-linked list
A list in which every node has a successor; the "last" element is succeeded by the "first" element
Merge Sort
A list is split into individual lists, these are then combined (2 lists at a time).
Algorithms
A methodical, logical rule or procedure that guarantees solving a particular problem.
Stack
A pile of data that can only work with the value on top; uses push(): adds data to top, pop(): returns and removes data on top, and peek(): returns the data on top without removing.
Insertion Sort
A simple sorting algorithm that builds the final sorted array (or list) one item at time. It is much less efficient on large lists than more advanced algorithms such as quicksort, heapsort, or merge sort.
Selection Sort
A sort algorithm that repeatedly scans for the smallest item in the list and swaps it with the element at the current index. The index is then incremented, and the process repeats until the last two elements are sorted.
Queue
A standing line of data where each value has a priority in the line
Big O Notation
A way of expressing the worst-case run-time of an algorithm, useful for comparing the speed of two algorithms.
sorting algorithm
An algorithm that puts a list into alphabetic or numeric order. Can be ascending or descending
Bubble Sort Big O notation
Best Case: O(n) Average Case: O(n^2) Worst Case: O(n^2) Space Complexity: O(1)
Merge Sort Big O notation
Best case: O(n log n) Average case: O(n log n) Worst case: O(n log n) Space Complexity: O(n)
Quick Sort Big O notation
Best case: O(n log n) Average case: O(n log n) Worst case: O(n^2) Space Complexity: O(log n)
Insertion Sort Big O notation
Best case: O(n) Average case: O(n^2) Worst case: O(n^2) Space Complexity: O(1)
Selection Sort Big O notation
Best case: O(n^2) Average Case: O(n^2) Worst Case: O(n^2) Space Complexity: O(1)
Abstract data types
Data type used to represent something that is a bit more complicated than numbers
Data structures
Different ways of organizing data programmatically
Bubble Sort
Moving through a list repeatedly, swapping elements that are in the wrong order.
Radix Sort
Non-comparative integer sorting algorithm that sorts data with integer keys by grouping keys by the individual digits which share the same significant position and value. Two classifications of radix sorts are least significant digit (LSD) radix sorts and most significant digit (MSD) radix sorts.
Binary Search Worst Case
O(log n)
Linear Search Worst Case
O(n)
List
Similar to an array with a linear sequence of data; ordered sequence of data; linked ____ or array____.
Selection Sort example
Starting Array: 38 68 52 85 42 16 79 First Pass: 16 68 52 85 42 38 79 Second Pass: 16 38 52 85 42 68 79 Third Pass: 16 38 42 85 52 68 79 Fourth Pass: 16 38 42 52 85 68 79 Fifth Pass: 16 38 42 52 68 85 79 Sixth Pass: 16 38 42 52 68 79 85
Bubble sort example
Starting Array: 38 68 52 85 42 16 79 First pass: 38 52 68 42 16 79 85 Second pass: 38 52 42 16 68 79 85 Third pass: 38 42 16 52 68 79 85 Fourth pass: 38 16 42 52 68 79 85 Fifth pass: 16 38 42 52 68 79 85
Classes
This abstract data type has attributes and member functions
Quick Sort
Unstable, O(n log n) for a good pivot,O(n^2) for a bad pivot Ω(n log n) : Uses partitioning O(n), Pick a median of 1st, middle, and last element for pivot. Random selection is also good, but expensive. Algorithm can be slow because of many function calls.
Namespaces
Used to disambiguate classes in C++
Recursive function example
Void Message() { cout << "this function is recursive\n"; Message(); }
Recursion
When a function calls itself; used in algorithms to break down a problem into sub-problems and combines the solution
Encapsulation
When data is bundled together; let's us hide and restrict access to data
linked list
a collection of nodes arranged so that each node contains a link to the next node in the sequence; Only has to keep track of the head(first value) of the list or the tail (last value) of the list. Can be singly-linked, doubly-linked, circular-linked, doubly circular-linked
Singly-linked list
a data structure in which each list element contains a pointer to the next list element; typical functions: isEmpty(), getLength(), append(x), insertAfter(x,w), remove(x), search(x), print()
Doubly-linked list
a linked list in which each element has both forward and backward pointers.
Binary Search
a search algorithm that starts at the middle of a sorted set of numbers and removes half of the data; this process repeats until the desired value is found or all elements have been eliminated.
Linear Search
a search algorithm which checks each element of a list, in order, until the desired value is found or all elements in the list have been checked.