Building a Python Module for Complexity Calculation #148594
-
Hello Everyone, I hope you're doing well! I’m currently working on a Python module that can be used to calculate the complexity of algorithms. The goal is to provide a tool that helps developers, students, and data scientists easily assess the time and space complexity of their code. Features I'm Considering: Analysis of code execution time in terms of Big O notation (e.g., O(n), O(log n), O(n^2), etc.) Evaluate the space consumed by the algorithm with respect to the input size. Arrays, Linked Lists, Trees, Graphs, Hashmaps, Stacks, Queues, etc. A decorator that wraps any function and reports its time complexity based on the input size. Looking forward to your suggestions and insights! |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 9 replies
-
Thanks for posting in the GitHub Community, @shahiakhilesh1304 ! We’ve moved your post to our Programming Help 🧑💻 category, which is more appropriate for this type of discussion. Please review our guidelines about the Programming Help category for more information. |
Beta Was this translation helpful? Give feedback.
-
@queenofcorgis : Can you please Elevate this discussion. I needed a solution and I am not finding this thread much helpful. |
Beta Was this translation helpful? Give feedback.
-
Thats a very interesting idea. Time complexity:My initial thought was to run a function multiple times with increasing input sizes and using regression, fit a curve to approximate complexity using its execution time. However, I think I got a better idea now with ML. We can start by collecting execution times for different input sizes and extract features like mean, variance and time difference. Then with using a set of known algorithm complexities as our training data, we can train a classifier model and predict. I actually tried this with RandomForestClassifier() and results were pretty good. Let me know if you want the code. I can share. Space complexity:This one's pretty easy, just use Please mark this answer helpful! |
Beta Was this translation helpful? Give feedback.
-
Your project sounds like a great tool for developers! For dynamic time complexity analysis, consider using AST (Abstract Syntax Tree) to analyze loop structures and recursion patterns. You can also use profiling tools like cProfile or timeit for empirical measurements. For space complexity, track memory usage with sys.getsizeof() and tracemalloc. To improve accuracy, combine static code analysis with runtime profiling to refine Big O estimations based on varying input sizes. Would love to see how this evolves! 🚀 |
Beta Was this translation helpful? Give feedback.
-
Check this, code . Try it out!
|
Beta Was this translation helpful? Give feedback.
Check this, code . Try it out!