Big O Notation Quiz

Reviewed by Godwin Iheuwa
Godwin Iheuwa, MS, Computer Science |
Computer Expert
Review Board Member
Godwin is a proficient Database Administrator currently employed at MTN Nigeria. He holds as MS in Computer Science from the University of Bedfordshire, where he specialized in Agile Methodologies and Database Administration. He also earned a Bachelor's degree in Computer Science from the University of Port Harcourt. With expertise in SQL Server Integration Services (SSIS) and SQL Server Management Studio, Godwin's knowledge and experience enhance the authority of our quizzes, ensuring accuracy and relevance in the realm of computer science.
, MS, Computer Science
Approved & Edited by ProProfs Editorial Team
The editorial team at ProProfs Quizzes consists of a select group of subject experts, trivia writers, and quiz masters who have authored over 10,000 quizzes taken by more than 100 million users. This team includes our in-house seasoned quiz moderators and subject matter experts. Our editorial experts, spread across the world, are rigorously trained using our comprehensive guidelines to ensure that you receive the highest quality quizzes.
Learn about Our Editorial Process
| By Aziz
A
Aziz
Community Contributor
Quizzes Created: 1 | Total Attempts: 23,171
Questions: 22 | Attempts: 23,370

SettingsSettingsSettings
Big O Notation Quiz - Quiz

Are you ready to put your coding skills to the test? Introducing the Big O Notation Quiz, where you'll navigate the treacherous terrain of algorithmic complexity! Strap on your thinking cap and get ready for a thrilling adventure through the land of efficiency. This interactive quiz will challenge your understanding of time and space complexity, as you conquer mind-boggling questions that require you to analyze code snippets and determine their Big O notation. Will you emerge as the Big O champion, or will you get tangled up in the complexities? Join us now and find out! It's time to flex Read moreyour coding muscles and embark on this exciting quest.


