Friday, August 24, 2012

টাইম কমপ্লেক্সিটি শিখতেই হবে

তাহলেই বুঝতে পারবেন আপনার অ্যালগোরিদমটি অন্যদের চেয়ে কতটা ভাল কাজ করে।
ইনপুটের সাপেক্ষে-
Order of Growth n Time (ms) Comment
O(1) 1000 1 Excellent, almost impossible for most cases
O(log n) 1000 9.96 Very good, example: Binary Search
O(n) 1000 1000 Normal, Linear time algorithm
O(n log n) 1000 9960 Average, this is usually found in sorting algorithm such as Quick sort
O(n^2) 1000 1000000 Slow
O(n^3) 1000 10^9 Slow, btw, All Pairs Shortest Paths algorithm: Floyd Warshall, is O(N^3)
O(2^n) 1000 2^1000 Poor, exponential growth… try to avoid this. Use Dynamic Programming if you can.
O(n!) 1000 uncountable Typical NP-Complete problems.
সময়ের সাপেক্ষে-
Order of Growth Time (ms) Max Possible n Comment
O(1) 60.000 ms Virtually infinite Best
O(log n) 60.000 ms 6^18.000 A very very large number
O(n) 60.000 ms 60.000 Still a very big number
O(n log n) 60.000 ms ~ 5.000 Moderate, average real life size
O(n^2) 60.000 ms 244 small
O(n^3) 60.000 ms 39 very small
O(2^n) 60.000 ms 16 avoid if you can
O(n!) 60.000 ms 8 extremely too small.
মনে রাখতে হবে কমপ্লেক্সিটির ক্রম- constant < log n < n < n log n < n^2 < n^3 < 2^n < n!