36 Lecture

CS301

Midterm & Final Term Short Notes

Running Time Analysis

Running time analysis is the process of evaluating the efficiency of an algorithm by determining the time it takes to execute as a function of its input size. This analysis is typically done using asymptotic notation, such as big O notation, whi


Important Mcq's
Midterm & Finalterm Prepration
Past papers included

Download PDF
  1. What is the time complexity of a linear search algorithm? a) O(n) b) O(log n) c) O(n^2) d) O(1) Answer: a) O(n)

  2. Which of the following is not an asymptotic notation used for running time analysis? a) Big O notation b) Theta notation c) Little O notation d) Epsilon notation Answer: d) Epsilon notation

  3. What is the time complexity of a binary search algorithm? a) O(n) b) O(log n) c) O(n^2) d) O(1) Answer: b) O(log n)

  4. Which of the following is a constant time complexity algorithm? a) Bubble sort b) Insertion sort c) Quick sort d) Counting sort Answer: d) Counting sort

  5. Which of the following is an example of an exponential time complexity algorithm? a) Merge sort b) Quick sort c) Bubble sort d) Traveling salesman problem Answer: d) Traveling salesman problem

  6. Which of the following is not a factor that can affect the running time of an algorithm? a) Input size b) Memory usage c) Hardware configuration d) Implementation details Answer: b) Memory usage

  7. What is the time complexity of a worst-case scenario for a sorting algorithm? a) O(n) b) O(log n) c) O(n^2) d) O(1) Answer: c) O(n^2)

  8. What is the time complexity of a best-case scenario for a sorting algorithm? a) O(n) b) O(log n) c) O(n^2) d) O(1) Answer: a) O(n)

  9. Which of the following is an example of a logarithmic time complexity algorithm? a) Merge sort b) Quick sort c) Binary search d) Bubble sort Answer: c) Binary search

  10. Which of the following is an example of a quadratic time complexity algorithm? a) Merge sort b) Quick sort c) Insertion sort d) Heap sort Answer: c) Insertion sort



Subjective Short Notes
Midterm & Finalterm Prepration
Past papers included

Download PDF
  1. What is running time analysis? Answer: Running time analysis is the process of evaluating the efficiency of an algorithm by determining the time it takes to execute as a function of its input size.

  2. What is the difference between best-case and worst-case time complexity? Answer: Best-case time complexity refers to the minimum time required by an algorithm to complete its task on a given input, whereas worst-case time complexity refers to the maximum time required by an algorithm to complete its task on a given input.

  3. What is the purpose of asymptotic notation in running time analysis? Answer: Asymptotic notation, such as big O notation, provides an upper bound on the growth rate of an algorithm's running time. It is used to describe how the running time of an algorithm increases as the size of its input increases.

  4. What is the time complexity of an algorithm that takes constant time to execute? Answer: An algorithm that takes constant time to execute has a time complexity of O(1).

  5. What is the time complexity of an algorithm that executes a loop n times, where n is the size of the input? Answer: An algorithm that executes a loop n times, where n is the size of the input, has a time complexity of O(n).

  6. What is the difference between logarithmic and linear time complexity? Answer: Logarithmic time complexity refers to an algorithm whose running time increases logarithmically with the size of its input, while linear time complexity refers to an algorithm whose running time increases linearly with the size of its input.

  7. What is the difference between average-case and worst-case time complexity? Answer: Average-case time complexity refers to the expected time required by an algorithm to complete its task on a given input, while worst-case time complexity refers to the maximum time required by an algorithm to complete its task on a given input.

  8. What is the purpose of analyzing the running time of an algorithm? Answer: The purpose of analyzing the running time of an algorithm is to identify the most efficient algorithm to solve a problem, taking into account the size of the input.

  9. What is the time complexity of an algorithm that executes a loop within a loop, where both loops iterate n times? Answer: An algorithm that executes a loop within a loop, where both loops iterate n times, has a time complexity of O(n^2).

  10. Can the running time of an algorithm be measured in seconds? Answer: The running time of an algorithm can be measured in seconds, but it is not a useful metric for comparing the efficiency of algorithms, as it depends on the hardware configuration of the computer on which the algorithm is executed. Asymptotic notation is a more useful metric for comparing the efficiency of algorithms.

Running time analysis is a crucial aspect of computer science that is used to evaluate the efficiency of algorithms. It involves determining the time it takes for an algorithm to complete its task as a function of the input size. The goal of running time analysis is to identify the most efficient algorithm to solve a problem, taking into account the size of the input. Asymptotic notation, such as big O notation, is commonly used in running time analysis to describe how the running time of an algorithm increases as the size of its input increases. Big O notation provides an upper bound on the growth rate of an algorithm's running time, which makes it easier to compare the efficiency of different algorithms. The running time of an algorithm can be expressed in terms of its best-case, worst-case, or average-case time complexity. Best-case time complexity refers to the minimum time required by an algorithm to complete its task on a given input. Worst-case time complexity refers to the maximum time required by an algorithm to complete its task on a given input. Average-case time complexity refers to the expected time required by an algorithm to complete its task on a given input. The time complexity of an algorithm can be expressed in terms of various orders of magnitude, such as constant time (O(1)), logarithmic time (O(log n)), linear time (O(n)), quadratic time (O(n^2)), and exponential time (O(2^n)). Algorithms with lower time complexity are generally more efficient than those with higher time complexity. Running time analysis is essential for determining the scalability of an algorithm, which is its ability to handle increasingly larger inputs. An algorithm with a high time complexity may not be scalable and may not be suitable for solving large-scale problems. In conclusion, running time analysis is a critical aspect of algorithm design and computer science. It helps us to identify the most efficient algorithm for solving a problem and provides insights into the scalability of an algorithm. Asymptotic notation, such as big O notation, is a commonly used tool in running time analysis to compare the efficiency of different algorithms.