Big O Notation Questions and Answers

  • 1. 

    What is the time complexity of the insert(index) method in ArrayList?

    • A.

      O(n)

    • B.

      O(n^2)

    • C.

      O(nlogn)

    • D.

      O(logn)

    Correct Answer
    A. O(n)
    Explanation
    The time complexity of the insert(index) method in ArrayList is O(n). This means that the time it takes to insert an element at a specific index in an ArrayList grows linearly with the size of the ArrayList. In other words, if the ArrayList has n elements, it will take approximately n operations to insert an element at a specific index.

    Rate this question:

  • 2. 

    Indicate constant time complexity in terms of Big-O notation.

    • A.

      O(n)

    • B.

      O(1)

    • C.

      O(logn)

    • D.

      O(n^2)

    Correct Answer
    B. O(1)
    Explanation
    The correct answer is O(1) because it indicates constant time complexity. In Big-O notation, O(1) means that the algorithm's running time does not depend on the input size. It implies that the algorithm takes the same amount of time to execute, regardless of the size of the input. This is the most efficient time complexity as it guarantees a constant and predictable performance.

    Rate this question:

  • 3. 

    Indicate exponential time complexity in terms of big-O notation.

    • A.

      O(n)

    • B.

      O(n^2)

    • C.

      O(2^n)

    • D.

      O(logn)

    Correct Answer
    C. O(2^n)
    Explanation
    Exponential time complexity, represented by O(2^n), means that the time required to solve a problem increases exponentially with the size of the input. This notation indicates that the algorithm's running time doubles with each additional input element. It is the slowest time complexity among the options provided, as it grows very quickly and becomes impractical for larger inputs.

    Rate this question:

  • 4. 

    Find the slowest time.

    • A.

      O(n)

    • B.

      O(n^2)

    • C.

      O(n!)

    • D.

      O(2^n)

    Correct Answer
    C. O(n!)
    Explanation
    The answer O(n!) indicates that the time complexity of the algorithm is factorial, meaning that the runtime grows exponentially with the size of the input. This suggests that the algorithm has a very inefficient and slow performance, as the factorial function grows extremely quickly. In comparison, O(n), O(n^2), and O(2^n) have better time complexities and would be faster than O(n!) for larger inputs.

    Rate this question:

  • 5. 

    What is the time complexity of the ArrayList remove(index) method?

    • A.

      O(n)

    • B.

      O(2n)

    • C.

      O(logn)

    • D.

      O(n^2)

    Correct Answer
    A. O(n)
    Explanation
    The time complexity of the ArrayList remove(index) method is O(n). This means that the time it takes to remove an element from the ArrayList is directly proportional to the number of elements in the list. The method needs to shift all the subsequent elements to fill the gap left by the removed element, which requires iterating through the remaining elements. Therefore, the time complexity is linear, or O(n).

    Rate this question:

  • 6. 

    What is the time complexity of adding an item before a LinkedList?

    • A.

      O(logn)

    • B.

      O(1)

    • C.

      O(n^2)

    • D.

      O(2^n)

    Correct Answer
    B. O(1)
    Explanation
    The time complexity of adding an item before a LinkedList is O(1). This means that regardless of the size of the LinkedList, the time it takes to add an item before it remains constant. This is because LinkedLists use pointers to connect each node, so adding an item before it simply involves updating the pointers of the new item and the existing item, which can be done in constant time.

    Rate this question:

  • 7. 

    What is the time complexity of adding elements at the beginning of ArrayList?

    • A.

      O(n)

    • B.

      O(n^2)

    • C.

      O(2n)

    • D.

      O(nlogn)

    Correct Answer
    A. O(n)
    Explanation
    Adding elements at the beginning of an ArrayList requires shifting all existing elements to the right to make space for the new element. This operation has a time complexity of O(n) because it needs to iterate through all the elements in the ArrayList to shift them. Therefore, the correct answer is O(n).

    Rate this question:

  • 8. 

    Indicate logarithm polynomial time complexity.

    • A.

      O(n^const(const=2,3…) )

    • B.

      O(n^2)

    • C.

      O(2n)

    • D.

      O(2^n)

    Correct Answer
    A. O(n^const(const=2,3…) )
    Explanation
    The correct answer is O(n^const(const=2,3…)). This indicates that the algorithm's time complexity is polynomial, specifically a power of n. The notation O(n^const(const=2,3…)) represents a polynomial time complexity where the highest power of n is a constant value (2, 3, etc.). This means that the algorithm's running time grows at a rate proportional to some constant power of the input size n.

    Rate this question:

  • 9. 

    What is the time complexity of the insert(index) method in ArrayList?

    • A.

      O(n)

    • B.

      O(2n)

    • C.

      O(logn)

    • D.

      O(nlogn)

    Correct Answer
    A. O(n)
    Explanation
    The time complexity of the insert(index) method in ArrayList is O(n). This means that the time it takes to insert an element at a specific index in an ArrayList is directly proportional to the number of elements already in the ArrayList. As the number of elements increases, the time taken to insert an element also increases linearly.

    Rate this question:

  • 10. 

    What is the time complexity of the recursive Binary Search algorithm?

    • A.

      O(n)

    • B.

      O(2^n)

    • C.

      O(logn)

    • D.

      O(nlogn)

    Correct Answer
    C. O(logn)
    Explanation
    The time complexity of the recursive Binary Search algorithm is O(logn) because in each recursive call, the algorithm divides the search space in half, reducing the number of elements to search by half each time. This results in a logarithmic time complexity as the search space is continually halved until the target element is found or the search space becomes empty. Therefore, the time complexity of the recursive Binary Search algorithm is O(logn).

    Rate this question:

  • 11. 

    What is the time complexity of the linear search algorithm?

    • A.

      O(n)

    • B.

      O(n^2)

    • C.

      O(2^n)

    • D.

      O(1)

    Correct Answer
    A. O(n)
    Explanation
    The time complexity of the linear search algorithm is O(n) because it has to iterate through each element in the worst case scenario. This means that the time it takes to execute the algorithm increases linearly with the size of the input.

    Rate this question:

  • 12. 

    Search a binary search tree costs?

    • A.

      O(n)

    • B.

      O(n^2)

    • C.

      O(logn)

    • D.

      O(nlogn)

    Correct Answer
    C. O(logn)
    Explanation
    The search operation in a binary search tree has a time complexity of O(logn). This is because in a binary search tree, the elements are arranged in a specific order, allowing for efficient searching. At each step of the search, the current node is compared with the target value, and based on the result, the search continues either in the left or right subtree. Since the tree is balanced and each comparison reduces the search space by half, the time complexity of the search operation is logarithmic in the number of elements in the tree.

    Rate this question:

  • 13. 

    Element insertion to a Binary Search tree costs?

    • A.

      O(n)

    • B.

      O(n^2)

    • C.

      O(logn)

    • D.

      O(2^n)

    Correct Answer
    C. O(logn)
    Explanation
    The correct answer is O(logn) because when inserting an element into a binary search tree, we start from the root and compare the value of the element with the current node. Based on the comparison, we move either to the left or right subtree. This process is repeated until we find an empty spot to insert the element. Since at each step we divide the search space in half, the time complexity of element insertion in a binary search tree is logarithmic, making it O(logn).

    Rate this question:

  • 14. 

    Insert and remove items from a heap costs?

    • A.

      O(n)

    • B.

      O(n^2)

    • C.

      O(logn)

    • D.

      O(1)

    Correct Answer
    C. O(logn)
    Explanation
    Inserting and removing items from a heap typically costs O(log n) time complexity, where "n" is the number of elements in the heap. This is because heaps are typically implemented as binary trees (binary min-heap or max-heap), and in a well-implemented heap, the height of the tree is logarithmic in the number of elements. So, the correct answer is O(log n).

    Rate this question:

  • 15. 

    The average time complexity of the Selection sort is?

    • A.

      O(n)

    • B.

      N^2 

    • C.

      O(logn)

    • D.

      O(nlogn)

    Correct Answer
    B. N^2 
    Explanation
    The average time complexity of Selection Sort is O(n^2), where "n" represents the number of elements in the array. This complexity arises because, in each pass of the algorithm, it searches for the minimum (or maximum) element from the unsorted portion and swaps it with the element in the current position, resulting in a quadratic time complexity.

    Rate this question:

  • 16. 

    What is the average time complexity of the Heap sort?

    • A.

      O(n)

    • B.

      O(2^n)

    • C.

      O(logn)

    • D.

      O(nlogn)

    Correct Answer
    D. O(nlogn)
    Explanation
    The average time complexity of Heap sort is O(nlogn). This means that the time taken to sort a list of n elements using Heap sort will increase in proportion to n multiplied by the logarithm of n. This complexity arises from the fact that Heap sort involves building a heap and then repeatedly extracting the maximum element from the heap and re-heapifying the remaining elements. The process of building the heap takes O(n) time, and the extraction and re-heapification process is repeated n times, each taking O(logn) time. Thus, the overall average time complexity is O(nlogn).

    Rate this question:

  • 17. 

    The average time complexity of Quicksort is?

    • A.

      O(n)

    • B.

      O(n^2)

    • C.

      O(2+nlogn)

    • D.

      O(nlogn)

    Correct Answer
    D. O(nlogn)
    Explanation
    Quicksort is a sorting algorithm that divides the input array into two smaller sub-arrays, and recursively sorts these sub-arrays. The pivot element is chosen and the elements are partitioned around it. The average time complexity of Quicksort is O(nlogn) because in each recursion, the algorithm divides the array into two parts, which takes O(logn) time. Additionally, the partitioning step takes O(n) time in the average case. Therefore, the overall time complexity is O(nlogn).

    Rate this question:

  • 18. 

    The average time complexity of Insertion sort is?

    • A.

      O(n)

    • B.

      O(n^2)

    • C.

      O(2^n)

    • D.

      O(logn)

    Correct Answer
    B. O(n^2)
    Explanation
    Insertion sort is a simple sorting algorithm that works by repeatedly inserting elements into their correct positions within a sorted subarray. It iterates through the array, comparing each element with the elements before it and shifting them to the right if they are greater. The average time complexity of Insertion sort is O(n^2) because in the worst-case scenario, when the array is in reverse order, it would require comparisons and shifts for each element, resulting in a quadratic time complexity.

    Rate this question:

  • 19. 

    A hash table uses hashing to transform an item's key into a table index so that iterations, retrievals, and deletions can be performed in expected ___________ time.

    • A.

      O(n)

    • B.

      O(logn)

    • C.

      O(1)

    • D.

      O(false)

    Correct Answer
    C. O(1)
    Explanation
    A hash table uses hashing to transform an item's key into a table index so that iterations, retrievals, and deletions can be performed in expected constant time. This means that regardless of the size of the hash table or the number of items stored in it, the time it takes to perform these operations remains constant. Therefore, the correct answer is O(1).

    Rate this question:

  • 20. 

    The average time complexity of Merge sort is?

    • A.

      O(n)

    • B.

      O(2^n)

    • C.

      O(logn)

    • D.

      O(nlogn)

    Correct Answer
    D. O(nlogn)
    Explanation
    Merge sort has a time complexity of O(nlogn) because it divides the array into two halves recursively, sorts them separately, and then merges them back together. The time complexity of merging two sorted arrays of size n/2 each is O(n), and since the array is divided in half at each step, the total time complexity is O(nlogn).

    Rate this question:

  • 21. 

    The average time complexity of Shell sort is?

    • A.

      O(n)

    • B.

      O(n^2)

    • C.

      O(n^1.25)

    • D.

      O(n^2.25)

    Correct Answer
    C. O(n^1.25)
    Explanation
    Shell sort is an efficient sorting algorithm that improves upon the time complexity of insertion sort. It achieves this by sorting elements that are far apart before progressively reducing the gap between elements to be sorted. The average time complexity of Shell sort is O(n^1.25), which means that the time it takes to sort a list of n elements increases at a slower rate than n^2 but faster than n. This makes Shell sort faster than insertion sort, but slower than more advanced sorting algorithms like quicksort or mergesort.

    Rate this question:

  • 22. 

    The average time complexity of Bubble sort is?

    • A.

      O(n^2)

    • B.

      O(n)

    • C.

      O(logn)

    • D.

      O(nlogn)

    Correct Answer
    A. O(n^2)
    Explanation
    Bubble sort is a simple sorting algorithm that repeatedly steps through the list, and compares adjacent elements, and swaps them if they are in the wrong order. The algorithm continues to do this until the entire list is sorted. In the worst-case scenario, where the list is in reverse order, Bubble sort will have to make n-1 passes through the list, each time comparing and swapping adjacent elements. This results in a time complexity of O(n^2), where n is the number of elements in the list.

    Rate this question:

Godwin Iheuwa |MS, Computer Science |
Computer Expert
Godwin is a proficient Database Administrator currently employed at MTN Nigeria. He holds as MS in Computer Science from the University of Bedfordshire, where he specialized in Agile Methodologies and Database Administration. He also earned a Bachelor's degree in Computer Science from the University of Port Harcourt. With expertise in SQL Server Integration Services (SSIS) and SQL Server Management Studio, Godwin's knowledge and experience enhance the authority of our quizzes, ensuring accuracy and relevance in the realm of computer science.

Quiz Review Timeline +

Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.

  • Current Version
  • Mar 26, 2024
    Quiz Edited by
    ProProfs Editorial Team

    Expert Reviewed by
    Godwin Iheuwa
  • May 24, 2018
    Quiz Created by
    Aziz
Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.