টাইম কমপ্লেক্সিটি (টুকিটাকি)

  • O(1) The running time of a constant-time algorithm does not depend on the input size. A typical constant-time algorithm is a direct formula that calculates the answer.
  • O(logn) A logarithmic algorithm often halves the input size at each step. The running time of such an algorithm is logarithmic, because log2n equals the number of times n must be divided by 2 to get 1.
  • O(√n) A square root algorithm is slower than O(logn) but faster than O(n). A special property of square roots is that √n=n/√n, so the square root √n lies, in some sense, in the middle of the input.
  • O(n) A linear algorithm goes through the input a constant number of times. This is often the best possible time complexity, because it is usually necessary to access each input element at least once before reporting the answer.
  • O(nlogn) This time complexity often indicates that the algorithm sorts the input, because the time complexity of efficient sorting algorithms is O(nlogn). Another possibility is that the algorithm uses a data structure where each operation takes O(logn) time.
  • O(n2) A quadratic algorithm often contains two nested loops. It is possible to go through all pairs of the input elements in O(n2) time.
  • O(n3) A cubic algorithm often contains three nested loops. It is possible to go through all triplets of the input elements in O(n3) time.
  • O(2n) This time complexity often indicates that the algorithm iterates through all subsets of the input elements. For example, the subsets of {1,2,3} are;, {1}, {2}, {3}, {1,2}, {1,3}, {2,3} and {1,2,3}.
  • O(n!) This time complexity often indicates that the algorithm iterates through all permutations of the input elements. For example, the permutations of {1,2,3} are (1,2,3), (1,3,2), (2,1,3), (2,3,1), (3,1,2) and (3,2,1).

আমি এইটা Competitive Programmer’s Handbook by Antti Laaksonen থেকে পুরোটা তুলে দিসি। বইটার লিংকঃ এখানে

শাফায়াত ভাইয়ের ব্লগে সুন্দর ভাবে বাংলায় বলা আছে। এখানে

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *