Dannys Cards Flashcards
What is the time complexity of Counting Sort?
O(n)
What is a Sequential Structure?
We can only access an element after we have accessed all the elements before it
Whats the difference between Direct Access and Hash Tables?
Direct Access: key “k” is stored in slot k
Hash Table: key “k” is stored in hash(k)
How does Counting Sort work?
Creates array to store count of all elements
Changes the array so the count also adds all the elements prior
Iterates through main list and takes count number and places it in new list with index of the count number
Repeat until done, -1 from count when used
Why do collisions happen in Hash Tables?
Because we’re mapping elements to normally smaller domain of slots, collisions are likely to happen
How does MSD radix sort work?
Unlike LSD radix sort, it starts from left most (most significant) digit groups those together, then goes to next digit on the right and groups those together in sub groups, then groups the next digits on the right in sub sub groups and so on.
540,330,545,350,333,578,570
First grouping of digit of 100s
Eg. 330,350,333 540,545,570,578
2nd grouping of 10’s
330,333 350 540, 545 570,578
3rd and final grouping of 1’s to make completed list
330,333,350,540,545,570,578
What is a Circular List?
The link member of the last node points to the first node
What are the rules of Binary Search Trees?
the value of left node must be smaller than the parent node, and the value of right node must be greater than the parent node
What is the benefit of a Balanced Tree?
Increases efficiency of searching
If a tree is balanced we can perform most operations in O(log n)
How does Quicksort work?
- Pick an item, is called the “pivot”
- Sort the other elements so that smaller elements are on its left and bigger are on its right
- Now you have two piles of items repeat this until each pile has 1 card
- Once sorted add all piles together
What is a Direct Access Structure?
Any element of the structure can be accessed directly
How long does a Simple Step take in RAM?
1 time step
How do Lists differ from Arrays?
They don’t have a fixed size, but like arrays then can only store elements of the same type
-> Homogenous Structure
Explain O(n^2) time
Quadratic
Relatively efficient for non large input sizes
Typical of algorithms that have to analyse all pairs of element of the input
Define an edge
A connection between 2 nodes
What is an Insertion Sort?
Builds the final sorted array one element at a time by inserting elements into their correct positions
Define a leave
Nodes that have no children
What is the Bernoulli Process?
A series of executions of Bernoulli trials
What type of algorithm is Quick Sort?
Divide and Conquer
How does Merge Sort work?
Splits list into separate lists then merges the lists back together in order
Define a Dense Graph?
graph with a large number of edges in relation to the number of vertices, and the number of edges is close to the maximum possible number
E is close to V^2
E = O(V^2)
Explain O(n^3) time
Cubic
Not very efficient but still polynomial
Example is Matrix Multiplication
Explain O(n) time
Linear, algorithms that are forced to pass through all elements of the input, a number of times
What is the worst case of an Insertion Sort?
O(n^2)
Same as selection sort