├── Array ├── Javascript │ └── MovingMedian │ │ ├── ReadMe.md │ │ └── MovingMedian.js ├── Python │ ├── FibonacciNumber │ │ ├── Readme.md │ │ └── NthFibonacciNumber.py │ ├── FibbonaciNumberEfficient │ │ ├── Readme.md │ │ └── Fibbonacci.py │ ├── EquilibriumIndex │ │ ├── ReadMe.md │ │ └── EquilibriumIndex.py │ ├── FirstDuplicateValue │ │ ├── FirstDuplicateValue.py │ │ └── Readme.md │ ├── ArrayPrefix │ │ ├── PrefixSum │ │ │ ├── ArrayPrefix.py │ │ │ └── Readme.md │ │ ├── SubArrayWithZero │ │ │ ├── Readme.md │ │ │ └── SubArrayWithZero.py │ │ └── SumIndexBetweenLandR │ │ │ ├── Readme.md │ │ │ └── SumIndexBetweenLandR.py │ ├── Rotation │ │ ├── LeftJogglingAlgorithm │ │ │ ├── __pycache__ │ │ │ │ ├── LeftRotation.cpython-310.pyc │ │ │ │ └── left_rotation_test.cpython-310-pytest-7.1.3.pyc │ │ │ ├── Readme.md │ │ │ ├── LeftRotation.py │ │ │ └── left_rotation_test.py │ │ └── RightJogglingAlgorithm │ │ │ ├── __pycache__ │ │ │ ├── RightRotation.cpython-310.pyc │ │ │ ├── rightRotationTest.cpython-310-pytest-7.1.3.pyc │ │ │ └── right_rotation_test.cpython-310-pytest-7.1.3.pyc │ │ │ ├── Readme.md │ │ │ ├── RightRotation.py │ │ │ └── right_rotation_test.py │ ├── MaximumSubArrayValue │ │ ├── Readme.md │ │ └── MaximumSubArray.py │ ├── Valid-Subsequence │ │ ├── ReadMe.md │ │ └── ValidSubsequence.py │ ├── KthMaxSubArrayInefficient │ │ ├── Readme.md │ │ └── MaxSubArray.py │ ├── MoveAllZeros │ │ ├── Readme.md │ │ └── MoveZeros.py │ ├── RearrangeArrayEvenPositionedGreaterThanOdd │ │ ├── Readme.md │ │ └── Rearrange.py │ ├── AlternatePositiveAndNegativeNumbers │ │ ├── AlternativePositiveAndNegative │ │ │ ├── Readme.md │ │ │ └── AlternativePositiveAndNegative.py │ │ └── AlternativePositiveAndNegativeOptimal │ │ │ ├── Readme.md │ │ │ └── AlternativePositiveAndNegative.py │ ├── FindMaxArrayRotationSum │ │ ├── Readme.md │ │ └── FindMaxArrayRotation.py │ ├── ReorderArrayToGivenIndex │ │ ├── Readme.md │ │ └── ReorderArray.py │ └── MergeOverlappingIntervals │ │ ├── MergeOverlappingIntervals.py │ │ └── ReadMe.md ├── TwoDArray │ └── Java │ │ └── HourGlassJava │ │ ├── ReadMe.md │ │ ├── HourGlass.java │ │ └── Main.java ├── Mo'sAlgorithm │ ├── PowerfulArray │ │ ├── Readme.md │ │ └── PowerfulArray.py │ ├── QueryRangeSum │ │ ├── Readme.md │ │ └── QueryRange.py │ ├── SherlockAndInversion │ │ ├── Readme.md │ │ └── SherlockInversion.py │ ├── DistictElementsInAQueryRange │ │ ├── Readme.md │ │ └── NumberOfDistinctElementInAQueryRange.py │ └── NumberOfElementsInAQueryRange │ │ ├── Readme.md │ │ └── NumberOfElementInAQueryRange.py └── Dart │ ├── Sorted-Squared-Array │ ├── SortedSquaredArray.dart │ └── README.md │ └── Valid-Subsequence │ ├── ValidSubSequence.dart │ └── README.md ├── Search ├── Dart │ ├── binary_search │ │ ├── CHANGELOG.md │ │ ├── .gitignore │ │ ├── README.md │ │ ├── pubspec.yaml │ │ ├── bin │ │ │ └── binary_search.dart │ │ ├── lib │ │ │ └── binary_search.dart │ │ ├── analysis_options.yaml │ │ └── pubspec.lock │ └── Interpolation-Search │ │ ├── InterpolationSearch.dart │ │ └── README.md ├── dart │ └── linear_search │ │ ├── CHANGELOG.md │ │ ├── .gitignore │ │ ├── README.md │ │ ├── pubspec.yaml │ │ ├── bin │ │ └── linear_search.dart │ │ ├── test │ │ └── linear_search_test.dart │ │ ├── lib │ │ └── linear_search.dart │ │ ├── analysis_options.yaml │ │ └── pubspec.lock ├── C++ │ └── Binary_Search │ │ ├── ReadMe.md │ │ └── BinarySearch.cpp ├── Python │ ├── LinearSearch │ │ ├── ReadMe.md │ │ └── LinearSearch.py │ ├── SearchRotatedArray │ │ ├── Readme.md │ │ └── SearchRotatedArray.py │ ├── FindTwoPairOfAGivenSumRotatedArray │ │ ├── ReadMe.md │ │ └── FindPair.py │ └── BinarySearch │ │ ├── ReadMe.md │ │ └── BinarySearch.py ├── java │ └── Depth_First_Search_Farmer_Algorithm │ │ ├── Node.java │ │ ├── README.md │ │ ├── Graph.java │ │ └── Dfs.java └── C │ └── BinarySearch │ ├── BinarySearch.h │ └── README.md ├── HashMap ├── dart │ └── count_occurance_of_a_word │ │ ├── CHANGELOG.md │ │ ├── .gitignore │ │ ├── test │ │ └── count_occurance_of_a_word_test.dart │ │ ├── bin │ │ └── count_occurance_of_a_word.dart │ │ ├── pubspec.yaml │ │ ├── README.md │ │ ├── lib │ │ └── count_occurance_of_a_word.dart │ │ ├── analysis_options.yaml │ │ └── pubspec.lock └── Python │ ├── RepeatingNumber │ ├── ReadMe.md │ └── ReapeatingNumber.py │ └── Element-That-Appear-Once │ └── ElementAppearOnce │ ├── ReadMe.md │ └── ElementThatAppearOnce.py ├── Sorting ├── Java │ ├── CountingSort │ │ ├── Readme.md │ │ └── CountingSort.java │ ├── QuickSort │ │ ├── ReadMe.md │ │ └── Quicksort.java │ ├── MergeSortJava │ │ ├── ReadMe.md │ │ └── MergeSort.java │ ├── SelectionSort │ │ ├── ReadMe.md │ │ └── SelectionSort.java │ └── BubbleSort │ │ └── BubbleSort.java ├── Python │ ├── KthSmallestElementInArray │ │ ├── KthSmallest.py │ │ └── Readme.md │ ├── MergeSort │ │ ├── Readme.md │ │ └── MergeSort.py │ ├── Klargest │ │ ├── Readme.md │ │ └── Klargest.py │ └── MeanAndMedian │ │ ├── Readme.md │ │ └── MeanAndMedian.py └── JavaScript │ ├── BubbleSort │ ├── ReadMe.md │ └── BubbleSort.js │ └── MergeSort │ ├── ReadMe.md │ └── MergeSort.js ├── Recursion ├── Cpp │ └── TowerOfHanoi │ │ ├── ReadMe.md │ │ └── TowerofHanoi.cpp ├── C │ └── PrimeNumber │ │ ├── ReadMe.md │ │ └── PrimeNumber.c └── Python │ └── Product-Sum │ ├── ReadMe.md │ └── ProductSum.py ├── TwoPointer └── Python │ ├── TwoSum │ ├── ReadMe.md │ └── TwoSum.py │ ├── ContainerWithMaximumWater │ ├── ReadMe.md │ └── ContainerWithMaximumWater.py │ ├── TripletSumInArray │ ├── ReadMe.md │ └── TripletSum.py │ └── ThreeClosestSum │ ├── ReadMe.md │ └── ThreeClosestSum.py ├── DynamicProgramming └── Python │ ├── CyclicLength │ ├── Readme.md │ └── CynclicLength.py │ └── SparseTable │ ├── Readme.md │ └── Sparse.py ├── Xor └── Python │ └── SingleNonRepeatingInteger │ ├── SingleNonRepeatingInteger.py │ └── ReadMe.md ├── Tree └── C │ └── SymmetricTree │ ├── ReadMe.md │ ├── SymmetricTree.h │ └── SymmetricTree.c ├── AVLTree └── JavaScript │ ├── ReadMe.md │ └── AVLTree.js ├── Stack └── Array │ └── C │ ├── Stack.h │ ├── ReadMe.md │ └── Stack.c ├── Moore-Voting-Algorithm ├── MooreVotingAlgorithmNBy2 │ ├── python │ │ ├── MooreVoting.py │ │ └── Readme.md │ └── Dart │ │ ├── MooreVotingAlgorithm.dart │ │ └── README.md ├── MooreVotingAlgorithmBy3 │ ├── Readme.md │ └── Python │ │ └── MajorityElement3.py └── Dart │ ├── MooreVotingAlgorithm.dart │ └── README.md ├── LinkedList └── C │ ├── SinglyLinkedList.c │ ├── DoublyLinkedList.c │ ├── CircularLinkedList.c │ ├── .gitignore │ ├── linked.h │ ├── FreeLinkedList.c │ ├── PrintLinkedList.c │ ├── DeleteLinkedList.c │ ├── README.md │ └── CreateLinkedList.c ├── README.md ├── CODE_OF_CONDUCT.md ├── LICENSE └── CONTRIBUTING.md /Array/Javascript/MovingMedian/ReadMe.md: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Search/Dart/binary_search/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## 1.0.0 2 | 3 | - Initial version. 4 | -------------------------------------------------------------------------------- /Search/dart/linear_search/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## 1.0.0 2 | 3 | - Initial version. 4 | -------------------------------------------------------------------------------- /HashMap/dart/count_occurance_of_a_word/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## 1.0.0 2 | 3 | - Initial version. 4 | -------------------------------------------------------------------------------- /Sorting/Java/CountingSort/Readme.md: -------------------------------------------------------------------------------- 1 | COUNTING SORT 2 | https://www.geeksforgeeks.org/counting-sort/ 3 | 4 | Time Complexity : O(n) 5 | Space Complexity : O(k) 6 | -------------------------------------------------------------------------------- /Search/Dart/binary_search/.gitignore: -------------------------------------------------------------------------------- 1 | # Files and directories created by pub. 2 | .dart_tool/ 3 | .packages 4 | 5 | # Conventional directory for build output. 6 | build/ 7 | -------------------------------------------------------------------------------- /Search/dart/linear_search/.gitignore: -------------------------------------------------------------------------------- 1 | # Files and directories created by pub. 2 | .dart_tool/ 3 | .packages 4 | 5 | # Conventional directory for build output. 6 | build/ 7 | -------------------------------------------------------------------------------- /Recursion/Cpp/TowerOfHanoi/ReadMe.md: -------------------------------------------------------------------------------- 1 | # Tower Of Hanoiu using Recursion 2 | 3 | 4 | 5 | 6 | [Algorithm Explanation](https://www.geeksforgeeks.org/c-program-for-tower-of-hanoi/) 7 | -------------------------------------------------------------------------------- /HashMap/dart/count_occurance_of_a_word/.gitignore: -------------------------------------------------------------------------------- 1 | # Files and directories created by pub. 2 | .dart_tool/ 3 | .packages 4 | 5 | # Conventional directory for build output. 6 | build/ 7 | -------------------------------------------------------------------------------- /Array/Python/FibonacciNumber/Readme.md: -------------------------------------------------------------------------------- 1 | Time complexity - O(n) 2 | Space Complexity - O(n) 3 | 4 | [Algorithm Explanation](https://www.techiedelight.com/program-to-find-nth-fibonacci-number/) 5 | -------------------------------------------------------------------------------- /Sorting/Java/QuickSort/ReadMe.md: -------------------------------------------------------------------------------- 1 | # Quick Sort in java 2 | 3 | Time complexity - O(n log(n)) 4 | Space Complexity - O(log(n)) 5 | 6 | [Algorithm Explanation](https://www.baeldung.com/java-quicksort) 7 | -------------------------------------------------------------------------------- /Array/Python/FibbonaciNumberEfficient/Readme.md: -------------------------------------------------------------------------------- 1 | Time complexity - O(n) 2 | Space Complexity - O(1) 3 | 4 | [Algorithm Explanation](https://www.techiedelight.com/program-to-find-nth-fibonacci-number/) 5 | -------------------------------------------------------------------------------- /Sorting/Java/MergeSortJava/ReadMe.md: -------------------------------------------------------------------------------- 1 | # Merge Sort in java 2 | 3 | Time complexity - O(n log(n)) 4 | Space Complexity - O(n) 5 | 6 | [Algorithm Explanation](https://www.geeksforgeeks.org/merge-sort/) 7 | -------------------------------------------------------------------------------- /TwoPointer/Python/TwoSum/ReadMe.md: -------------------------------------------------------------------------------- 1 | # Two Sum in python 2 | 3 | Time complexity - O(n) 4 | Space Complexity - O(n) 5 | 6 | 7 | [Algorithm Explanation](https://www.geeksforgeeks.org/two-pointers-technique/) -------------------------------------------------------------------------------- /Search/dart/linear_search/README.md: -------------------------------------------------------------------------------- 1 | # Linear Search in Dart 2 | 3 | Time complexity - O(1) 4 | Space Complexity - O(1) 5 | 6 | [algorithm Explanation](https://iq.opengenus.org/time-complexity-of-linear-search/) 7 | -------------------------------------------------------------------------------- /Array/TwoDArray/Java/HourGlassJava/ReadMe.md: -------------------------------------------------------------------------------- 1 | # HourGlass Data Structure in java 2 | 3 | reference: https://www.hackerrank.com/challenges/2d-array/problem 4 | 5 | Time complexity - O(n2) 6 | Space Complexity - O(1) 7 | -------------------------------------------------------------------------------- /HashMap/dart/count_occurance_of_a_word/test/count_occurance_of_a_word_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:count_occurance_of_a_word/count_occurance_of_a_word.dart'; 2 | import 'package:test/test.dart'; 3 | 4 | void main() {} 5 | -------------------------------------------------------------------------------- /Sorting/Java/SelectionSort/ReadMe.md: -------------------------------------------------------------------------------- 1 | # Selection Sort Algorithm 2 | https://www.programiz.com/dsa/selection-sort 3 | Read about Selection Sort in the blog post above. 4 | 5 | Time Complexity:O(n²). 6 | Space Complexity:O(1). 7 | -------------------------------------------------------------------------------- /TwoPointer/Python/ContainerWithMaximumWater/ReadMe.md: -------------------------------------------------------------------------------- 1 | # Two Sum in python 2 | 3 | Time complexity - O(n) 4 | Space Complexity - O(1) 5 | 6 | 7 | [Algorithm Explanation](https://www.geeksforgeeks.org/container-with-most-water/) -------------------------------------------------------------------------------- /Array/Python/EquilibriumIndex/ReadMe.md: -------------------------------------------------------------------------------- 1 | # Equilibrium Index of an array 2 | 3 | Time complexity - O(n) 4 | Space Complexity - O(1) 5 | 6 | [Algorithm Explanation](https://www.geeksforgeeks.org/equilibrium-index-of-an-array/?ref=lbp) 7 | -------------------------------------------------------------------------------- /Search/C++/Binary_Search/ReadMe.md: -------------------------------------------------------------------------------- 1 | # Binary Search algorithm implementation in C== 2 | 3 | Time complexity - O( Log(n) ) 4 | Space Complexity - O(1) 5 | 6 | 7 | [Algorithm Explanation](https://www.geeksforgeeks.org/binary-search/) 8 | -------------------------------------------------------------------------------- /Search/Python/LinearSearch/ReadMe.md: -------------------------------------------------------------------------------- 1 | # Linear Search algorithm implementation in python 2 | 3 | Time complexity - O(n) 4 | Space Complexity - O(1) 5 | 6 | 7 | [Algorithm Explanation](https://dev.to/abubakarismail/linear-search-4fio) -------------------------------------------------------------------------------- /HashMap/Python/RepeatingNumber/ReadMe.md: -------------------------------------------------------------------------------- 1 | # Find the Reapeating Number in python 2 | 3 | Time complexity - O(n) 4 | Space Complexity - O(n) 5 | 6 | 7 | [Algorithm Explanation](https://www.geeksforgeeks.org/find-repetitive-element-1-n-1/) -------------------------------------------------------------------------------- /Recursion/C/PrimeNumber/ReadMe.md: -------------------------------------------------------------------------------- 1 | # Prime Number Using Recursion 2 | 3 | Here is the implementation explanation 4 | 5 | [C Program for Prime Number](https://dev.to/sulaimanaminubarkindo/c-program-for-prime-number-using-recursion-2ij4) 6 | -------------------------------------------------------------------------------- /TwoPointer/Python/TripletSumInArray/ReadMe.md: -------------------------------------------------------------------------------- 1 | # Triplet sum in python 2 | 3 | Time complexity - O(n2) 4 | Space Complexity - O(1) 5 | 6 | 7 | [Algorithm Explanation](https://www.geeksforgeeks.org/find-a-triplet-that-sum-to-a-given-value/) -------------------------------------------------------------------------------- /Array/Python/FirstDuplicateValue/FirstDuplicateValue.py: -------------------------------------------------------------------------------- 1 | def firstDuplicateValue(array): 2 | tmp = [] 3 | for i in array: 4 | if i in tmp: 5 | return i 6 | else: 7 | tmp.append(i) 8 | return -1 9 | -------------------------------------------------------------------------------- /Array/Python/ArrayPrefix/PrefixSum/ArrayPrefix.py: -------------------------------------------------------------------------------- 1 | def findPrefix(arr): 2 | sum = 0 3 | for i in range(len(arr)): 4 | sum += arr[i] 5 | arr[i] = sum 6 | return arr 7 | 8 | arr = [10, 20, 10, 5, 15] 9 | 10 | print(findPrefix(arr)) -------------------------------------------------------------------------------- /Array/Python/Rotation/LeftJogglingAlgorithm/__pycache__/LeftRotation.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ismaelsadeeq/Data-Structures-Algorithms-Problems/HEAD/Array/Python/Rotation/LeftJogglingAlgorithm/__pycache__/LeftRotation.cpython-310.pyc -------------------------------------------------------------------------------- /DynamicProgramming/Python/CyclicLength/Readme.md: -------------------------------------------------------------------------------- 1 | 3n + 1 Problem AKA Collatz Conjecture 2 | 3 | Time complexity - Unknown 4 | Space Complexity - O(n) 5 | 6 | [Algorithm Explanation](https://www.spoj.com/problems/PROBTNPO/) 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /Recursion/Python/Product-Sum/ReadMe.md: -------------------------------------------------------------------------------- 1 | # Product Sum algorithm implementation in python 2 | 3 | Time complexity - O(n) 4 | Space Complexity - O(1) 5 | 6 | [Algorithm Explanation](https://dev.to/sfrasica/algorithms-product-sum-from-an-array-dc6) 7 | -------------------------------------------------------------------------------- /Search/java/Depth_First_Search_Farmer_Algorithm/Node.java: -------------------------------------------------------------------------------- 1 | package Search.java.Depth_First_Search_Farmer_Algorithm; 2 | 3 | public class Node { 4 | char data; 5 | 6 | Node(char data) { 7 | this.data = data; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Sorting/Python/KthSmallestElementInArray/KthSmallest.py: -------------------------------------------------------------------------------- 1 | def findKLargest(arr,k): 2 | 3 | arr.sort() 4 | 5 | return arr[k-1] 6 | 7 | 8 | print(findKLargest([7, 10, 4, 3, 20, 15],3)) 9 | print(findKLargest([7, 10, 4, 3, 20, 15],4)) 10 | -------------------------------------------------------------------------------- /Array/Python/Rotation/RightJogglingAlgorithm/__pycache__/RightRotation.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ismaelsadeeq/Data-Structures-Algorithms-Problems/HEAD/Array/Python/Rotation/RightJogglingAlgorithm/__pycache__/RightRotation.cpython-310.pyc -------------------------------------------------------------------------------- /Xor/Python/SingleNonRepeatingInteger/SingleNonRepeatingInteger.py: -------------------------------------------------------------------------------- 1 | def singleNonRepeating(nums): 2 | 3 | value = nums[0] 4 | 5 | for i in range(0,len(nums)): 6 | 7 | value = value ^ nums[i] 8 | 9 | 10 | return value 11 | -------------------------------------------------------------------------------- /Array/Python/ArrayPrefix/PrefixSum/Readme.md: -------------------------------------------------------------------------------- 1 | # Prefix of an array 2 | 3 | Time complexity - O(n) 4 | Space Complexity - O(1) 5 | 6 | [Algorithm Explanation](https://www.geeksforgeeks.org/prefix-sum-array-implementation-applications-competitive-programming/) 7 | -------------------------------------------------------------------------------- /Array/Python/ArrayPrefix/SubArrayWithZero/Readme.md: -------------------------------------------------------------------------------- 1 | # Find if there is a subarray with 0 sum 2 | 3 | Time complexity - O(n) 4 | Space Complexity - O(n) 5 | 6 | [Algorithm Explanation](https://www.geeksforgeeks.org/find-if-there-is-a-subarray-with-0-sum/) 7 | -------------------------------------------------------------------------------- /Sorting/Python/MergeSort/Readme.md: -------------------------------------------------------------------------------- 1 | 2 | # sort an array using the merge sort algorithmin python 3 | 4 | Time complexity - O(nlogn) 5 | Space Complexity - O(1) 6 | 7 | 8 | [Algorithm Explanation](https://www.geeksforgeeks.org/merge-sort/) 9 | 10 | -------------------------------------------------------------------------------- /DynamicProgramming/Python/SparseTable/Readme.md: -------------------------------------------------------------------------------- 1 | Sparse Table Algoritm for range minimum Query 2 | 3 | Time complexity - O(nlogn) 4 | Space Complexity - O(1) 5 | 6 | [Algorithm Explanation](https://www.youtube.com/watch?v=c5O7E_PDO4U) 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /TwoPointer/Python/ThreeClosestSum/ReadMe.md: -------------------------------------------------------------------------------- 1 | 2 | # Three Closest Sum in an Integer array in python 3 | 4 | Time complexity - O(n2) 5 | Space Complexity - O(1) 6 | 7 | 8 | [Algorithm Explanation](https://dev.to/abubakarismail/3sum-closest-2jpi) 9 | 10 | -------------------------------------------------------------------------------- /Array/Python/FibonacciNumber/NthFibonacciNumber.py: -------------------------------------------------------------------------------- 1 | def getNthFib(n): 2 | # Write your code here. 3 | seq = [0, 1] 4 | for i in range(n): 5 | if i == 0 or i == 1: 6 | continue 7 | seq.append(seq[-1] + seq[-2]) 8 | 9 | return seq[n-1] -------------------------------------------------------------------------------- /Array/Python/MaximumSubArrayValue/Readme.md: -------------------------------------------------------------------------------- 1 | This is an algorthm for finding the maximum overlapping sub array sum 2 | 3 | Time complexity - O(n) 4 | Space Complexity - O(1) 5 | 6 | [Algorithm Explanation](https://www.geeksforgeeks.org/largest-sum-contiguous-subarray/) 7 | -------------------------------------------------------------------------------- /Search/Python/SearchRotatedArray/Readme.md: -------------------------------------------------------------------------------- 1 | # Linear Search algorithm implementation in python 2 | 3 | Time complexity - O(logn) 4 | Space Complexity - O(1) 5 | 6 | 7 | [Algorithm Explanation](https://www.geeksforgeeks.org/search-an-element-in-a-sorted-and-pivoted-array/) -------------------------------------------------------------------------------- /Array/Python/Rotation/LeftJogglingAlgorithm/Readme.md: -------------------------------------------------------------------------------- 1 | # Left Array rotation using juggling algorithm 2 | 3 | Time complexity - O(n) 4 | Space Complexity - O(1) 5 | 6 | [Algorithm Explanation](https://www.youtube.com/watch?v=VEUta79Lt2c&list=PLWb0cWXA-TbCD9xkgaDicM3G6Ch6jfhnO) 7 | -------------------------------------------------------------------------------- /HashMap/Python/Element-That-Appear-Once/ElementAppearOnce/ReadMe.md: -------------------------------------------------------------------------------- 1 | # Elements that appear once in python 2 | 3 | Time complexity - O(n) 4 | Space Complexity - O(n) 5 | 6 | 7 | [Algorithm Explanation](https://dev.to/abubakarismail/find-the-element-that-appear-once-in-array-1955) -------------------------------------------------------------------------------- /Xor/Python/SingleNonRepeatingInteger/ReadMe.md: -------------------------------------------------------------------------------- 1 | # Single Non Repeating Integer in python 2 | 3 | Time complexity - O(n) 4 | Space Complexity - O(1) 5 | 6 | 7 | [Algorithm Explanation](https://www.geeksforgeeks.org/find-element-appears-array-every-element-appears-twice/?ref=lbp) -------------------------------------------------------------------------------- /Array/Python/Rotation/RightJogglingAlgorithm/Readme.md: -------------------------------------------------------------------------------- 1 | # Right Array rotation using juggling algorithm 2 | 3 | Time complexity - O(n) 4 | Space Complexity - O(1) 5 | 6 | [Algorithm Explanation](https://www.youtube.com/watch?v=VEUta79Lt2c&list=PLWb0cWXA-TbCD9xkgaDicM3G6Ch6jfhnO) 7 | -------------------------------------------------------------------------------- /Sorting/Python/Klargest/Readme.md: -------------------------------------------------------------------------------- 1 | 2 | # find the top k largest elements array in python 3 | 4 | Time complexity - O(nlogn) 5 | Space Complexity - O(k) 6 | 7 | 8 | [Algorithm Explanation](https://www.geeksforgeeks.org/k-largestor-smallest-elements-in-an-array/) 9 | 10 | -------------------------------------------------------------------------------- /Array/Python/Rotation/LeftJogglingAlgorithm/__pycache__/left_rotation_test.cpython-310-pytest-7.1.3.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ismaelsadeeq/Data-Structures-Algorithms-Problems/HEAD/Array/Python/Rotation/LeftJogglingAlgorithm/__pycache__/left_rotation_test.cpython-310-pytest-7.1.3.pyc -------------------------------------------------------------------------------- /Array/Python/Rotation/RightJogglingAlgorithm/__pycache__/rightRotationTest.cpython-310-pytest-7.1.3.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ismaelsadeeq/Data-Structures-Algorithms-Problems/HEAD/Array/Python/Rotation/RightJogglingAlgorithm/__pycache__/rightRotationTest.cpython-310-pytest-7.1.3.pyc -------------------------------------------------------------------------------- /Array/Python/Rotation/RightJogglingAlgorithm/__pycache__/right_rotation_test.cpython-310-pytest-7.1.3.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ismaelsadeeq/Data-Structures-Algorithms-Problems/HEAD/Array/Python/Rotation/RightJogglingAlgorithm/__pycache__/right_rotation_test.cpython-310-pytest-7.1.3.pyc -------------------------------------------------------------------------------- /Array/Python/ArrayPrefix/SumIndexBetweenLandR/Readme.md: -------------------------------------------------------------------------------- 1 | # Sum of an array between indexes L and R using Prefix Sum 2 | 3 | Time complexity - O(n) 4 | Space Complexity - O(n) 5 | 6 | [Algorithm Explanation](https://www.geeksforgeeks.org/prefix-sum-array-implementation-applications-competitive-programming/) 7 | -------------------------------------------------------------------------------- /Array/Python/Valid-Subsequence/ReadMe.md: -------------------------------------------------------------------------------- 1 | # A valid subsequence of an array 2 | 3 | Time complexity - O(n) 4 | Space Complexity - O(n) 5 | 6 | [Algorithm Explanation](https://karanchauhan16.medium.com/validate-subsequence-with-python-68ebeb5563e3#:~:text=A%20subsequence%20of%20an%20array,6%2C8%2C10%5D.) 7 | -------------------------------------------------------------------------------- /Sorting/Python/MeanAndMedian/Readme.md: -------------------------------------------------------------------------------- 1 | 2 | # find the mean and median of an unsorted array in python 3 | 4 | Time complexity - O(nlogn) 5 | Space Complexity - O(1) 6 | 7 | 8 | [Algorithm Explanation](https://www.geeksforgeeks.org/program-for-mean-and-median-of-an-unsorted-array/?ref=lbp) 9 | 10 | -------------------------------------------------------------------------------- /Array/Python/KthMaxSubArrayInefficient/Readme.md: -------------------------------------------------------------------------------- 1 | This is a brute force algorthm for finding the k maximum overlapping sub arrays 2 | 3 | Time complexity - O(n*3) 4 | Space Complexity - O(n) 5 | 6 | [Algorithm Explanation](https://www.geeksforgeeks.org/k-maximum-sum-overlapping-contiguous-sub-arrays/?ref=lbp) 7 | -------------------------------------------------------------------------------- /Array/Python/MoveAllZeros/Readme.md: -------------------------------------------------------------------------------- 1 | # Move all zeroes to end of array 2 | Given an array of random numbers, Push all the zero’s of a given array to the end of the array. 3 | Time complexity - O(n) 4 | Space Complexity - O(1) 5 | 6 | [Algorithm Explanation](https://www.geeksforgeeks.org/move-zeroes-end-array/) 7 | -------------------------------------------------------------------------------- /Search/Dart/binary_search/README.md: -------------------------------------------------------------------------------- 1 | # Binary Search in Dart 2 | 3 | Time complexity - O(log(n)) 4 | Space Complexity - O(1) 5 | 6 | [algorithm Explanation](https://iq.opengenus.org/binary-search-iterative-recursive/#:~:text=The%20major%20difference%20between%20the,the%20iterative%20version%20is%20efficient.) 7 | -------------------------------------------------------------------------------- /Sorting/Python/KthSmallestElementInArray/Readme.md: -------------------------------------------------------------------------------- 1 | 2 | # find the top kth smallest elements array in python 3 | 4 | Time complexity - O(nlogn) 5 | Space Complexity - O(1) 6 | 7 | 8 | [Algorithm Explanation](https://www.geeksforgeeks.org/kth-smallest-largest-element-in-unsorted-array/?ref=lbp) 9 | 10 | -------------------------------------------------------------------------------- /Array/Python/RearrangeArrayEvenPositionedGreaterThanOdd/Readme.md: -------------------------------------------------------------------------------- 1 | Rearrange array such that even positioned are greater than odd 2 | 3 | Time complexity - O(n) 4 | Space Complexity - O(n) 5 | 6 | [Algorithm Explanation](https://www.geeksforgeeks.org/rearrange-array-such-that-even-positioned-are-greater-than-odd/) 7 | -------------------------------------------------------------------------------- /Tree/C/SymmetricTree/ReadMe.md: -------------------------------------------------------------------------------- 1 | # Symmetric Tree 2 | Time Complexity: O(n), where n is the number of nodes in the tree 3 | 4 | Space Complexity: O(h), where h is the maximum height of the tree 5 | 6 | [Algorithm Explanation](https://www.geeksforgeeks.org/symmetric-tree-tree-which-is-mirror-image-of-itself/) 7 | 8 | 9 | -------------------------------------------------------------------------------- /Array/Python/AlternatePositiveAndNegativeNumbers/AlternativePositiveAndNegative/Readme.md: -------------------------------------------------------------------------------- 1 | # Rearrange positive and negative numbers in O(n) time and O(n) extra space 2 | 3 | Time complexity - O(n) 4 | Space Complexity - O(n) 5 | 6 | [Algorithm Explanation](https://www.geeksforgeeks.org/rearrange-positive-and-negative-numbers-publish/) 7 | -------------------------------------------------------------------------------- /Array/Python/FirstDuplicateValue/Readme.md: -------------------------------------------------------------------------------- 1 | Given an array of integers, this algorithm returns the first integer that appears more than once and returns -1 if none. 2 | 3 | Time complexity - O(n) 4 | Space Complexity - O(n) 5 | 6 | [Algorithm Explanation](https://betterprogramming.pub/algorithms-find-the-first-duplicate-eb7ab30d7da8) 7 | -------------------------------------------------------------------------------- /Array/Python/AlternatePositiveAndNegativeNumbers/AlternativePositiveAndNegativeOptimal/Readme.md: -------------------------------------------------------------------------------- 1 | # Rearrange positive and negative numbers in O(n) time and O(1) extra space 2 | 3 | Time complexity - O(n) 4 | Space Complexity - O(1) 5 | 6 | [Algorithm Explanation](https://www.geeksforgeeks.org/rearrange-positive-and-negative-numbers-publish/) 7 | -------------------------------------------------------------------------------- /Array/Python/FibbonaciNumberEfficient/Fibbonacci.py: -------------------------------------------------------------------------------- 1 | 2 | def findFib(n): 3 | 4 | if n < 0: 5 | return -1 6 | 7 | previousFib = 0 8 | currentFib = 1 9 | 10 | for i in range(n-1): 11 | 12 | newFib = previousFib + currentFib 13 | previousFib = currentFib 14 | currentFib = newFib 15 | 16 | return currentFib 17 | -------------------------------------------------------------------------------- /Search/Dart/binary_search/pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: binary_search 2 | description: A sample command-line application. 3 | version: 1.0.0 4 | # homepage: https://www.example.com 5 | 6 | environment: 7 | sdk: '>=2.18.2 <3.0.0' 8 | 9 | # dependencies: 10 | # path: ^1.8.0 11 | 12 | dev_dependencies: 13 | lints: ^2.0.0 14 | test: ^1.16.0 15 | -------------------------------------------------------------------------------- /Search/dart/linear_search/pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: linear_search 2 | description: A sample command-line application. 3 | version: 1.0.0 4 | # homepage: https://www.example.com 5 | 6 | environment: 7 | sdk: '>=2.18.2 <3.0.0' 8 | 9 | # dependencies: 10 | # path: ^1.8.0 11 | 12 | dev_dependencies: 13 | lints: ^2.0.0 14 | test: ^1.16.0 15 | -------------------------------------------------------------------------------- /Sorting/Python/Klargest/Klargest.py: -------------------------------------------------------------------------------- 1 | def findKLargest(arr,k): 2 | 3 | arr.sort() 4 | ans = [] 5 | n = len(arr) 6 | while(k!=0): 7 | ans.append(arr[n-1]) 8 | n-=1 9 | k-=1 10 | 11 | return ans 12 | 13 | 14 | print(findKLargest([1, 23, 12, 9, 30, 2, 50],3)) 15 | print(findKLargest([11, 5, 12, 9, 44, 17, 2],2)) 16 | -------------------------------------------------------------------------------- /Array/Python/FindMaxArrayRotationSum/Readme.md: -------------------------------------------------------------------------------- 1 | # Find maximum value of Sum( i*arr[i]) with only rotations on given array allowed Implementation in Python 2 | 3 | Time complexity - O(n) 4 | Space Complexity - O(1) 5 | 6 | [Algorithm Explanation](https://www.geeksforgeeks.org/find-maximum-value-of-sum-iarri-with-only-rotations-on-given-array-allowed/) 7 | -------------------------------------------------------------------------------- /Search/dart/linear_search/bin/linear_search.dart: -------------------------------------------------------------------------------- 1 | import 'package:linear_search/linear_search.dart' as linear_search; 2 | 3 | void main(List arguments) { 4 | List arrays = [9, 1, 8, 2, 7, 3, 6, 4, 5]; 5 | int findElement = 7; 6 | int results = linear_search.linearSearch(arrays, findElement); 7 | print("results $results"); 8 | } 9 | -------------------------------------------------------------------------------- /Array/Mo'sAlgorithm/PowerfulArray/Readme.md: -------------------------------------------------------------------------------- 1 | # Find the powerful value of elements every query range of an array. [l,r] [l,r] 2 | 3 | Time complexity - O(n (sqrt(n) log(n))) 4 | Space Complexity - O(n) 5 | 6 | [Algorithm Explanation](https://codeforces.com/contest/86/problem/D) 7 | 8 | [Algorithm Explanation](https://blog.anudeep2011.com/mos-algorithm/) 9 | -------------------------------------------------------------------------------- /Array/Python/MaximumSubArrayValue/MaximumSubArray.py: -------------------------------------------------------------------------------- 1 | def maxSubArray(arr): 2 | 3 | maxSum = arr[0] 4 | currSum = 0 5 | 6 | for n in arr: 7 | if currSum < 0: 8 | currSum = 0 9 | currSum += n 10 | maxSum = max(maxSum,currSum) 11 | 12 | return maxSum 13 | 14 | arr = [4, -8, 9, -4, 1, -8, -1, 6] 15 | print(maxSubArray(arr)) -------------------------------------------------------------------------------- /HashMap/dart/count_occurance_of_a_word/bin/count_occurance_of_a_word.dart: -------------------------------------------------------------------------------- 1 | import 'package:count_occurance_of_a_word/count_occurance_of_a_word.dart' 2 | as hashmap; 3 | 4 | void main(List arguments) { 5 | String sentence = "The cat ate the dog"; 6 | Map results = hashmap.hashmap(sentence); 7 | print("results $results"); 8 | } 9 | -------------------------------------------------------------------------------- /Search/dart/linear_search/test/linear_search_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:linear_search/linear_search.dart'; 2 | import 'package:test/test.dart'; 3 | 4 | void main() { 5 | test('linearSearch', () { 6 | List arrays = [9, 1, 8, 2, 7, 3, 6, 4, 5]; 7 | int findElement = 7; 8 | expect(linearSearch(arrays, findElement), 4); 9 | }); 10 | } 11 | -------------------------------------------------------------------------------- /Array/Mo'sAlgorithm/QueryRangeSum/Readme.md: -------------------------------------------------------------------------------- 1 | # Find the sum of every query range in an array. [l,r] [l,r] 2 | 3 | Time complexity - O(n (sqrt(n))) 4 | Space Complexity - O(n) 5 | 6 | [Algorithm Explanation](https://www.geeksforgeeks.org/mos-algorithm-query-square-root-decomposition-set-1-introduction/) 7 | 8 | [Algorithm Explanation](https://youtu.be/BJhzd_VG61k?t=1126) 9 | -------------------------------------------------------------------------------- /HashMap/dart/count_occurance_of_a_word/pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: count_occurance_of_a_word 2 | description: A sample command-line application. 3 | version: 1.0.0 4 | # homepage: https://www.example.com 5 | 6 | environment: 7 | sdk: '>=2.18.2 <3.0.0' 8 | 9 | # dependencies: 10 | # path: ^1.8.0 11 | 12 | dev_dependencies: 13 | lints: ^2.0.0 14 | test: ^1.16.0 15 | -------------------------------------------------------------------------------- /Sorting/JavaScript/BubbleSort/ReadMe.md: -------------------------------------------------------------------------------- 1 | # BubbleSort in JavaScript 2 | 3 | # Time Complexity 4 | 1) Best(O(n)), 5 | 2) Average(0(n^2)), 6 | 3) Worst(O(n^2)) 7 | # Space Complexity 8 | 1) Worst (O(1)) 9 | 10 | 11 | [Algorithm Explanation](https://www.simplilearn.com/tutorials/data-structure-tutorial/bubble-sort-algorithm) -------------------------------------------------------------------------------- /Search/Python/FindTwoPairOfAGivenSumRotatedArray/ReadMe.md: -------------------------------------------------------------------------------- 1 | # Find if there is a pair with a given sum in the rotated sorted Array implementation in python 2 | 3 | Time complexity - O(n) 4 | Space Complexity - O(1) 5 | 6 | 7 | [Algorithm Explanation](https://www.geeksforgeeks.org/given-a-sorted-and-rotated-array-find-if-there-is-a-pair-with-a-given-sum/) 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /Array/Python/ReorderArrayToGivenIndex/Readme.md: -------------------------------------------------------------------------------- 1 | This is an Algo that given two integer arrays of same size, “arr[]” and “index[]”, reorder elements in “arr[]” according to given index array. It is not allowed to given array arr’s length 2 | Time complexity - O(n) 3 | Space Complexity - O(1) 4 | 5 | [Algorithm Explanation](https://www.geeksforgeeks.org/reorder-a-array-according-to-given-indexes/) 6 | -------------------------------------------------------------------------------- /Search/Python/BinarySearch/ReadMe.md: -------------------------------------------------------------------------------- 1 | # Binary Search algorithm implementation in python 2 | 3 | Time complexity - O( Log(n) ) 4 | Space Complexity - O(1) 5 | 6 | 7 | [Algorithm Explanation](https://www.geeksforgeeks.org/python-program-for-binary-search/#:~:text=Python%20Program%20for%20Binary%20Search%20%28Recursive%20and%20Iterative%29,must%20lie%20in%20the%20left%20%28lower%29%20half.%20) 8 | -------------------------------------------------------------------------------- /Array/Mo'sAlgorithm/SherlockAndInversion/Readme.md: -------------------------------------------------------------------------------- 1 | # Sherlock and Inversions 2 | # Find inversions of every query range of an array. [l,r] [l,r] 3 | 4 | Time complexity - O(n (sqrt(n) log(n))) 5 | Space Complexity - O(n) 6 | 7 | 8 | [Algorithm Explanation](https://blog.anudeep2011.com/mos-algorithm/) 9 | 10 | [Algorithm Explanation](https://www.codechef.com/problems/IITI15?tab=statement) 11 | -------------------------------------------------------------------------------- /Array/Python/MergeOverlappingIntervals/MergeOverlappingIntervals.py: -------------------------------------------------------------------------------- 1 | def mergeOverlappingIntervals(intervals): 2 | intervals.sort() 3 | output = [] 4 | 5 | for start, end in intervals: 6 | if not output or start > output[-1][1]: 7 | output.append([start, end]) 8 | else: 9 | output[-1][1] = max(output[-1][1], end) 10 | 11 | return output -------------------------------------------------------------------------------- /AVLTree/JavaScript/ReadMe.md: -------------------------------------------------------------------------------- 1 | ## AVL Tree in JavaScript 2 | 3 | An AVL tree is a self-balancing Binary Search Tree (BST) where the heights of the two child subtrees of any node cannot differ by more than one. If at any time they differ by more than one, rebalancing is done through LL, RR, LR or RL rotations to restore this property. 4 | 5 | [Further Explanation on AVL Tree](https://www.javatpoint.com/avl-tree) -------------------------------------------------------------------------------- /Tree/C/SymmetricTree/SymmetricTree.h: -------------------------------------------------------------------------------- 1 | #ifndef SYMMETRIC_TREE_H 2 | #define SYMMETRIC_TREE_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | typedef struct Node { 9 | int key; 10 | struct Node *left, *right; 11 | } Node; 12 | 13 | Node *newNode(int key); 14 | bool isMirror(Node *root1, Node *root2); 15 | bool isSymmetric(Node *root); 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /HashMap/dart/count_occurance_of_a_word/README.md: -------------------------------------------------------------------------------- 1 | Big Time complexity - O(1) 2 | Space Complexity - O(n) 3 | 4 | [Algorithm Explanation](https://stackoverflow.com/questions/63369213/is-the-extra-space-complexity-of-a-function-that-counts-letter-occurrences-o1) 5 | 6 | [Algorithm Explanation](https://stackoverflow.com/questions/27334494/space-complexity-of-hashmap-when-iterating-over-an-array-in-linear-time) 7 | -------------------------------------------------------------------------------- /Array/Python/MergeOverlappingIntervals/ReadMe.md: -------------------------------------------------------------------------------- 1 | This is an Algo that takes in a non-empty array of arbitrary intervals, merges any overlapping intervals, and returns the new merged array. 2 | 3 | Time complexity - O(n) 4 | Space Complexity - O(n) 5 | 6 | [Algorithm Explanation](https://www.geeksforgeeks.org/merging-intervals/#:~:text=A%20simple%20approach%20is%20to,remaining%20intervals%20after%20the%20first.) 7 | -------------------------------------------------------------------------------- /Array/Python/MoveAllZeros/MoveZeros.py: -------------------------------------------------------------------------------- 1 | def moveAllZeros(arr): 2 | 3 | j = 0 4 | for i in range(len(arr)): 5 | 6 | if arr[i] != 0: 7 | arr[i],arr[j] = arr[j], arr[i] 8 | j+=1 9 | 10 | return arr 11 | 12 | 13 | 14 | arr = [1, 2, 0, 4, 3, 0, 5, 0] 15 | arr2 = [1, 2, 0, 0, 0, 3, 6] 16 | print(moveAllZeros(arr)) 17 | print(moveAllZeros(arr2)) -------------------------------------------------------------------------------- /Search/dart/linear_search/lib/linear_search.dart: -------------------------------------------------------------------------------- 1 | /** 2 | * ! Linear Search:: 3 | * find element = 7 4 | * loop through array 5 | * if element array[i] == elemenet 6 | * return index 7 | * 8 | * 9 | */ 10 | 11 | linearSearch(List arrays, findElement) { 12 | for (int i = 0; i < arrays.length; i++) { 13 | if (arrays[i] == findElement) { 14 | return i; 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Search/Dart/binary_search/bin/binary_search.dart: -------------------------------------------------------------------------------- 1 | import 'package:binary_search/binary_search.dart' as binary_search; 2 | 3 | void main(List arguments) { 4 | List array = [3, 4, 5, 6, 7, 8, 9]; 5 | int findNumber = 4; 6 | int low = 0; 7 | int high = array.length - 1; 8 | 9 | int results = binary_search.binary_search(array, findNumber, low, high); 10 | print("returning $results"); 11 | } 12 | -------------------------------------------------------------------------------- /Search/Python/BinarySearch/BinarySearch.py: -------------------------------------------------------------------------------- 1 | def binary_search(arr, a, low, high): 2 | 3 | # Repeat until low and high meet each other 4 | while low <= high: 5 | 6 | mid = low + (high - low)//2 7 | 8 | if arr[mid] == a: 9 | return mid 10 | 11 | elif arr[mid] < a: 12 | low = mid + 1 13 | 14 | else: 15 | high = mid - 1 16 | 17 | return -1 18 | -------------------------------------------------------------------------------- /Sorting/Python/MeanAndMedian/MeanAndMedian.py: -------------------------------------------------------------------------------- 1 | def findMeanAndMedian(arr): 2 | n = len(arr) 3 | arr.sort() 4 | mean = sum(arr) / n 5 | arr.sort() 6 | median = 0 7 | if n % 2 != 0: 8 | median = arr[n//2] 9 | else: 10 | median = (arr[int(n/2)] + arr[int((n/2)-1)]) / 2 11 | 12 | return [mean,median] 13 | 14 | 15 | 16 | arr = [1, 3, 4, 2, 6, 5, 8, 7] 17 | 18 | print(findMeanAndMedian(arr)) 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /Array/Mo'sAlgorithm/DistictElementsInAQueryRange/Readme.md: -------------------------------------------------------------------------------- 1 | # Find the number of elements every query range of an array. [l,r] [l,r] 2 | 3 | Time complexity - O(n (sqrt(n) log(n))) 4 | Space Complexity - O(n) 5 | 6 | [Algorithm Explanation](https://practice.geeksforgeeks.org/problems/interesting-queries4742/1?utm_source=gfg&utm_medium=article&utm_campaign=bottom_sticky_on_article) 7 | 8 | [Algorithm Explanation](https://blog.anudeep2011.com/mos-algorithm/) 9 | -------------------------------------------------------------------------------- /Array/Mo'sAlgorithm/NumberOfElementsInAQueryRange/Readme.md: -------------------------------------------------------------------------------- 1 | # Find the number of elements every query range of an array. [l,r] [l,r] 2 | 3 | Time complexity - O(n (sqrt(n) log(n))) 4 | Space Complexity - O(n) 5 | 6 | [Algorithm Explanation](https://practice.geeksforgeeks.org/problems/interesting-queries4742/1?utm_source=gfg&utm_medium=article&utm_campaign=bottom_sticky_on_article) 7 | 8 | [Algorithm Explanation](https://blog.anudeep2011.com/mos-algorithm/) 9 | -------------------------------------------------------------------------------- /Recursion/Cpp/TowerOfHanoi/TowerofHanoi.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | void toh(int n, char src, char dest, char helper){ 4 | if(n==0){ 5 | return; 6 | } 7 | 8 | toh(n-1,src,helper,dest); 9 | cout<<"Moving "< array, int findNumber, int low, int high) { 2 | while (low <= high) { 3 | double middle = (low + (high - low) / 2); 4 | int mid = middle.toInt(); 5 | if (findNumber == array[mid]) { 6 | return mid; 7 | } else if (findNumber >= array[mid]) { 8 | low = mid + 1; 9 | } else { 10 | high = mid - 1; 11 | } 12 | } 13 | return -1; 14 | } 15 | -------------------------------------------------------------------------------- /Stack/Array/C/Stack.h: -------------------------------------------------------------------------------- 1 | #ifndef STACK 2 | #define STACK 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | typedef struct Stack { 9 | int top; 10 | unsigned capacity; 11 | int *array; 12 | } Stack; 13 | 14 | Stack *createStack(unsigned capacity); 15 | int isFull(Stack *stack); 16 | int isEmpty(Stack *stack); 17 | void push(Stack *stack, int item); 18 | int pop(Stack *stack); 19 | int peek(Stack *stack); 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /Array/Python/Rotation/LeftJogglingAlgorithm/LeftRotation.py: -------------------------------------------------------------------------------- 1 | def rotate(arr,r): 2 | n = len(arr) 3 | if n == 0: 4 | return 5 | gcd = findGcd(n,r) 6 | 7 | for i in range(0,gcd): 8 | temp = arr[i] 9 | j = i 10 | while True: 11 | k = (j+r) % n 12 | if k == i: 13 | break 14 | arr[j] = arr[k] 15 | j = k 16 | arr[j] = temp 17 | 18 | 19 | 20 | def findGcd(a,b): 21 | if b == 0: 22 | return a 23 | else: 24 | return findGcd(b,a%b) -------------------------------------------------------------------------------- /HashMap/Python/RepeatingNumber/ReapeatingNumber.py: -------------------------------------------------------------------------------- 1 | 2 | # Online Python - IDE, Editor, Compiler, Interpreter 3 | 4 | def findRepetingNum(arr): 5 | 6 | dict = {} 7 | 8 | for i in range(0,len(arr)-1): 9 | if dict.get(arr[i]): 10 | return arr[i] 11 | else: 12 | dict[arr[i]] = 1 13 | 14 | return arr-1 15 | 16 | 17 | print(findRepetingNum([1,3,2,3,4])) 18 | 19 | # complexity O(n), time and space 20 | 21 | 22 | -------------------------------------------------------------------------------- /Array/Python/ArrayPrefix/SubArrayWithZero/SubArrayWithZero.py: -------------------------------------------------------------------------------- 1 | def subArrayWithZero(arr): 2 | 3 | prefixSum = arr[0] 4 | prefixMap = {} 5 | prefixMap[prefixSum] = 1 6 | 7 | for i in range(1, len(arr)): 8 | prefixSum +=arr[i] 9 | if prefixMap.get(prefixSum) == 1: 10 | return True 11 | 12 | if prefixSum == 0: 13 | return True 14 | 15 | prefixMap[prefixSum] = 1 16 | 17 | 18 | return False 19 | 20 | arr = [-3, 2, 3, 1, 6] 21 | print(subArrayWithZero(arr)) -------------------------------------------------------------------------------- /Sorting/JavaScript/MergeSort/ReadMe.md: -------------------------------------------------------------------------------- 1 | # MergeSort in Javascript 2 | 3 | # Time complexity 4 | 1) Best(O(n log(n))) 5 | 2) Average(0(n log(n))) 6 | 3) Worst(O(n log(n))) 7 | 8 | # Space Complexity 9 | 1) Worst (O(n)) 10 | 11 | [Algorithm Explanation](https://www.w3resource.com/javascript-exercises/searching-and-sorting-algorithm/searching-and-sorting-algorithm-exercise-2.php#:~:text=the%20sorted%20output.%22-,Algorithm%3A,is%20only%201%20sublist%20remaining.) -------------------------------------------------------------------------------- /Search/Python/LinearSearch/LinearSearch.py: -------------------------------------------------------------------------------- 1 | """ 2 | Linear Search is an algorthm that takes two input array and Integer" 3 | It returns the index of the integer in the array or -1 if it does not exist" 4 | 5 | 6 | @param array is an array of elements 7 | @param number is and element to be searched 8 | 9 | """ 10 | def linear_search(array,number): 11 | 12 | 13 | for i in range(0,len(array)): 14 | 15 | if array[i] == number: 16 | return i 17 | 18 | return -1 19 | 20 | 21 | -------------------------------------------------------------------------------- /Array/Python/EquilibriumIndex/EquilibriumIndex.py: -------------------------------------------------------------------------------- 1 | # Your task is to ocomplete this function 2 | # Function should return an integer 3 | def findEquilibrium(a,n): 4 | 5 | if n==0 : 6 | return -1 7 | if n == 1: 8 | return 1 9 | arrSum = sum(a) 10 | tempSum = a[0] 11 | for i in range(1,n): 12 | 13 | currSum = tempSum + a[i] 14 | if tempSum == (arrSum - currSum): 15 | return i 16 | else: 17 | tempSum = currSum 18 | 19 | return - 1 20 | -------------------------------------------------------------------------------- /Array/Python/Rotation/RightJogglingAlgorithm/RightRotation.py: -------------------------------------------------------------------------------- 1 | def rotate(arr,r): 2 | n = len(arr) 3 | if n == 0: 4 | return 5 | 6 | gcd = findGcd(n,r) 7 | 8 | r = n-r 9 | for i in range(0,gcd): 10 | temp = arr[n-i-1] 11 | j = n - i - 1 12 | while True: 13 | k = (j + r) % n 14 | if k == (n - i -1): 15 | break 16 | arr[j] = arr[k] 17 | j = k 18 | arr[j] = temp 19 | 20 | 21 | def findGcd(a,b): 22 | if b == 0: 23 | return a 24 | else: 25 | return findGcd(b,a%b) -------------------------------------------------------------------------------- /Moore-Voting-Algorithm/MooreVotingAlgorithmNBy2/python/MooreVoting.py: -------------------------------------------------------------------------------- 1 | def majorityElement(A, N): 2 | #Your code here 3 | index = 0 4 | count = 1 5 | for i in range(N): 6 | if A[i] == A[index]: 7 | count+=1 8 | else: 9 | count -=1 10 | if count == 0: 11 | index = i 12 | count=1 13 | 14 | majCount = 0 15 | for i in range(N): 16 | if A[i] == A[index]: 17 | majCount+=1 18 | 19 | 20 | if majCount > N/2: 21 | return A[index] 22 | 23 | return -1 24 | -------------------------------------------------------------------------------- /TwoPointer/Python/TwoSum/TwoSum.py: -------------------------------------------------------------------------------- 1 | """ 2 | The function that checks whether there are two numbers 3 | that makes up a sum in an array 4 | using two pointer approach 5 | """ 6 | 7 | def two_pointer(array,x): 8 | 9 | array.sort() 10 | 11 | left = 0 12 | 13 | right = 0 14 | for i in range(0,len(array)-1): 15 | 16 | sum = array[left] + array[right] 17 | if sum == x: 18 | return True 19 | elif sum > x: 20 | right-=1 21 | elif sum < x: 22 | left+=1 23 | 24 | return False 25 | -------------------------------------------------------------------------------- /Array/Python/ArrayPrefix/SumIndexBetweenLandR/SumIndexBetweenLandR.py: -------------------------------------------------------------------------------- 1 | def findSumOfIndex(arr,Q): 2 | 3 | sum = 0 4 | for i in range(len(arr)): 5 | sum+=arr[i] 6 | arr[i] = sum 7 | 8 | ans = [] 9 | for i in range(len(Q)): 10 | l = Q[i][0]-1 11 | r = Q[i][1]-1 12 | if l > 0: 13 | ans.append(arr[r] - arr[(l-1)]) 14 | else: 15 | ans.append(arr[r]) 16 | 17 | return ans 18 | 19 | arr = [3, 6, 2, 8, 9, 2] 20 | Q = [[2, 3], [4, 6], [1, 5], [3, 6]] 21 | print(findSumOfIndex(arr,Q)) 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /Recursion/Python/Product-Sum/ProductSum.py: -------------------------------------------------------------------------------- 1 | """ 2 | In this case, a "special" array is given that contains 3 | either integers or a sub-array. The Product Sum is the 4 | sum of elements inside the array (or sub-array) multiplied by 5 | the level of depth 6 | 7 | The depth is how far nested the array is. 8 | """ 9 | 10 | def productSum(array, depth=1): 11 | currentSum = 0 12 | for el in array: 13 | if type(el) is int: 14 | currentSum += el 15 | continue 16 | currentSum += productSum(el, depth + 1) 17 | return depth * currentSum -------------------------------------------------------------------------------- /Search/C/BinarySearch/BinarySearch.h: -------------------------------------------------------------------------------- 1 | #ifndef _BINARY_SEARCH_H 2 | #define _BINARY_SEARCH_H 3 | 4 | int BinarySearch(int arr[], int x, int low, int high) 5 | { 6 | while (low <= high) 7 | { 8 | 9 | int mid = low + (high - low) / 2; 10 | 11 | if (arr[mid] == x) 12 | { 13 | return mid; 14 | } 15 | else if (arr[mid] < x) 16 | { 17 | low = mid + 1; 18 | } 19 | else 20 | { 21 | high = mid - 1; 22 | } 23 | } 24 | 25 | return -1; 26 | } 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /Array/Python/ReorderArrayToGivenIndex/ReorderArray.py: -------------------------------------------------------------------------------- 1 | def reOrder(arr,index,n): 2 | 3 | 4 | for i in range(0,n): 5 | 6 | while (index[i] != i): 7 | 8 | 9 | oldValue = arr[index[i]] 10 | 11 | oldTarget = index[index[i]] 12 | 13 | 14 | arr[index[i]] = arr[i] 15 | index[index[i]] = index[i] 16 | 17 | 18 | arr[i] = oldValue 19 | index[i] = oldTarget 20 | 21 | return arr 22 | -------------------------------------------------------------------------------- /Stack/Array/C/ReadMe.md: -------------------------------------------------------------------------------- 1 | # Stack Data Structure in C Using Array 2 | Time Complexity: Worst Case Scenario would be O(n) in case of an array implementation of stack where the array is completely filled, then the array size needs to be changed and all the elements must be copied from one array to another, this would result in time complexity being O(n). 3 | 4 | Space Complexity: Space complexity for each operation in a stack is O(1), as no extra space is required for any operation. 5 | 6 | [Stack Data Structure Explanation](https://www.geeksforgeeks.org/introduction-to-stack-data-structure-and-algorithm-tutorials/) 7 | -------------------------------------------------------------------------------- /Array/Python/KthMaxSubArrayInefficient/MaxSubArray.py: -------------------------------------------------------------------------------- 1 | 2 | def findKSubArr(arr,k): 3 | 4 | sums = [] 5 | 6 | for i in range(len(arr)): 7 | for j in range(len(arr)): 8 | subArrSum = sum(arr[i:j+1]) 9 | sums.append(subArrSum) 10 | 11 | sums.sort() 12 | 13 | j = len(sums) - 1 14 | ans = [] 15 | for i in range(k): 16 | ans.append(sums[j]) 17 | j-=1 18 | 19 | return ans 20 | 21 | arr = [4, -8, 9, -4, 1, -8, -1, 6] 22 | k = 4 23 | k2 = 3 24 | arr2 = [-2, -3, 4, -1, -2, 1, 5, -3] 25 | print(findKSubArr(arr,k)) 26 | print(findKSubArr(arr2,k2)) 27 | -------------------------------------------------------------------------------- /LinkedList/C/SinglyLinkedList.c: -------------------------------------------------------------------------------- 1 | #include "linked.h" 2 | 3 | /** 4 | * main - Test run the code 5 | * 6 | * Return: 0 7 | */ 8 | 9 | int main() 10 | { 11 | int array[] = {1, 2, 3, 4, 6, 7, 9}; 12 | size_t length; 13 | node_t *new_list; 14 | 15 | length = sizeof(array) / sizeof(array[0]); 16 | new_list = create_linked_list(array, length); 17 | printf("Printing the singly linked list after created...\n"); 18 | print_linked_list(new_list); 19 | delete_last_node_singly_linked_list(new_list); 20 | printf("\nPrinting the last node after the last node is deleted...\n"); 21 | print_linked_list(new_list); 22 | free_linked_list(new_list); 23 | return (0); 24 | } 25 | -------------------------------------------------------------------------------- /Sorting/Python/MergeSort/MergeSort.py: -------------------------------------------------------------------------------- 1 | def mergeSort(arr): 2 | n = len(arr) 3 | if(n>1): 4 | mid = n//2 5 | L = arr[:mid] 6 | R = arr[mid:] 7 | 8 | mergeSort(L) 9 | mergeSort(R) 10 | 11 | i=j=k=0 12 | while(i maxSum: 16 | maxSum = currValue 17 | 18 | 19 | 20 | return maxSum 21 | 22 | 23 | array1 = [10, 1, 2, 3, 4, 5, 6, 7, 8, 9] 24 | array2 = [1, 20, 2, 10] 25 | print(findMaxValueOfSum(array1)) 26 | print(findMaxValueOfSum(array2)) -------------------------------------------------------------------------------- /TwoPointer/Python/TripletSumInArray/TripletSum.py: -------------------------------------------------------------------------------- 1 | #Function to find if there exists a triplet in the 2 | #array A[] which sums up to X. 3 | def find3Numbers(self,A, n, x): 4 | # Your Code Here 5 | A.sort() 6 | 7 | for i in range(0,n-1): 8 | 9 | left = i+1 10 | right = n-1 11 | 12 | while(left x: 17 | right-=1 18 | elif sum < x: 19 | left+=1 20 | 21 | return 0 22 | 23 | -------------------------------------------------------------------------------- /Moore-Voting-Algorithm/MooreVotingAlgorithmNBy2/python/Readme.md: -------------------------------------------------------------------------------- 1 | # MOORE'S VOTING ALGORIGHM 2 | 📌 **Time Complexity:** O(n)
3 | 📌 **Space Complexity:** O(1)
4 | 📌 **Path:** Data-Structures-Algorithms-Problems/Array/Python/ 5 | 6 | ## What is majorityElement Algorithm? 7 | 8 | The Boyer-Moore``majorityElement`` method is a popular optimal technique for determining the majority element among provided array items with more than N/ 2 occurrences. 9 | ## How does it work? 10 | 11 | ``majorityElement`` in an array ``mooreArray`` of size n is an element that appears more than n/2 times (and hence there is at most one such element). 12 | # Explanation [Explanation ](https://www.geeksforgeeks.org/majority-element/?ref=lbp) 13 | -------------------------------------------------------------------------------- /Recursion/C/PrimeNumber/PrimeNumber.c: -------------------------------------------------------------------------------- 1 | /** 2 | * is_prime - detects if an input number is a prime number. 3 | * @n: input number. 4 | * @: iterator. 5 | * Return: 1 if n is a prime number. 0 if n is not a prime number. 6 | */ 7 | int is_prime(unsigned int n, unsigned int i) 8 | { 9 | if (n % i == 0) 10 | { 11 | if (n == i) 12 | return (1); 13 | else 14 | return (0); 15 | } 16 | return (0 + is_prime(n, i + 1)); 17 | } 18 | /** 19 | * is_prime_number - detects if an input number is a prime number. 20 | * @n: input number. 21 | * Return: 1 if n is a prime number. 0 if n is not a prime number. 22 | */ 23 | int is_prime_number(int n) 24 | { 25 | if (n <= 1) 26 | return (0); 27 | return (is_prime(n, 2)); 28 | } 29 | -------------------------------------------------------------------------------- /Array/Python/AlternatePositiveAndNegativeNumbers/AlternativePositiveAndNegativeOptimal/AlternativePositiveAndNegative.py: -------------------------------------------------------------------------------- 1 | def rearrange(self,arr, n): 2 | 3 | part = -1 4 | 5 | for i in range(0,len(arr)): 6 | if arr[i]<0: 7 | part+=1 8 | x = arr[i] 9 | y=arr[part] 10 | arr[i] = y 11 | arr[part] = x 12 | 13 | 14 | neg = 0 15 | part+=1 16 | while neg < part: 17 | x = arr[neg] 18 | y = arr[part] 19 | arr[neg] = y 20 | arr[part] = x 21 | neg+=2 22 | part+=1 23 | 24 | return arr 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | ![Repo image](https://user-images.githubusercontent.com/89482825/194586491-fdb405a3-4430-427a-9899-a0393125cddf.png) 3 | 4 | 5 | # Algorithms-Problems-and-Data-Structures 6 | This repository contains Data structure/algorithms Implementations, and problems solved in various programming language with explanation. 7 | 8 | ## 👩🏽‍💻 Contributing 9 | 10 | - Contributions make the open source community such an amazing place to learn, inspire, and create. 11 | - We value your contributions and thank you in advance. 12 | - Check out our [contribution guidelines](/CONTRIBUTING.md) for more information. 13 | 14 | ## 🛡️ License 15 | 16 | This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details. 17 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | In short: Be nice. No harassment, trolling, or spamming. 2 | 3 | Harassment includes sexual language and imagery, deliberate intimidation, stalking, name-calling, unwelcome attention, libel, and any malicious hacking or social engineering. freeCodeCamp should be a harassment-free experience for everyone, regardless of gender, gender identity and expression, age, sexual orientation, disability, physical appearance, body size, race, national origin, or religion (or lack thereof). 4 | Trolling includes posting inflammatory comments to provoke an emotional response or disrupt discussions. 5 | Spamming includes posting off-topic messages to disrupt discussions, promote a product, solicit donations, advertise a job / internship / gig, or flooding discussions with files or text. 6 | -------------------------------------------------------------------------------- /Array/TwoDArray/Java/HourGlassJava/HourGlass.java: -------------------------------------------------------------------------------- 1 | package TwoDArray.HourGlassJava; 2 | 3 | import java.util.List; 4 | 5 | public class HourGlass { 6 | public static int hourglassSum(List> arr) { 7 | int sum = 0; 8 | int maxValue = Integer.MIN_VALUE; 9 | for (int i = 0; i < arr.size() - 2; i++) { // O(n) 10 | for (int j = 0; j < arr.get(i).size() - 2; j++) { // O(n) 11 | sum = arr.get(i).get(j) + arr.get(i).get(j + 1) + arr.get(i).get(j + 2) + arr.get(i + 1).get(j + 1) 12 | + arr.get(i + 2).get(j) + arr.get(i + 2).get(j + 1) + arr.get(i + 2).get(j + 2); 13 | maxValue = Math.max(maxValue, sum); 14 | } 15 | } 16 | 17 | return maxValue; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Array/Dart/Sorted-Squared-Array/SortedSquaredArray.dart: -------------------------------------------------------------------------------- 1 | List sortedSquaredarray(List arr) { 2 | int start = 0, end = arr.length - 1; 3 | int sortedIndex = arr.length - 1; 4 | List answer = List.filled(arr.length, 0); 5 | 6 | while (end >= start) { 7 | if (arr[start].abs() > arr[end].abs()) { 8 | answer[sortedIndex] = arr[start] * arr[start]; 9 | start += 1; 10 | } else { 11 | answer[sortedIndex] = arr[end] * arr[end]; 12 | end -= 1; 13 | } 14 | sortedIndex -= 1; 15 | } 16 | 17 | return answer; 18 | } 19 | 20 | void main() { 21 | print( 22 | sortedSquaredarray([-1, -1, 2, 3, 3, 3, 4])); // [1, 1, 4, 9, 9, 9, 16]); 23 | 24 | print( 25 | sortedSquaredarray([1, 2, 3, 4, 5, 6, 7])); // [1, 4, 9, 16, 25, 36, 49]); 26 | } 27 | -------------------------------------------------------------------------------- /Moore-Voting-Algorithm/MooreVotingAlgorithmBy3/Readme.md: -------------------------------------------------------------------------------- 1 | # MOORE'S VOTING ALGORIGHM 2 | 📌 **Time Complexity:** O(n)
3 | 📌 **Space Complexity:** O(1)
4 | 📌 **Path:** Data-Structures-Algorithms-Problems/Array/Python/ 5 | 6 | ## What is majorityElement Algorithm? 7 | 8 | The Boyer-Moore``majorityElement 2`` method is a popular optimal technique for determining the majority element among provided array items with more than N/ 2 occurrences. 9 | # How does it work? 10 | 11 | ``majorityElement`` in an array ``mooreArray`` of size n is an element that appears more than n/2 times (and hence there is at most one such element). 12 | # Explanation [Explanation ](https://www.geeksforgeeks.org/majority-element/?ref=lbp) 13 | 14 | # Problem [Statement ](https://leetcode.com/problems/majority-element-ii) 15 | -------------------------------------------------------------------------------- /DynamicProgramming/Python/CyclicLength/CynclicLength.py: -------------------------------------------------------------------------------- 1 | 2 | cache = {} 3 | def cyclicLength(i,j): 4 | totalCount = 0 5 | while i >= j: 6 | count = 1 7 | val = i 8 | while val != 1: 9 | if cache.get(val) != None: 10 | count += cache[val] - 1 11 | break 12 | count +=1 13 | if val % 2 == 0: 14 | val = val/2 15 | else: 16 | val = (3*val + 1) 17 | 18 | cache[i] = count 19 | totalCount = max(count,totalCount) 20 | i-=1 21 | return totalCount; 22 | 23 | arr = [ [10,1],[200,100],[210,201],[1000,900],[1000000,1],[5,1],[22232,254]] 24 | 25 | for i in range(len(arr)): 26 | 27 | print(cyclicLength(arr[i][0],arr[i][1])) 28 | -------------------------------------------------------------------------------- /Moore-Voting-Algorithm/Dart/MooreVotingAlgorithm.dart: -------------------------------------------------------------------------------- 1 | /// Moore's Voting Algorithm Implementation in Dart 2 | int majorityElement(List array, int n) { 3 | array.sort(); 4 | 5 | var count = 1, max = -1, temporary = array[0], ele = 0, f = 0; 6 | 7 | for (int i = 1; i < n; i++) { 8 | if (temporary == array[i]) { 9 | count++; 10 | } else { 11 | count = 1; 12 | temporary = array[i]; 13 | } 14 | if (max < count) { 15 | max = count; 16 | ele = array[i]; 17 | 18 | if (max > (n / 2)) { 19 | f = 1; 20 | break; 21 | } 22 | } 23 | } 24 | return (f == 1 ? ele : -1); 25 | } 26 | 27 | void main() { 28 | List arr = [1, 1, 2, 1, 3, 5, 1]; 29 | int n = arr.length; 30 | print( 31 | majorityElement(arr, n), 32 | ); 33 | } 34 | -------------------------------------------------------------------------------- /LinkedList/C/DoublyLinkedList.c: -------------------------------------------------------------------------------- 1 | #include "linked.h" 2 | /** 3 | * main - Funtion to test the doubly linked list 4 | * 5 | * Return: return 0 6 | */ 7 | int main() 8 | { 9 | node_d *new_node; 10 | int array[] = {23, 564, 2, 4, 65, 23, 76}; 11 | size_t length; 12 | 13 | length = sizeof(array) / sizeof(array[0]); 14 | printf("Creating a doubly linked list...\n"); 15 | new_node = create_doubly_linked_list(array, length); 16 | printf("\nPrinting the doubly linked list...\n"); 17 | print_doubly_linked_list(new_node); 18 | printf("\nPrinting the doubly linked list "); 19 | printf("after deleting the last node...\n"); 20 | delete_last_node_doubly_linked_list(new_node); 21 | print_doubly_linked_list(new_node); 22 | printf("Freeing the doubly linked list...\n"); 23 | free_doubly_linked_list(new_node); 24 | return (0); 25 | } 26 | -------------------------------------------------------------------------------- /Moore-Voting-Algorithm/MooreVotingAlgorithmNBy2/Dart/MooreVotingAlgorithm.dart: -------------------------------------------------------------------------------- 1 | // Moore's Voting Algorithm Implementation in Dart 2 | int majorityElement(List array, int n) { 3 | array.sort(); 4 | 5 | var count = 1, max = -1, temporary = array[0], ele = 0, f = 0; 6 | 7 | for (int i = 1; i < n; i++) { 8 | if (temporary == array[i]) { 9 | count++; 10 | } else { 11 | count = 1; 12 | temporary = array[i]; 13 | } 14 | if (max < count) { 15 | max = count; 16 | ele = array[i]; 17 | 18 | if (max > (n / 2)) { 19 | f = 1; 20 | break; 21 | } 22 | } 23 | } 24 | return (f == 1 ? ele : -1); 25 | } 26 | 27 | void main() { 28 | List arr = [1, 1, 2, 1, 3, 5, 1]; 29 | int n = arr.length; 30 | print( 31 | majorityElement(arr, n), 32 | ); 33 | } 34 | -------------------------------------------------------------------------------- /TwoPointer/Python/ContainerWithMaximumWater/ContainerWithMaximumWater.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def maxArea(self, height): 3 | if len(height)<2: 4 | return 0 5 | 6 | maxWater = 0 7 | left = 0 8 | right = len(height)-1 9 | for i in range(0,len(height)): 10 | length = (right+1)-(left+1) 11 | tall = 0 12 | if(height[left]< height[right]): 13 | tall = height[left] 14 | else: 15 | tall = height[right] 16 | temp = length * tall 17 | if temp > maxWater: 18 | maxWater = temp 19 | if height[left] > height[right]: 20 | right-=1 21 | else: 22 | left+=1 23 | 24 | return maxWater 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /Sorting/JavaScript/BubbleSort/BubbleSort.js: -------------------------------------------------------------------------------- 1 | function bubbleSort(arr) 2 | { 3 | let temp =0; 4 | //Take a temp variable assing it to 0 5 | for(let i=0;i arr[i+j]) 12 | //if(54 is greater than 32 ) in first itreation 13 | { 14 | temp = arr[i]; 15 | // 0 is now 54 16 | arr[i] = arr[i +j]; 17 | //54 is now 32 18 | arr[i + j ] = temp; 19 | //32 is now 54 20 | } 21 | } 22 | } 23 | return arr; 24 | //sorted array returned 25 | } 26 | const arr = [54,32,34,76,23,12,11,56,88,43]; 27 | 28 | console.log(bubbleSort(arr)); -------------------------------------------------------------------------------- /LinkedList/C/CircularLinkedList.c: -------------------------------------------------------------------------------- 1 | #include "linked.h" 2 | 3 | /** 4 | * main - Function to run the code 5 | * 6 | * Return: No return 7 | */ 8 | int main() 9 | { 10 | node_d *new_node; 11 | size_t length; 12 | int array[] = {23, 434, 765, 534, 34, 3, 3564, 32, 97, 23, 73}; 13 | 14 | length = sizeof(array) / sizeof(array[0]); 15 | printf("\nCreating a doubly linked list...\n"); 16 | new_node = create_circularly_linked_list(array, length); 17 | printf("\nPrinting a doubly linked list...\n"); 18 | print_circularly_linked_list(new_node); 19 | printf("\nPrinting after deleting the last node in a "); 20 | printf("circularly linked list...\n"); 21 | delete_last_node_circularly_linked_list(new_node); 22 | print_circularly_linked_list(new_node); 23 | printf("\nFreeing a doubly linked list...\n"); 24 | free_circularly_linked_list(new_node); 25 | 26 | return (0); 27 | } 28 | -------------------------------------------------------------------------------- /Search/Dart/Interpolation-Search/InterpolationSearch.dart: -------------------------------------------------------------------------------- 1 | int interpolationSearch(List arr, int n, int key) { 2 | int low = 0, high = n - 1; 3 | while (low <= high && key >= arr[low] && key <= arr[high]) { 4 | /* Calculate the nearest possible position of key */ 5 | int pos = low + 6 | (((key - arr[low]) * (high - low)) / (arr[high] - arr[low])).round(); 7 | if (key > arr[pos]) 8 | low = pos + 1; 9 | else if (key < arr[pos]) 10 | high = pos - 1; 11 | else /* Found */ 12 | return pos; 13 | } 14 | /* Not found */ 15 | return -1; 16 | } 17 | 18 | int main() { 19 | List arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; 20 | var n = arr.length; 21 | var key = 5; 22 | print("I want to found $key at $arr"); 23 | var index = interpolationSearch(arr, n, key); 24 | print("Element found at position: $index"); 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /Array/Python/Valid-Subsequence/ValidSubsequence.py: -------------------------------------------------------------------------------- 1 | """ 2 | Given 2 non-empty arrays of integers, check wether the second array is a valid subsequence of the first one 3 | 4 | A subsequence array is a set of numbers that aren't necessarily adjacent in the array but that are in the same order as they appear in the array 5 | 6 | For example: 7 | a = [1, 2, 3, 4, 5] 8 | b = [1, 3] 9 | c = [4, 2, 1] 10 | 11 | > b is a valid subsequence of a 12 | > c is not a valid subsequence of a 13 | """ 14 | 15 | def isValidSubsequence(array, sequence): 16 | 17 | for i in sequence: 18 | if i in array: 19 | ind = array.index(i) 20 | array = array[ind + 1:] 21 | 22 | else: 23 | return False 24 | return True 25 | a = [1, 2, 3, 4, 5] 26 | b = [1, 3] 27 | c = [4, 2, 1] 28 | print(isValidSubsequence(a,b)) 29 | print() 30 | print(isValidSubsequence(a,c)) 31 | -------------------------------------------------------------------------------- /HashMap/Python/Element-That-Appear-Once/ElementAppearOnce/ElementThatAppearOnce.py: -------------------------------------------------------------------------------- 1 | """ 2 | Given an array of items find the element that occurred once 3 | """ 4 | 5 | def occurredOnce(array): 6 | 7 | # Dictionary of items 8 | items = {} 9 | 10 | for i in range(0,len(array)): 11 | 12 | # items has array[i] as key? 13 | if(items.get(array[i])): 14 | # if yes increments its value by 1 15 | items[array[i]] = items[array[i]] +1 16 | else: 17 | # It does not has the key, create it with 1 as the value 18 | items[array[i]] = 1 19 | 20 | 21 | # loop through items to get the key with 1 as value 22 | for item in items: 23 | # check if one is the value of item 24 | if items[item] == 1: 25 | # if yes return the item 26 | return item 27 | 28 | # there is no value with 1 return -1 29 | return -1 -------------------------------------------------------------------------------- /Array/Python/Rotation/LeftJogglingAlgorithm/left_rotation_test.py: -------------------------------------------------------------------------------- 1 | from LeftRotation import findGcd 2 | from LeftRotation import rotate 3 | 4 | 5 | def test_gcd(): 6 | assert findGcd(0,6) == 6 7 | assert findGcd(2,3) == 1 8 | assert findGcd(3,6) == 3 9 | 10 | 11 | 12 | def test_positive_integers_rotation(): 13 | arr = [1,2,3,4,5,6] 14 | pivot = 2 15 | result = [3,4,5,6,1,2] 16 | rotate(arr,pivot) 17 | assert arr == result 18 | 19 | def test_negative_integers_rotation(): 20 | arr = [-1,-2,-3,-4,-5,-6] 21 | pivot = 2 22 | result = [-3,-4,-5,-6,-1,-2] 23 | rotate(arr,pivot) 24 | assert arr == result 25 | 26 | 27 | def test_single_item_rotation(): 28 | arr = [6] 29 | pivot = 2 30 | result = [6] 31 | rotate(arr,pivot) 32 | assert arr == result 33 | 34 | def test_empty_array_rotation(): 35 | arr = [] 36 | pivot = 2 37 | result = [] 38 | rotate(arr,pivot) 39 | assert arr == result 40 | 41 | 42 | -------------------------------------------------------------------------------- /Array/Python/Rotation/RightJogglingAlgorithm/right_rotation_test.py: -------------------------------------------------------------------------------- 1 | from RightRotation import findGcd 2 | from RightRotation import rotate 3 | 4 | 5 | def test_gcd(): 6 | assert findGcd(0,6) == 6 7 | assert findGcd(2,3) == 1 8 | assert findGcd(3,6) == 3 9 | 10 | 11 | 12 | def test_positive_integers_rotation(): 13 | arr = [1,2,3,4,5,6] 14 | pivot = 2 15 | result = [5,6,1,2,3,4] 16 | rotate(arr,pivot) 17 | assert arr == result 18 | 19 | def test_negative_integers_rotation(): 20 | arr = [-1,-2,-3,-4,-5,-6] 21 | pivot = 2 22 | result = [-5,-6,-1,-2,-3,-4] 23 | rotate(arr,pivot) 24 | assert arr == result 25 | 26 | 27 | def test_single_item_rotation(): 28 | arr = [6] 29 | pivot = 2 30 | result = [6] 31 | rotate(arr,pivot) 32 | assert arr == result 33 | 34 | def test_empty_array_rotation(): 35 | arr = [] 36 | pivot = 2 37 | result = [] 38 | rotate(arr,pivot) 39 | assert arr == result 40 | 41 | 42 | -------------------------------------------------------------------------------- /Array/Python/RearrangeArrayEvenPositionedGreaterThanOdd/Rearrange.py: -------------------------------------------------------------------------------- 1 | def assign (self, arr, n) : 2 | #Complete the function 3 | 4 | arr.sort() 5 | half = 0 6 | if n % 2 ==0: 7 | half = (n/2) -1 8 | else: 9 | half = n//2 10 | 11 | l = [] 12 | h = [] 13 | myArr = [] 14 | for i in range (n): 15 | if i <= half: 16 | l.append(arr[i]) 17 | else: 18 | h.append(arr[i]) 19 | 20 | myArr.append(0) 21 | length = 0 22 | i = 0 23 | while(i!=n and length < len(l)): 24 | myArr[i]= l[length] 25 | length+=1 26 | i+=2 27 | 28 | length = len(h)-1 29 | i = 1 30 | while(i!=n and length>=0): 31 | myArr[i] = h[length] 32 | length-=1 33 | i+=2 34 | return myArr 35 | -------------------------------------------------------------------------------- /LinkedList/C/.gitignore: -------------------------------------------------------------------------------- 1 | # Created by https://www.toptal.com/developers/gitignore/api/c 2 | # Edit at https://www.toptal.com/developers/gitignore?templates=c 3 | 4 | ### C ### 5 | # Prerequisites 6 | *.d 7 | 8 | # Object files 9 | *.o 10 | *.ko 11 | *.obj 12 | *.elf 13 | 14 | # Linker output 15 | *.ilk 16 | *.map 17 | *.exp 18 | 19 | # Precompiled Headers 20 | *.gch 21 | *.pch 22 | 23 | # Libraries 24 | *.lib 25 | *.a 26 | *.la 27 | *.lo 28 | 29 | # Shared objects (inc. Windows DLLs) 30 | *.dll 31 | *.so 32 | *.so.* 33 | *.dylib 34 | 35 | # Executables 36 | *.exe 37 | *.out 38 | *.app 39 | *.i*86 40 | *.x86_64 41 | *.hex 42 | 43 | # Debug files 44 | *.dSYM/ 45 | *.su 46 | *.idb 47 | *.pdb 48 | 49 | # Kernel Module Compile Results 50 | *.mod* 51 | *.cmd 52 | .tmp_versions/ 53 | modules.order 54 | Module.symvers 55 | Mkfile.old 56 | dkms.conf 57 | 58 | # End of https://www.toptal.com/developers/gitignore/api/c 59 | 60 | # Personally created git ignore files 61 | *.sh 62 | *.exe 63 | *.exe.stackdump 64 | -------------------------------------------------------------------------------- /Search/C++/Binary_Search/BinarySearch.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int binary_search(vector &numbers, int value) 7 | { 8 | int left = 0, right = numbers.size() - 1; 9 | while(left <= right) { 10 | int i = (left + (right - left) / 2); 11 | if (numbers[i] == value) { 12 | return i; 13 | } 14 | if (numbers[i] < value) { 15 | left = i + 1; 16 | }else { 17 | right = i -1; 18 | } 19 | } 20 | return -1; 21 | 22 | } 23 | 24 | int main() { 25 | 26 | vector nums{1,2,3,4,5,6,7,8,9,10}; 27 | vector values{2, 4, 20}; 28 | 29 | for (int val : values) { 30 | int index = binary_search(nums, val); 31 | if (index != -1) { 32 | cout << "Value " << val << " exists in index " << index << endl; 33 | } else { 34 | cout << "Value " << val << " does not exist." << endl; 35 | } 36 | } 37 | 38 | } -------------------------------------------------------------------------------- /TwoPointer/Python/ThreeClosestSum/ThreeClosestSum.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def threeSumClosest(self, nums, target): 3 | nums.sort() 4 | 5 | 6 | maxSum = 0 7 | for i in range(0, len(nums)-2): 8 | 9 | left = i + 1 10 | right = len(nums) - 1 11 | 12 | while left < right: 13 | 14 | sum = nums[i] + nums[left] + nums[right] 15 | 16 | if i == 0 and sum > 0: 17 | maxSum = sum 18 | 19 | if sum == target: 20 | return sum 21 | if target < 0: 22 | if target - sum > target - maxSum: 23 | maxSum = sum 24 | else: 25 | if target - sum < target - maxSum: 26 | maxSum = sum 27 | if sum > target: 28 | right-=1 29 | if sum < target: 30 | left+=1 31 | 32 | return maxSum -------------------------------------------------------------------------------- /Sorting/Java/CountingSort/CountingSort.java: -------------------------------------------------------------------------------- 1 | public class CountingSort{ 2 | public static void countingsort(int arr[]){ 3 | int largest = Integer.MIN_VALUE; 4 | for(int i=0; i 0){ 15 | arr[j]=i; 16 | j++; 17 | count[i]--; 18 | } 19 | } 20 | 21 | } 22 | public static void printarr(int arr[]){ 23 | for(int i=0 ; i 6 | 📌 **Space Complexity:** O(V)
7 | 8 | 9 | 10 | https://www.simplilearn.com/tutorials/data-structure-tutorial/dfs-algorithm 11 | 12 | 13 | 14 | If a graph is represented as an adjacency matrix(which is of our case) 15 | then the whole row in the matrix will have to be transversed in the matrix, which means each row corresponds to a node in the graph and will store information about each edges it merges from that vertex. 16 | 17 | Therefore, resulting as time complexity will be considered as O(V.V) = O(v2) 18 | Since we have to keep track of last visited vertex, resulting in our stack increasing by the graph's vertices, the space complexity would be O(V) 19 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Abubakar Sadiq Ismail 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /HashMap/dart/count_occurance_of_a_word/lib/count_occurance_of_a_word.dart: -------------------------------------------------------------------------------- 1 | import 'dart:collection'; 2 | 3 | /*** 4 | * The purpose is to use hashmap and count the number of times a word appears in a phrase also called word frequency 5 | * for example: 6 | * 1. hello world:: 7 | * hello: 1 8 | * world: 1 9 | * 2. the cat ate the dog 10 | * the: 2 11 | * cat: 1 12 | * ate: 1 13 | * dog: 1 14 | * 15 | * Using HashMap to store the words and count the numbers 16 | * first we need to tokenize the phrase 17 | * 18 | * method should take the sentence and return a hashmap 19 | */ 20 | 21 | Map hashmap(String sentence) { 22 | final Map map = HashMap(); 23 | List tokenize = sentence.split(" "); 24 | for (int i = 0; i < tokenize.length; i++) { 25 | String word = tokenize[i].toLowerCase(); 26 | print("word $word"); 27 | if (map.containsKey(word)) { 28 | int count = map[tokenize[i]] ?? 0; 29 | var data = {word: count + 1}; 30 | map.addAll(data); 31 | } else { 32 | var data = {word: 1}; 33 | map.addAll(data); 34 | } 35 | } 36 | return map; 37 | } 38 | -------------------------------------------------------------------------------- /Search/Dart/binary_search/analysis_options.yaml: -------------------------------------------------------------------------------- 1 | # This file configures the static analysis results for your project (errors, 2 | # warnings, and lints). 3 | # 4 | # This enables the 'recommended' set of lints from `package:lints`. 5 | # This set helps identify many issues that may lead to problems when running 6 | # or consuming Dart code, and enforces writing Dart using a single, idiomatic 7 | # style and format. 8 | # 9 | # If you want a smaller set of lints you can change this to specify 10 | # 'package:lints/core.yaml'. These are just the most critical lints 11 | # (the recommended set includes the core lints). 12 | # The core lints are also what is used by pub.dev for scoring packages. 13 | 14 | include: package:lints/recommended.yaml 15 | 16 | # Uncomment the following section to specify additional rules. 17 | 18 | # linter: 19 | # rules: 20 | # - camel_case_types 21 | 22 | # analyzer: 23 | # exclude: 24 | # - path/to/excluded/files/** 25 | 26 | # For more information about the core and recommended set of lints, see 27 | # https://dart.dev/go/core-lints 28 | 29 | # For additional information about configuring this file, see 30 | # https://dart.dev/guides/language/analysis-options 31 | -------------------------------------------------------------------------------- /Search/dart/linear_search/analysis_options.yaml: -------------------------------------------------------------------------------- 1 | # This file configures the static analysis results for your project (errors, 2 | # warnings, and lints). 3 | # 4 | # This enables the 'recommended' set of lints from `package:lints`. 5 | # This set helps identify many issues that may lead to problems when running 6 | # or consuming Dart code, and enforces writing Dart using a single, idiomatic 7 | # style and format. 8 | # 9 | # If you want a smaller set of lints you can change this to specify 10 | # 'package:lints/core.yaml'. These are just the most critical lints 11 | # (the recommended set includes the core lints). 12 | # The core lints are also what is used by pub.dev for scoring packages. 13 | 14 | include: package:lints/recommended.yaml 15 | 16 | # Uncomment the following section to specify additional rules. 17 | 18 | # linter: 19 | # rules: 20 | # - camel_case_types 21 | 22 | # analyzer: 23 | # exclude: 24 | # - path/to/excluded/files/** 25 | 26 | # For more information about the core and recommended set of lints, see 27 | # https://dart.dev/go/core-lints 28 | 29 | # For additional information about configuring this file, see 30 | # https://dart.dev/guides/language/analysis-options 31 | -------------------------------------------------------------------------------- /Moore-Voting-Algorithm/MooreVotingAlgorithmBy3/Python/MajorityElement3.py: -------------------------------------------------------------------------------- 1 | def majorityElement(arr) : 2 | num1 = -1 3 | num2 = -1 4 | 5 | count = 0 6 | count2 = 0 7 | 8 | for i in range(len(arr)): 9 | 10 | if arr[i] == num1: 11 | count+=1 12 | elif arr[i] == num2: 13 | count2+=1 14 | elif count ==0: 15 | num1 = arr[i] 16 | count = 1 17 | elif count2 ==0: 18 | num2 = arr[i] 19 | count2 =1 20 | else: 21 | count -=1 22 | count2-=1 23 | 24 | count = 0 25 | count2 = 0 26 | 27 | for i in range(len(arr)): 28 | if arr[i] == num1: 29 | count+=1 30 | elif arr[i] == num2: 31 | count2+=1 32 | 33 | if count > len(arr)/3 and count2 > len(arr)/3: 34 | return [num1,num2] 35 | 36 | 37 | if count > len(arr)/3: 38 | return [num1] 39 | 40 | 41 | if count2 > len(arr)/3: 42 | return [num2] 43 | 44 | return [] 45 | -------------------------------------------------------------------------------- /HashMap/dart/count_occurance_of_a_word/analysis_options.yaml: -------------------------------------------------------------------------------- 1 | # This file configures the static analysis results for your project (errors, 2 | # warnings, and lints). 3 | # 4 | # This enables the 'recommended' set of lints from `package:lints`. 5 | # This set helps identify many issues that may lead to problems when running 6 | # or consuming Dart code, and enforces writing Dart using a single, idiomatic 7 | # style and format. 8 | # 9 | # If you want a smaller set of lints you can change this to specify 10 | # 'package:lints/core.yaml'. These are just the most critical lints 11 | # (the recommended set includes the core lints). 12 | # The core lints are also what is used by pub.dev for scoring packages. 13 | 14 | include: package:lints/recommended.yaml 15 | 16 | # Uncomment the following section to specify additional rules. 17 | 18 | # linter: 19 | # rules: 20 | # - camel_case_types 21 | 22 | # analyzer: 23 | # exclude: 24 | # - path/to/excluded/files/** 25 | 26 | # For more information about the core and recommended set of lints, see 27 | # https://dart.dev/go/core-lints 28 | 29 | # For additional information about configuring this file, see 30 | # https://dart.dev/guides/language/analysis-options 31 | -------------------------------------------------------------------------------- /Sorting/Java/BubbleSort/BubbleSort.java: -------------------------------------------------------------------------------- 1 | import java.util.Arrays; 2 | 3 | // We keep swapping to keep max element at its right index 4 | 5 | public class BubbleSort { 6 | public static void main(String[] args) { 7 | int arr[] = {-1,9,-2,3,4,12,0}; 8 | bubbleSort(arr); 9 | System.out.println(Arrays.toString(arr)); 10 | } 11 | static void bubbleSort(int[] arr){ 12 | boolean swapped; 13 | // run the steps n - 1 times 14 | for (int i = 0; i < arr.length - 1; i++) { 15 | swapped = false; 16 | // for each step. max item will come at the last respective index 17 | for (int j = 1; j <= arr.length - i -1 ; j++) { 18 | // swap if item is smaller than previous item 19 | if (arr[j] < arr[j-1]){ 20 | //swap 21 | int temp = arr[j]; 22 | arr[j] = arr[j-1]; 23 | arr[j-1] = temp; 24 | swapped = true; 25 | } 26 | } 27 | // if there is no swap for i = 0, then array is sorted 28 | if(! swapped) { 29 | break; 30 | } 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Tree/C/SymmetricTree/SymmetricTree.c: -------------------------------------------------------------------------------- 1 | #include "SymmetricTree.h" 2 | 3 | /** 4 | * newNode - utility function to create new node 5 | * @key: value used to make operation on the node 6 | * Return: returns pointer to a new node 7 | */ 8 | Node *newNode(int key) 9 | { 10 | Node *temp = malloc(sizeof(Node)); 11 | temp->key = key; 12 | temp->left = temp->right = NULL; 13 | return (temp); 14 | } 15 | 16 | /** 17 | * isMirror - checks if two trees are mirror of each other 18 | * @root1: pointer to root node of the first tree 19 | * @root2: pointer to root node of the second tree 20 | * Return: return true if both trees are empty or mirror 21 | * otherwise returns false 22 | */ 23 | bool isMirror(Node *root1, Node *root2) 24 | { 25 | if (root1 == NULL && root2 == NULL) 26 | return true; 27 | 28 | if (root1 && root2 && root1->key == root2->key) 29 | return isMirror(root1->left, root2->right) 30 | && isMirror(root1->right, root2->left); 31 | 32 | return false; 33 | } 34 | 35 | /** 36 | * isSymmetric - checks if a tree mirror of itself 37 | * @root: pointer to root node of the tree 38 | * Return: return true if a tree is mirror of itself 39 | */ 40 | bool isSymmetric(Node *root) 41 | { 42 | return isMirror(root, root); 43 | } 44 | -------------------------------------------------------------------------------- /Array/Python/AlternatePositiveAndNegativeNumbers/AlternativePositiveAndNegative/AlternativePositiveAndNegative.py: -------------------------------------------------------------------------------- 1 | def rearrange(self,arr, n): 2 | 3 | positiveArr = [] 4 | negativeArr = [] 5 | for i in range(0,len(arr)): 6 | if(arr[i]<0): 7 | negativeArr.append(arr[i]) 8 | else: 9 | positiveArr.append(arr[i]) 10 | 11 | negativeIndex = 0 12 | positiveIndex = 0 13 | 14 | for i in range(0,len(arr)): 15 | 16 | if i % 2 == 0 : 17 | 18 | if positiveIndex < len(positiveArr): 19 | arr[i] = positiveArr[positiveIndex] 20 | positiveIndex+=1 21 | else: 22 | arr[i] = negativeArr[negativeIndex] 23 | negativeIndex +=1 24 | else: 25 | 26 | if negativeIndex < len(negativeArr): 27 | arr[i] = negativeArr[negativeIndex] 28 | negativeIndex+=1 29 | else: 30 | arr[i] = positiveArr[positiveIndex] 31 | positiveIndex+=1 32 | 33 | return arr 34 | 35 | 36 | -------------------------------------------------------------------------------- /Sorting/Java/QuickSort/Quicksort.java: -------------------------------------------------------------------------------- 1 | package QuickSortJava; 2 | 3 | public class Quicksort { 4 | public static void main(String args[]) { 5 | int[] array = { 8, 2, 5, 3, 9, 4, 7, 6, 1 }; 6 | 7 | quickSort(array, 0, array.length - 1); 8 | 9 | for (int i : array) { 10 | System.out.print(i + " "); 11 | } 12 | } 13 | 14 | private static void quickSort(int[] array, int start, int end) { 15 | 16 | if (end <= start) 17 | return; // base case 18 | 19 | int pivot = partition(array, start, end); 20 | quickSort(array, start, pivot - 1); 21 | quickSort(array, pivot + 1, end); 22 | } 23 | 24 | private static int partition(int[] array, int start, int end) { 25 | 26 | int pivot = array[end]; 27 | int i = start - 1; 28 | 29 | for (int j = start; j <= end; j++) { 30 | if (array[j] < pivot) { 31 | i++; 32 | int temp = array[i]; 33 | array[i] = array[j]; 34 | array[j] = temp; 35 | } 36 | } 37 | i++; 38 | int temp = array[i]; 39 | array[i] = array[end]; 40 | array[end] = temp; 41 | 42 | return i; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Sorting/JavaScript/MergeSort/MergeSort.js: -------------------------------------------------------------------------------- 1 | 2 | const MergedArr = (arr1,arr2)=> 3 | //First we are taking two sorted array 4 | { 5 | const MergerdArr2 = []; 6 | //taking a blank array 7 | let arr1Item =arr1[0]; 8 | //arr1[0] item into arr1Item (eaxmple 12) 9 | let arr2Item = arr2[0]; 10 | //arr2[0] item into arr2Item (eaxmple 10) 11 | let i = 1; 12 | //Initialise i = 1 13 | let j = 1; 14 | //Initialise j =1 15 | 16 | while(arr1Item !== undefined) 17 | //untill arr1Item is not undefined 18 | { 19 | if(arr2Item === undefined || arr1Item < arr2Item) 20 | //if arr1Item is less than arr2Item 21 | { 22 | MergerdArr2.push(arr1Item); 23 | //then MergerArr2 ++ 24 | arr1Item = arr1[i]; 25 | //then arr1Item will be equal to arr1Item will be 32 26 | 27 | i++; 28 | //i =2 29 | } 30 | else 31 | { 32 | MergerdArr2.push(arr2Item); 33 | //Else MergedArr2 ++ 34 | arr2Item = arr2[i]; 35 | ///arr2Item = be 31 36 | j++; 37 | //j=2 38 | } 39 | } 40 | return MergerdArr2; 41 | } 42 | console.log(MergedArr([12,32,43,54,65],[10,31,42,53,64])); -------------------------------------------------------------------------------- /LinkedList/C/linked.h: -------------------------------------------------------------------------------- 1 | #ifndef _LINKED_H_ 2 | #define _LINKED_H_ 3 | 4 | /** 5 | * Built-in C libraries 6 | */ 7 | #include 8 | #include 9 | #include 10 | 11 | /** 12 | * Structure for the singly linked list 13 | */ 14 | typedef struct linked 15 | { 16 | struct linked *next; 17 | int value; 18 | } node_t; 19 | 20 | /** 21 | * Structure for a doubly linked list 22 | */ 23 | typedef struct doubly 24 | { 25 | int value; 26 | struct doubly *next; 27 | struct doubly *prev; 28 | } node_d; 29 | 30 | /** 31 | * Self written functions 32 | */ 33 | void print_linked_list(node_t *list); 34 | node_t *create_linked_list(int *array, size_t length); 35 | void free_linked_list(node_t *list); 36 | void print_doubly_linked_list(node_d *node); 37 | node_d *create_doubly_linked_list(int *array, size_t length); 38 | void free_doubly_linked_list(node_d *node); 39 | node_d *create_circularly_linked_list(int *array, size_t length); 40 | void print_circularly_linked_list(node_d *node); 41 | void free_circularly_linked_list(node_d *node); 42 | node_t *delete_last_node_singly_linked_list(node_t *new_node); 43 | node_d *delete_last_node_doubly_linked_list(node_d *new_node); 44 | node_d *delete_last_node_circularly_linked_list(node_d *new_node); 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /Array/Dart/Valid-Subsequence/ValidSubSequence.dart: -------------------------------------------------------------------------------- 1 | // Valid subsequence algorithm in Dart 2 | bool isValidSubsequence( 3 | {required List array, required List sequence}) { 4 | int arrayIndex = 0, sequenceIndex = 0; 5 | while (arrayIndex < array.length && sequenceIndex < sequence.length) { 6 | if (array[arrayIndex] == sequence[sequenceIndex]) sequenceIndex++; 7 | arrayIndex++; 8 | } 9 | return sequenceIndex == sequence.length; 10 | } 11 | 12 | int main() { 13 | print("🚩 Testing `isValidSubsequence` function..."); 14 | List firstArray = [5, 1, 22, 25, 6, -1, 8, 10], 15 | firstSequence = [1, 6, -1, 10]; 16 | List secondArray = [ 17 | "alpha", 18 | "beta", 19 | "gamma", 20 | "delta", 21 | "tau", 22 | "psi", 23 | "omega" 24 | ], 25 | secondSequence = ["alpha", "kappa", "phi"]; 26 | print("🔖ARRAY → ${firstArray} 📍SEQUENCE → ${firstSequence}"); 27 | print( 28 | "ISVALIDSUBSEQUENCE 👉 ${isValidSubsequence(array: firstArray, sequence: firstSequence)}"); 29 | print("⦿⦿⦿⦿⦿⦿⦿⦿⦿⦿⦿⦿⦿⦿⦿"); 30 | print("🔖ARRAY → ${secondArray} 📍SEQUENCE → ${secondSequence}"); 31 | print( 32 | "ISVALIDSUBSEQUENCE 👉 ${isValidSubsequence(array: secondArray, sequence: secondSequence)}"); 33 | 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /LinkedList/C/FreeLinkedList.c: -------------------------------------------------------------------------------- 1 | #include "linked.h" 2 | /** 3 | * free_linked_list - Function that clears the memory space 4 | * consumed by the program 5 | * 6 | * Return: No return 7 | */ 8 | void free_linked_list(node_t *list) 9 | { 10 | node_t *new; 11 | 12 | if (!list) 13 | return ; 14 | 15 | while (list != NULL) 16 | { 17 | new = list; 18 | list = list->next; 19 | free(new); 20 | } 21 | } 22 | /** 23 | * free_circularly_linked_list - Function to free the allocated space in the 24 | * circularly linked list 25 | * @head: Pointer to the head node of the singly linked list 26 | * Return: No return 27 | */ 28 | void free_circularly_linked_list(node_d *head) 29 | { 30 | node_d *new; 31 | 32 | if (!head) 33 | return ; 34 | 35 | new = head; 36 | new->prev->next = NULL; 37 | while (new -> next != NULL) 38 | { 39 | new = new->next; 40 | free(new->prev); 41 | } 42 | free(new); 43 | } 44 | /** 45 | * free_doubly_linked_list - Function to free the space occupied by the doubly 46 | * doubly linked list 47 | * @node: Pointer to the head of the doubly linked list 48 | * Return: No return 49 | */ 50 | void free_doubly_linked_list(node_d *node) 51 | { 52 | node_d *old; 53 | 54 | if (!node) 55 | return ; 56 | 57 | while (node != NULL) 58 | { 59 | old = node; 60 | node = node->next; 61 | free(old); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /Array/Dart/Valid-Subsequence/README.md: -------------------------------------------------------------------------------- 1 | # VALID SUBSEQUENCE ALGORIGHM 2 | 3 | 📌 **Time Complexity:** O(n)
4 | 📌 **Space Complexity:** O(1)
5 | 📌 **Path:** Data-Structures-Algorithms-Problems/Array/Dart/Valid-Subsequence/ValidSubSequence.dart 6 | 7 | ## What is ValidSubSequence Algorithm? 8 | 9 | ``ValidSubSequence`` Algorithm is a algorithm to check if a sequence is valid or not in an array 10 | ## How does it work? 11 | 12 | ``ValidSubSequence`` Algorithm takes two parameters first one is the array and the second one is the sequence and it returns a boolean value 13 | ## ⚡ Code 14 | ```dart 15 | bool isValidSubsequence( 16 | {required List array, required List sequence}) { 17 | int arrayIndex = 0, sequenceIndex = 0; 18 | while (arrayIndex < array.length && sequenceIndex < sequence.length) { 19 | if (array[arrayIndex] == sequence[sequenceIndex]) sequenceIndex++; 20 | arrayIndex++; 21 | } 22 | return sequenceIndex == sequence.length; 23 | } 24 | ``` 25 | ## 💡Examples 26 | ```Dart 27 | List arrayA = [5,1,22,25,6,-1,8,10] 28 | List sequenceA = [1,6,-1,10] 29 | isValidSubSequence(arrayA,sequenceA) // returns true 30 | List arrayB = ["alpha","beta","gamma","delta","tau","psi","omega"] 31 | List sequenceB = ["alpha","kappa","phi"] 32 | isValidSubSequence(array,sequence) // returns false 33 | ``` 34 | -------------------------------------------------------------------------------- /Moore-Voting-Algorithm/Dart/README.md: -------------------------------------------------------------------------------- 1 | # MOORE'S VOTING ALGORIGHM 2 | 📌 **Time Complexity:** O(n)
3 | 📌 **Space Complexity:** O(1)
4 | 📌 **Path:** Data-Structures-Algorithms-Problems/Array/Dart/Moore-Voting-Algorithm/MooreVotingAlgorithm.dart 5 | 6 | ## What is majorityElement Algorithm? 7 | 8 | The Boyer-Moore``majorityElement`` method is a popular optimal technique for determining the majority element among provided array items with more than N/ 2 occurrences. 9 | 10 | ## How does it work? 11 | ``majorityElement`` in an array ``mooreArray`` of size n is an element that appears more than n/2 times (and hence there is at most one such element). 12 | 13 | 14 | ## ⚡ Code 15 | ```dart 16 | int majorityElement(List array, int n) { 17 | array.sort(); 18 | var count = 1, max = -1, temporary = array[0], ele = 0, f = 0; 19 | for (int i = 1; i < n; i++) { 20 | if (temporary == array[i]) { 21 | count++; 22 | } else { 23 | count = 1; 24 | temporary = array[i]; 25 | } 26 | if (max < count) { 27 | max = count; 28 | ele = array[i]; 29 | if (max > (n / 2)) { 30 | f = 1; 31 | break; 32 | } 33 | } 34 | } 35 | return (f == 1 ? ele : -1); 36 | } 37 | ``` 38 | ## 💡Example 39 | ```Dart 40 | List arr = [1, 1, 2, 1, 3, 5, 1]; 41 | int n = arr.length; 42 | majorityElement(arr, n); // returns 1 43 | -------------------------------------------------------------------------------- /Search/Python/FindTwoPairOfAGivenSumRotatedArray/FindPair.py: -------------------------------------------------------------------------------- 1 | def findPivot(A,l,r): 2 | 3 | if l > r: 4 | return -1 5 | 6 | mid = (l + r) // 2 7 | 8 | if A[mid] < A[mid -1] : 9 | return mid 10 | 11 | if A[mid] > A[mid+1] : 12 | return mid+1 13 | 14 | if A[mid] < A[l]: 15 | return findPivot(A,l,mid-1) 16 | return findPivot(A,mid+1,r) 17 | 18 | def checkSum(A,l,r,x): 19 | 20 | 21 | pivot = findPivot(A,l,r) 22 | 23 | if pivot != -1: 24 | l = pivot 25 | r = pivot -1 26 | 27 | for i in range(0, len(A)): 28 | sum = A[l] + A[r] 29 | if sum == x: 30 | print(True) 31 | return True 32 | elif sum > x: 33 | r -= 1 34 | elif sum < x: 35 | l +=1 36 | if l == len(A): 37 | l = 0 38 | break 39 | 40 | for i in range(0,len(A)): 41 | sum = A[l] + A[r] 42 | if sum == x: 43 | print(True) 44 | return True 45 | if l == r: 46 | print(False) 47 | return False 48 | if sum > x: 49 | r -= 1 50 | if sum < x: 51 | l +=1 52 | 53 | 54 | array = [11, 15, 26, 38, 9, 10] 55 | checkSum(array,0,6,45) 56 | -------------------------------------------------------------------------------- /Search/Dart/Interpolation-Search/README.md: -------------------------------------------------------------------------------- 1 | # INTERPOLATION SEARCH 2 | 📌 **Time Complexity**: `O(log(log(n)))` 3 | 📌 **Space Complexity**: `O(1)` 4 | 📌 **Path:** Data-Structures-Algorithms-Problems/Array/Dart/Interpolation-Search/InterpolationSearch.dart 5 | 6 | ## Interpolation Search 7 | The Interpolation Search is an improvement over Binary Search for instances, where the values in a sorted array are uniformly distributed. Binary Search always goes to the middle element to check. On the other hand, interpolation search may go to different locations according to the value of the key being searched. For example, if the value of the key is closer to the last element, interpolation search is likely to start search toward the end side. 8 | 9 | ## ⚡ Code 10 | ```dart 11 | int interpolationSearch(List arr, int n, int key) { 12 | int low = 0, high = n - 1; 13 | while (low <= high && key >= arr[low] && key <= arr[high]) { 14 | int pos = low + 15 | (((key - arr[low]) * (high - low)) / (arr[high] - arr[low])).round(); 16 | if (key > arr[pos]) 17 | low = pos + 1; 18 | else if (key < arr[pos]) 19 | high = pos - 1; 20 | else 21 | return pos; 22 | } 23 | return -1; 24 | } 25 | ``` 26 | ## 💡Examples 27 | ```Dart 28 | List arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; 29 | var n = arr.length; 30 | var key = 5; 31 | interpolationSearch(arr, n, key); // returns 5 32 | ``` 33 | -------------------------------------------------------------------------------- /Array/Dart/Sorted-Squared-Array/README.md: -------------------------------------------------------------------------------- 1 | # SORTED SQUARED ARRAY 2 | 📌 **Time complexity:** O(n) 3 | 📌 **Space complexity:** O(n) 4 | 📌 **Path:** Data-Structures-Algorithms-Problems/Array/Dart/Sorted-Squared-Array/SortedSquaredArray.dart 5 | 6 | ## Sorted Squared array 7 | 8 | Given an integer array nums sorted in non-decreasing order, return an array of the squares of each number sorted in non-decreasing order. 9 | 10 | ## How does it work? 11 | Given an array of integers that are sorted in increasing order, the```Sorted Squared array``` squares all the integers in the array and returns them in a new array, also sorted in increasing order. 12 | 13 | ## ⚡ Code 14 | ```dart 15 | List sortedSquaredarray(List arr) { 16 | int start = 0, end = arr.length - 1; 17 | int sortedIndex = arr.length - 1; 18 | List answer = List.filled(arr.length, 0); 19 | 20 | while (end >= start) { 21 | if (arr[start].abs() > arr[end].abs()) { 22 | answer[sortedIndex] = arr[start] * arr[start]; 23 | start += 1; 24 | } else { 25 | answer[sortedIndex] = arr[end] * arr[end]; 26 | end -= 1; 27 | } 28 | sortedIndex -= 1; 29 | } 30 | 31 | return answer; 32 | } 33 | ``` 34 | ## 💡Examples 35 | ```Dart 36 | sortedSquaredarray([-1, -1, 2, 3, 3, 3, 4])); // returns [1, 1, 4, 9, 9, 9, 16]); 37 | sortedSquaredarray([1, 2, 3, 4, 5, 6, 7]); // returns [1, 4, 9, 16, 25, 36, 49]); 38 | ``` 39 | -------------------------------------------------------------------------------- /Search/Python/SearchRotatedArray/SearchRotatedArray.py: -------------------------------------------------------------------------------- 1 | 2 | class Solution: 3 | def search(self, A : list, l : int, h : int, key : int): 4 | # l: The starting index 5 | # h: The ending index, you have to search the key in this range 6 | # Complete this function 7 | pivot = Solution.searchPivot(A,l,h) 8 | if key > A[h-1]: 9 | return Solution.binarySearch(A,l,pivot,key) 10 | else: 11 | return Solution.binarySearch(A,pivot,h,key) 12 | 13 | def binarySearch(arr,start,end,key): 14 | 15 | if start > end : 16 | return -1 17 | mid = (end + start) // 2 18 | if arr[mid] == key: 19 | return mid 20 | if arr[mid] > key: 21 | return Solution.binarySearch(arr,start,mid-1,key) 22 | else: 23 | return Solution.binarySearch(arr,mid+1,end,key) 24 | 25 | def searchPivot(A,l,h): 26 | 27 | if(l>h): 28 | return -1 29 | if l==h: 30 | return l 31 | 32 | mid = (h+l) //2 33 | 34 | if A[mid] < A[mid-1]: 35 | return mid 36 | 37 | if A[mid] > A[mid+1]: 38 | return mid+1 39 | 40 | if A[l] > A[mid]: 41 | return Solution.searchPivot(A,l,mid-1) 42 | 43 | return Solution.searchPivot(A,mid+1,h) 44 | -------------------------------------------------------------------------------- /Moore-Voting-Algorithm/MooreVotingAlgorithmNBy2/Dart/README.md: -------------------------------------------------------------------------------- 1 | # MOORE'S VOTING ALGORIGHM 2 | 📌 **Time Complexity:** O(n)
3 | 📌 **Space Complexity:** O(1)
4 | 📌 **Path:** Data-Structures-Algorithms-Problems/Array/Dart/Moore-Voting-Algorithm/MooreVotingAlgorithm.dart 5 | 6 | ## What is majorityElement Algorithm? 7 | 8 | The Boyer-Moore``majorityElement`` method is a popular optimal technique for determining the majority element among provided array items with more than N/ 2 occurrences. 9 | ## How does it work? 10 | 11 | ``majorityElement`` in an array ``mooreArray`` of size n is an element that appears more than n/2 times (and hence there is at most one such element). 12 | 13 | 14 | ## ⚡ Code 15 | ```dart 16 | int majorityElement(List array, int n) { 17 | array.sort(); 18 | 19 | var count = 1, max = -1, temporary = array[0], ele = 0, f = 0; 20 | 21 | for (int i = 1; i < n; i++) { 22 | if (temporary == array[i]) { 23 | count++; 24 | } else { 25 | count = 1; 26 | temporary = array[i]; 27 | } 28 | if (max < count) { 29 | max = count; 30 | ele = array[i]; 31 | 32 | if (max > (n / 2)) { 33 | f = 1; 34 | break; 35 | } 36 | } 37 | } 38 | return (f == 1 ? ele : -1); 39 | } 40 | 41 | ``` 42 | ## 💡Example 43 | ```Dart 44 | List arr = [1, 1, 2, 1, 3, 5, 1]; 45 | int n = arr.length; 46 | majorityElement(arr, n); // returns 1 47 | ``` 48 | 49 | -------------------------------------------------------------------------------- /Array/Mo'sAlgorithm/NumberOfElementsInAQueryRange/NumberOfElementInAQueryRange.py: -------------------------------------------------------------------------------- 1 | import math 2 | 3 | def solveQueries( nums, Queries, k): 4 | #Code here 5 | answers= [0] * len(Queries) 6 | 7 | count = {} 8 | n = int(math.sqrt(len(nums)))+1 9 | q = list(enumerate(Queries)) 10 | 11 | q.sort(key=lambda a:[int(a[1][0]/n),-a[1][1]]) 12 | currentL=0 13 | currentR=-1 14 | ans = 0 15 | 16 | for i in q: 17 | left =i[1][0]-1 18 | right =i[1][1]-1 19 | 20 | while(currentRright): 34 | count[nums[currentR]]-=1 35 | if count[nums[currentR]]==k-1: 36 | ans-=1 37 | currentR-=1 38 | while(currentL>left): 39 | currentL-=1 40 | count[nums[currentL]]=count.get(nums[currentL],0)+1 41 | if count[nums[currentL]]==k: 42 | ans+=1 43 | 44 | answers[i[0]]=ans 45 | 46 | return answers 47 | -------------------------------------------------------------------------------- /DynamicProgramming/Python/SparseTable/Sparse.py: -------------------------------------------------------------------------------- 1 | import math 2 | def create_sparse(arr,n): 3 | 4 | 5 | sparse = [[]] * n 6 | 7 | 8 | 9 | for i in range(n): 10 | 11 | sparse[i] = [i] 12 | 13 | j = 1 14 | 15 | while(pow(2,j) < n): 16 | 17 | k = 0 18 | while (k + pow(2,j-1) < n and j - 1 < len(sparse[k + pow(2,j-1)]) ): 19 | first = sparse[k][j-1] 20 | inc = k + pow(2,j-1) 21 | second = sparse[inc][j-1] 22 | if arr[ first ] < arr[ second ]: 23 | sparse[k].append(sparse[k][j-1]) 24 | else: 25 | sparse[k].append(sparse[inc][j-1]) 26 | 27 | k = k+1 28 | 29 | j = j+1 30 | 31 | 32 | return sparse 33 | 34 | def rmq(low,high,sparse): 35 | 36 | l = (high-low) +1 37 | k = math.floor(math.log2(l)) 38 | firstElement = arr[sparse[low][k]] 39 | secondElement = arr[sparse[low + (l - pow(2,k))][k]] 40 | 41 | return min(firstElement,secondElement) 42 | 43 | 44 | 45 | # arr = [4,6,1,5,7,3] 46 | # n = len(arr) 47 | # sparse = create_sparse(arr,n) 48 | # print(rmq(3,5,sparse)) 49 | # print(rmq(0,5,sparse)) 50 | # print(rmq(0,3,sparse)) 51 | 52 | 53 | 54 | 55 | arr = [7, 2, 3, 0, 5, 10, 3, 12, 18] 56 | 57 | n = len(arr) 58 | sparse = create_sparse(arr,n) 59 | print(rmq(0,4,sparse)) 60 | print(rmq(4,7,sparse)) 61 | print(rmq(7,8,sparse)) -------------------------------------------------------------------------------- /Search/C/BinarySearch/README.md: -------------------------------------------------------------------------------- 1 | # Binary Search algorithm implementation in C 2 | 3 | Time complexity - O( Log(n) ) 4 | Space Complexity - O(1) 5 | 6 | ## Implementation of `BinarySearch` 7 | 8 | The `BinarySearch` function requires to pass an array of numbers and the number to be found in the array with the lowest possible index and the highest possible index. 9 | 10 | It returns the index of the number you searched for if it has found the number or else it returns -1. 11 | 12 | ```c 13 | BinarySearch(int arr[], int x, int low, int high) 14 | ``` 15 | 16 | ## How to run the program 17 | 18 | This folder contains the header you can include when compiling your program. You will need to create a C/C++ file with a main function. 19 | 20 | Here is how you can do it: 21 | 22 | - Create a new c/c++ file 23 | 24 | ```bash 25 | touch main.c 26 | ``` 27 | 28 | - Include "BinarySearch.h" in your file 29 | 30 | ```c 31 | #include "BinarySearch.h" 32 | ``` 33 | 34 | - Write a main function 35 | 36 | ```c 37 | 38 | #include "BinarySearch.h" 39 | 40 | int main() { 41 | int nums = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; 42 | 43 | int num = BinarySearch(nums, 0, 5, 10 - 1); 44 | 45 | printf("result: %d", num); 46 | 47 | return 0; 48 | } 49 | ``` 50 | 51 | - Compile and run 52 | You can use your preferred compiler :D 53 | 54 | ```bash 55 | clang main.c -o binary_search 56 | ./binary_search 57 | ``` 58 | 59 | By running the program, now you can see the result printed as the index of the number in the array. 60 | -------------------------------------------------------------------------------- /LinkedList/C/PrintLinkedList.c: -------------------------------------------------------------------------------- 1 | #include "linked.h" 2 | /** 3 | * print_linked_list - Function to print contents of the linked list 4 | * @list: Pointer to the head of the linked list 5 | * Return: No return 6 | */ 7 | void print_linked_list(node_t *list) 8 | { 9 | int num = 0; 10 | 11 | if (!list) 12 | return ; 13 | 14 | while (list != NULL) 15 | { 16 | printf("The %d value is %d\n", num, list->value); 17 | num = num + 1; 18 | list = list -> next; 19 | } 20 | } 21 | /** 22 | * print_circularly_linked_list - Function to print the values in the 23 | * circularly linked list 24 | * @head: Pointer to the head of the circularly linked list 25 | * Return: No return 26 | */ 27 | void print_circularly_linked_list(node_d *head) 28 | { 29 | node_d *old; 30 | size_t num = 0; 31 | 32 | if (!head) 33 | return ; 34 | 35 | old = head; 36 | while (old -> next != head) 37 | { 38 | printf("The %ld value in the circularly linked ", num); 39 | printf("list is %d\n", old->value); 40 | num++; 41 | old = old->next; 42 | } 43 | } 44 | /** 45 | * print_doubly_linked_list - Function to print the doubly linked list 46 | * @node: Pointer to the head node of the doubly linked list 47 | * Return: No return 48 | */ 49 | void print_doubly_linked_list(node_d *node) 50 | { 51 | node_d *path; 52 | size_t num = 0; 53 | 54 | if (!node) 55 | return ; 56 | 57 | path = node; 58 | while(path->next != NULL) 59 | { 60 | printf("The %ld value in the doubly linked list is %d\n", num, path->value); 61 | num++; 62 | path = path->next; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /Sorting/Java/SelectionSort/SelectionSort.java: -------------------------------------------------------------------------------- 1 | // Java program for implementation of Selection Sort 2 | 3 | class SelectionSort 4 | 5 | { 6 | 7 | void sort(int arr[]) 8 | 9 | { 10 | 11 | int n = arr.length; 12 | 13 | 14 | 15 | // One by one move boundary of unsorted subarray 16 | 17 | for (int i = 0; i < n-1; i++) 18 | 19 | { 20 | 21 | // Find the minimum element in unsorted array 22 | 23 | int min_idx = i; 24 | 25 | for (int j = i+1; j < n; j++) 26 | 27 | if (arr[j] < arr[min_idx]) 28 | 29 | min_idx = j; 30 | 31 | 32 | 33 | // Swap the found minimum element with the first 34 | 35 | // element 36 | 37 | int temp = arr[min_idx]; 38 | 39 | arr[min_idx] = arr[i]; 40 | 41 | arr[i] = temp; 42 | 43 | } 44 | 45 | } 46 | 47 | 48 | 49 | // Prints the array 50 | 51 | void printArray(int arr[]) 52 | 53 | { 54 | 55 | int n = arr.length; 56 | 57 | for (int i=0; i nodes; 7 | int[][] matrix; 8 | 9 | Graph(int size) { 10 | nodes = new ArrayList(); 11 | matrix = new int[size][size]; 12 | } 13 | 14 | public void addNote(Node node) { 15 | nodes.add(node); 16 | } 17 | 18 | public void addEdge(int source, int destination) { 19 | matrix[source][destination] = 1; 20 | } 21 | 22 | public boolean checkEdge(int source, int destination) { 23 | if (matrix[source][destination] == 1) { 24 | return true; 25 | } 26 | return false; 27 | } 28 | 29 | public void print() { 30 | System.out.print(""); 31 | for (Node node : nodes) { 32 | System.out.print(node.data + ""); 33 | } 34 | System.out.println(""); 35 | } 36 | 37 | public void depthFirstSearch(int source) { 38 | boolean[] visited = new boolean[matrix.length]; 39 | dfsHelper(source, visited); 40 | } 41 | 42 | private void dfsHelper(int source, boolean[] visited) { 43 | if (visited[source] == true) { 44 | return; 45 | } else { 46 | visited[source] = true; 47 | System.out.println(nodes.get(source).data + " = visted"); 48 | } 49 | for (int i = 0; i < matrix[source].length; i++) { 50 | if (matrix[source][i] == i) { 51 | dfsHelper(i, visited); 52 | } 53 | } 54 | return; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /Array/Mo'sAlgorithm/PowerfulArray/PowerfulArray.py: -------------------------------------------------------------------------------- 1 | import math 2 | 3 | 4 | def powerFulArray(nums, query): 5 | 6 | 7 | n = int(math.sqrt(len(nums))) + 1 8 | 9 | answer = [0] * len(query) 10 | 11 | q = list(enumerate(query)) 12 | 13 | q.sort(key=lambda a:[int(a[1][0]/n),-a[1][1]]) 14 | 15 | F = [0] * (max(nums) +1) 16 | 17 | currentL = q[0][1][0]-1 18 | currentR = q[0][1][0]-2 19 | 20 | count = 0 21 | 22 | 23 | for i in q: 24 | left = i[1][0]-1 25 | right = i[1][1] -1 26 | 27 | while(currentR < right): 28 | currentR+=1 29 | if F[nums[currentR]] > 0: 30 | count-= (F[nums[currentR]] ** 2 ) * nums[currentR] 31 | F[nums[currentR]]+=1 32 | count+= (F[nums[currentR]] ** 2 ) * nums[currentR] 33 | 34 | while(currentL < left): 35 | count-= (F[nums[currentL]] ** 2 ) * nums[currentL] 36 | F[nums[currentL]]-=1 37 | count+= (F[nums[currentL]]**2) * nums[currentL] 38 | currentL+=1 39 | 40 | while(currentR > right): 41 | count-= (F[nums[currentR]] **2) * nums[currentR] 42 | F[nums[currentR]]-=1 43 | count+= (F[nums[currentR]]**2) * nums[currentR] 44 | currentR-=1 45 | 46 | while(currentL > left): 47 | if F[nums[currentL]] > 0: 48 | count-= (F[nums[currentL]]**2) * nums[currentL] 49 | F[nums[currentL]]+=1 50 | count+= (F[nums[currentL]]**2) * nums[currentL] 51 | currentL-=1 52 | 53 | answer[i[0]] = count 54 | 55 | return answer 56 | 57 | 58 | 59 | # nums = [1, 2, 1] 60 | # q = [[1,2],[1,3]] 61 | 62 | 63 | nums = [1 ,1, 2, 2, 1, 3, 1, 1] 64 | q = [[2,7],[1,6],[2,7]] 65 | 66 | print(powerFulArray(nums,q)) 67 | 68 | 69 | 70 | 71 | -------------------------------------------------------------------------------- /Array/Javascript/MovingMedian/MovingMedian.js: -------------------------------------------------------------------------------- 1 | function findMovingMovingMedian(arr){ 2 | 3 | //check edge cases 4 | let median = '' 5 | if(arr.length==0){ 6 | return median 7 | } 8 | if(arr.length ==1){ 9 | return arr[0] 10 | } 11 | if(arr[0] < 0){ 12 | return median; 13 | } 14 | // [3,1,3,5,10,6,4,3,1] 15 | 16 | //output [1,2,3,5,6,6,4,3] 17 | let n = arr[0] 18 | 19 | let newArr = arr.slice(1,arr.length) 20 | 21 | let j = 0; 22 | 23 | for(let i = 1;i right): 28 | inversions = decrementR(arr,currentR,inversions) 29 | currentR-=1 30 | 31 | while(currentL > left): 32 | inversions = incrementL(arr,currentL,currentR,inversions) 33 | currentL-=1 34 | 35 | answer[q[0]] = len(inversions) 36 | 37 | return answer 38 | 39 | 40 | def incrementR(arr,l,r,inv): 41 | inversions = inv 42 | 43 | for i in range(len(arr[l:r])): 44 | if arr[i] > arr[r]: 45 | inversions.append((arr[i],arr[r])) 46 | return inversions 47 | 48 | def incrementL(arr,l,r,inv): 49 | inversions = inv 50 | for i in range(len(arr[l+1,r+1])): 51 | if arr[l] > arr[i]: 52 | inversions.append((arr[l],arr[i])) 53 | 54 | return inversions 55 | 56 | def decrementL(arr,l,inversions): 57 | return list(filter(lambda x:x[0] != arr[l],inversions)) 58 | 59 | def decrementR(arr,r,inversions): 60 | return list(filter(lambda x:x[1] != arr[r],inversions)) 61 | 62 | 63 | arr = [7, 9, 3, 5, 1, 6, 4] 64 | q = [[1, 4], [3, 5], [1, 2], [1, 7]] 65 | 66 | print(sherlockInversion(arr=arr,queries=q)) 67 | 68 | 69 | 70 | 71 | 72 | -------------------------------------------------------------------------------- /LinkedList/C/DeleteLinkedList.c: -------------------------------------------------------------------------------- 1 | #include "linked.h" 2 | 3 | /** 4 | * delete_last_node_singly_linked_list - Function to delete the last node in 5 | * a singly linked list 6 | * @node: Pointer to the head node of the linked list 7 | * Return: Pointer to the head node after deletion or NULL 8 | */ 9 | node_t *delete_last_node_singly_linked_list(node_t *new_node) 10 | { 11 | node_t *current, *new_end; 12 | 13 | if (!new_node) 14 | return (NULL); 15 | 16 | current = new_node; 17 | while (current->next) 18 | { 19 | new_end = current; 20 | current = current->next; 21 | } 22 | new_end->next = NULL; 23 | free(current); 24 | return (new_node); 25 | } 26 | /** 27 | * delete_last_node_doubly_linked_list - Function to delete the last node from 28 | * a singly linked list 29 | * @node: Pointer to the head of the doubly linked list 30 | * Return: Pointer to the head of a doubly linked list or NULL 31 | */ 32 | node_d *delete_last_node_doubly_linked_list(node_d *new_node) 33 | { 34 | node_d *current, *present; 35 | 36 | if (!new_node) 37 | return (NULL); 38 | 39 | current = new_node; 40 | while (current->next) 41 | { 42 | present = current; 43 | current = current->next; 44 | } 45 | present -> next = NULL; 46 | current -> prev = NULL; 47 | free(current); 48 | return (new_node); 49 | } 50 | /** 51 | * delete_last_node_circularly_linked_list - Function to delete the last node in 52 | * a circularly linked list 53 | * @new_node: Pointer to the head of the circularly linked list 54 | * Return: pointer to the head of the circularly linked list 55 | */ 56 | node_d *delete_last_node_circularly_linked_list(node_d *new_node) 57 | { 58 | node_d *current, *present; 59 | 60 | if (!new_node) 61 | return (NULL); 62 | 63 | current = new_node; 64 | while (current->next != new_node) 65 | { 66 | present = current; 67 | current = current->next; 68 | } 69 | free(current); 70 | present->next = new_node; 71 | new_node->prev = present; 72 | return (new_node); 73 | } 74 | -------------------------------------------------------------------------------- /Array/Mo'sAlgorithm/DistictElementsInAQueryRange/NumberOfDistinctElementInAQueryRange.py: -------------------------------------------------------------------------------- 1 | import math 2 | 3 | 4 | def distinctElements(nums,query): 5 | 6 | n = int(math.sqrt(len(nums))) + 1 7 | 8 | query = list(enumerate(query)) 9 | print(query) 10 | query.sort(key= lambda a:[int(a[1][0]/n),-a[1][1]]) 11 | 12 | ans = [0] * len(query) 13 | 14 | maxVal = max(nums) 15 | 16 | F = [0] * (maxVal+1) 17 | 18 | count = 0 19 | 20 | start = query[0][1][0]-1 21 | end = query[0][1][0]-2 22 | 23 | for q in query: 24 | 25 | left = q[1][0]-1 26 | right = q[1][1]-1 27 | 28 | while(end < right): 29 | end+=1 30 | val = nums[end] 31 | F[val] +=1 32 | if F[val] == 1: 33 | count+=1 34 | 35 | 36 | while(start < left): 37 | val = nums[start] 38 | F[val]-=1 39 | if F[val] == 0: 40 | count-=1 41 | 42 | start +=1 43 | 44 | while (end > right): 45 | val = nums[end] 46 | F[val] -=1 47 | if F[val] == 0: 48 | count-=1 49 | 50 | end-=1 51 | 52 | while(start > left): 53 | val = nums[start] 54 | F[val]+=1 55 | if F[val] == 1: 56 | count+=1 57 | 58 | 59 | start+=1 60 | 61 | 62 | 63 | 64 | print(count) 65 | 66 | # ans[q[0]] = count 67 | 68 | # return ans 69 | 70 | 71 | 72 | n = int(input()) 73 | 74 | numsStr = input() 75 | 76 | nums = [] 77 | for i in range(len(numsStr)): 78 | nums.append(int(numsStr[i])) 79 | 80 | 81 | q = int(input()) 82 | query = [] 83 | for i in range(q): 84 | singleQuery = input() 85 | query.append([int(singleQuery[0]),int(singleQuery[1])]) 86 | 87 | 88 | distinctElements(nums,query) -------------------------------------------------------------------------------- /Array/TwoDArray/Java/HourGlassJava/Main.java: -------------------------------------------------------------------------------- 1 | package TwoDArray.HourGlassJava; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | public class Main { 7 | public static void main(String[] args) { 8 | ArrayList> arr = new ArrayList<>(); 9 | ArrayList firstRow = new ArrayList<>(); 10 | ArrayList secondRow = new ArrayList<>(); 11 | ArrayList thirdRow = new ArrayList<>(); 12 | ArrayList forthRow = new ArrayList<>(); 13 | ArrayList fifthRow = new ArrayList<>(); 14 | ArrayList sixthRow = new ArrayList<>(); 15 | firstRow.add(1); 16 | firstRow.add(1); 17 | firstRow.add(1); 18 | firstRow.add(0); 19 | firstRow.add(0); 20 | firstRow.add(0); 21 | secondRow.add(0); 22 | secondRow.add(1); 23 | secondRow.add(0); 24 | secondRow.add(0); 25 | secondRow.add(0); 26 | secondRow.add(0); 27 | 28 | thirdRow.add(1); 29 | thirdRow.add(1); 30 | thirdRow.add(1); 31 | thirdRow.add(0); 32 | thirdRow.add(0); 33 | thirdRow.add(0); 34 | forthRow.add(0); 35 | forthRow.add(0); 36 | forthRow.add(2); 37 | forthRow.add(4); 38 | forthRow.add(4); 39 | forthRow.add(0); 40 | 41 | fifthRow.add(0); 42 | fifthRow.add(0); 43 | fifthRow.add(0); 44 | fifthRow.add(2); 45 | fifthRow.add(0); 46 | fifthRow.add(0); 47 | sixthRow.add(0); 48 | sixthRow.add(0); 49 | sixthRow.add(1); 50 | sixthRow.add(2); 51 | sixthRow.add(4); 52 | sixthRow.add(0); 53 | arr.add(firstRow); 54 | arr.add(secondRow); 55 | arr.add(thirdRow); 56 | arr.add(forthRow); 57 | arr.add(fifthRow); 58 | arr.add(sixthRow); 59 | int result = HourGlass.hourglassSum(arr); 60 | System.out.println(result); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /Stack/Array/C/Stack.c: -------------------------------------------------------------------------------- 1 | #include "Stack.h" 2 | 3 | /** 4 | * createStack - creates stack of given capacity 5 | * @capacity: capacity of the stack 6 | * Return: returns pointer to new stack otherwise NULL 7 | */ 8 | Stack *createStack(unsigned capacity) 9 | { 10 | Stack *stack = malloc(sizeof(Stack)); 11 | if (stack == NULL) 12 | return NULL; 13 | stack->capacity = capacity; 14 | stack->top = -1; 15 | stack->array = malloc(stack->capacity * sizeof(int)); 16 | return stack; 17 | } 18 | 19 | /** 20 | * isFull - check if stack is full 21 | * @stack: pointer to the stack to check 22 | * Return: returns true if stack is full otherwise false 23 | */ 24 | int isFull(Stack *stack) 25 | { 26 | return stack->top == stack->capacity - 1; 27 | } 28 | 29 | /** 30 | * isEmpty - check if stack is empty 31 | * @stack: pointer to the stack to check 32 | * Return: returns true if stack is empty otherwise false 33 | */ 34 | int isEmpty(Stack *stack) 35 | { 36 | return stack->top == -1; 37 | } 38 | 39 | /** 40 | * push - add an item to the top of the stack 41 | * @stack: pointer to the stack to check 42 | * @item: item to add 43 | */ 44 | void push(Stack *stack, int item) 45 | { 46 | if (isFull(stack)) 47 | return; 48 | stack->array[++stack->top] = item; 49 | printf("%d pushed to stack\n", item); 50 | } 51 | 52 | /** 53 | * pop - removes the top item 54 | * @stack: pointer to the stack to check 55 | * Return: returns the removed item or 56 | * minimum int value if stack is empty 57 | */ 58 | int pop(Stack *stack) 59 | { 60 | if (isEmpty(stack)) 61 | return INT_MIN; 62 | return stack->array[stack->top--]; 63 | } 64 | 65 | /** 66 | * peek - returns top item without removing it 67 | * @stack: pointer to the stack to check 68 | * Return: returns the top item or 69 | * minimum int value if stack is empty 70 | */ 71 | int peek(Stack *stack) 72 | { 73 | if (isEmpty(stack)) 74 | return INT_MIN; 75 | return stack->array[stack->top]; 76 | } 77 | -------------------------------------------------------------------------------- /LinkedList/C/README.md: -------------------------------------------------------------------------------- 1 | # Linked Lists 2 | A Linked list is a data stucture in which data are collected linearly through the nodes. To know more about a linked list, check out this [article](https://medium.com/@dilibe/getting-started-with-linked-list-fdf4da268ff9) 3 | 4 | # How to run the program 5 | No C program can run with out the main function. 6 | The GCC (which is what we will be using) will show an error without the main function. 7 | Create your main function to test this. 8 | Replace it with the section ``in the command. 9 | The linked list accept integers as data inputs. 10 | You can add as much flags or options as you want. 11 | Take a look at the `linked.h` header file to see the prototype to use 12 | 13 | ### Singly Linked List 14 | 15 | ``` 16 | gcc -Wall -Wextra -Werror -pedantic -std=gnu89 PrintLinkedList.c FreeLinkedList.c CreateLinkedList.c DeleteLinkedList.c -o 17 | ``` 18 | 19 | ### Doubly Linked List 20 | 21 | ``` 22 | gcc -Wall -Werror -Wextra -pedantic -std=gnu89 PrintLinkedList.c FreeLinkedList.c CreateLinkedList.c DeleteLinkedList.c -o 23 | ``` 24 | 25 | ### Circularly Linked List 26 | 27 | ``` 28 | gcc -Wall -Werror -Wextra -pedantic -std=gnu89 PrintLinkedList.c FreeLinkedList.c CreateLinkedList.c DeleteLinkedList.c -o 29 | ``` 30 | 31 | # How to create the `main_file` 32 | 33 | Before a C program is complied, It must contain only one main function. 34 | To create the main file which contains the main function, follow the steps 35 | - The first line must contain `#include "linked.h"` 36 | - After this, other libraries can be declared 37 | - The main function can also be declared. The main function is a very essential part in C programming. 38 | - Prototypes that care included in `linked.h` file can be used as function calls in the main function 39 | 40 | [Take a look at my functions to get a clue](https://github.com/Ddilibe/Data-Structures-Algorithms-Problems_ismaelsadeeq/tree/linked/LinkedList/C) 41 | 42 | ## Note 43 | All allocated blocks were freed and there is no possibility of a leak. The confirmation was verified from valgrind 44 | -------------------------------------------------------------------------------- /Sorting/Java/MergeSortJava/MergeSort.java: -------------------------------------------------------------------------------- 1 | import java.util.Arrays; 2 | 3 | // Merge sort in Java 4 | 5 | class MergeSort { 6 | 7 | // Merge two sub arrays L and M into array 8 | void merge(int array[], int p, int q, int r) { 9 | 10 | int n1 = q - p + 1; 11 | int n2 = r - q; 12 | 13 | int L[] = new int[n1]; 14 | int M[] = new int[n2]; 15 | 16 | // fill the left and right array 17 | for (int i = 0; i < n1; i++) 18 | L[i] = array[p + i]; 19 | for (int j = 0; j < n2; j++) 20 | M[j] = array[q + 1 + j]; 21 | 22 | // Maintain current index of sub-arrays and main array 23 | int i, j, k; 24 | i = 0; 25 | j = 0; 26 | k = p; 27 | 28 | // Until we reach either end of either L or M, pick larger among 29 | // elements L and M and place them in the correct position at A[p..r] 30 | // for sorting in descending 31 | // use if(L[i] >= <[j]) 32 | while (i < n1 && j < n2) { 33 | if (L[i] <= M[j]) { 34 | array[k] = L[i]; 35 | i++; 36 | } else { 37 | array[k] = M[j]; 38 | j++; 39 | } 40 | k++; 41 | } 42 | 43 | // When we run out of elements in either L or M, 44 | // pick up the remaining elements and put in A[p..r] 45 | while (i < n1) { 46 | array[k] = L[i]; 47 | i++; 48 | k++; 49 | } 50 | 51 | while (j < n2) { 52 | array[k] = M[j]; 53 | j++; 54 | k++; 55 | } 56 | } 57 | 58 | // Divide the array into two sub arrays, sort them and merge them 59 | void mergeSort(int array[], int left, int right) { 60 | if (left < right) { 61 | 62 | // m is the point where the array is divided into two sub arrays 63 | int mid = (left + right) / 2; 64 | 65 | // recursive call to each sub arrays 66 | mergeSort(array, left, mid); 67 | mergeSort(array, mid + 1, right); 68 | 69 | // Merge the sorted sub arrays 70 | merge(array, left, mid, right); 71 | } 72 | } 73 | 74 | public static void main(String args[]) { 75 | 76 | // created an unsorted array 77 | int[] array = { 6, 5, 12, 10, 9, 1 }; 78 | 79 | MergeSort ob = new MergeSort(); 80 | 81 | // call the method mergeSort() 82 | // pass argument: array, first index and last index 83 | ob.mergeSort(array, 0, array.length - 1); 84 | 85 | System.out.println("Sorted Array:"); 86 | System.out.println(Arrays.toString(array)); 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /LinkedList/C/CreateLinkedList.c: -------------------------------------------------------------------------------- 1 | #include "linked.h" 2 | /** 3 | * create_linked_list - Function to create a linked list 4 | * @array: An array containing the integers to be inputed in the list 5 | * @length: The size of the list 6 | * Return: Pointer to the created list 7 | */ 8 | node_t *create_linked_list(int *array, size_t length) 9 | { 10 | node_t *old, *new; 11 | size_t size; 12 | 13 | new = malloc(sizeof(node_t) * length); 14 | 15 | if (!new || !array) 16 | return NULL; 17 | 18 | old = new; 19 | size = 0; 20 | 21 | if (!array || new == NULL) 22 | return new; 23 | 24 | while (size < length) 25 | { 26 | new -> value = array[size]; 27 | if ((size + 1) < length) 28 | { 29 | new -> next = malloc(sizeof(node_t)); 30 | new = new -> next; 31 | } 32 | size = size + 1; 33 | } 34 | 35 | new->next = NULL; 36 | return old; 37 | } 38 | /** 39 | * create_circularly_linked_list - Function to create a circularly linked list 40 | * @array: An array of integers 41 | * @length: Length of the array 42 | * Return: Pointer to the head of the array or NULL 43 | */ 44 | node_d *create_circularly_linked_list(int *array, size_t length) 45 | { 46 | node_d *new, *old, *present; 47 | size_t size = 0; 48 | 49 | new = malloc(sizeof(node_d)); 50 | 51 | if (!array || new == NULL) 52 | return NULL; 53 | 54 | old = new; 55 | while (size < length) 56 | { 57 | old -> value = array[size]; 58 | size++; 59 | present = old; 60 | old -> next = malloc(sizeof(node_d)); 61 | old = old -> next; 62 | old -> prev = present; 63 | present->next = old; 64 | } 65 | old -> next = new; 66 | new -> prev = old; 67 | return (new); 68 | } 69 | /** 70 | * create_doubly_linked_list - Function to create a doubly linked list 71 | * @array: An array of integers 72 | * @length: Length of the array of integers 73 | * Return: Pointer to the head of the newly created linked list 74 | */ 75 | node_d *create_doubly_linked_list(int *array, size_t length) 76 | { 77 | node_d *past, *present, *future; 78 | size_t size = 0, place; 79 | 80 | future = malloc(sizeof(node_d) * length); 81 | 82 | if (!future || !array) 83 | return NULL; 84 | 85 | past = future; 86 | while (size < length) 87 | { 88 | place = size; 89 | size++; 90 | past->value = array[place]; 91 | present = past; 92 | past->next = malloc(sizeof(node_d) * length); 93 | past = past->next; 94 | if (size == 0) 95 | { 96 | past->prev = NULL; 97 | } 98 | else 99 | { 100 | past->prev = present; 101 | present->next = past; 102 | } 103 | } 104 | past->next = NULL; 105 | return future; 106 | } 107 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Data Structures-Algorithms-Problems Contributing guidelines 2 | 3 | Welcome to Data-Structures-Algorithms-Problems. Please make sure you have read the entire guideline before sending in your pull requests. If you have any doubts about the contributing guide, please don't hesitate to make it known in an issue. 4 | 5 | ### Contributing and 6 | ### Contributor 7 | We are thrilled that you are considering implementing Algorithms, Data-Structures, or solving problems for others! 8 | This repository is referenced and used by learners from around the globe. As one of our contributors, you agree and confirm that: 9 | 10 | Please Any plagiarized work will not be merged. You did your work - plagiarism is not allowed in any way. Your work will be distributed under MIT LICENCE once your pull request is merged. Your submitted work must fulfill our styles and standards. We welcome new implementation. For example, new approaches to a problem, different graph data structure representation, or algorithm designs of different degrees of complexity. 11 | 12 | Improving comments or writing proper tests are also highly welcome. 13 | 14 | ### Contribution 15 | We appreciate any contribution, from fixing grammar mistakes to implementing complex algorithms. Please read this section if you are contributing to this repository. 16 | 17 | If you submit a pull request (PR) that resolves an open issue, please add fixes: #{$ISSUE_NO} in your commit message to help us keep our issue list short. If your PR is merged, the issue will be resolved. 18 | 19 | ### What is an Algorithm? 20 | An Algorithm is one or more functions (or classes) that: 21 | 22 | - take one or more inputs 23 | - perform some internal calculations or data manipulations 24 | - return one or more outputs 25 | - have minimal side effects 26 | 27 | Algorithms should be packaged in a way that would make it easy for readers to put them into larger programs. 28 | 29 | ### Algorithms should: 30 | 31 | - have intuitive class and function names that make their purpose clear to readers 32 | - use programming naming conventions, clean code and intuitive variable names to ease comprehension. 33 | - be flexible to take different input values. 34 | 35 | ### Data Structure 36 | Arrangement of data in order to solve a problem. 37 | 38 | ### Problems 39 | Solution to known list of coding challenges or problems using an Algorithm,and or a Data-structure 40 | 41 | ### You can use any programming language to contribute. 42 | ### Implementing same Algorithm, Data-Structure, or a problem solution in another programming language is also welcome 43 | 44 | #### File Naming Convention 45 | filenames should use the UpperCamelCase (PascalCase) style. 46 | There should be no spaces in filenames. 47 | Example: LinkedList.py is allowed but linkedlist.py,Linkedlist.py,linked-list.py,linkedList.py are not. 48 | 49 | ### Folder Structure 50 | A folder name is also Upper-Camel-Case with hypen between. 51 | Folder name should be a Data structure Implementation, Algorithm Implementation, or a Problem name. 52 | E.g folder Sort, should include all sorting algorithms implementation. 53 | E.g folder Array should have problems solved with the array data-structure 54 | E.g folder Two-Pointer should have have problems solved with the two pointer algorithm 55 | E.g folder Sliding-Window should have problems solved with the sliding window algorithm. 56 | 57 | Create a new folder if one doesn't already exist for the Data-Structure, Algorithm, or problem you solved. Make a folder with the name of the Data-Structure or Algorithm. In the folder if their is no folder for the programming language create another folder with the programming language name. e.g Python then inside it create another folder for the Data-Structure e.g LinkedList, 58 | inside LinkedList create source file for the Data-Structute e.g Js-Linked-List.js to write your solution. 59 | Add a ReadMe.md file with a brief description of the problem or algorithm, its complexity and runtime, and a link to an explanation blog post. 60 | 61 | ### Testing 62 | Be confident that your code works. When was the last time you committed a code change, your build failed and half of your app stopped working? Mine was last week. Writing tests for our Algorithms will help us ensure the implementations are air tight even after multiple fixes and code changes. 63 | 64 | It is advised that the algorithm file (module) does not contain any "live" code but rather just exports the function(s) needed to execute the algorithm. 65 | 66 | Please refrain from printing to the console in your implementation AND test code. 67 | 68 | 69 | Written by @ismaelsadeeq 2022 70 | -------------------------------------------------------------------------------- /AVLTree/JavaScript/AVLTree.js: -------------------------------------------------------------------------------- 1 | // Class to create node 2 | class Node { 3 | constructor(num) { 4 | this.value = num; 5 | this.height = 1; 6 | this.left = null; 7 | this.right = null; 8 | } 9 | } 10 | 11 | // Class to create AVL Tree 12 | class AVLTree { 13 | constructor() { 14 | let root = null; 15 | 16 | //get height of node 17 | this.height = (N) => { 18 | if (N === null) { 19 | return 0; 20 | } 21 | 22 | return N.height; 23 | }; 24 | 25 | //rotations: 26 | //right rotation 27 | this.rightRotation = (b) => { 28 | let a = b.left; 29 | let c = a.right; 30 | a.right = b; 31 | b.left = c; 32 | b.height = Math.max(this.height(b.left), this.height(b.right)) + 1; 33 | a.height = Math.max(this.height(a.left), this.height(a.right)) + 1; 34 | return a; 35 | }; 36 | 37 | //left rotation 38 | this.leftRotation = (a) => { 39 | let b = a.right; 40 | let c = b.left; 41 | b.left = a; 42 | a.right = c; 43 | a.height = Math.max(this.height(a.left), this.height(a.right)) + 1; 44 | b.height = Math.max(this.height(b.left), this.height(b.right)) + 1; 45 | return b; 46 | }; 47 | 48 | // get the balance factor of node 49 | this.balanceFactorGetter = (N) => { 50 | if (N == null) { 51 | return 0; 52 | } 53 | 54 | return this.height(N.left) - this.height(N.right); 55 | }; 56 | 57 | 58 | // function to help in node insertion 59 | const nodeInserter = (node, number) => { 60 | 61 | // find the position and insert node 62 | if (node === null) { 63 | return (new Node(number)); 64 | } 65 | 66 | if (number < node.value) { 67 | node.left = nodeInserter(node.left, number); 68 | } else if (number > node.value) { 69 | node.right = nodeInserter(node.right, number); 70 | } else { 71 | return node; 72 | } 73 | 74 | // update the balance factor of each node 75 | node.height = 1 + Math.max(this.height(node.left), this.height(node.right)); 76 | 77 | let balanceFactor = this.balanceFactorGetter(node); 78 | 79 | //balance AVL Tree 80 | if (balanceFactor > 1) { 81 | if (number < node.left.value) { 82 | return this.rightRotation(node); 83 | } 84 | else if (number > node.left.value) { 85 | node.left = this.leftRotation(node.left); 86 | return this.rightRotation(node); 87 | } 88 | } 89 | 90 | if (balanceFactor < -1) { 91 | if (number > node.right.value) { 92 | return this.leftRotation(node); 93 | } 94 | else if (number < node.right.value) { 95 | node.right = this.rightRotation(node.right); 96 | return this.leftRotation(node); 97 | } 98 | } 99 | 100 | return node; 101 | }; 102 | 103 | // insert a node 104 | this.insertNode = (number) => { 105 | root = nodeInserter(root, number); 106 | }; 107 | 108 | //get node with minimum value 109 | this.mimumValueNode = (node) => { 110 | let current = node; 111 | while (current.left !== null) { 112 | current = current.left; 113 | } 114 | return current; 115 | }; 116 | 117 | // delete helper 118 | const nodeDeleter = (root, number) => { 119 | 120 | // find the particular node and delete it 121 | if (root == null) { 122 | return root; 123 | } 124 | if (number < root.value) { 125 | root.left = nodeDeleter(root.left, number); 126 | } 127 | else if (number > root.value) { 128 | root.right = nodeDeleter(root.right, number); 129 | } 130 | else { 131 | if ((root.left === null) || (root.right === null)) { 132 | let temp = null; 133 | if (temp == root.left) { 134 | temp = root.right; 135 | } 136 | else { 137 | temp = root.left; 138 | } 139 | 140 | if (temp == null) { 141 | temp = root; 142 | root = null; 143 | } 144 | else { 145 | root = temp; 146 | } 147 | } 148 | else { 149 | let temp = this.mimumValueNode(root.right); 150 | root.value = temp.value; 151 | root.right = nodeDeleter(root.right, temp.value); 152 | } 153 | } 154 | if (root == null) { 155 | return root; 156 | } 157 | 158 | // Update the balance factor of each node 159 | root.height = Math.max(this.height(root.left), this.height(root.right)) + 1; 160 | 161 | let balanceFactor = this.balanceFactorGetter(root); 162 | 163 | //balance AVL Tree 164 | if (balanceFactor > 1) { 165 | if (this.balanceFactorGetter(root.left) >= 0) { 166 | return this.rightRotation(root); 167 | } 168 | else { 169 | root.left = this.leftRotation(root.left); 170 | return this.rightRotation(root); 171 | } 172 | } 173 | if (balanceFactor < -1) { 174 | if (this.balanceFactorGetter(root.right) <= 0) { 175 | return this.leftRotation(root); 176 | } 177 | else { 178 | root.right = this.rightRotation(root.right); 179 | return this.leftRotation(root); 180 | } 181 | } 182 | return root; 183 | }; 184 | 185 | //node deletion 186 | this.deleteNode = (number) => { 187 | root = nodeDeleter(root, number); 188 | }; 189 | 190 | // print the tree 191 | this.printTreeOrder = () => { 192 | treeOrder(root); 193 | }; 194 | 195 | const treeOrder = (node) => { 196 | if (node) { 197 | console.log(node.value); 198 | treeOrder(node.left); 199 | treeOrder(node.right); 200 | } 201 | }; 202 | } 203 | } 204 | 205 | 206 | //test 207 | var tree = new AVLTree(); 208 | tree.insertNode(40); 209 | tree.insertNode(32); 210 | tree.insertNode(43); 211 | tree.insertNode(8); 212 | tree.insertNode(27); 213 | tree.insertNode(65); 214 | tree.insertNode(8); 215 | tree.insertNode(); 216 | tree.printTreeOrder(); 217 | tree.deleteNode(13); 218 | //console.log("After Deleting"); 219 | tree.printTreeOrder(); 220 | -------------------------------------------------------------------------------- /Search/Dart/binary_search/pubspec.lock: -------------------------------------------------------------------------------- 1 | # Generated by pub 2 | # See https://dart.dev/tools/pub/glossary#lockfile 3 | packages: 4 | _fe_analyzer_shared: 5 | dependency: transitive 6 | description: 7 | name: _fe_analyzer_shared 8 | url: "https://pub.dartlang.org" 9 | source: hosted 10 | version: "50.0.0" 11 | analyzer: 12 | dependency: transitive 13 | description: 14 | name: analyzer 15 | url: "https://pub.dartlang.org" 16 | source: hosted 17 | version: "5.2.0" 18 | args: 19 | dependency: transitive 20 | description: 21 | name: args 22 | url: "https://pub.dartlang.org" 23 | source: hosted 24 | version: "2.3.1" 25 | async: 26 | dependency: transitive 27 | description: 28 | name: async 29 | url: "https://pub.dartlang.org" 30 | source: hosted 31 | version: "2.10.0" 32 | boolean_selector: 33 | dependency: transitive 34 | description: 35 | name: boolean_selector 36 | url: "https://pub.dartlang.org" 37 | source: hosted 38 | version: "2.1.0" 39 | collection: 40 | dependency: transitive 41 | description: 42 | name: collection 43 | url: "https://pub.dartlang.org" 44 | source: hosted 45 | version: "1.17.0" 46 | convert: 47 | dependency: transitive 48 | description: 49 | name: convert 50 | url: "https://pub.dartlang.org" 51 | source: hosted 52 | version: "3.1.1" 53 | coverage: 54 | dependency: transitive 55 | description: 56 | name: coverage 57 | url: "https://pub.dartlang.org" 58 | source: hosted 59 | version: "1.6.1" 60 | crypto: 61 | dependency: transitive 62 | description: 63 | name: crypto 64 | url: "https://pub.dartlang.org" 65 | source: hosted 66 | version: "3.0.2" 67 | file: 68 | dependency: transitive 69 | description: 70 | name: file 71 | url: "https://pub.dartlang.org" 72 | source: hosted 73 | version: "6.1.4" 74 | frontend_server_client: 75 | dependency: transitive 76 | description: 77 | name: frontend_server_client 78 | url: "https://pub.dartlang.org" 79 | source: hosted 80 | version: "3.1.0" 81 | glob: 82 | dependency: transitive 83 | description: 84 | name: glob 85 | url: "https://pub.dartlang.org" 86 | source: hosted 87 | version: "2.1.0" 88 | http_multi_server: 89 | dependency: transitive 90 | description: 91 | name: http_multi_server 92 | url: "https://pub.dartlang.org" 93 | source: hosted 94 | version: "3.2.1" 95 | http_parser: 96 | dependency: transitive 97 | description: 98 | name: http_parser 99 | url: "https://pub.dartlang.org" 100 | source: hosted 101 | version: "4.0.2" 102 | io: 103 | dependency: transitive 104 | description: 105 | name: io 106 | url: "https://pub.dartlang.org" 107 | source: hosted 108 | version: "1.0.3" 109 | js: 110 | dependency: transitive 111 | description: 112 | name: js 113 | url: "https://pub.dartlang.org" 114 | source: hosted 115 | version: "0.6.5" 116 | lints: 117 | dependency: "direct dev" 118 | description: 119 | name: lints 120 | url: "https://pub.dartlang.org" 121 | source: hosted 122 | version: "2.0.1" 123 | logging: 124 | dependency: transitive 125 | description: 126 | name: logging 127 | url: "https://pub.dartlang.org" 128 | source: hosted 129 | version: "1.1.0" 130 | matcher: 131 | dependency: transitive 132 | description: 133 | name: matcher 134 | url: "https://pub.dartlang.org" 135 | source: hosted 136 | version: "0.12.12" 137 | meta: 138 | dependency: transitive 139 | description: 140 | name: meta 141 | url: "https://pub.dartlang.org" 142 | source: hosted 143 | version: "1.8.0" 144 | mime: 145 | dependency: transitive 146 | description: 147 | name: mime 148 | url: "https://pub.dartlang.org" 149 | source: hosted 150 | version: "1.0.2" 151 | node_preamble: 152 | dependency: transitive 153 | description: 154 | name: node_preamble 155 | url: "https://pub.dartlang.org" 156 | source: hosted 157 | version: "2.0.1" 158 | package_config: 159 | dependency: transitive 160 | description: 161 | name: package_config 162 | url: "https://pub.dartlang.org" 163 | source: hosted 164 | version: "2.1.0" 165 | path: 166 | dependency: transitive 167 | description: 168 | name: path 169 | url: "https://pub.dartlang.org" 170 | source: hosted 171 | version: "1.8.2" 172 | pool: 173 | dependency: transitive 174 | description: 175 | name: pool 176 | url: "https://pub.dartlang.org" 177 | source: hosted 178 | version: "1.5.1" 179 | pub_semver: 180 | dependency: transitive 181 | description: 182 | name: pub_semver 183 | url: "https://pub.dartlang.org" 184 | source: hosted 185 | version: "2.1.2" 186 | shelf: 187 | dependency: transitive 188 | description: 189 | name: shelf 190 | url: "https://pub.dartlang.org" 191 | source: hosted 192 | version: "1.4.0" 193 | shelf_packages_handler: 194 | dependency: transitive 195 | description: 196 | name: shelf_packages_handler 197 | url: "https://pub.dartlang.org" 198 | source: hosted 199 | version: "3.0.1" 200 | shelf_static: 201 | dependency: transitive 202 | description: 203 | name: shelf_static 204 | url: "https://pub.dartlang.org" 205 | source: hosted 206 | version: "1.1.1" 207 | shelf_web_socket: 208 | dependency: transitive 209 | description: 210 | name: shelf_web_socket 211 | url: "https://pub.dartlang.org" 212 | source: hosted 213 | version: "1.0.2" 214 | source_map_stack_trace: 215 | dependency: transitive 216 | description: 217 | name: source_map_stack_trace 218 | url: "https://pub.dartlang.org" 219 | source: hosted 220 | version: "2.1.1" 221 | source_maps: 222 | dependency: transitive 223 | description: 224 | name: source_maps 225 | url: "https://pub.dartlang.org" 226 | source: hosted 227 | version: "0.10.11" 228 | source_span: 229 | dependency: transitive 230 | description: 231 | name: source_span 232 | url: "https://pub.dartlang.org" 233 | source: hosted 234 | version: "1.9.1" 235 | stack_trace: 236 | dependency: transitive 237 | description: 238 | name: stack_trace 239 | url: "https://pub.dartlang.org" 240 | source: hosted 241 | version: "1.11.0" 242 | stream_channel: 243 | dependency: transitive 244 | description: 245 | name: stream_channel 246 | url: "https://pub.dartlang.org" 247 | source: hosted 248 | version: "2.1.1" 249 | string_scanner: 250 | dependency: transitive 251 | description: 252 | name: string_scanner 253 | url: "https://pub.dartlang.org" 254 | source: hosted 255 | version: "1.1.1" 256 | term_glyph: 257 | dependency: transitive 258 | description: 259 | name: term_glyph 260 | url: "https://pub.dartlang.org" 261 | source: hosted 262 | version: "1.2.1" 263 | test: 264 | dependency: "direct dev" 265 | description: 266 | name: test 267 | url: "https://pub.dartlang.org" 268 | source: hosted 269 | version: "1.21.6" 270 | test_api: 271 | dependency: transitive 272 | description: 273 | name: test_api 274 | url: "https://pub.dartlang.org" 275 | source: hosted 276 | version: "0.4.14" 277 | test_core: 278 | dependency: transitive 279 | description: 280 | name: test_core 281 | url: "https://pub.dartlang.org" 282 | source: hosted 283 | version: "0.4.18" 284 | typed_data: 285 | dependency: transitive 286 | description: 287 | name: typed_data 288 | url: "https://pub.dartlang.org" 289 | source: hosted 290 | version: "1.3.1" 291 | vm_service: 292 | dependency: transitive 293 | description: 294 | name: vm_service 295 | url: "https://pub.dartlang.org" 296 | source: hosted 297 | version: "9.4.0" 298 | watcher: 299 | dependency: transitive 300 | description: 301 | name: watcher 302 | url: "https://pub.dartlang.org" 303 | source: hosted 304 | version: "1.0.2" 305 | web_socket_channel: 306 | dependency: transitive 307 | description: 308 | name: web_socket_channel 309 | url: "https://pub.dartlang.org" 310 | source: hosted 311 | version: "2.2.0" 312 | webkit_inspection_protocol: 313 | dependency: transitive 314 | description: 315 | name: webkit_inspection_protocol 316 | url: "https://pub.dartlang.org" 317 | source: hosted 318 | version: "1.2.0" 319 | yaml: 320 | dependency: transitive 321 | description: 322 | name: yaml 323 | url: "https://pub.dartlang.org" 324 | source: hosted 325 | version: "3.1.1" 326 | sdks: 327 | dart: ">=2.18.2 <3.0.0" 328 | -------------------------------------------------------------------------------- /Search/dart/linear_search/pubspec.lock: -------------------------------------------------------------------------------- 1 | # Generated by pub 2 | # See https://dart.dev/tools/pub/glossary#lockfile 3 | packages: 4 | _fe_analyzer_shared: 5 | dependency: transitive 6 | description: 7 | name: _fe_analyzer_shared 8 | url: "https://pub.dartlang.org" 9 | source: hosted 10 | version: "49.0.0" 11 | analyzer: 12 | dependency: transitive 13 | description: 14 | name: analyzer 15 | url: "https://pub.dartlang.org" 16 | source: hosted 17 | version: "5.1.0" 18 | args: 19 | dependency: transitive 20 | description: 21 | name: args 22 | url: "https://pub.dartlang.org" 23 | source: hosted 24 | version: "2.3.1" 25 | async: 26 | dependency: transitive 27 | description: 28 | name: async 29 | url: "https://pub.dartlang.org" 30 | source: hosted 31 | version: "2.9.0" 32 | boolean_selector: 33 | dependency: transitive 34 | description: 35 | name: boolean_selector 36 | url: "https://pub.dartlang.org" 37 | source: hosted 38 | version: "2.1.0" 39 | collection: 40 | dependency: transitive 41 | description: 42 | name: collection 43 | url: "https://pub.dartlang.org" 44 | source: hosted 45 | version: "1.17.0" 46 | convert: 47 | dependency: transitive 48 | description: 49 | name: convert 50 | url: "https://pub.dartlang.org" 51 | source: hosted 52 | version: "3.1.1" 53 | coverage: 54 | dependency: transitive 55 | description: 56 | name: coverage 57 | url: "https://pub.dartlang.org" 58 | source: hosted 59 | version: "1.6.1" 60 | crypto: 61 | dependency: transitive 62 | description: 63 | name: crypto 64 | url: "https://pub.dartlang.org" 65 | source: hosted 66 | version: "3.0.2" 67 | file: 68 | dependency: transitive 69 | description: 70 | name: file 71 | url: "https://pub.dartlang.org" 72 | source: hosted 73 | version: "6.1.4" 74 | frontend_server_client: 75 | dependency: transitive 76 | description: 77 | name: frontend_server_client 78 | url: "https://pub.dartlang.org" 79 | source: hosted 80 | version: "3.0.0" 81 | glob: 82 | dependency: transitive 83 | description: 84 | name: glob 85 | url: "https://pub.dartlang.org" 86 | source: hosted 87 | version: "2.1.0" 88 | http_multi_server: 89 | dependency: transitive 90 | description: 91 | name: http_multi_server 92 | url: "https://pub.dartlang.org" 93 | source: hosted 94 | version: "3.2.1" 95 | http_parser: 96 | dependency: transitive 97 | description: 98 | name: http_parser 99 | url: "https://pub.dartlang.org" 100 | source: hosted 101 | version: "4.0.2" 102 | io: 103 | dependency: transitive 104 | description: 105 | name: io 106 | url: "https://pub.dartlang.org" 107 | source: hosted 108 | version: "1.0.3" 109 | js: 110 | dependency: transitive 111 | description: 112 | name: js 113 | url: "https://pub.dartlang.org" 114 | source: hosted 115 | version: "0.6.4" 116 | lints: 117 | dependency: "direct dev" 118 | description: 119 | name: lints 120 | url: "https://pub.dartlang.org" 121 | source: hosted 122 | version: "2.0.0" 123 | logging: 124 | dependency: transitive 125 | description: 126 | name: logging 127 | url: "https://pub.dartlang.org" 128 | source: hosted 129 | version: "1.1.0" 130 | matcher: 131 | dependency: transitive 132 | description: 133 | name: matcher 134 | url: "https://pub.dartlang.org" 135 | source: hosted 136 | version: "0.12.12" 137 | meta: 138 | dependency: transitive 139 | description: 140 | name: meta 141 | url: "https://pub.dartlang.org" 142 | source: hosted 143 | version: "1.8.0" 144 | mime: 145 | dependency: transitive 146 | description: 147 | name: mime 148 | url: "https://pub.dartlang.org" 149 | source: hosted 150 | version: "1.0.2" 151 | node_preamble: 152 | dependency: transitive 153 | description: 154 | name: node_preamble 155 | url: "https://pub.dartlang.org" 156 | source: hosted 157 | version: "2.0.1" 158 | package_config: 159 | dependency: transitive 160 | description: 161 | name: package_config 162 | url: "https://pub.dartlang.org" 163 | source: hosted 164 | version: "2.1.0" 165 | path: 166 | dependency: transitive 167 | description: 168 | name: path 169 | url: "https://pub.dartlang.org" 170 | source: hosted 171 | version: "1.8.2" 172 | pool: 173 | dependency: transitive 174 | description: 175 | name: pool 176 | url: "https://pub.dartlang.org" 177 | source: hosted 178 | version: "1.5.1" 179 | pub_semver: 180 | dependency: transitive 181 | description: 182 | name: pub_semver 183 | url: "https://pub.dartlang.org" 184 | source: hosted 185 | version: "2.1.2" 186 | shelf: 187 | dependency: transitive 188 | description: 189 | name: shelf 190 | url: "https://pub.dartlang.org" 191 | source: hosted 192 | version: "1.4.0" 193 | shelf_packages_handler: 194 | dependency: transitive 195 | description: 196 | name: shelf_packages_handler 197 | url: "https://pub.dartlang.org" 198 | source: hosted 199 | version: "3.0.1" 200 | shelf_static: 201 | dependency: transitive 202 | description: 203 | name: shelf_static 204 | url: "https://pub.dartlang.org" 205 | source: hosted 206 | version: "1.1.1" 207 | shelf_web_socket: 208 | dependency: transitive 209 | description: 210 | name: shelf_web_socket 211 | url: "https://pub.dartlang.org" 212 | source: hosted 213 | version: "1.0.2" 214 | source_map_stack_trace: 215 | dependency: transitive 216 | description: 217 | name: source_map_stack_trace 218 | url: "https://pub.dartlang.org" 219 | source: hosted 220 | version: "2.1.0" 221 | source_maps: 222 | dependency: transitive 223 | description: 224 | name: source_maps 225 | url: "https://pub.dartlang.org" 226 | source: hosted 227 | version: "0.10.10" 228 | source_span: 229 | dependency: transitive 230 | description: 231 | name: source_span 232 | url: "https://pub.dartlang.org" 233 | source: hosted 234 | version: "1.9.1" 235 | stack_trace: 236 | dependency: transitive 237 | description: 238 | name: stack_trace 239 | url: "https://pub.dartlang.org" 240 | source: hosted 241 | version: "1.10.0" 242 | stream_channel: 243 | dependency: transitive 244 | description: 245 | name: stream_channel 246 | url: "https://pub.dartlang.org" 247 | source: hosted 248 | version: "2.1.1" 249 | string_scanner: 250 | dependency: transitive 251 | description: 252 | name: string_scanner 253 | url: "https://pub.dartlang.org" 254 | source: hosted 255 | version: "1.1.1" 256 | term_glyph: 257 | dependency: transitive 258 | description: 259 | name: term_glyph 260 | url: "https://pub.dartlang.org" 261 | source: hosted 262 | version: "1.2.1" 263 | test: 264 | dependency: "direct dev" 265 | description: 266 | name: test 267 | url: "https://pub.dartlang.org" 268 | source: hosted 269 | version: "1.21.6" 270 | test_api: 271 | dependency: transitive 272 | description: 273 | name: test_api 274 | url: "https://pub.dartlang.org" 275 | source: hosted 276 | version: "0.4.14" 277 | test_core: 278 | dependency: transitive 279 | description: 280 | name: test_core 281 | url: "https://pub.dartlang.org" 282 | source: hosted 283 | version: "0.4.18" 284 | typed_data: 285 | dependency: transitive 286 | description: 287 | name: typed_data 288 | url: "https://pub.dartlang.org" 289 | source: hosted 290 | version: "1.3.1" 291 | vm_service: 292 | dependency: transitive 293 | description: 294 | name: vm_service 295 | url: "https://pub.dartlang.org" 296 | source: hosted 297 | version: "9.4.0" 298 | watcher: 299 | dependency: transitive 300 | description: 301 | name: watcher 302 | url: "https://pub.dartlang.org" 303 | source: hosted 304 | version: "1.0.2" 305 | web_socket_channel: 306 | dependency: transitive 307 | description: 308 | name: web_socket_channel 309 | url: "https://pub.dartlang.org" 310 | source: hosted 311 | version: "2.2.0" 312 | webkit_inspection_protocol: 313 | dependency: transitive 314 | description: 315 | name: webkit_inspection_protocol 316 | url: "https://pub.dartlang.org" 317 | source: hosted 318 | version: "1.2.0" 319 | yaml: 320 | dependency: transitive 321 | description: 322 | name: yaml 323 | url: "https://pub.dartlang.org" 324 | source: hosted 325 | version: "3.1.1" 326 | sdks: 327 | dart: ">=2.18.2 <3.0.0" 328 | -------------------------------------------------------------------------------- /HashMap/dart/count_occurance_of_a_word/pubspec.lock: -------------------------------------------------------------------------------- 1 | # Generated by pub 2 | # See https://dart.dev/tools/pub/glossary#lockfile 3 | packages: 4 | _fe_analyzer_shared: 5 | dependency: transitive 6 | description: 7 | name: _fe_analyzer_shared 8 | url: "https://pub.dartlang.org" 9 | source: hosted 10 | version: "49.0.0" 11 | analyzer: 12 | dependency: transitive 13 | description: 14 | name: analyzer 15 | url: "https://pub.dartlang.org" 16 | source: hosted 17 | version: "5.1.0" 18 | args: 19 | dependency: transitive 20 | description: 21 | name: args 22 | url: "https://pub.dartlang.org" 23 | source: hosted 24 | version: "2.3.1" 25 | async: 26 | dependency: transitive 27 | description: 28 | name: async 29 | url: "https://pub.dartlang.org" 30 | source: hosted 31 | version: "2.9.0" 32 | boolean_selector: 33 | dependency: transitive 34 | description: 35 | name: boolean_selector 36 | url: "https://pub.dartlang.org" 37 | source: hosted 38 | version: "2.1.0" 39 | collection: 40 | dependency: transitive 41 | description: 42 | name: collection 43 | url: "https://pub.dartlang.org" 44 | source: hosted 45 | version: "1.17.0" 46 | convert: 47 | dependency: transitive 48 | description: 49 | name: convert 50 | url: "https://pub.dartlang.org" 51 | source: hosted 52 | version: "3.1.1" 53 | coverage: 54 | dependency: transitive 55 | description: 56 | name: coverage 57 | url: "https://pub.dartlang.org" 58 | source: hosted 59 | version: "1.6.1" 60 | crypto: 61 | dependency: transitive 62 | description: 63 | name: crypto 64 | url: "https://pub.dartlang.org" 65 | source: hosted 66 | version: "3.0.2" 67 | file: 68 | dependency: transitive 69 | description: 70 | name: file 71 | url: "https://pub.dartlang.org" 72 | source: hosted 73 | version: "6.1.4" 74 | frontend_server_client: 75 | dependency: transitive 76 | description: 77 | name: frontend_server_client 78 | url: "https://pub.dartlang.org" 79 | source: hosted 80 | version: "3.0.0" 81 | glob: 82 | dependency: transitive 83 | description: 84 | name: glob 85 | url: "https://pub.dartlang.org" 86 | source: hosted 87 | version: "2.1.0" 88 | http_multi_server: 89 | dependency: transitive 90 | description: 91 | name: http_multi_server 92 | url: "https://pub.dartlang.org" 93 | source: hosted 94 | version: "3.2.1" 95 | http_parser: 96 | dependency: transitive 97 | description: 98 | name: http_parser 99 | url: "https://pub.dartlang.org" 100 | source: hosted 101 | version: "4.0.2" 102 | io: 103 | dependency: transitive 104 | description: 105 | name: io 106 | url: "https://pub.dartlang.org" 107 | source: hosted 108 | version: "1.0.3" 109 | js: 110 | dependency: transitive 111 | description: 112 | name: js 113 | url: "https://pub.dartlang.org" 114 | source: hosted 115 | version: "0.6.4" 116 | lints: 117 | dependency: "direct dev" 118 | description: 119 | name: lints 120 | url: "https://pub.dartlang.org" 121 | source: hosted 122 | version: "2.0.0" 123 | logging: 124 | dependency: transitive 125 | description: 126 | name: logging 127 | url: "https://pub.dartlang.org" 128 | source: hosted 129 | version: "1.1.0" 130 | matcher: 131 | dependency: transitive 132 | description: 133 | name: matcher 134 | url: "https://pub.dartlang.org" 135 | source: hosted 136 | version: "0.12.12" 137 | meta: 138 | dependency: transitive 139 | description: 140 | name: meta 141 | url: "https://pub.dartlang.org" 142 | source: hosted 143 | version: "1.8.0" 144 | mime: 145 | dependency: transitive 146 | description: 147 | name: mime 148 | url: "https://pub.dartlang.org" 149 | source: hosted 150 | version: "1.0.2" 151 | node_preamble: 152 | dependency: transitive 153 | description: 154 | name: node_preamble 155 | url: "https://pub.dartlang.org" 156 | source: hosted 157 | version: "2.0.1" 158 | package_config: 159 | dependency: transitive 160 | description: 161 | name: package_config 162 | url: "https://pub.dartlang.org" 163 | source: hosted 164 | version: "2.1.0" 165 | path: 166 | dependency: transitive 167 | description: 168 | name: path 169 | url: "https://pub.dartlang.org" 170 | source: hosted 171 | version: "1.8.2" 172 | pool: 173 | dependency: transitive 174 | description: 175 | name: pool 176 | url: "https://pub.dartlang.org" 177 | source: hosted 178 | version: "1.5.1" 179 | pub_semver: 180 | dependency: transitive 181 | description: 182 | name: pub_semver 183 | url: "https://pub.dartlang.org" 184 | source: hosted 185 | version: "2.1.2" 186 | shelf: 187 | dependency: transitive 188 | description: 189 | name: shelf 190 | url: "https://pub.dartlang.org" 191 | source: hosted 192 | version: "1.4.0" 193 | shelf_packages_handler: 194 | dependency: transitive 195 | description: 196 | name: shelf_packages_handler 197 | url: "https://pub.dartlang.org" 198 | source: hosted 199 | version: "3.0.1" 200 | shelf_static: 201 | dependency: transitive 202 | description: 203 | name: shelf_static 204 | url: "https://pub.dartlang.org" 205 | source: hosted 206 | version: "1.1.1" 207 | shelf_web_socket: 208 | dependency: transitive 209 | description: 210 | name: shelf_web_socket 211 | url: "https://pub.dartlang.org" 212 | source: hosted 213 | version: "1.0.2" 214 | source_map_stack_trace: 215 | dependency: transitive 216 | description: 217 | name: source_map_stack_trace 218 | url: "https://pub.dartlang.org" 219 | source: hosted 220 | version: "2.1.0" 221 | source_maps: 222 | dependency: transitive 223 | description: 224 | name: source_maps 225 | url: "https://pub.dartlang.org" 226 | source: hosted 227 | version: "0.10.10" 228 | source_span: 229 | dependency: transitive 230 | description: 231 | name: source_span 232 | url: "https://pub.dartlang.org" 233 | source: hosted 234 | version: "1.9.1" 235 | stack_trace: 236 | dependency: transitive 237 | description: 238 | name: stack_trace 239 | url: "https://pub.dartlang.org" 240 | source: hosted 241 | version: "1.10.0" 242 | stream_channel: 243 | dependency: transitive 244 | description: 245 | name: stream_channel 246 | url: "https://pub.dartlang.org" 247 | source: hosted 248 | version: "2.1.1" 249 | string_scanner: 250 | dependency: transitive 251 | description: 252 | name: string_scanner 253 | url: "https://pub.dartlang.org" 254 | source: hosted 255 | version: "1.1.1" 256 | term_glyph: 257 | dependency: transitive 258 | description: 259 | name: term_glyph 260 | url: "https://pub.dartlang.org" 261 | source: hosted 262 | version: "1.2.1" 263 | test: 264 | dependency: "direct dev" 265 | description: 266 | name: test 267 | url: "https://pub.dartlang.org" 268 | source: hosted 269 | version: "1.21.6" 270 | test_api: 271 | dependency: transitive 272 | description: 273 | name: test_api 274 | url: "https://pub.dartlang.org" 275 | source: hosted 276 | version: "0.4.14" 277 | test_core: 278 | dependency: transitive 279 | description: 280 | name: test_core 281 | url: "https://pub.dartlang.org" 282 | source: hosted 283 | version: "0.4.18" 284 | typed_data: 285 | dependency: transitive 286 | description: 287 | name: typed_data 288 | url: "https://pub.dartlang.org" 289 | source: hosted 290 | version: "1.3.1" 291 | vm_service: 292 | dependency: transitive 293 | description: 294 | name: vm_service 295 | url: "https://pub.dartlang.org" 296 | source: hosted 297 | version: "9.4.0" 298 | watcher: 299 | dependency: transitive 300 | description: 301 | name: watcher 302 | url: "https://pub.dartlang.org" 303 | source: hosted 304 | version: "1.0.2" 305 | web_socket_channel: 306 | dependency: transitive 307 | description: 308 | name: web_socket_channel 309 | url: "https://pub.dartlang.org" 310 | source: hosted 311 | version: "2.2.0" 312 | webkit_inspection_protocol: 313 | dependency: transitive 314 | description: 315 | name: webkit_inspection_protocol 316 | url: "https://pub.dartlang.org" 317 | source: hosted 318 | version: "1.2.0" 319 | yaml: 320 | dependency: transitive 321 | description: 322 | name: yaml 323 | url: "https://pub.dartlang.org" 324 | source: hosted 325 | version: "3.1.1" 326 | sdks: 327 | dart: ">=2.18.2 <3.0.0" 328 | --------------------------------------------------------------------------------