CS133-8: Quiz 1-4
how much computing power and time it takes the algorithm to run
Define the cost of an algorithm. The cost of an algorithm is ___________________________________________.
O(1/n^3)
If a function required 5/n + 12/(n^3) + 100/(nlogn) steps to run, what would its big-O notation be?
True
True or False: 2^n = Ω(n^1000)
True
True or False: Different implementations of the same algorithm can lead to different efficiency measures.
False
True or False: O(nlogn) < = O(nloglogn)
O(n)
What is the best case running time of Bubble Sort?
1 3 4 2
What is the first change that selection sort would make to this sequence to put it into ascending order: "3 1 4 2"?
When the list has only a few elements and When performing a single search in an unordered list
Where is linear searching used?
Quick sort's big-O notation is no better than merge sort's or heap sort's, and can even be worse if bad pivots are chosen.
Why is quick sort's name misleading?
Bubble sort will detect that the list is in order after one pass, while selection sort always takes O(n) steps to sort a list.
Why would bubble sort be more efficient on the list (1, 2, 3, 4, 5, 6, 7) than selection sort?
divide and conquer
A binary search algorithm works on the principle of _____?
Greater time complexities compared to other searching algorithms
A disadvantage of linear search
2
Consider the following array: {1, 2, 5, 8, 9, 2, 6, 7, 6} What is the minimum number of jumps required to reach the end of the array?
Smaller elements 'bubble' to the top
One of the simplest sorting algorithms is called bubble sort. Do you know why?
KHz Real running time
The efficiency and complexity of an algorithm are measured in _____ because it allows for easy comparisons of similar algorithms.
middle element
The first step to perform a binary search for a target value in a sorted array is to identify the __________ of the array.
Growth analysis
The process of determining the rate of growth of a function is called:
False
True or False: When doing a binary search, every element in the array or tree is examined.
Bubble sort, because the list is in nearly sorted order.
What sorting algorithm might you choose for the following list? Why? (1, 2, 3, 6, 5, 9)
sorted
binary search works only on _____ arrays.
When each sublist has one element
A mergesort works by first breaking a sequence in half a number of times so it is working with smaller pieces. When does it stop breaking the list into sublists (in its simplest version)?
Bubble Sort
Consider the following consecutive configurations of a list while it it being sorted: (4, 5, 3, 1) (4, 5, 3, 1) (4, 3, 5, 1) (4, 3, 1, 5) What sorting algorithm is being used?
Selection sort
Consider the intermediate configurations of an array being sorted below. What sort is being used? (4, 5, 2, 1, 7) (1, 5, 2, 4, 7) (1, 2, 5, 4, 7)
1 and 3, 3 and 4, 4 and 7, 5 and 7, 7 and 8, 8 and 9
For merge sort to merge the following two arrays: (1, 4, 5, 8) and (3, 7, 9, 13), what comparisons have to take place?
5
How many comparisons would it take merge sort to merge the following lists (1, 2, 3, 4, 5) and (6, 7, 8, 9, 10)?
The sort runs inefficiently because the pivots always divide the lists into an empty list and a large list.
Imagine that we run quick sort on an already ordered list, picking the pivot by taking the first element. What problem do we run into?
divide and conquer
Merge sort uses which of the following algorithms to implement sorting?
A value in the middle of the current sublist
Quicksort works by choosing a pivot value and moving list elements around. Each element less than the pivot will be closer to the beginning of the list than the pivot, and each element greater than the pivot will be closer to the end of the list. By doing this operation many times with different pivots, the list will become sorted. For the fastest operation, which would be the best pivot value?
Bubble sort
The intermediate configurations below are characteristic of which sorting algorithm? (5, 1, 4, 8, 2) (1, 5, 4, 8, 2) (1, 4, 5, 8, 2) (1, 4, 5, 2, 8)
True
True or False: 3n = O(n^2)
False
True or False: 3n^2 = O(nlgn)
False
True or False: A doubly-linked list would allow for random access whereas a singly-linked list wouldn't.
True
True or False: Arrays allow for random access.
True
True or False: Binary search only operates on sorted sequence
False
True or False: Different platforms running the same algorithm always take the same amount of time
True
True or False: For faster and frequent searches, sorted sequences are better to work on
True
True or False: Heap sort guarantees O(nlgn) performance
True
True or False: Heap sort makes use of heap data structure
False
True or False: Linked lists allow for random access.
True
True or False: Merge sort has linear space requirement
True
True or False: When comparing two functions, we focus on the limit of the function as n approaches 0.
False
True or False: bubble sort gains efficiency by splitting the data in half.
True
True or False: for some data sets, quick sort will be slower than bubble sort.
False
True or False: merge sort and quick sort can only be used on lists whose length is a power of 2.
True
True or False: nlgn = Θ(20000nlgn)
False
True or False: selection sort can sometimes run as fast as O(n).
True
True or False: selection sort' efficiency is independent of the data being sorted.
True
True or False: the data structure a programmer uses in an algorithm can have an effect on an algorithm's efficiency.
None of the above; insertion sort doesn't make swaps, it does shifts.
What is the first swap insertion sort would make on the following list? (5, 3, 4, 9, 1)
None of the above; selection sort doesn't make swaps.
What is the first swap selection sort would make on the following list? (5, 3, 4, 9, 1)
Heap sort always sorts a list in O(nlog(n))
What makes heap sort attractive as opposed to quick sort?
Bubble sort, because it can "short circuit" (use flag) its operation when it detects that the list is in order.
What sort might you use if you know that your data will be pretty much in order to begin with and why would you use that sort?
Because they divide the list they're given into smaller lists and then sort those smaller lists.
Why are merge sort and quick sort known as "divide and conquer" algorithms?
Since sorting is a very common operation in computer science it is important that it be performed in an efficient manner; many processes rely on sorting.
Why are we so concerned with the efficiencies of sorting algorithms?
Because re-heaping often increases the number of inversions (out of order elements) in the array.
Why might it seem counterintuitive that heap sort can run so efficiently?