Câu hỏi phỏng vấn Big-O Notation
Câu hỏi

Name some types of Big O complexity and corresponding algorithms

Câu trả lời

Big O notation is a mathematical notation used to describe the limiting behavior of a function when the argument tends towards a particular value or infinity. It is commonly used in computer science to classify algorithms based on their time and space complexity. Here are some common types of Big O complexity and corresponding algorithms:

O(1) - Constant Time Complexity

  • Description: The execution time of the algorithm is constant and does not change with the input size.
  • Example Algorithms:
    • Accessing an element in an array by index.
    • Push and pop operations on a stack or queue.
    • Initializing a variable and printing it[1][4][6].

O(log n) - Logarithmic Time Complexity

  • Description: The execution time grows logarithmically with the input size.
  • Example Algorithms:
    • Binary search in a sorted array.
    • Operations on balanced trees like AVL trees and Red-Black trees[1][4][6].

O(n) - Linear Time Complexity

  • Description: The execution time grows linearly with the input size.
  • Example Algorithms:
    • Linear search through an unsorted array.
    • Iterating through elements of a list or array[1][4][6].

O(n log n) - Linearithmic Time Complexity

  • Description: The execution time grows in proportion to the input size multiplied by the logarithm of the input size.
  • Example Algorithms:
    • Efficient sorting algorithms like mergesort and heapsort.
    • Certain divide-and-conquer algorithms[1][4][6].

O(n^2) - Quadratic Time Complexity

  • Description: The execut...
middle

middle

Gợi ý câu hỏi phỏng vấn

junior

What is Worst Case?

middle

What is meant by "Constant Amortized Time" when talking about time complexity of an algorithm?

junior

Explain the difference between O(1) vs O(n) space complexities

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào