This repository contains Python implementations and analysis of the time complexity of several fundamental algorithms. The algorithms included in this analysis are:
Selection Sort Towers of Hanoi Permutations of an Array of length n Sum of n Numbers in an Array Boolean Permutations of an Array of length n For each algorithm, we provide a Python implementation along with a detailed analysis of its time complexity. Additionally, we have created graphs to visualize the time complexity of these algorithms for different input sizes using matplotlib.pyplot.
Algorithms Included
-
Selection Sort Selection Sort is a simple sorting algorithm that repeatedly selects the smallest (or largest) element from the unsorted portion of the array and moves it to the sorted portion. The time complexity of Selection Sort is O(n^2), where n is the number of elements in the array.
-
Towers of Hanoi The Towers of Hanoi is a classic problem that involves moving disks from one rod to another, respecting the rules that no larger disk can be placed on top of a smaller disk. The time complexity of the Towers of Hanoi algorithm is O(2^n), where n is the number of disks.
-
Permutations of an Array of length n This algorithm generates all possible permutations of an array of length n. The time complexity of generating all permutations of an array is O(n!), where n is the length of the array.
-
Sum of n Numbers in an Array This algorithm calculates the sum of n numbers in an array using iterative or recursive approaches. The time complexity of calculating the sum of n numbers in an array is O(n), where n is the number of elements in the array.
-
Boolean Permutations of an Array of length n This algorithm generates all possible boolean permutations of an array of length n, where each element can be either True or False. The time complexity of generating all boolean permutations of an array is O(2^n), where n is the length of the array.
Graphs We have provided graphs for each algorithm depicting the time complexity for different input sizes. These graphs are generated using matplotlib.pyplot library in Python. You can find the code for generating these graphs in the respective Python files for each algorithm.
Getting Started To run the code and generate the graphs, you need to have Python installed on your system along with the matplotlib library. You can install the required library using pip:
bash Copy code pip install matplotlib After installing the required dependencies, you can run each Python file to execute the algorithms and generate the corresponding graphs.
Contributions Contributions to improve the analysis, provide alternative implementations, or add new algorithms are welcome! Please feel free to open a pull request with your changes.
License This repository is licensed under the MIT License. See the LICENSE file for details.