Cal Poly CPE-202 Big-O time complexity Quiz
Quick Sort is always faster than Merge Sort T / F
False
Assume the Python List is of length "n", was is the Big-O time complexity to Return the value of the first entry in a Python List?
O(1)
Find a key in a hash table (typical case, efficient hash table, low load factor)
O(1)
Find a key in a hash table (typical case, low load factor)
O(1)
Given a key, remove the key/value pair from a hash table (typical case, efficient hash table, low load factor)
O(1)
Perform peek operation to return (but don't delete) minimum key from Minimum Binary Heap
O(1)
Assuming a circular array implementation for a Queue (as in Lab 3), the dequeue() operation
O(1)?
Dequeue an item from a queue (do not assume an implementation)
O(1)?
Use of the append operation to add an item to a Python List
O(1)?
class Node: """Node for use with singly-linked list""" ......def __init__(self, item, next=None): ............self.item = item # item held by Node ............self.next = next # reference to next Node class LinkedList: ......def __init__(self): ............self.head = None # head of linked list Add a new node to the head of a linked list as shown above
O(1)?
Binary search on an ordered list implemented with an array
O(log n)??
Find the minimum key in a Red-Black Tree
O(log(n))
Remove (dequeue) the maximum key from a Maximum Binary Heap
O(log(n))
Worst case for the insertion of a key into a Red-Black Tree
O(log(n))
Assume the Python List is of length "n", was is the Big-O time complexity to Execute a binary search for a value within an already sorted Python List?
O(long(n))
Build a Binary Heap by repeated insertion of keys
O(n log(n))
Perform "top down" construction of a binary heap (repeated insertions of keys)
O(n log(n))
Perform Heap Sort on a sorted list
O(n log(n))
Perform Heap Sort on an already sorted set of data
O(n log(n))
Perform Heap Sort on random set of data
O(n log(n))
Perform Merge Sort on random set of data
O(n log(n))
Perform Quick Sort on random data, using "median of 3" pivot (average case)
O(n log(n))
Starting with empty Red-Black Tree, build a tree with "n" insertions
O(n log(n))
Suppose we have an O(n) time algorithm that finds the median of an unsorted array. Now consider a Quick Sort implementation where we first find the median using the above algorithm, then use the median as the pivot. What will be the worst case time complexity of this modified Quick Sort, including the operation that finds the median?
O(n log(n))
What is the Big-O time complexity of my_function as it relates to the input parameter, n? def my_function(n): # n is a positive integer ......x = 0 ......for i in range(n//2): ............j = 1 ............while j < n: ..................x += j*i ..................j = 2*j ......return x
O(n log(n))
Assume the Python List is of length "n", was is the Big-O time complexity to Find the minimum value in a Python List of random integers?
O(n)
Assume the Python List is of length "n", was is the Big-O time complexity to Sequential (linear) search for an item in a Python List?
O(n)
Assume the Python List is of length "n", was is the Big-O time complexity to Sum the values of a Python List of integers?
O(n)
Breadth First Search of a graph
O(n)
Build a Binary Heap using the Bottom Up method
O(n)
Find the height of a Red-Black Tree
O(n)
Given a starting vertex, searching for all vertices in a connected graph
O(n)
In-order traversal of a Red-Black Tree
O(n)
Perform "bottom up" construction of a binary heap
O(n)
Perform Insertion Sort on an already sorted set of data
O(n)
Resize a hash table (e.g. growing hash table as in Project 4, when load factor > .5)
O(n)
Worst case for the insertion of a key into a "standard" Binary Search Tree
O(n)
def func1(n, x): # n and x are positive integers ......val = 0 ......for i in range(n): ............for j in range(n*x): ............val += i*j ......return val For func1 above, if x = 0, was is the Big-O time complexity?
O(n)
Find a node containing a certain data value within a linked list
O(n)?
class Node: """Node for use with singly-linked list""" ......def __init__(self, item, next=None): ............self.item = item # item held by Node ............self.next = next # reference to next Node class LinkedList: ......def __init__(self): ............self.head = None # head of linked list Add a new node to the tail end of a linked list that only has a head reference (no tail reference in the linked list class, as shown above)
O(n)?
Perform Insertion Sort on random set of data
O(n^)
Perform Bubble sort on random set of data
O(n^2)
Perform Quick Sort on already sorted set of data, using value at first index for pivot
O(n^2)
Perform Selection Sort on random set of data
O(n^2)
def func1(n, x): # n and x are positive integers ......val = 0 ......for i in range(n): ............for j in range(n*x): ............val += i*j ......return val For func1 above, if x = 1 was is the Big-O time complexity?
O(n^2)
Use of the pop(0) operation to repeatedly remove all items from a Python List
O(n^2)?
Merge Sort is guaranteed to be O(n log(n)) T / F
True
For Merge Sort, if we have two arrays, each of size n/2, what are the best case and worst case number of comparisons for the merge operation (best case, worst case)?
n/2, n-1