Everything Flashcards
What is an algorithm?
a set of instructions for accomplishing a task
True or False? For binary search to work, its elements have to be sorted.
True
State briefly how the binary search works.
With binary search, you guess the middle number and eliminate half the remaining numbers every time.
Suppose you’re looking for a word in the dictionary. The dictionary has 240,000 words. In the worst case, how many steps do you think each search will take?
Simple Search?
Binary Search?
In general, for any list of size n, binary search will take ______ steps to run in the worst case, whereas simple search will take __ steps.
log2n
n
Binary search runs in _______ time
logarithmic
What’s the Big O for a linear search?
O(n)
What’s the Big O for a binary search?
O(logn)
What does the Big O notation tell you?
How fast an algorithm is. The worst case.
True or false? Big O tells you how fast the algorithm grows.
True
Big O establishes a _____-case runtime
worst
How does a selection sort algorithm work?
The selection sort algorithm sorts an array by repeatedly finding the minimum element (considering ascending order) from unsorted part and putting it at the beginning.
What’s the Big O of a selection sort algorithm?
O(n2)
What’s the Big O of the Quicksort Algorithm?
O(nlogn)
If you want to insert an element into the middle of a list, what’s better to use, arrays or linked lists?
Linked lists, since in arrays you would have to shift everything down.
What if you want to delete an element from a list? Which is better? Array or Linked List.
Linked List. With arrays, you would have to shift all of the elements.
When searching for elements, what are the two types of access?
Random access and Sequential Access
_______ ________ means reading elements one by one, starting at the first element.
Sequential Access
True or False? Linked lists can do random access or sequential access.
False. Only sequential access
_______ _______ means you can jump directly to the 10th element.
Random Access
True or false? Arrays are faster at reads than linked lists
True. Arrays allow for random access while linked lists only allow for sequential access
True or false? There is a performance benefit to using recursion
False.
Every recursive function has two parts. What are they?
The base case and the recursive case.
True or false? Quicksort is faster than selection sort
True
What is the Big O for quicksort?
O(nlogn)
Selection sort has a Big O of _____.
O(n2)