Skip to content

Latest commit

 

History

38 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🚀 DSA-TimeComplexity

📌 Understanding Time Complexity in Data Structures & Algorithms

This repository contains Python implementations of various time complexity examples, helping you understand how different algorithms perform as input size increases.


📂 Contents

1️⃣ Measuring Execution Time (⚠️ Not Recommended)

  • Using time.time() to measure execution time.
  • Why it's not reliable due to varying machine specs.

2️⃣ Iterative vs Recursive Algorithms

  • Countdown using while loop.
  • Factorial function O(n) complexity (Iterative vs Recursive).

3️⃣ String Conversion (Integer to String)

  • Understanding how integers are converted to strings manually.

4️⃣ Nested Loops & Pair Generation

  • O(n²) complexity: Generating pairs in a list.
  • O(n × m) complexity: Comparing two lists element-wise.

5️⃣ Triple Nested Loops

  • Understanding how O(n³) complexity arises.

6️⃣ Swapping Elements in a List

  • Optimized O(n) approach to reverse a list in-place.

7️⃣ Fibonacci Sequence (Exponential Complexity 🚨)

  • O(2ⁿ) complexity: Why recursive Fibonacci is inefficient.

8️⃣ Dynamic Arrays

  • Understanding resizing strategy and amortized time complexity.
  • How dynamic arrays achieve O(1) average-time complexity for append().
  • Implementing a custom dynamic array in Python.

⏳ Time Complexity Summary

Algorithm Time Complexity
Iterative Factorial O(n)
Recursive Factorial O(n)
Nested Loops (Pairs) O(n²)
Comparing Two Lists O(n × m)
Triple Nested Loops O(n³)
List Reversal O(n)
Recursive Fibonacci O(2ⁿ) (Exponential)
Dynamic Array Append O(1) (Amortized)

🚀 How to Run the Code?

  1. Clone the repository:
    git clone https://github.com/kamalaly611/DSA-TimeCompleixty.git
  2. Navigate to the folder:
    cd DynamicArrays.py
  3. Run the Python file:
    python filename.py

🤔 Why is Time Complexity Important?

  • Helps optimize algorithms for large inputs.
  • Determines scalability of a solution.
  • Avoids inefficiencies in real-world applications.

🔗 Contribute & Learn More

Want to contribute? Feel free to fork, star ⭐, or open an issue!

📩 Author: kamalaly611

Happy Coding! 🚀

About

This repository explores the time complexity of various data structures and algorithms, providing detailed analysis, visualizations, and code implementations. It serves as a reference for developers and students aiming to optimize their algorithms and improve problem-solving efficiency.

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages