3 |
4 | bool array_mirror_inverse(int[], int);
5 | int main()
6 | {
7 | int n;
8 | bool f;
9 | printf("Enter the size of the array:");
10 | scanf("%d", &n);
11 | int arr[n];
12 | printf("Enter the elements:");
13 | for (int i = 0; i < n; ++i)
14 | {
15 | scanf("%d", &arr[i]);
16 | }
17 |
18 | f = array_mirror_inverse(arr, n);
19 | if (f)
20 | printf("The given array is mirror-inverse");
21 | else
22 | printf("The given array is not the mirror-inverse");
23 | }
24 |
25 | // Boolean Function which return if the array is mirror-inverse or not
26 | bool array_mirror_inverse(int arr[], int n)
27 | {
28 | bool f = true;
29 | for (int i = 0; i < n; ++i)
30 | {
31 | if (arr[arr[i]] != i)
32 | {
33 | f = false;
34 | }
35 | }
36 |
37 | return f;
38 | }
39 |
40 | /*
41 | Time Complexity: O(N)
42 |
43 | Sample Output
44 | Enter the size of the array:5
45 | Enter the elements:1 0 2 4 3
46 | The given array is mirror-inverse
47 | */
48 |
49 |
--------------------------------------------------------------------------------
/C/cp/README.md:
--------------------------------------------------------------------------------
1 |
2 | 
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 | # Codes in the C language
11 |
12 | ## Competitive Programming
13 |
14 | [Kadane's Algorithm for max sum subArray](cp/Kadane's_Alogorithm.c)
15 |
--------------------------------------------------------------------------------
/C/cp/bulbSwitch.c:
--------------------------------------------------------------------------------
1 | /*
2 | Bulb Swither problem
3 |
4 | There are n bulbs that are initially off. You first turn on all the bulbs, then you turn off every second bulb.
5 | On the third round, you toggle every third bulb (turning on if it's off or turning off if it's on). For the ith round, you toggle every i bulb.
6 | For the nth round, you only toggle the last bulb.
7 |
8 | Return the number of bulbs that are on after n rounds.
9 |
10 | Link to problem: https://leetcode.com/problems/bulb-switcher/
11 | */
12 |
13 | #include
14 |
15 | int bulbSwitch(int n) {
16 | int bulb = 1, ans = 0;
17 | //A bulb is ON if it is toggled odd times
18 | while (bulb * bulb <= n) {
19 | ans++;
20 | bulb++;
21 | }
22 | return ans;
23 | }
24 |
25 | int main() {
26 | int n;
27 | printf("Enter the no. of bulbs: \n");
28 | scanf("%d", &n);
29 | printf("%d \n", bulbSwitch(n));
30 | return 0;
31 | }
32 |
33 | /*
34 | Sample Input:
35 | Enter the no. of bulbs:
36 | 4
37 | Output:
38 | 2
39 | Time complexity: O(n)
40 | Space complexity: O(1)
41 | */
42 |
--------------------------------------------------------------------------------
/C/cp/possible_code_recursion.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #define MAX 10
4 |
5 | void decode(char *code, char *ans, int i, int j) {
6 | // i is index of code array
7 | // j is index of ans array
8 | if (i >= strlen(code)) {
9 | printf("%s ", ans);
10 | return;
11 | }
12 | // getting all possible sequences recursives
13 | if (code[i + 1] != '0') {
14 | ans[j] = (code[i] - '0' + 96);
15 | decode(code, ans, i + 1, j + 1);
16 | }
17 | // converting a num to char
18 | if (code[i + 1]) {
19 | int result = (code[i] - '0') * 10 + (code[i + 1] - '0') - 1;
20 | if (result <= 25) {
21 | ans[j] = result + 97;
22 | ans[j + 1] = '\0';
23 | decode(code, ans, i + 2, j + 1);
24 | }
25 | }
26 | }
27 | int main() {
28 | // creating a null string
29 | char ans[50] = { '\0' };
30 | // input string
31 | char code[MAX];
32 | printf("Enter the code: ");
33 | scanf("%s", code);
34 | decode(code, ans, 0, 0);
35 | }
36 |
37 | /*
38 | OUTPUT:
39 | Enter the code: 1123
40 | aabc aaw alc kbc kw
41 | Time Complexity : O(n)
42 | Space complexity : O(n)
43 | */
44 |
--------------------------------------------------------------------------------
/C/cp/sum_of_triplet.c:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HarshCasper/NeoAlgo/4f1e5bdd6d9d899fa354de94740e0aecf5ecd2be/C/cp/sum_of_triplet.c
--------------------------------------------------------------------------------
/C/cryptography/README.md:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HarshCasper/NeoAlgo/4f1e5bdd6d9d899fa354de94740e0aecf5ecd2be/C/cryptography/README.md
--------------------------------------------------------------------------------
/C/dp/README.md:
--------------------------------------------------------------------------------
1 | # Dynamic Programming
2 |
3 | - [Fibonacci Nth term](dp/Fibonacci.c)
4 |
--------------------------------------------------------------------------------
/C/dp/Unique_BST.c:
--------------------------------------------------------------------------------
1 | // Unique BSTs using DP
2 | // Given n, how many structurally unique BST's that store values 1 ... n?
3 |
4 | #include
5 |
6 | int max(int num1, int num2) {
7 | return (num1 > num2) ? num1 : num2;
8 | }
9 |
10 | int uniqueBST(int n) {
11 | int count[n + 1];
12 | for (int i = 0; i < n + 1; i++)
13 | count[i] = 0;
14 | // for each 'i' number of nodes
15 | for (int i = 1; i <= n; ++i) {
16 | for (int j = 0; j < i; ++j) {
17 | // No. of trees if j is a root
18 | count[i] += max(count[j], 1) * max(count[i - j - 1], 1);
19 | }
20 | }
21 | return count[n];
22 | }
23 |
24 | int main() {
25 | int n;
26 | printf("Enter the number: \n");
27 | scanf("%d", &n);
28 | int num = uniqueBST(n);
29 | printf("Number of Unique BSTs %d is: \n", num);
30 | return 0;
31 | }
32 |
33 | /*
34 | input:
35 | Enter value:3
36 | output:
37 | Number of Unique BSTs 5
38 | Time complexity : O(n^2)
39 | */
40 |
--------------------------------------------------------------------------------
/C/ds/FenwickTree.c:
--------------------------------------------------------------------------------
1 | **Fenwick Tree**
2 |
3 | #include
4 |
5 | int FWtree[100] = {0};
6 | int SIZE;
7 |
8 | int get_sum(int i)
9 | {
10 | int sum = FWtree[i];
11 | while(i)
12 | {
13 | i -= (i & (-i));
14 | sum += FWtree[i];
15 | }
16 | return sum;
17 | }
18 |
19 | void add(int i, int value)
20 | {
21 | while(i < SIZE)
22 | {
23 | FWtree[i] += value;
24 | i += (i & (-i));
25 | }
26 | }
27 |
28 | void init_fw_tree(int my_array[], int start, int end)
29 | {
30 | SIZE = end-start+2;
31 | for(int i = 1; i <= end-start+2; i++)
32 | {
33 | add(i, my_array[ start+i-1 ]);
34 | }
35 | }
36 |
37 | int main()
38 | {
39 | int my_array[] = {1, 3, 2, 4, 5 ,9, 6, 5 ,0, 3, 4, 3, 2, 2};
40 | init_fw_tree(my_array, 0, 13);
41 |
42 | //get sum of all the numbers in the array
43 | printf("Sum of all numbers in the array is = %d\n",get_sum(14));
44 |
45 | // update 5th index with value 9
46 | add(5,9);
47 | printf("New sum after updating 5th index with value 8 is = %d\n",get_sum(14));
48 |
49 | return 0;
50 | }
51 |
52 |
--------------------------------------------------------------------------------
/C/ds/README.md:
--------------------------------------------------------------------------------
1 | a
2 |
--------------------------------------------------------------------------------
/C/graphs/README.md:
--------------------------------------------------------------------------------
1 | a
2 |
--------------------------------------------------------------------------------
/C/math/GCD_In_C.c:
--------------------------------------------------------------------------------
1 | /*Euclidean Algorithm for GCD
2 | GCD of two numbers is the largest number that divides both of them
3 | */
4 | #include
5 |
6 | int Euclid_GCD(int, int);
7 | int main()
8 | {
9 | int num1, num2, gcd;
10 | printf("Enter the two numbers:");
11 | scanf("%d %d", &num1, &num2);
12 | gcd = Euclid_GCD(num1, num2);
13 | printf("GCD=%d", gcd);
14 | return 0;
15 | }
16 |
17 | // Recursive function to show Euclidean Algorithm
18 | int Euclid_GCD(int num1, int num2)
19 | {
20 | if (num2 == 0)
21 | return num1;
22 | else
23 | return (Euclid_GCD(num2, num1 % num2));
24 | }
25 |
26 | /*
27 | Sample Output
28 | Enter the two numbers:77 121
29 | GCD=11
30 |
31 | Complexities
32 | Time Complexity:O(logN)
33 | Space Complexity:O(1)
34 | */
35 |
36 |
--------------------------------------------------------------------------------
/C/math/Magic_Number.c:
--------------------------------------------------------------------------------
1 | // A number is said to be Magic Number, when the recursive sum of the digits is 1.
2 | #include
3 |
4 | int calsum(int);
5 | int magic_num(int);
6 | int main()
7 | {
8 | int num;
9 | printf("Enter the number to be checked:");
10 | scanf("%d", &num);
11 | if (magic_num(num) == 1)
12 | printf("%d is a magic number", num);
13 | else
14 | printf("%d is not a magic number", num);
15 | return 0;
16 | }
17 |
18 | // Function to check if the number is a magic number or not
19 | int magic_num(int num)
20 | {
21 | int sum;
22 | while (num > 9)
23 | {
24 | sum = calsum(num);
25 | num = sum;
26 | }
27 |
28 | return num;
29 | }
30 |
31 | // Function to calculate the sum of digits
32 | int calsum(int num)
33 | {
34 | int sum = 0, rem;
35 | while (num > 0)
36 | {
37 | rem = num % 10;
38 | sum = sum + rem;
39 | num = num / 10;
40 | }
41 |
42 | return sum;
43 | }
44 |
45 | /*
46 | Sample Output
47 | Enter the number to be checked:1729
48 | 1729 is a magic number
49 |
50 | Complexities
51 | Time Complexity:O(n)
52 | Space Complexity:O(n)
53 | */
54 |
55 |
--------------------------------------------------------------------------------
/C/math/Neon_number.c:
--------------------------------------------------------------------------------
1 | /* C Program to check whether a number is Neon or not.
2 | A neon number is a number where the sum of digits of square of the number is equal to the number.
3 | */
4 |
5 | #include
6 | #include
7 | void neon(int n)
8 | {
9 | int i, sum = 0, t = 1;
10 | t = pow(n, 2);
11 | while (t != 0)
12 | {
13 | sum = sum + (t % 10);
14 | t = t / 10;
15 | }
16 | if (sum == n)
17 | {
18 | printf("Neon number.\n");
19 | }
20 | else
21 | {
22 | printf("Not a neon number\n");
23 | }
24 | }
25 | int main()
26 | {
27 | int n;
28 | printf("Enter a number ");
29 | scanf("%d", &n);
30 | neon(n);
31 | }
32 | /* Sample Input/output
33 | Example 1-
34 | Enter a number 9
35 | Neon number.
36 | Example 2-
37 | Enter a number 144
38 | Not a neon number
39 |
40 | Space Complexity O(1)
41 | Time Complexity O(log(n))
42 | */
43 |
--------------------------------------------------------------------------------
/C/math/Quadratic_Equation.c:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HarshCasper/NeoAlgo/4f1e5bdd6d9d899fa354de94740e0aecf5ecd2be/C/math/Quadratic_Equation.c
--------------------------------------------------------------------------------
/C/math/README.md:
--------------------------------------------------------------------------------
1 | a
2 |
--------------------------------------------------------------------------------
/C/math/armstrong_number.c:
--------------------------------------------------------------------------------
1 | // C Program to check whether a number is Armstrong or not
2 |
3 | #include
4 | #include
5 |
6 | void ArmstrongNumber(int n){
7 | int num=n, rem, sum=0;
8 |
9 | // Counting number of digits
10 | int digits = (int) log10(num) + 1;
11 |
12 | while(num > 0)
13 | {
14 | rem = num % 10;
15 | sum = sum + pow(rem,digits);
16 | num = num / 10;
17 | }
18 |
19 | if(n==sum)
20 | printf("%d is an Armstrong number.",n);
21 | else
22 | printf("%d is not an Armstrong number.",n);
23 | }
24 |
25 | int main(){
26 | int num;
27 |
28 | printf("Enter the number: ");
29 | scanf("%d",&num);
30 |
31 | ArmstrongNumber(num);
32 |
33 | return 0;
34 | }
35 |
36 | /*
37 | Sample input/output:
38 |
39 | Example 1:
40 | Enter the number: 153
41 | 153 is an Armstrong number.
42 |
43 | Example 2:
44 | Enter the number: 1094
45 | 1094 is not an Armstrong number.
46 |
47 | Time Complexity= O(log(n))
48 | Space Complexity= O(1)
49 | */
50 |
--------------------------------------------------------------------------------
/C/math/automorphic_no.c:
--------------------------------------------------------------------------------
1 | /*
2 | C program to check whether the number is automorphic or not.
3 | Automorphic number is a number whose square ends with the original number itself
4 | */
5 | #include
6 |
7 | int automorphic_num(int);
8 | int main()
9 | {
10 | int n, l;
11 | printf("Enter the number to check:\n");
12 | scanf("%d", &n);
13 | l = automorphic_num(n);
14 | if (l == n)
15 | printf("\nAUTOMORPHIC NUMBER !");
16 | else
17 | printf("\nNOT AUTOMORPHIC NUMBER !");
18 | return 0;
19 | }
20 |
21 | // Function to check if the number is automorphic or not
22 | int automorphic_num(int n)
23 | {
24 | int s, temp, l;
25 | temp = n;
26 | s = n * n;
27 | int flag = 1;
28 | while (n != 0)
29 | {
30 | flag = flag * 10;
31 | n = n / 10;
32 | }
33 |
34 | l = s % flag;
35 | return l;
36 | }
37 |
38 | /*
39 | Sample Input-Output:1
40 | Enter the number to check:
41 | 7
42 | NOT AUTOMORPHIC NUMBER !
43 |
44 | Sample Input-Output:2
45 | Enter the number to check:
46 | 5
47 | AUTOMORPHIC NUMBER !
48 |
49 | Time Complexity: O(n)
50 | */
51 |
52 |
--------------------------------------------------------------------------------
/C/math/binary_to_decimal.c:
--------------------------------------------------------------------------------
1 | /*
2 | AIM - To take binary number from the user
3 | and convert it into binary number.
4 | */
5 | #include
6 | #include
7 |
8 | /*Function decleration*/
9 | int BinarytoDecimal (char s[]);
10 |
11 | int main()
12 | {
13 | char temp[100];
14 | printf("Enter the binary number : ");
15 | gets(temp);
16 | printf("Decimal equivalent = %d",BinarytoDecimal(temp));
17 | return 0;
18 | }
19 | /*Function to convert binary to decimal*/
20 | int BinarytoDecimal (char temp[])
21 | {
22 | int i,decimal=0;
23 | for(i=0;temp[i];i++)
24 | {
25 | if(temp[i]=='0')
26 | decimal=decimal*2+0;
27 | else
28 | decimal=decimal*2+1;
29 | }
30 | return(decimal);
31 | }
32 |
33 | /*
34 |
35 | Sample Input/Output:
36 |
37 | Enter the binary number : 1111
38 | Decimal equivalent = 15
39 |
40 |
41 | Time Complexity : O(n)
42 | Space Complexity : O(n)
43 |
44 | */
45 |
--------------------------------------------------------------------------------
/C/math/factorial.c:
--------------------------------------------------------------------------------
1 | // C Program to find the Factorial of a number
2 | #include
3 |
4 | long long unsigned int factorial(int num)
5 | {
6 | if (num == 0)
7 | return 1;
8 | return num * factorial(num - 1);
9 | }
10 |
11 | int main()
12 | {
13 | int num;
14 | printf("\nEnter the number: ");
15 | scanf("%d", &num);
16 |
17 | // Factorials are undefined for negative integers
18 | if (num < 0)
19 | {
20 | printf("Factorials are undefined for negative integers");
21 | }
22 |
23 | // Call the function
24 | long long unsigned int fact = factorial(num);
25 | // Print the obtained factorial
26 | printf("The factorial of the given number is: %lld", fact);
27 | return 0;
28 | }
29 |
30 | /*
31 |
32 | Time Complexity- O(num), where 'num' is the given number
33 | Space Complexity- O(1)
34 |
35 | SAMPLE INPUT AND OUTPUT
36 |
37 | SAMPLE I
38 |
39 | Enter the number: 12
40 | The factorial of the given number is: 479001600
41 |
42 | */
43 |
--------------------------------------------------------------------------------
/C/math/happy_number.c:
--------------------------------------------------------------------------------
1 | //C Program to check a number is Happy Number or not.
2 | #include
3 |
4 | int happy_number(int);
5 | int main()
6 | {
7 | int n, ans;
8 | printf("Enter a number: ");
9 | scanf("%d", &n);
10 | ans = happy_number(n);
11 | if (ans == 1)
12 | printf("%d is a happy number", n);
13 | else
14 | printf("%d is not a happy number", n);
15 | return 0;
16 | }
17 |
18 | // Function to check if the number is a happy number or not
19 | int happy_number(int n)
20 | {
21 | int temp = n;
22 | int sum = 0, digit;
23 | while (sum != 1 && sum != 4)
24 | {
25 | sum = 0;
26 | while (temp != 0)
27 | {
28 | digit = temp % 10;
29 | sum += digit * digit;
30 | temp = temp / 10;
31 | }
32 |
33 | temp = sum;
34 |
35 | }
36 |
37 | return sum;
38 | }
39 |
40 | /*
41 | Sample Output:
42 | Enter a number: 32
43 | 32 is a happy number.
44 |
45 | Complexities
46 | Time Complexity:O(logn)
47 | Space Complexity:O(1)
48 | */
49 |
50 |
--------------------------------------------------------------------------------
/C/math/number_of_digits.c:
--------------------------------------------------------------------------------
1 | // C Program to find the Number of Digits of a given number
2 | #include
3 |
4 | int sum_of_digits(int num)
5 | {
6 | int cnt = 0;
7 | while (num != 0)
8 | {
9 | cnt++;
10 | // Removing the least significant digit
11 | num = num / 10;
12 | }
13 | return cnt;
14 | }
15 |
16 | int main()
17 | {
18 | int num, cnt;
19 | printf("\nEnter the number: ");
20 | scanf("%d", &num);
21 |
22 | // If the number is negative, convert it into positive
23 | if (num < 0)
24 | {
25 | num = num * -1;
26 | }
27 |
28 | // Call the function
29 | cnt = sum_of_digits(num);
30 | // Print the obtained count
31 | printf("The number of digits in the given number is: %d", cnt);
32 | return 0;
33 | }
34 |
35 | /*
36 | Time Complexity- O(log(num)), where 'num' is the given num
37 | Space Complexity- O(1)
38 |
39 | SAMPLE INPUT AND OUTPUT
40 |
41 | SAMPLE 1
42 |
43 | Enter the number: 1231
44 | The number of digits in the given number is: 4
45 | */
46 |
--------------------------------------------------------------------------------
/C/math/reverse_number.c:
--------------------------------------------------------------------------------
1 | // C program to reverse a number.
2 | #include
3 |
4 | // Function to reverse a number.
5 | int reverse(int num)
6 | {
7 | int rev = 0;
8 | while (num > 0)
9 | {
10 | rev = rev * 10;
11 | //Extract the last digit of the number.
12 | int rem = num % 10;
13 | rev = rev + rem;
14 | num = num / 10;
15 | }
16 | return rev;
17 | }
18 |
19 | int main()
20 | {
21 | int num;
22 | printf("Enter the number: ");
23 | scanf("%d", &num);
24 | int rev = reverse(num);
25 | printf("The reverse of the given number is %d.", rev);
26 | return 0;
27 | }
28 |
29 | /*
30 | Time Complexity: O(log(n)), where 'n' is the given number
31 | Space Complexity: O(1)
32 |
33 | SAMPLE INPUT AND OUTPUT
34 |
35 | SAMPLE 1
36 | Enter the number: 1234
37 | The reverse of the given number is 4321.
38 |
39 | SAMPLE 2
40 | Enter the number: 785487
41 | The reverse of the given number is 784587.
42 | */
43 |
--------------------------------------------------------------------------------
/C/math/special.c:
--------------------------------------------------------------------------------
1 | /*The program is to check whether a given number is a special number or not.
2 | A special number is a number whose all digits are 1
3 | Example-11
4 | */
5 |
6 | #include
7 |
8 | void special(int);
9 |
10 | int main() {
11 | int num;
12 | printf("Enter a number\n");
13 | scanf("%d",&num);
14 | /*Calling of function*/
15 | special(num);
16 |
17 | return 0;
18 | }
19 |
20 | void special(int n)
21 | {
22 | int b,s=0,c=0;
23 | while(n!=0)
24 | {
25 | b=n%10;
26 | /*Sum of digits*/
27 | s=s+b;
28 | /*Count of digits*/
29 | c++;
30 | n=n/10;
31 | }
32 | /*if sum and count are equal
33 | then special number*/
34 | if(s==c)
35 | printf("The given number is special");
36 | else
37 | printf("The given number is not special");
38 | }
39 |
40 | /*
41 | Time Complexity:O(n)
42 | Space Complexity:O(1)
43 | Input/Output:
44 | Enter a number
45 | 123
46 | The given number is not special
47 | */
48 |
--------------------------------------------------------------------------------
/C/other/Palindrome.c:
--------------------------------------------------------------------------------
1 | /*
2 | C Program to check whether a number is Palindrome or not
3 | An integer is a palindrome if the reverse of that number is equal to the original number.
4 | Example of Palindromes are 11,44,101,121,
5 | */
6 | #include
7 |
8 | int reverse_num(int);
9 | int main()
10 | {
11 | int n, rev;
12 | printf("\n Enter a number:");
13 | scanf("%d", &n);
14 | rev = reverse_num(n);
15 | if (rev == n)
16 | {
17 | printf("\n %d is a palindrome", n);
18 | }
19 | else
20 | {
21 | printf("\n %d is not a palindrome", n);
22 | }
23 | return 0;
24 | }
25 | int reverse_num(int num)
26 | {
27 | int rev = 0;
28 | int rem;
29 | while (num > 0)
30 | {
31 | rem = num % 10;
32 | rev = rev *10 + rem;
33 | num = num / 10;
34 | }
35 | return rev;
36 | }
37 |
38 | /*
39 | Sample Output
40 | Enter a number: 121
41 | 121 is a palindrome
42 |
43 | Complexities
44 | Time Complexity: O(n)
45 | Space Complexity: O(1)
46 | */
47 |
48 |
--------------------------------------------------------------------------------
/C/other/README.md:
--------------------------------------------------------------------------------
1 | a
2 |
--------------------------------------------------------------------------------
/C/other/Swap_two_nibbles.c:
--------------------------------------------------------------------------------
1 | //algorithm for swap nibbles in O(1) time complexity and O(1) space complexity
2 |
3 | #include
4 |
5 | int swapnibbles(int num)
6 | {
7 | return (((num & 0x0F) << 4) | ((num & 0xF0) >> 4));
8 | }
9 |
10 | int main()
11 | {
12 | //taking input
13 | int num;
14 | printf(" Enter a number : \n");
15 | scanf("%d",&num);
16 | int result = swapnibbles(num);
17 | printf("output is %d\n",result);
18 | }
19 |
20 | /*
21 | Input:
22 | Enter a number: 50
23 | Output:
24 | 35
25 | */
26 |
--------------------------------------------------------------------------------
/C/other/check_for_subsequence.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | int main()
5 | {
6 | char str1[1000] , str2[1000];
7 | int i = 0 , j = 0; // i will point to string 1 and j will point to string 2
8 | printf(" Enter first string :\n");
9 | scanf("%s" , str1); // str1 is substring
10 | printf(" Enter second string :\n");
11 | scanf("%s" , str2); //str2 is full string
12 | while (i < strlen(str1) && j < strlen(str2))
13 | {
14 | if (str1[i] == str2[j])
15 | {
16 | i++;
17 | }
18 | j++;
19 | }
20 |
21 | if (i == strlen(str1))
22 | {
23 | printf("Yes, str1 is substring of str2\n");
24 | }
25 | else
26 | {
27 | printf("No, str1 is not a substring of str2\n");
28 | }
29 |
30 | return 0;
31 | }
32 |
33 | /*
34 | Time Complexity: O(n)
35 | Space Complexity: O(1)
36 | Input:
37 | DTH SDFDTHFGB
38 | QBR EQVBA
39 | Output:
40 | Yes, str1 is substring of str2
41 | No, str1 is not substring of str2
42 | */
43 |
44 |
--------------------------------------------------------------------------------
/C/other/concatenate_two_strings.c:
--------------------------------------------------------------------------------
1 | //C Program to concatenate two strings without using the strcat() function.
2 | #include
3 | #include
4 |
5 | int main() {
6 |
7 | char str1[100], str2[100];
8 | printf("Enter the first string:");
9 | scanf("%s", str1);
10 | printf("Enter the second string:");
11 | scanf("%s", str2);
12 | int length, j;
13 |
14 | length = 0;
15 | while (str1[length] != '\0') {
16 | ++length;
17 | }
18 |
19 | for (j = 0; str2[j] != '\0'; ++j, ++length) {
20 | str1[length] = str2[j];
21 | }
22 |
23 | str1[length] = '\0';
24 |
25 | printf("After concatenation, Final string will be:\n ");
26 | puts(str1);
27 |
28 | return 0;
29 | }
30 |
31 | /*
32 | INPUT:
33 | Enter the first string:Hello
34 | Enter the second string:World
35 |
36 | OUTPUT:
37 | After concatenation, Final string will be:
38 | HelloWorld
39 | */
--------------------------------------------------------------------------------
/C/search/README.md:
--------------------------------------------------------------------------------
1 | a
2 |
--------------------------------------------------------------------------------
/C/sort/README.md:
--------------------------------------------------------------------------------
1 | a
2 |
--------------------------------------------------------------------------------
/Dart/maths/Factorial.dart:
--------------------------------------------------------------------------------
1 | import 'dart:io';
2 |
3 | // Calculate factorial of number
4 | int get_factorial(int number) {
5 | int count = 1;
6 | int factorial = 1;
7 |
8 | // Iterate from 1 till number
9 | while (count <= number) {
10 | factorial *= count;
11 | count++;
12 | }
13 |
14 | return factorial;
15 | }
16 |
17 | // Main Function, with driver code
18 | void main() {
19 | print("Enter a number:");
20 | int input = int.parse(stdin.readLineSync()!);
21 |
22 | // Call factorial function
23 | int factorial = get_factorial(input);
24 | print("Factorial of $input is $factorial");
25 | }
26 | /**
27 | * Sample input/output:
28 | * Enter a number:
29 | * 5
30 | * Factorial of 5 is 120
31 | *
32 | * Enter a number:
33 | * 12
34 | * Factorial of 12 is 479001600
35 | */
36 |
--------------------------------------------------------------------------------
/Dart/maths/NeonNumber.dart:
--------------------------------------------------------------------------------
1 | /*
2 | A number is said to be a neon number when the sum of digits of the square of the number
3 | is equal to the number itself
4 | */
5 | import 'dart:io';
6 |
7 | // Function to check if number is a neon number
8 | bool isNeon(int num) {
9 | int sum = 0;
10 | int square = num*num;
11 |
12 | while (square > 0) {
13 | int digit = square % 10;
14 | sum += digit;
15 | square ~/= 10;
16 | }
17 | if (sum == num) {
18 | return true;
19 | }
20 | return false;
21 | }
22 |
23 | // Main Function with driver code
24 | void main() {
25 | print("Enter a number :");
26 | int num = int.parse(stdin.readLineSync()!);
27 |
28 | // Call function to check if number is a neon number
29 | if (isNeon(num)) {
30 | print("$num is a Neon Number");
31 | } else {
32 | print("$num is not a Neon Number");
33 | }
34 | }
35 |
36 | /**
37 | Space Complexity O(1)
38 | Time Complexity O(log(n))
39 |
40 | Sample input/output:
41 | Enter a number :
42 | 9
43 | 9 is a Neon Number
44 |
45 | Enter a number :
46 | 12
47 | 12 is not a Neon Number
48 | */
49 |
--------------------------------------------------------------------------------
/Dart/maths/SumOfDigits.dart:
--------------------------------------------------------------------------------
1 | import 'dart:io';
2 |
3 | // Find sum of digits of number
4 | int sum_digits(int number) {
5 | int sum = 0;
6 |
7 | // Extract individual digits and add to sum
8 | while (number > 0) {
9 | int digit = number % 10;
10 | number ~/= 10;
11 | sum += digit;
12 | }
13 | return sum;
14 | }
15 |
16 | // Main Function, with driver code
17 | void main() {
18 | print("Enter a number:");
19 | int input = int.parse(stdin.readLineSync()!);
20 |
21 | // Call sum of digits function
22 | int sum_of_digits = sum_digits(input);
23 | print("Sum of digits in $input is $sum_of_digits");
24 | }
25 | /**
26 | Time Complexity: O(log(n))
27 | Space Complexity: O(1)
28 |
29 | Enter a number:
30 | 401
31 | Sum of digits in 401 is 5
32 |
33 | Enter a number:
34 | 123
35 | Sum of digits in 123 is 6
36 | */
37 |
--------------------------------------------------------------------------------
/Dart/maths/catalan_number.dart:
--------------------------------------------------------------------------------
1 | /*
2 | Catalan numbers is a "number sequence", Its useful in a number of
3 | combinatorial problems, often involving recursively-defined objects.
4 | */
5 |
6 | import 'dart:io';
7 |
8 | // To find nth catalan number using recursive function
9 | int catalan(int n){
10 | if (n <= 1)
11 | return 1;
12 | int res = 0;
13 | for (int i = 0; i < n; i++)
14 | res = res + catalan(i) * catalan(n - i - 1);
15 |
16 | return res;
17 | }
18 |
19 | int main(){
20 | print("Enter the Number:");
21 | int n = int.parse(stdin.readLineSync()!);
22 | for (int i = 0; i < n; i++)
23 | {
24 | stdout.write(catalan(i));
25 | stdout.write(" ");
26 | }
27 | return 0;
28 | }
29 |
30 | /*
31 | Input:
32 | Enter the Number:
33 | 13
34 | Output:
35 | 1 1 2 5 14 42 132 429 1430 4862 16796 58786 208012
36 |
37 | Time Complexity: O(2^n)
38 | Space Complexity: O(1)
39 | */
--------------------------------------------------------------------------------
/Go/math/Binary/checkisnumberpoweroftwo.go:
--------------------------------------------------------------------------------
1 | package binary
2 |
3 | // IsPowerOfTwo This function uses the fact that powers of 2 are represented
4 | // like 10...0 in binary, and numbers one less than the power of 2
5 | // are represented like 11...1.
6 | // Therefore, using the and function:
7 | // 10...0
8 | // & 01...1
9 | // 00...0 -> 0
10 | // This is also true for 0, which is not a power of 2, for which we
11 | // have to add and extra condition.
12 | func IsPowerOfTwo(x int) bool {
13 | return x > 0 && (x&(x-1)) == 0
14 | }
15 |
16 | // IsPowerOfTwoLeftShift This function takes advantage of the fact that left shifting a number
17 | // by 1 is equivalent to multiplying by 2. For example, binary 00000001 when shifted by 3 becomes 00001000,
18 | // which in decimal system is 8 or = 2 * 2 * 2
19 | func IsPowerOfTwoLeftShift(number uint) bool {
20 | if number == 0 {
21 | return false
22 | }
23 | for p := uint(1); p > 0; p = p << 1 {
24 | if number == p {
25 | return true
26 | }
27 | }
28 | return false
29 | }
30 |
--------------------------------------------------------------------------------
/Go/math/README.md:
--------------------------------------------------------------------------------
1 | a
2 |
--------------------------------------------------------------------------------
/Go/math/areas/2D/Areas2D.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 | "math"
6 | )
7 |
8 | // Area of a Rectangle
9 |
10 | func rectangle(l, b float64) float64 {
11 | return l * b
12 | }
13 |
14 | // Area of a Square
15 |
16 | func square(l float64) float64 {
17 | return l * l
18 | }
19 |
20 | // Area of a Triangle
21 |
22 | func triangle(b, h float64) float64 {
23 | return (b * h) / 2.0
24 | }
25 |
26 | // Area of a Circle
27 |
28 | func circle(r float64) float64 {
29 | return math.Pi * math.Pow(r, 2)
30 | }
31 |
32 | // Area of a Parallelogram
33 |
34 | func parallelogram(b, h float64) float64 {
35 | return b * h
36 | }
37 |
38 | // Area of a Trapezium
39 |
40 | func trapezium(a, b, h float64) float64 {
41 | return (a + b) * h / 2.0
42 | }
43 |
44 | func main() {
45 | fmt.Println(rectangle(3.0, 5.0))
46 | fmt.Println(square(4.0))
47 | fmt.Println(triangle(4.0, 6.0))
48 | fmt.Println(circle(3.5))
49 | fmt.Println(parallelogram(4.0, 7.0))
50 | fmt.Println(trapezium(4.0, 3.5, 6.5))
51 | }
52 |
53 | // Time Complexity - O(1)
54 | // Space Complexity - O(1)
55 |
--------------------------------------------------------------------------------
/Go/search/binary_search/binary_search.go:
--------------------------------------------------------------------------------
1 | // Binary Search in Go
2 | // Requires array to be sorted
3 | // Return index of found element else return -1
4 | package main
5 |
6 | import (
7 | "fmt"
8 | )
9 |
10 | func main() {
11 | arr := []int{2, 4, 6, 8, 10, 12, 14, 16, 18, 20}
12 | fmt.Printf("Array: %v\n", arr)
13 | var find int
14 | fmt.Printf("Please enter element to be found: ")
15 | fmt.Scan(&find)
16 | result := search(arr, find)
17 | fmt.Printf("Result: %d", result)
18 | }
19 |
20 | func search(list []int, item int) int {
21 | low := 0
22 | high := len(list) - 1
23 | for low <= high {
24 | middle := (low + high) / 2
25 | if list[middle] == item {
26 | return middle
27 | } else if list[middle] < item {
28 | low = middle + 1
29 | } else {
30 | high = middle - 1
31 | }
32 | }
33 | return -1
34 | }
35 |
--------------------------------------------------------------------------------
/Go/search/interpolation_search/interpolation_search.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import "fmt"
4 |
5 | func Search(array []int, number int) int {
6 | low := 0
7 | high := len(array) - 1
8 |
9 | for {
10 | var key int
11 | var size int
12 | var first int
13 | var last int
14 | var value int
15 |
16 | first = array[low]
17 | last = array[high]
18 |
19 | if high == low {
20 | key = high
21 | } else {
22 | size = high - low
23 | value = int((float64(size-1) * (float64(number-first) / float64(last-first))))
24 | key = low + value
25 | }
26 | if array[key] == number {
27 | return key
28 | }
29 | if array[key] > number {
30 | high = key - 1
31 | } else {
32 | low = key + 1
33 | }
34 | }
35 | }
36 |
37 | // Input
38 |
39 | func main() {
40 | items := []int{1, 16, 28, 37, 49, 52, 60, 75, 85, 99, 105}
41 | fmt.Println(Search(items, 85))
42 | }
43 |
44 | // Output = 8
45 |
46 | // Time Complexity = O(n), Space Complexity = O(n)
47 |
--------------------------------------------------------------------------------
/Go/search/linear_search/linear_search.go:
--------------------------------------------------------------------------------
1 | // Linear Search in Go
2 | // Return index of found element else return -1
3 | package main
4 |
5 | import (
6 | "fmt"
7 | )
8 |
9 | func main() {
10 | arr := []int{1, 5, 2, -5, 8, 4, 9, -12}
11 | fmt.Printf("Array: %v\n", arr)
12 | var find int
13 | fmt.Printf("Please enter element to be found: ")
14 | fmt.Scan(&find)
15 | result := search(arr, find)
16 | fmt.Printf("Result: %d", result)
17 | }
18 |
19 | func search(list []int, item int) int {
20 | for i := range list {
21 | if list[i] == item {
22 | return i
23 | }
24 | }
25 | return -1
26 | }
27 |
--------------------------------------------------------------------------------
/Java/Algorithms/kadanes_Java.java:
--------------------------------------------------------------------------------
1 | // Java Program for Kadane's Algorithm.
2 |
3 | import java.util.*;
4 | public class kadanes_Java {
5 |
6 | public static void main(String[] args) {
7 | Scanner sc = new Scanner(System.in);
8 | int n = sc.nextInt();
9 | int[] arr = new int[n];
10 | int maxSoFar = Integer.MIN_VALUE;
11 | int curSum = 0;
12 | for (int i = 0; i < arr.length; i++) {
13 | arr[i] = sc.nextInt();
14 | }
15 | for (int i = 0; i < arr.length; i++) {
16 | if (curSum + arr[i] < 0)
17 | curSum = 0;
18 | else
19 | curSum = curSum + arr[i];
20 | if (curSum > maxSoFar)
21 | maxSoFar = curSum;
22 | }
23 | System.out.println(maxSoFar);
24 | sc.close();
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/Java/blockchain/README.md:
--------------------------------------------------------------------------------
1 | a
2 |
--------------------------------------------------------------------------------
/Java/cp/ArmStrongRecursion.java:
--------------------------------------------------------------------------------
1 | // Checking Armstrong number with Recursion
2 |
3 | import java.util.Scanner;
4 | class ArmStrongRecursion
5 | {
6 | static int p;
7 | public static int armstrong(int i)
8 | { if(i<10) //base class
9 | return (int)(Math.pow(i,p));
10 | else
11 | return((int)Math.pow(i%10,p)+armstrong(i/10));
12 | }
13 | public static void main(String args[])
14 | {
15 | Scanner sc=new Scanner(System.in);
16 | System.out.print("N = ");
17 | int n=sc.nextInt();
18 | p=Integer.toString(n).length(); //calculating the number of digits in the number by converting it into String
19 |
20 | if(n==armstrong(n))
21 | System.out.println(n+" is an Armstrong number");
22 | else
23 | System.out.println(n+" is not an Armstrong number");
24 | }
25 | }
26 |
27 | /*
28 | Sample Input and Output :
29 | N = 153
30 | 153 is an Armstrong number
31 | Space Complexity: O(1)
32 | Time Complexity : O(p)
33 | */
34 |
--------------------------------------------------------------------------------
/Java/cp/Count_Words.java:
--------------------------------------------------------------------------------
1 | /* This is a java code of finding total number of
2 | words in given string.
3 | */
4 | import java.util.*;
5 | import java.lang.*;
6 | import java.io.*;
7 | import java.lang.String;
8 | public class count_words
9 | {
10 | public static int countWords(String str)
11 | {
12 | /* The java.util.StringTokenizer class allows
13 | you to break a string into tokens.
14 | */
15 | StringTokenizer tokens = new StringTokenizer(str);
16 | return tokens.countTokens();
17 | }
18 | public static void main(String[] args)
19 | {
20 | Scanner scan = new Scanner(System.in);
21 | System.out.print("Enter your string : ")
22 | String str = scan.next();
23 | System.out.println("No of words: " + countWords(str));
24 | }
25 | }
26 | /*
27 | Time complexity is O(n)
28 | Space complexity is O(1)
29 |
30 | Input :
31 | Enter your string : I like to contribute here
32 |
33 | Output:
34 | No of words: 5
35 | */
36 |
--------------------------------------------------------------------------------
/Java/cp/Defanged_IPv4.java:
--------------------------------------------------------------------------------
1 | import java.util.*;
2 | class Main {
3 | public static void main(String args[]) {
4 | int c = 0;
5 | Scanner sc = new Scanner(System.in);
6 | System.out.println("Enter IPv4 address");
7 | String s = sc.next();
8 | for (int i = 0; i < s.length(); i++)
9 | if (s.charAt(i) == '.')
10 | c++;
11 | s = s.replace(".", "[.]");
12 | if (c == 3)
13 | System.out.println("Defanged IPv4 address : " + s);
14 | else
15 | System.out.println("Not a valid IPv4 address");
16 |
17 | }
18 | }
19 |
20 | /*
21 | Sample Input and Output :
22 |
23 | Enter IPv4 address
24 | 1.1.1.1
25 | Defanged IPv4 address : 1[.]1[.]1[.]1
26 | Enter IPv4 address
27 | 2500.100.50.0
28 | Defanged IPv4 address : 2500[.]100[.]50[.]0
29 | Enter IPv4 address
30 | 1.1.1.1.
31 | Not a valid IPv4 address
32 |
33 | Time Complexity: O(n) where n is the length of address
34 | Space Complexity: O(1)
35 | */
36 |
--------------------------------------------------------------------------------
/Java/cp/Longest_Common_Prefix.java:
--------------------------------------------------------------------------------
1 | import java.util.*;
2 | class Longest_Common_Prefix{
3 | public static String LongestCommonPrefixFn(String[] strs) {
4 | if(strs.length==0){
5 | return "";
6 | }
7 | String st = strs[0];
8 | for(int i=1; i 1; j--)
14 | arr[j] = arr[j] + arr[j - 1];
15 | arr[i + 1] = arr[i];
16 | for (int j = i + 1; j > 1; j--)
17 | arr[j] = arr[j] + arr[j - 1];
18 | System.out.printf("%d ", arr[i + 1] - arr[i]);
19 | }
20 | }
21 | }
22 |
23 | /*
24 | Sample input and output
25 | Enter number: 7
26 |
27 | 1 2 5 14 42 132 429
28 |
29 | time complexity: O(n^2)
30 | space complexity: O(n)
31 | */
32 |
--------------------------------------------------------------------------------
/Java/math/Factorial.java:
--------------------------------------------------------------------------------
1 | /*
2 | Factorial is the product of all positive integers less than or equal to a given positive integer
3 | and denoted by that integer and an exclamation point.
4 | Thus, factorial five is written 5!, meaning 1 × 2 × 3 × 4 × 5.
5 | Factorial zero is defined as equal to 1.
6 | */
7 |
8 | import java.util.Scanner;
9 |
10 | public class Factorial {
11 | public static void main(String[] args) {
12 | Scanner sc = new Scanner(System.in);
13 | System.out.println("Enter Number: ");
14 | int n = sc.nextInt();
15 | System.out.println("Factorial of " +n+ " is: " + fact(n));
16 | }
17 | public static int fact(int n){
18 | if(n==0)
19 | return 1;
20 |
21 | return n*fact(n-1);
22 | }
23 | }
24 |
25 | /*
26 | Test Cases:
27 | Enter Number: 7
28 | Factorial of 7 is: 5040
29 |
30 | Enter Number: 0
31 | Factorial of 0 is: 1
32 |
33 | Time Complexity: O(n)
34 | Space Complexity: O(n)
35 | */
--------------------------------------------------------------------------------
/Java/math/PalindromeRecursion.java:
--------------------------------------------------------------------------------
1 | // Checking Palindrome number with Recursion
2 |
3 | import java.util.Scanner;
4 | class PalindromeRecursion
5 | {
6 | static long revNum=0; //stored reversed number
7 | public static long palindrome(long i)
8 | { if(i>0) //base class
9 | { revNum=(revNum*10)+(i%10);
10 | palindrome(i/10);
11 | }
12 | else
13 | return revNum;
14 | return revNum;
15 | }
16 | public static void main(String args[])
17 | {
18 | Scanner sc=new Scanner(System.in);
19 | System.out.print("N = ");
20 | long n=sc.nextLong();
21 | if(n==palindrome(n))
22 | System.out.println(n+" is a Palindrome number");
23 | else
24 | System.out.println(n+" is not a Palindrome number");
25 | }
26 | }
27 |
28 | /*
29 | Sample Input and Output :
30 | N = 153
31 | 153 is not a Palindrome number
32 | Space Complexity: O(1)
33 | Time Complexity : O(i) i=Number of digits in n
34 | */
35 |
--------------------------------------------------------------------------------
/Java/math/README.md:
--------------------------------------------------------------------------------
1 | a
2 |
--------------------------------------------------------------------------------
/Java/math/Squares_in_2n_Chessboard.java:
--------------------------------------------------------------------------------
1 | /**
2 | Find total number of Squares in a N*N cheesboard.
3 | */
4 |
5 | import java.io.*;
6 | import java.util.*;
7 |
8 | class Code{
9 | public static void main(String args[]) throws IOException{
10 | // taking input
11 | BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
12 | System.out.println("Enter the num")
13 | Long num = Long.parseLong(read.readLine());
14 | Sol obj = new Sol();
15 | System.out.println("The square : ")
16 | System.out.println(obj.squares(num));
17 | }
18 | }
19 | class Sol {
20 | // using maths logic
21 | static Long squares(Long n) {
22 | return (long) (n*(n+1)*(2*n+1))/6;
23 | }
24 | };
25 |
26 | /*
27 | Time complexity : O(N)
28 | Space complexity : O(1)
29 | */
30 |
31 | /*
32 | Input :
33 | Enter the number : 1
34 | Output :
35 | The square is : 1
36 | */
37 |
--------------------------------------------------------------------------------
/Java/math/countDigits/iterative.java:
--------------------------------------------------------------------------------
1 | /*Iterative:*/
2 | import java.util.Scanner;
3 |
4 | public class CountDigits {
5 |
6 | public static void countdigit(int n) {
7 | int count=0;
8 | while(n!=0){
9 | count=count+1;
10 | n=n/10;
11 | }
12 | System.out.println(count);
13 |
14 | }
15 |
16 | public static void main(String[] args) {
17 |
18 | Scanner sc=new Scanner(System.in);
19 |
20 | System.out.print("Enter a number : ");
21 | int n=sc.nextInt();
22 |
23 | System.out.println("Number of digits in a number are : ");
24 | countdigit(n);
25 |
26 | }
27 | /*
28 | Sample Input :
29 | Enter a number : 24567
30 |
31 | Sample Output : 5
32 |
33 | */
34 |
--------------------------------------------------------------------------------
/Java/math/countDigits/recursive.java:
--------------------------------------------------------------------------------
1 | /*Recursive:*/
2 | import java.util.Scanner;
3 |
4 | public class CountDigits {
5 |
6 | public static int countdigit(int n) {
7 | if(n==0){
8 | return 0;
9 | }
10 | return 1 + countdigit(n/10);
11 |
12 | }
13 |
14 | public static void main(String[] args) {
15 |
16 | Scanner sc=new Scanner(System.in);
17 |
18 | System.out.print("Enter a number : ");
19 | int n=sc.nextInt();
20 |
21 | System.out.println("Number of digits in a number are : ");
22 | System.out.println(countdigit(n));
23 |
24 | }
25 | /*
26 | Sample Input :
27 | Enter a number : 24567
28 |
29 | Sample Output : 5
30 |
31 | */
32 |
--------------------------------------------------------------------------------
/Java/math/countDigits/stringmethod.java:
--------------------------------------------------------------------------------
1 | /*String Method:*/
2 | import java.util.Scanner;
3 |
4 | public class CountDigits {
5 |
6 | public static int countdigit(int n) {
7 | if(n==0){
8 | return 1;
9 | }
10 | return (Integer.toString(n).length());
11 | }
12 |
13 | public static void main(String[] args) {
14 |
15 | Scanner sc=new Scanner(System.in);
16 |
17 | System.out.print("Enter a number : ");
18 | int n=sc.nextInt();
19 |
20 | System.out.println("Number of digits in a number are : ");
21 | System.out.println(countdigit(n));
22 |
23 | }
24 | }
25 | /*
26 | Sample Input :
27 | Enter a number : 24567
28 |
29 | Sample Output : 5
30 |
31 |
32 | */
33 |
--------------------------------------------------------------------------------
/Java/other/README.md:
--------------------------------------------------------------------------------
1 | a
2 |
--------------------------------------------------------------------------------
/Java/other/RecursionCount.java:
--------------------------------------------------------------------------------
1 | import java.util.Scanner;
2 |
3 | public class RecursionCount {
4 |
5 | public static void main(String args[]) {
6 | Scanner scanner = new Scanner(System.in);
7 | System.out.println("Enter first string:");
8 | String str1 = scanner.nextLine();
9 | System.out.println("Enter second string:");
10 | String str2 = scanner.nextLine();
11 | scanner.close();
12 |
13 | System.out.println("Number of occurrences of \"" + str2 + "\" in \"" + str1 + "\":" + countSubstring(str1, str2));
14 | }
15 |
16 | static int countSubstring(String str1, String str2) {
17 | // recursive function
18 | if(str1.contains(str2)) {
19 | return 1 + countSubstring(str1.replaceFirst(str2, ""), str2);
20 | } else {
21 | return 0;
22 | }
23 | }
24 | }
25 | /*
26 | * Sample input/output:
27 | * Enter first string:
28 | * abcdabc
29 | * Enter second string:
30 | * abc
31 | * Number of occurrences of "abc" in "abcdabc":2
32 | *
33 | * Time complexity: O(n)
34 | */
35 |
--------------------------------------------------------------------------------
/Java/other/SwapNibbles.java:
--------------------------------------------------------------------------------
1 | import java.util.Scanner;
2 |
3 | public class SwapNibbles {
4 |
5 | public static void main(String[] args) {
6 | Scanner sc = new Scanner(System.in);
7 | System.out.println("Enter a number:");
8 | int num = sc.nextInt();
9 |
10 | int result = swapNibbles(num);
11 |
12 | System.out.println("Number after swapping nibbles:" + result);
13 | sc.close();
14 | }
15 |
16 | private static int swapNibbles(int x) {
17 | /* (x & 0x0F) << 4 gives us the last 4 bits of the number and
18 | shifts it by 4 bits to the left.
19 | (x & 0xF0) >> 4 gives us the last 4 bits of the number and
20 | shifts it to right by 4 bits. */
21 | return ((x & 0x0F) << 4 | (x & 0xF0) >> 4);
22 | }
23 | }
24 | /*
25 | * Sample input/output
26 | * Enter a number:
27 | * 100
28 | * Number after swapping nibbles:70
29 | *
30 | * Space and Time complexity = O(1)
31 | */
32 |
--------------------------------------------------------------------------------
/Java/search/README.md:
--------------------------------------------------------------------------------
1 | a
2 |
--------------------------------------------------------------------------------
/Java/search/Stack_Search.java:
--------------------------------------------------------------------------------
1 | /* Stack search is a method to search an element in a stack and return the index at which its found. */
2 |
3 | import java.util.*;
4 |
5 | public class stack_search{
6 |
7 | public static void main(String[] args) {
8 |
9 | Scanner sc = new Scanner(System.in);
10 | //enter the no of elemnts to be there inside stack
11 | int n = sc.nextInt();
12 | int no;
13 | Stack st = new Stack ();
14 | for(int i = 1; i <= n; i++) {
15 | no = sc.nextInt();
16 | st.push(no);
17 | }
18 | // Displaying the Stack
19 | System.out.println("The stack is: " + st);
20 | //enter the element to be searched
21 | int item = sc.nextInt();
22 | // Checking for the element
23 | int search = st.search(item);
24 | System.out.println(item+" is seached at index="+(n-search+1));
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/Java/sort/README.md:
--------------------------------------------------------------------------------
1 | a
2 |
--------------------------------------------------------------------------------
/Java/sort/SelectionSort.java:
--------------------------------------------------------------------------------
1 | import java.util.*;
2 | class SelectionSort
3 | {
4 | public static void main(String[] args) {
5 | int indexI,arrayLength,indexJ,temp=0,minElementIndex=0;
6 | Scanner sc=new Scanner(System.in);
7 | System.out.println("Enter size of array");
8 | arrayLength=sc.nextInt();
9 | int array[]=new int[arrayLength];
10 | System.out.println("Enter Elements of array");
11 | for(indexI=0;indexIarray[indexJ])
19 | minElementIndex=indexJ;
20 | }
21 |
22 | temp=array[indexI];
23 | array[indexI]=array[minElementIndex];
24 | array[minElementIndex]=temp;
25 | }
26 |
27 | for(indexI=0;indexI 0) {
16 |
17 | //extracting the last digit
18 | let rem = temp % 10;
19 |
20 | //summation
21 | sum += parseInt(rem ** n);
22 |
23 | // removing last digit from the number
24 | // convert float into integer
25 | temp = parseInt(temp / 10);
26 | }
27 |
28 | //checking for armstrong no.
29 | if (sum == number) {
30 | console.log(`${number} is an Armstrong number`);
31 | } else {
32 | console.log(`${number} is not an Armstrong number.`);
33 | }
--------------------------------------------------------------------------------
/JavaScript/math/Perfect_Number.js:
--------------------------------------------------------------------------------
1 | /*
2 | Perfect number is a positive integer which is equal to the sum of its proper positive divisors.
3 | For example: 6 is the first perfect number
4 | Proper divisors of 6 are 1, 2, 3
5 | Sum of its proper divisors = 1 + 2 + 3 = 6.
6 | Hence 6 is a perfect number.
7 | */
8 |
9 | const prompt = require("prompt-sync")({ sigint: true });
10 | let n = +prompt("Enter a number to check whether it is a perfect number or not: ");
11 | let sum = 0;
12 |
13 | for (let i = 1; i < n; i++)
14 | {
15 | if (n % i == 0)
16 | sum += i;
17 | }
18 |
19 | if (sum == n)
20 | console.log(`${n} is a perfect number.`);
21 | else
22 | console.log(`${n} is not a perfect number.`);
23 |
24 | /*
25 |
26 | Time Complexity: O(n)
27 | Space Complexity: O(1)
28 |
29 | node JavaScript/math/Perfect_Number.js
30 |
31 | sample 1: Enter a number to check whether it is a perfect number or not: 6
32 | Output: 6 is a perfect number.
33 |
34 | sample 2: Enter a number to check whether it is a perfect number or not: 7
35 | output: 7 is not a perfect number.
36 |
37 | */
38 |
--------------------------------------------------------------------------------
/JavaScript/math/README.md:
--------------------------------------------------------------------------------
1 | a
2 |
--------------------------------------------------------------------------------
/JavaScript/math/bin_exp.js:
--------------------------------------------------------------------------------
1 | /*
2 | Binary exponentiation (also known as exponentiation by squaring) is a trick which allows to calculate an using only O(logn) multiplications (instead of O(n) multiplications required by the naive approach).
3 | */
4 |
5 | function binary_expo(a,b,mod)
6 | {
7 | //End Result Store Here
8 | let ans=1;
9 | while(b>0)
10 | {
11 | if(b%2!=0)
12 | {
13 | //Making the power even
14 | ans=((ans%mod)*(a%mod))%mod;
15 | //Decrease the power by 1
16 | b--;
17 | }
18 | else
19 | {
20 | //performing sqaure to reduce the power by 2
21 | a=((a%mod)*(a%mod))%mod;
22 | //reducing the power by 2.
23 | b=b/2;
24 | }
25 | }
26 | return ans;
27 | }
28 | console.log(binary_expo(2,3,10000));
29 | //binary_expo(number 1,number 2, mod) (a^b)%mod
30 | //Time Complexity = O (log b)
--------------------------------------------------------------------------------
/JavaScript/math/catalan_number.js:
--------------------------------------------------------------------------------
1 | /*
2 | Catalan numbers is a number sequence, which is found useful in a number of
3 | combinatorial problems, often involving recursively-defined objects.
4 | */
5 |
6 | var n = prompt("Enter the number:");
7 |
8 | var c = [];
9 |
10 | function catalan(n) {
11 | if (n == 0) return 1;
12 | if (!c[n]) {
13 | var s = 0;
14 | for (var i = 0; i < n; i++)
15 | s += catalan(i) * catalan(n - i - 1);
16 | c[n] = s;
17 | }
18 | return c[n];
19 | }
20 | document.write("Nth Catalan Number are:")
21 | document.write("
");
22 | for (var i = 0; i <= n; i++) {
23 | document.write(catalan(i));
24 | document.write("
");
25 | }
26 |
27 | /*
28 | Input:
29 | Enter the number:
30 | 15
31 | Output:
32 | Nth Catalan Number are:
33 | 1
34 | 1
35 | 2
36 | 5
37 | 14
38 | 42
39 | 132
40 | 429
41 | 1430
42 | 4862
43 | 16796
44 | 58786
45 | 208012
46 | 742900
47 | 2674440
48 | 9694845
49 |
50 | Time Complexity: O(2^n)
51 | Space Complexity: O(1)
52 | */
--------------------------------------------------------------------------------
/JavaScript/other/README.md:
--------------------------------------------------------------------------------
1 | a
2 |
--------------------------------------------------------------------------------
/JavaScript/search/README.md:
--------------------------------------------------------------------------------
1 | a
2 |
--------------------------------------------------------------------------------
/JavaScript/sort/BubbleSort.js:
--------------------------------------------------------------------------------
1 | /**
2 | * time complexity O(n*n) - space complexity O(1)
3 | */
4 |
5 | function BubbleSort(arr) {
6 | for (let i = 0; i < arr.length; i++) {
7 | // outer loop
8 | let isSwapped = false; // create a boolean to keep track of whether or not there was a successful comparison made
9 | for (let j = 0; j < arr.length - 1; j++) {
10 | // inner loop
11 | if (arr[j] > arr[j + 1]) {
12 | // check if the current value is greater than next value
13 | [arr[j], arr[j + 1]] = [arr[j + 1], arr[j]]; // Swap the current value and next value
14 | isSwapped = true; // Set swap variable to true
15 | }
16 | }
17 | if (!isSwapped) {
18 | // if there's no swap, the arr is fully sorted and can exit there, we break.
19 | break;
20 | }
21 | }
22 |
23 | return arr; // return the sorted array
24 | }
25 |
26 | console.log(BubbleSort([4, 2, 1, 3]));
27 | // output should be => [1, 2, 3, 4]
28 |
29 | console.log(BubbleSort([-4, 18, 2, 0, 6]));
30 | // output should be => [-4, 0, 2, 6, 18]
31 |
--------------------------------------------------------------------------------
/JavaScript/sort/README.md:
--------------------------------------------------------------------------------
1 | a
2 |
--------------------------------------------------------------------------------
/Julia/Bit--Manipulation/count_num_of_set_bits.jl:
--------------------------------------------------------------------------------
1 | # Julia program to count the number of set bits in a number
2 |
3 | function countNumSetBits(num)
4 | cnt = 0
5 | while(num > 0)
6 | cnt = cnt + (num & 1)
7 | num = (num>>1)
8 | end
9 | return cnt
10 | end
11 |
12 |
13 |
14 | print("Enter the number: ")
15 | num = readline()
16 | num = parse(Int, num)
17 | res = countNumSetBits(num)
18 | print("The number of set bits present in the given number is $res")
19 |
20 |
21 | """
22 | Time Complexity: O(log(n)), where n is the given number
23 | Space Complexity: O(1)
24 |
25 | SAMPLE INPUT AND OUTPUT
26 |
27 | SAMPLE I
28 |
29 | Enter the number: 12354
30 | The number of set bits present in the given number is 4
31 |
32 | SAMPLE II
33 |
34 | Enter the number: 2048
35 | The number of set bits present in the given number is 1
36 | """
37 |
--------------------------------------------------------------------------------
/Julia/Bit--Manipulation/power_of_2.jl:
--------------------------------------------------------------------------------
1 | # Julia program to check if a number is a power of two.
2 |
3 | function power_of_two(n)
4 | # 0 is not a power of 2
5 | if(n != 0)
6 | if((n & (n-1)) == false)
7 | return true
8 | end
9 | end
10 | return false
11 | end
12 |
13 |
14 | print("Enter a number: ")
15 | n = readline()
16 | n = parse(Int, n)
17 | res = power_of_two(n)
18 | if(res)
19 | print("The given number is a power of 2.")
20 | else
21 | print("The given number is not a power of 2.")
22 | end
23 |
24 |
25 | """
26 | Time Complexity - O(1)
27 | Space Complexity - O(1)
28 |
29 | SAMPLE INPUT AND OUTPUT
30 |
31 | SAMPLE I
32 | Enter a number: 4
33 | The given number is a power of 2.
34 |
35 | SAMPLE II
36 | Enter a number: 0
37 | The given number is not a power of 2.
38 | """
39 |
--------------------------------------------------------------------------------
/Julia/Bit--Manipulation/reverse_bits.jl:
--------------------------------------------------------------------------------
1 | """
2 | Julia program to reverse the bits of a number
3 | Given an integer, reverse its bits in its binary equivalent and
4 | print the new number obtained in its decimal form
5 | """
6 |
7 | function reverse_bits(n)
8 | rev = 0
9 |
10 | while(n > 0)
11 | # Shift the bit of the reversed(answer) number to the right
12 | rev = rev << 1
13 | # Stores the temporary lsb of the given number
14 | rem = n & 1
15 | # Set the lsb of the answer variable with the stored value
16 | rev = rem | rev
17 | # Drops the already processed lsb of the given number
18 | n = n >> 1
19 | end
20 | return rev
21 | end
22 |
23 | print("Enter the number? ")
24 | num = readline()
25 | num = parse(Int, num)
26 | rev = reverse_bits(num)
27 | print("The bits-reversed number is: $rev")
28 |
29 | """
30 | Time Complexity: O(n)
31 | Space Complexity: O(1)
32 |
33 | SAMPLE INPUT AND OUTPUT
34 |
35 | Enter the number? 39
36 | The bits-reversed number is: 57
37 | """
38 |
--------------------------------------------------------------------------------
/Julia/Bit--Manipulation/toggle_kth_bit.jl:
--------------------------------------------------------------------------------
1 | # Julia program to toggle the k-th bit of a number.
2 | function toggle(num, k)
3 | return (num ⊻ (1 << (k-1)))
4 | end
5 |
6 | print("Enter the number: ")
7 | num = readline()
8 | num = parse(Int, num)
9 | print("Enter the value of k(where you need to toggle the k'th bit): ")
10 | k = readline()
11 | k = parse(Int, k)
12 | new_num = toggle(num, k)
13 | println("The given number, after toggling the k-th bit is $new_num.")
14 |
15 | """
16 | Time Complexity: O(1)
17 | Space Complexity: O(1)
18 |
19 | SAMPLE INPUT AND OUTPUT
20 |
21 | SAMPLE 1
22 | Enter the number: 24
23 | Enter the value of k(where you need to toggle the k'th bit): 3
24 | The given number, after toggling the k-th bit is 28.
25 |
26 | SAMPLE 2
27 | Enter the number: 33
28 | Enter the value of k(where you need to toggle the k'th bit): 12
29 | The given number, after toggling the k-th bit is 2081.
30 | """
31 |
--------------------------------------------------------------------------------
/Julia/cp/GCD.jl:
--------------------------------------------------------------------------------
1 | #= Finding the Greatest Common Divisor of 2 numbers using the Euclidean
2 | Formula to lessen the time complexity.
3 | =#
4 |
5 | ## Function
6 |
7 | function GCD(a, b)
8 | if (a == 0)
9 | return b
10 | end
11 | if (b == 0)
12 | return a
13 | end
14 | if (a < b)
15 | a, b = b, a
16 | end
17 | ans = a % b
18 | while (ans != 0)
19 | a = b
20 | b = ans
21 | ans = a % b
22 | end
23 | return b
24 | end
25 |
26 | ## Input
27 |
28 | a = readline()
29 | a = parse(Int64, a)
30 | b = readline()
31 | b = parse(Int64, b)
32 |
33 | ## Calling the function
34 |
35 | GCD(a, b)
36 |
37 | #=
38 | Sample Test case:
39 | Input:
40 | a = 1001 b = 2352
41 | Output:
42 | 7
43 | Time complexity: O( log (min(a,b)) )
44 | =#
45 |
--------------------------------------------------------------------------------
/Julia/cp/Maximum_subarray_sum.jl:
--------------------------------------------------------------------------------
1 | #=Given an Array you need to find the maximum sum of all the
2 | subarrays. Subarrays are consecutive elements of the array.
3 | There are a total of n*(n+1)/2 subarrays in an array with
4 | n elements. Out of all these sub arrays find the subarray with
5 | the maximum sum. Kadane's Algorithm helps us to do this in
6 | the least time complexity.=#
7 |
8 | ## Function
9 |
10 | function maxSubArray(array)
11 | best = 0
12 | sum = 0
13 | for i in array
14 | sum = max(i, sum + i)
15 | best = max(sum, best)
16 | end
17 | return best
18 | end
19 |
20 | ## Input
21 |
22 | n = readline()
23 | n = parse(Int64, n)
24 | arr = Int64[]
25 | for i = 1:n
26 | temp = readline()
27 | temp = parse(Int64, temp)
28 | push!(arr, temp)
29 | end
30 |
31 | ## Calling the function
32 |
33 | print(maxSubArray(arr))
34 |
35 | #=
36 | Sample test case:
37 | Input:
38 | n = 5
39 | array = 2 -3 5 4 -7
40 | Output:
41 | 9
42 |
43 | Time complexity: O(N)
44 | =#
45 |
--------------------------------------------------------------------------------
/Julia/cp/Prime_factorization.jl:
--------------------------------------------------------------------------------
1 | #= Given a number n, print its prime factorization. We could do it
2 | normal way which will be having time complexity of O (sqrt(N))
3 | but we will be using Sieve to lessen the time complexity
4 | We will make a sieve to get all the prime numbers and then get the
5 | prime factorization of the number using that.=#
6 |
7 | ## Function
8 |
9 | function PrimeFactor(n)
10 | a = zeros(Int64, n)
11 | for i = 2:n
12 | a[i] = i
13 | end
14 | for i = 2:n
15 | if (a[i] == i)
16 | for j = (i*i):i:n
17 | if (a[j] == j)
18 | a[j] = i
19 | end
20 | end
21 | end
22 | end
23 | while (n != 1)
24 | println(a[n])
25 | n = div(n, a[n])
26 | end
27 | end
28 |
29 | ## Input
30 |
31 | n = readline()
32 | n = parse(Int64, n)
33 |
34 | #Calling the function
35 |
36 | PrimeFactor(n)
37 |
38 | #=
39 | Sample Test case
40 | Input:
41 | n = 495
42 | Output:
43 | 3 3 5 11
44 |
45 | Time Complexity: O( log N )
46 | =#
--------------------------------------------------------------------------------
/Julia/cp/Sieve_of_Eratosthenes.jl:
--------------------------------------------------------------------------------
1 | #=Given a posititve number n find all the numbers from 2 to n which
2 | are prime and print them. Sieve of Eratosthenes is an optimal approach
3 | to find the prime numbers.We get an array of length n and if the value
4 | of array at index i is zero the number i is prime.=#
5 |
6 | ## Function
7 |
8 | function primeSieve(n)
9 | a = zeros(Int64, n + 5)
10 | for i = 2:n
11 | if (a[i] == 0)
12 | for j = (i*i):i:n
13 | a[j] = 1
14 | end
15 | end
16 | end
17 | for i = 2:n
18 | if (a[i] == 0)
19 | print("$(i) ")
20 | end
21 | end
22 | end
23 |
24 | ##Input
25 |
26 | n = readline()
27 | n = parse(Int64, n)
28 |
29 | #Calling the function
30 |
31 | primeSieve(n)
32 |
33 | #=
34 | Sample test case:
35 | Input:
36 | n = 20
37 | Output:
38 | 2 3 5 7 11 13 17 19
39 |
40 | Time complexity: O( N * log(log(N)) )
41 | =#
--------------------------------------------------------------------------------
/Julia/cp/factorials.jl:
--------------------------------------------------------------------------------
1 | #=Given a number N, find its factorial using recursion. It is quite easy
2 | but we want to add recursion algorithms in Julia.=#
3 |
4 | ## Function
5 |
6 | function fact(n)
7 | if (n == 0)
8 | return 1
9 | end
10 | if (n == 1)
11 | return 1
12 | end
13 | return n * fact(n - 1)
14 | end
15 |
16 | ## Input
17 |
18 | n = readline()
19 | n = parse(Int64, n)
20 |
21 | ## Calling the Function
22 |
23 | fact(n)
24 |
25 | #=
26 | Sample Test Case:
27 | Input:
28 | n=10
29 | Output:
30 | 3628800
31 | Time complexity: O( N )
32 | =#
33 |
--------------------------------------------------------------------------------
/Julia/cp/isPowerOf2.jl:
--------------------------------------------------------------------------------
1 | #= Given a number N check if it is a power of 2 in O(1). We will be
2 | using bitwise operator to get the calculation.=#
3 |
4 | ## Function
5 |
6 | function isPowerOfTwo(n)
7 | return (n & (n - 1) == 0)
8 | end
9 |
10 | ## Input
11 |
12 | println("Enter the number : ")
13 | n = readline()
14 | n = parse(Int64, n)
15 |
16 | ## Calling the function
17 |
18 | if (isPowerOfTwo(n))
19 | println("Its a power of 2")
20 | else
21 | println("Its not a power of 2")
22 | end
23 |
24 | #=
25 | Sample Test Case
26 | Input:
27 | Enter a number : 4294967296
28 | Output:
29 | Its a power of 2
30 | Time complexity: O( 1 )
31 | =#
32 |
--------------------------------------------------------------------------------
/Julia/cp/subsequence.jl:
--------------------------------------------------------------------------------
1 | #= Print all the subsequences of the string.
2 | =#
3 |
4 | ## Function
5 |
6 | function subsequence(s, ans)
7 | if (length(s) == 0)
8 | if (length(ans) >= 1)
9 | println(ans)
10 | end
11 | return
12 | end
13 | ch = s[1]
14 | rest_of_string = SubString(s, 2)
15 | subsequence(rest_of_string, ans)
16 | subsequence(rest_of_string, ans * ch)
17 | end
18 |
19 | ## Input
20 |
21 | println("Enter the string: ")
22 | s = readline()
23 |
24 | ## Calling the Function
25 |
26 | println("The subsequences are :")
27 | subsequence(s, "")
28 |
29 | #=
30 | Sample Test Case:
31 | Input:
32 | Enter the string: abc
33 | Output:
34 | The subsequences are :
35 | c
36 | b
37 | bc
38 | a
39 | ac
40 | ab
41 | abc
42 | Time complexity: O ( 2^N * l) (where l is the length of string)
43 | =#
44 |
--------------------------------------------------------------------------------
/Julia/dp/fibonacci.jl:
--------------------------------------------------------------------------------
1 | #= Finding the Nth number in the Fibonacci Sequence using Dynamic Programming
2 | =#
3 |
4 | ## Function
5 |
6 | function fibonacci(n)
7 | f = Int64[]
8 | push!(f, 0)
9 | push!(f, 1)
10 | for i = 3:n
11 | temp = f[i-1] + f[i-2]
12 | push!(f, temp)
13 | end
14 | return f[n]
15 | end
16 |
17 | ## Input
18 |
19 | print("Enter the number: ")
20 | n = readline()
21 | n = parse(Int64, n)
22 | println("The $(n)th fibonacci number is ")
23 |
24 | ## Calling the function
25 |
26 | fibonacci(n)
27 |
28 | #=
29 | Sample Test Case:
30 | Input:
31 | Enter the number: 5
32 | Output:
33 | The 5th fibonacci number is 3
34 |
35 | Time Complexity: O ( N )
36 | =#
37 |
--------------------------------------------------------------------------------
/Julia/math/neon_number.jl:
--------------------------------------------------------------------------------
1 | """Julia program to check if a number is a Neon Number or not
2 | A neon number is a number where the sum of digits of square of the number is equal to the number.
3 | """
4 |
5 | function check_neon_num(n)
6 | sum = 0
7 | temp = n ^ 2
8 | while(temp != 0)
9 | sum = sum + (temp % 10)
10 | temp = temp ÷ 10
11 | end
12 | if(sum == n)
13 | return true
14 | else
15 | return false
16 | end
17 | end
18 |
19 |
20 | print("Enter the number: ")
21 | n = readline()
22 | n = parse(Int, n)
23 | res = check_neon_num(n)
24 | if res
25 | println("The given number $n is a Neon Number.")
26 | else
27 | println("The given number $n is not a Neon Number.")
28 | end
29 |
30 |
31 | """
32 | Time Complexity: O(log(num)), where 'num' is the given number
33 | Space Complexity: O(1)
34 |
35 | SAMPLE INPUT AND OUTPUT
36 |
37 | SAMPLE 1
38 | Enter the number: 0
39 | The given number 0 is a Neon Number..
40 |
41 | SAMPLE 2
42 | Enter the number: 14
43 | The given number 14 is not a Neon Number.
44 |
45 | """
46 |
--------------------------------------------------------------------------------
/Julia/math/number_of_digits.jl:
--------------------------------------------------------------------------------
1 | # Julia program to Find the Number of Digits in a Number
2 |
3 | # Extracting the number of digits
4 | function number_of_digits(num)
5 | count = 0
6 | while(num != 0)
7 | count = count + 1
8 | num = num ÷ 10
9 | end
10 | return count
11 | end
12 |
13 | print("Enter the number: ")
14 | num = readline()
15 | num = parse(Int, num)
16 | count = number_of_digits(abs(num))
17 | println("The number of digits in the given number is $count.")
18 |
19 | """
20 | Time Complexity: O(log(num)), where 'num' is the length of the given number
21 | Space Complexity: O(1)
22 | SAMPLE INPUT AND OUTPUT
23 | SAMPLE 1
24 | Enter the number: -12
25 | The number of digits in the given number is 3.
26 | SAMPLE 2
27 | Enter the number: 43258
28 | The number of digits in the given number is 22.
29 | """
30 |
--------------------------------------------------------------------------------
/Julia/math/pronic_number.jl:
--------------------------------------------------------------------------------
1 | """
2 | Julia program to check if a number is a pronic number
3 | Pronic Numbers are those numbers that can be arranged to form a rectangle.
4 | It is a number which is the product of two consecutive integer
5 | """
6 |
7 | function check_pronic(x)
8 | i = 0
9 | while(i <= isqrt(x))
10 | if(x == i * (i + 1))
11 | return true
12 | end
13 | i = i + 1
14 | end
15 | return false
16 | end
17 |
18 |
19 | print("Enter the number: ")
20 | n = readline()
21 | n = parse(Int, n)
22 | res = check_pronic(abs(n))
23 | if(res)
24 | print("The given number $n is a pronic number.")
25 | else
26 | print("The given number $n is not a pronic number.")
27 | end
28 |
29 |
30 | """
31 | Time Complexity: O(log(n)), where 'n' is the given number
32 | Space Complexity: O(1)
33 |
34 | SAMPLE INPUT AND OUTPUT
35 |
36 | SAMPLE 1
37 |
38 | Enter the number: 154
39 | The given number 154 is not a pronic number.
40 |
41 | SAMPLE 2
42 | Enter the number: 72
43 | The given number 72 is a pronic number.
44 | """
45 |
--------------------------------------------------------------------------------
/Julia/math/reverse_number.jl:
--------------------------------------------------------------------------------
1 | # Julia program to reverse a number
2 |
3 | # Function to reverse a number.
4 | function reverse(num)
5 | rev = 0
6 | while(num > 0)
7 | # Extract the last digit of num and add it to rev
8 | rev = rev * 10 + num %10
9 | num = num ÷ 10
10 | end
11 | return rev
12 | end
13 |
14 | print("Enter the number: ")
15 | num = readline()
16 | num = parse(Int, num)
17 | rev = reverse(num)
18 | println("The reverse of the given number is $rev.")
19 |
20 |
21 | """
22 | Time Complexity: O(log(n)), where 'n' is the given number
23 | Space Complexity: O(1)
24 |
25 | SAMPLE INPUT AND OUTPUT
26 |
27 | SAMPLE 1
28 | Enter the number: 1234
29 | The reverse of the given number is 4321.
30 |
31 | SAMPLE 2
32 | Enter the number: 785487
33 | The reverse of the given number is 784587.
34 | """
35 |
--------------------------------------------------------------------------------
/Julia/math/sum_of_digits.jl:
--------------------------------------------------------------------------------
1 | # Julia program to Find the Sum of Digits of a Number
2 |
3 | # Extracting Each digits
4 | function sum_of_digits(num)
5 | sum = 0
6 | while(num != 0)
7 | sum = sum + (num % 10)
8 | num = num ÷ 10
9 | end
10 | return sum
11 | end
12 |
13 | print("Enter the number: ")
14 | num = readline()
15 | num = parse(Int, num)
16 | sum = sum_of_digits(abs(num))
17 | println("The sum of digits of the given number is $sum.")
18 |
19 | """
20 | Time Complexity: O(log(num)), where 'num' is the length of the given number
21 | Space Complexity: O(1)
22 |
23 | SAMPLE INPUT AND OUTPUT
24 |
25 | SAMPLE 1
26 | Enter the number: -12
27 | The sum of digits of the given number is 3.
28 |
29 | SAMPLE 2
30 | Enter the number: 43258
31 | The sum of digits of the given number is 22.
32 |
33 | """
34 |
--------------------------------------------------------------------------------
/Julia/math/sum_of_divisors.jl:
--------------------------------------------------------------------------------
1 | # Julia program to find the sum of divisors of a number.
2 |
3 | function sum_of_divisors(num)
4 | i = 1
5 | sum = 0
6 | while (i <= sqrt(num))
7 | if num % i == 0 && i == sqrt(num)
8 | sum = sum + i
9 | elseif num % i == 0
10 | sum = sum + i
11 | sum = sum + (num ÷ i)
12 | end
13 | i = i + 1
14 | end
15 | return sum
16 | end
17 |
18 |
19 | print("Enter the number: ")
20 | num = readline()
21 | num = parse(Int, num)
22 | sum = sum_of_divisors(num)
23 | print("The Sum of the Divisors of the given number is $sum.")
24 |
25 | """
26 | Time Complexity - O(n^(0.5)), where 'n' given is the number
27 | Space Complexity - O(1)
28 |
29 | SAMPLE INPUT AND OUTPUT
30 |
31 | SAMPLE I
32 |
33 | Enter the number: 256
34 | The Sum of the Divisors of the given number is 511.
35 |
36 | SAMPLE II
37 |
38 | Enter the number: 5687
39 | The Sum of the Divisors of the given number is 6384.
40 | """
41 |
--------------------------------------------------------------------------------
/Julia/math/towerOfHanoi.jl:
--------------------------------------------------------------------------------
1 | #= The famous Tower of Hanoi question where there are 3 towers with discs in them. You need
2 | to transfer all the discs from A to C =#
3 |
4 | ## Function
5 |
6 | function towerOfHanoi(discs, source = "A", destination = "C", helper = "B")
7 | if (discs == 0)
8 | return
9 | end
10 | towerOfHanoi(discs - 1, source, helper, destination)
11 | println("Move from $(source) to $(destination)")
12 | towerOfHanoi(discs - 1, helper, destination, source)
13 | end
14 |
15 | ## Input
16 |
17 | println("Enter the number of discs: ")
18 | n = readline()
19 | n = parse(Int64, n)
20 |
21 | ## Calling the function
22 |
23 | towerOfHanoi(n)
24 |
25 | #=
26 | Sample Test Case:
27 | Input:
28 | Enter the number of discs: 3
29 | Output:
30 | Move from A to C
31 | Move from A to B
32 | Move from C to B
33 | Move from A to C
34 | Move from B to A
35 | Move from B to C
36 | Move from A to C
37 | Time complexity: O(2^N)
38 | =#
39 |
--------------------------------------------------------------------------------
/Kotlin/Maths/Areas2D.kt:
--------------------------------------------------------------------------------
1 | package kotlin.math
2 |
3 | // Area of a Square
4 |
5 | fun square(a: Double): Double {
6 | return a * a
7 | }
8 |
9 | // Area of a Reactangle
10 |
11 | fun rectangle(l: Double, b: Double): Double{
12 | return l * b
13 | }
14 |
15 | // Area of a Circle
16 |
17 | fun circle(r: Double): Double{
18 | return PI * r * r
19 | }
20 |
21 | // Area of a Triangle
22 |
23 | fun triangle(b: Double, h: Double): Double{
24 | return b * h/2.0
25 | }
26 |
27 | // Area of a Parallelogram
28 |
29 | fun parallelogram(b: Double, h: Double): Double{
30 | return b * h
31 | }
32 |
33 | // Area of a Trapezium
34 |
35 | fun trapezium(a: Double, b:Double, h:Double): Double{
36 | return (a+b)*h/2.0
37 | }
38 |
39 |
40 | fun main() {
41 | println(square(2.0))
42 | println(rectangle(2.0, 4.6))
43 | println(circle(5.0))
44 | println(triangle(2.0,3.0))
45 | println(parallelogram(4.5,2.3))
46 | println(trapezium(1.5,4.5,6.0))
47 | }
48 |
49 |
50 | // Time Complexity - O(n)
51 | // Space Complexity - O(n)
52 |
--------------------------------------------------------------------------------
/Kotlin/Maths/Factorial.kt:
--------------------------------------------------------------------------------
1 | /*
2 | The factorial of a positive number n is given by:
3 | factorial of n (n!) = 1 * 2 * 3 * 4 * ... * n
4 | */
5 |
6 | import java.util.Scanner
7 |
8 | fun main(args: Array) {
9 |
10 | val reader = Scanner(System.`in`)
11 | print("Enter any number: ")
12 | var num :Int = reader.nextInt()
13 |
14 | var factorial: Long = 1
15 | for (i in 1..num) {
16 | // factorial = factorial * i;
17 | factorial *= i.toLong()
18 | }
19 | println("Factorial of $num = $factorial")
20 | }
21 |
22 | /*
23 | Sample Test case:
24 | Enter any number: 10
25 | Factorial of 10 = 3628800
26 | */
27 |
28 | /*
29 | Time Complexity : O(n)
30 | Auxiliary Space : O(1)
31 | */
32 |
33 |
--------------------------------------------------------------------------------
/Kotlin/Maths/FibonacciNumber.kt:
--------------------------------------------------------------------------------
1 | /*
2 | The Fibonacci series is a series where the next term is the sum of pervious two terms.
3 | The first two terms of the Fibonacci sequence is 0 followed by 1.
4 |
5 | The Fibonacci sequence: 0, 1, 1, 2, 3, 5, 8, 13, 21, ...
6 | */
7 | import java.util.Scanner
8 |
9 | fun main(args: Array) {
10 |
11 | val reader = Scanner(System.`in`)
12 | print("Enter any number: ")
13 | var number :Int = reader.nextInt()
14 |
15 | var index = 1
16 | var term1 = 0
17 | var term2 = 1
18 |
19 | print("Fibonacci series upto $number : ")
20 |
21 | while (index <= number) {
22 | print("$term1 , ")
23 |
24 | val sum = term1 + term2
25 | term1 = term2
26 | term2 = sum
27 |
28 | index++
29 | }
30 | }
31 |
32 | /*
33 | Sample Test case:
34 | Enter any number: 5
35 | Fibonacci series upto 5: 0 , 1 , 1 , 2 , 3
36 | */
37 |
38 | /*
39 | Time Complexity : O(n)
40 | Auxiliary Space : O(1)
41 | */
42 |
43 |
--------------------------------------------------------------------------------
/Kotlin/Maths/PalindromeNumber.kt:
--------------------------------------------------------------------------------
1 | //A palindromic number is a number that remains the same when its digits are reversed
2 |
3 | import java.util.*
4 |
5 | //Function to check Palindrome Number
6 | fun isPalindrome(number: Int): Boolean {
7 | var isPalindromeNumber = false
8 | var sum = 0
9 | var tempNum = number
10 |
11 | while (tempNum > 0) {
12 | val r = tempNum % 10
13 | sum = sum * 10 + r
14 | tempNum /= 10
15 | }
16 | if (sum == number) {
17 | isPalindromeNumber = true
18 | }
19 | return isPalindromeNumber
20 | }
21 |
22 | //Main Function, Entry Point of Program
23 | fun main(arg: Array) {
24 | val sc = Scanner(System.`in`)
25 |
26 | // Input Number
27 | println("Enter Number : ")
28 | val num: Int = sc.nextInt()
29 |
30 | //Call Function to check Number
31 | if (isPalindrome(num))
32 | println("$num is a Palindrome Number")
33 | else
34 | println("$num is not a Palindrome Number")
35 | }
36 |
37 | /*Sample Test Case:
38 | Enter Number :
39 | 12321
40 | 12321 is a Palindrome Number
41 | */
42 |
--------------------------------------------------------------------------------
/Kotlin/cp/ReverseString.kt:
--------------------------------------------------------------------------------
1 | /* Program to reverse a given sentence using a recursive loop in Kotlin
2 | We will create a recursive function and operate it till the end and store the reverse order.
3 | */
4 |
5 |
6 | import java.util.Scanner
7 |
8 | fun main(args: Array) {
9 |
10 | val reader = Scanner(System.`in`)
11 | print("Enter any sentence: ")
12 | var sentence :String = reader.nextString()
13 |
14 | val reversed = reverse(sentence)
15 | println("The reversed sentence is: $reversed")
16 | }
17 |
18 | fun reverse(sentence: String): String {
19 | if (sentence.isEmpty())
20 | return sentence
21 |
22 | return reverse(sentence.substring(1)) + sentence[0]
23 | }
24 |
25 | /*
26 | Sample Test case:
27 | Enter any sentence: Hello Kotlin
28 | The reversed sentence is : niltoK olleH
29 | */
30 |
31 | /*
32 | Time Complexity : O(n)
33 | Auxiliary Space : O(1)
34 | */
35 |
36 |
--------------------------------------------------------------------------------
/LOGO/Logo1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HarshCasper/NeoAlgo/4f1e5bdd6d9d899fa354de94740e0aecf5ecd2be/LOGO/Logo1.png
--------------------------------------------------------------------------------
/LOGO/Logo3.jpeg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HarshCasper/NeoAlgo/4f1e5bdd6d9d899fa354de94740e0aecf5ecd2be/LOGO/Logo3.jpeg
--------------------------------------------------------------------------------
/LOGO/logo2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HarshCasper/NeoAlgo/4f1e5bdd6d9d899fa354de94740e0aecf5ecd2be/LOGO/logo2.png
--------------------------------------------------------------------------------
/PHP/readme.md:
--------------------------------------------------------------------------------
1 |
2 | 
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 | # Codes in the PHP language
11 |
12 | ## Sorting Algorithms
13 |
14 | - [Insertion Sort](sort/InsertionSort.php)
15 | - [Selection Sort](sort/SelectionSort.php)
16 | - [Quick Sort](sort/quick_sort.php)
17 | - [Bubble Sort](sort/bubble_sort.php)
--------------------------------------------------------------------------------
/Python/Bit--Manipulation/count_num_of_set_bits.py:
--------------------------------------------------------------------------------
1 | # Python program to count the number of set bits in a number
2 |
3 | def countNumSetBits(num):
4 | cnt = 0
5 | while(num > 0):
6 | cnt = cnt + (num & 1)
7 | num = (num >> 1)
8 | return cnt
9 |
10 |
11 | if __name__ == '__main__':
12 | print("Enter the number: ")
13 | num = int(input())
14 | res = countNumSetBits(num)
15 | print("The number of set bits present in the given number is $res")
16 |
17 |
18 | """
19 | Time Complexity: O(log(n)), where n is the given number
20 | Space Complexity: O(1)
21 |
22 | SAMPLE INPUT AND OUTPUT
23 |
24 | SAMPLE I
25 |
26 | Enter the number: 12354
27 | The number of set bits present in the given number is 4
28 |
29 | SAMPLE II
30 |
31 | Enter the number: 2048
32 | The number of set bits present in the given number is 1
33 | """
34 |
--------------------------------------------------------------------------------
/Python/Bit--Manipulation/reverse_bits.py:
--------------------------------------------------------------------------------
1 | """
2 | Python program to reverse the bits of a number
3 | Given an integer, reverse its bits in its binary equivalent and
4 | print the new number obtained in its decimal form
5 | """
6 |
7 |
8 | def reverse_bits(n):
9 | rev = 0
10 |
11 | while(n > 0):
12 | # Shift the bit of the reversed(answer) number to the right
13 | rev = rev << 1
14 | # Stores the temporary lsb of the given number
15 | rem = n & 1
16 | # Set the lsb of the answer variable with the stored value
17 | rev = rem | rev
18 | # Drops the already processed lsb of the given number
19 | n = n >> 1
20 | return rev
21 |
22 |
23 | if __name__ == '__main__':
24 | print("Enter the number? ", end="")
25 | num = int(input())
26 | rev = reverse_bits(num)
27 | print("The bits-reversed number is: {}".format(rev))
28 |
29 | """
30 | Time Complexity: O(n)
31 | Space Complexity: O(1)
32 |
33 | SAMPLE INPUT AND OUTPUT
34 |
35 | Enter the number? 39
36 | The bits-reversed number is: 57
37 | """
38 |
--------------------------------------------------------------------------------
/Python/Bit--Manipulation/toggle_kth_bit.py:
--------------------------------------------------------------------------------
1 | # Python program to toggle the k-th bit of a number.
2 | def toggle(num, k):
3 | return (num ^ (1 << (k-1)))
4 |
5 |
6 | if __name__ == '__main__':
7 | print("Enter the number: ", end="")
8 | n = int(input())
9 | print("Enter the value of k(where you need to toggle the k'th bit): ", end="")
10 | b = int(input())
11 | res = toggle(n, b)
12 | print("The given number, after toggling the k-th bit is {}".format(res))
13 |
14 | """
15 | Time Complexity: O(1)
16 | Space Complexity: O(1)
17 |
18 | SAMPLE INPUT AND OUTPUT
19 |
20 | SAMPLE 1
21 | Enter the number: 24
22 | Enter the value of k(where you need to toggle the k'th bit): 3
23 | The given number, after toggling the k-th bit is 28.
24 |
25 | SAMPLE 2
26 | Enter the number: 33
27 | Enter the value of k(where you need to toggle the k'th bit): 12
28 | The given number, after toggling the k-th bit is 2081.
29 | """
30 |
--------------------------------------------------------------------------------
/Python/blockchain/README.md:
--------------------------------------------------------------------------------
1 | a
2 |
--------------------------------------------------------------------------------
/Python/cp/LetterCount.py:
--------------------------------------------------------------------------------
1 | """
2 | The program uses dictionary in python
3 | to count the number of occurence a letter
4 | makes in a word
5 | """
6 |
7 |
8 | def LetterCount(word):
9 | dict = {}
10 |
11 | for c in word:
12 | co = dict.get(c, 0)
13 | if co == 0:
14 | dict[c] = 1
15 | else:
16 | dict[c] = co + 1
17 |
18 | return(dict)
19 |
20 | if __name__ == '__main__':
21 | word = input("enter a word ").lower()
22 | LetterCount = LetterCount(word)
23 | print(LetterCount)
24 |
25 |
26 | """
27 | Sample Input-output
28 | enter a word aayuhsi
29 | {'a': 2, 'y': 1, 'u': 1, 'h': 1, 's': 1, 'i': 1}
30 | """
31 |
32 | """
33 | Time complexity- O(n)
34 |
35 | """
36 |
--------------------------------------------------------------------------------
/Python/cp/README.md:
--------------------------------------------------------------------------------
1 | a
2 |
--------------------------------------------------------------------------------
/Python/cp/Run_Length_Encoding.py:
--------------------------------------------------------------------------------
1 | def encode(s):
2 |
3 | j = 0
4 | #lenght of the input string
5 | length = len(s)
6 |
7 | while (j < length- 1):
8 |
9 | # counter for keeping the track of character
10 | counter = 1
11 | while (j < length - 1 and s[j] == s[j + 1]):
12 | counter += 1
13 | j += 1
14 | j += 1
15 | # printing the encoded value
16 | print(s[j - 1] + str(counter), end = " ")
17 |
18 |
19 | s = input("Enter the string to encode \n")
20 | print("Encoded string")
21 | encode(s)
22 |
23 | '''
24 | Time complexity : O(N)
25 | Space complexity O(1)
26 | '''
27 |
28 | '''
29 | Test Case :
30 | Input :
31 | Enter the string to encode
32 | tttyyss
33 | Output :
34 | Encoded string
35 | t3 y2 s2
36 | '''
--------------------------------------------------------------------------------
/Python/cp/Sort_An_Arrayof0s1sand2s.py:
--------------------------------------------------------------------------------
1 | def sort012(arr,n):
2 | listofZero = []
3 | listofOne = []
4 | listofTwo = []
5 |
6 | for i in range(0,n):
7 | if arr[i] == 0:
8 | listofZero.append(0)
9 | elif arr[i] == 1:
10 | listofOne.append(1)
11 | else:
12 | listofTwo.append(2)
13 |
14 | Total = listofZero+listofOne+listofTwo
15 | return Total
16 |
17 |
18 |
19 |
20 | arr = list(map(int,input("Enter the Number:\n").split()))
21 | n = len(arr)
22 | print(sort012(arr,n))
23 |
24 | '''
25 | Time Complexity is O(n)
26 | Space Complexity is O(1)
27 |
28 | Input:
29 | Enter the Number:
30 | 0 2 1 2 0
31 |
32 | Output:
33 | 0 0 1 2 2
34 | Explanation:
35 | 0s 1s and 2s are segregated
36 | into ascending order.
37 | '''
--------------------------------------------------------------------------------
/Python/cp/VowelsConsants.py:
--------------------------------------------------------------------------------
1 | '''
2 |
3 | The program helps to count the number of
4 | vowels and consants in a string.
5 |
6 | '''
7 |
8 | def Count(word):
9 | vc, cc = 0, 0
10 |
11 | for s in word:
12 | if (s.isalpha()):
13 | if (s == 'a' or s == 'e' or s == 'i' or s == 'o' or s == 'u'):
14 | vc = vc + 1
15 | else:
16 | cc = cc + 1
17 | return vc, cc
18 |
19 | if __name__ == "__main__":
20 | TheWord = input("Enter a string: ").lower()
21 | vc, cc = Count(TheWord)
22 | print("Vowel count = ", vc, " Consonant count = ", cc)
23 |
24 | else:
25 | print("File one executed when imported")
26 |
27 |
28 | """
29 | Time Complexity: O(n)
30 |
31 | Sample Input:
32 | Enter a string: Hello World
33 |
34 | Sample Output:
35 | Vowel count = 3 Consonant count = 7
36 | """
37 |
--------------------------------------------------------------------------------
/Python/cp/adjacent_elements_product.py:
--------------------------------------------------------------------------------
1 | """
2 | When given a list of integers,
3 | we have to find the pair of adjacent
4 | elements that have the largest product
5 | and return that product.
6 | """
7 |
8 |
9 | def MaxAdjacentProduct(intList):
10 | max = intList[0]*intList[1]
11 | a = 0
12 | b = 1
13 | for i in range(1, len(intList) - 1):
14 | if(intList[i]*intList[i+1] > max):
15 | a = i
16 | b = i+1
17 | max = intList[i]*intList[i+1]
18 | return(a, b, max)
19 |
20 | if __name__ == '__main__':
21 | intList = list(map(int, input("\nEnter the numbers : ").strip().split()))
22 | pos1, pos2, max = MaxAdjacentProduct(intList)
23 | print("Max= ", max, " product of elements at position ", pos1, ",", pos2)
24 |
25 | """
26 | Sample Input - Output:
27 |
28 | Enter the numbers : -5 -3 -2
29 | Max= 15 product of elements at position 0 , 1
30 |
31 | Time Complexity : O(n)
32 | Space Complexity : O(1)
33 |
34 | """
35 |
--------------------------------------------------------------------------------
/Python/cp/bulb_switcher.py:
--------------------------------------------------------------------------------
1 | '''
2 | Bulb switcher problem
3 |
4 | There are n bulbs that are initially off.
5 | You first turn on all the bulbs,then you turn off every second bulb.
6 | On the third round,toggle every third bulb (turn on if it's off or vice-versa)
7 | For the ith round, you toggle every i bulb.
8 | For the nth round, you only toggle the last bulb.
9 | Return the number of bulbs that are on after n rounds.
10 |
11 | Approach : By observation, a bulb is ON if it is toggled odd number of times
12 | only when `i` has perfect square root, its number of divisors is odd.
13 |
14 | Problem link: https://leetcode.com/problems/bulb-switcher/
15 |
16 | Time Complexity: O(N)
17 | Space Complexity: O(1)
18 | '''
19 |
20 |
21 | def bulbSwitcher(n):
22 | bulb = 0
23 | while bulb * bulb <= n:
24 | bulb += 1
25 | return bulb - 1
26 |
27 |
28 | N = int(input())
29 | print(bulbSwitcher(N))
30 |
31 | '''
32 | Input: 5
33 | output: 2
34 | '''
35 |
--------------------------------------------------------------------------------
/Python/cp/house_robber.py:
--------------------------------------------------------------------------------
1 | '''
2 | The rob function takes an array as input
3 | and returns total amount that can be robbed.
4 |
5 | '''
6 |
7 | def rob(nums):
8 | """
9 | :type nums: List[int]
10 | :rtype: int
11 | """
12 | if nums == [] or len(nums) == 0:
13 | return 0
14 | elif len(nums) == 1:
15 | return nums[0]
16 |
17 | runningTotal = [-1, -1]
18 | runningTotal[0] = nums[0]
19 | runningTotal[1] = max(nums[0], nums[1])
20 |
21 | for i in range(2, len(nums)):
22 | runningTotal.append(max([nums[i] + runningTotal[i - 2],
23 | runningTotal[i - 1]]))
24 |
25 | return runningTotal[-1]
26 |
27 | def main():
28 | nums = input()
29 |
30 | rob(nums)
31 |
32 | main()
33 |
34 | # Complexity -
35 |
36 | # Time O(N),
37 | # Space O(N); N = length of array
38 |
39 | # Sample input/output
40 | #input: nums = [2, 7, 9, 3, 1]
41 | #Output: 12
42 |
43 | #input: nums = [1, 2, 3, 1]
44 | #Output: 4
45 |
46 |
--------------------------------------------------------------------------------
/Python/cp/staircase_problem.py:
--------------------------------------------------------------------------------
1 | """This program finds the total number of possible combinations that can be used to
2 | climb statirs . EG : for 3 stairs ,combination and output will be 1,1,1 , 1,2 , 2,1 i.e 3 . """
3 |
4 | def counting_stairs(stair_number):
5 | result = stair_number
6 | # This function uses Recursion.
7 | if(stair_number <=1):
8 | result = 1
9 | else:
10 | result = (counting_stairs(stair_number-1) + counting_stairs(stair_number-2))
11 | return result
12 |
13 | if __name__ == '__main__':
14 | count_stair = int(input("Enter total number of stairs: "))
15 | print(f"Total Number of possible Combinations = {counting_stairs(count_stair)}")
16 |
17 |
18 | """Output
19 | Total Number of possible Combinations = 8
20 | Enter total number of stairs: 5
21 |
22 | Time Complexity : O(2^n)
23 | Space Complexity :O(1)
24 | Created by Shubham Patel on 16-12-2020 on WoC
25 | """
26 |
--------------------------------------------------------------------------------
/Python/cp/stock_span.py:
--------------------------------------------------------------------------------
1 | ''' Stock Span Problem
2 | Given a list of prices of a stock for N number of days,
3 | find stock span for each day.
4 | '''
5 |
6 |
7 | def calcSpan(price):
8 | day = len(price)
9 | stack = []
10 | span = [0 for i in range(0, day)]
11 |
12 | span[0] = 1
13 | stack.append(0)
14 |
15 | for i in range(1, day):
16 |
17 | while (len(stack) > 0 and price[stack[-1]] <= price[i]):
18 | stack.pop()
19 |
20 | if len(stack) <= 0:
21 | span[i] = i + 1
22 | else:
23 | span[i] = i - stack[-1]
24 |
25 | stack.append(i)
26 |
27 | print(span)
28 |
29 |
30 | prices = list(map(int, input().strip().split()))
31 | calcSpan(prices)
32 |
33 | '''
34 | sample Input:
35 | 10 30 20 50 20
36 | sample output:
37 | 1 2 1 4 1
38 |
39 | Time complexity: O(n)
40 | space complexity:O(n)
41 | '''
42 |
--------------------------------------------------------------------------------
/Python/graphs/README.md:
--------------------------------------------------------------------------------
1 | a
2 |
--------------------------------------------------------------------------------
/Python/graphs/dijkstras_algorithm.py:
--------------------------------------------------------------------------------
1 | # Importing Libraries
2 | import matplotlib.pyplot as plt
3 | import networkx as nx
4 |
5 | # Creating an empty Graph
6 | g = nx.Graph()
7 |
8 | # Adding Nodes to empty graph
9 | for i in range(1, 7):
10 | g.add_node(i)
11 |
12 | # Printing Nodes
13 | # print("Nodes are ")
14 | print(g.nodes())
15 | # Adding Edges
16 | g.add_edge(1, 2)
17 | g.add_edge(1, 3)
18 | g.add_edge(4, 6)
19 | g.add_edge(5, 4)
20 | g.add_edge(2, 3)
21 | g.add_edge(2, 6)
22 |
23 | # Edge Testing
24 | print("Edges are ")
25 | print(g.edges())
26 |
27 | nx.draw(g)
28 | plt.show()
29 |
30 | # dijkstra's Algorithm
31 | h = nx.Graph()
32 | e = [('a', 'b', 1), ('b', 'c', 2),
33 | ('a', 'c', 3), ('c', 'd', 4), ('d', 'e', 2), ('b', 'e', 1)]
34 |
35 | h.add_weighted_edges_from(e)
36 | nx.draw(h, with_labels=True)
37 | plt.show()
38 |
39 | print(nx.dijkstra_path(h, 'a', 'e'))
40 |
--------------------------------------------------------------------------------
/Python/math/Binary_Exponentiation.py:
--------------------------------------------------------------------------------
1 | # Python Program to find Binary Exponent Iteratively and Recursively.
2 |
3 | # Iterative function to calculate exponent.
4 | def binExpo_iterate(a,b):
5 | res=1
6 | while b>0:
7 | if b%2==1:
8 | res=(res*a)
9 | a=a*a
10 | b//=2
11 | return res
12 |
13 | # Recursive function to calculate exponent.
14 | def binExpo_recurse(a,b):
15 | if b==0:
16 | return 1
17 | res=int(binExpo_recurse(a,b//2))
18 | res=res*res
19 | if b%2==1:
20 | return (res*a)
21 | else:
22 | return res
23 |
24 | # Main function
25 | a=int(input())
26 | b=int(input())
27 |
28 | if a==0 and b==0:
29 | print("Math error")
30 | elif b<0:
31 | print("Exponent must be positive")
32 | elif a==0:
33 | print(0)
34 | else:
35 | resIterate=binExpo_iterate(a,b);
36 | resRecurse=binExpo_recurse(a,b);
37 | print(resIterate)
38 | print(resRecurse)
39 |
--------------------------------------------------------------------------------
/Python/math/CheckArmstrongNumber.py:
--------------------------------------------------------------------------------
1 | # This program checks whether a number is an armstrong number or not
2 |
3 | import math
4 |
5 | def no_of_digits(n : int) -> int:
6 | count = 0
7 | while n > 0:
8 | count += 1
9 | n = n // 10
10 | return count
11 |
12 | def add(n : int) -> int:
13 | temp = n
14 | tot = 0
15 | nod = no_of_digits(temp)
16 | while n > 0:
17 | r = n % 10
18 | tot += r ** nod
19 | n = n // 10
20 | return tot
21 |
22 | def checkArmstrong(num : int) -> bool:
23 | return add(num) == num
24 |
25 | num = int(input("Enter the number"))
26 | print(add(num))
27 | if checkArmstrong(num):
28 | print("It is an armstrong number")
29 | else:
30 | print("It is not an armstrong number")
31 |
32 | # Example:
33 | # 1. Input : 153
34 | # Output : It is an armstrong number
35 | # 2. Input : 12
36 | # Output : It is not an armstrong number
37 |
--------------------------------------------------------------------------------
/Python/math/Extended_Euclidean_Algorithm.py:
--------------------------------------------------------------------------------
1 | #Extended Euclidean Algorithm
2 |
3 | def Extended_gcd(a, b, x, y):
4 | #Base Case
5 | if a == 0:
6 | x = 0
7 | y = 1
8 | return b
9 |
10 | x1, y1 = 0, 0
11 | gcd = Extended_gcd(b % a, a, x1, y1)
12 |
13 | x = y1 - int(b / a) * x1
14 | y = x1
15 |
16 | return gcd
17 |
18 | #Main code
19 | a = int(input())
20 | b = int(input())
21 | x, y = 0, 0
22 | print("GCD of numbers " + str(a) + " and " + str(b) + " is " + str(Extended_gcd(a, b, x, y)))
23 |
--------------------------------------------------------------------------------
/Python/math/Fibonacci.py:
--------------------------------------------------------------------------------
1 | """
2 | Function to print first n Fibonacci Numbers
3 | n takes the input of first n numbers to be printed
4 | """
5 |
6 |
7 | def fibonaccinumber(n):
8 | """
9 | >>fibonaccinumber(6)
10 | 0 1 1 2 3 5
11 |
12 | >>fibonaccinumber(10)
13 | 0 1 1 2 3 5 8 13 21 34 55
14 |
15 | """
16 | a, b = 0, 1
17 | if n < 1:
18 | return
19 | for x in range(0, n-1):
20 | print (b, end=' ')
21 | a, b = b, a + b
22 |
23 | if __name__=="__main__":
24 | n = int(input("Enter the number of terms: "))
25 | print(0,end=' ')
26 | (fibonaccinumber(n))
27 |
--------------------------------------------------------------------------------
/Python/math/GCD_Euclidean_Algorithm.py:
--------------------------------------------------------------------------------
1 | def calculate_gcd(a, b):
2 | while b:
3 | a, b = b, a % b
4 | return a
5 |
6 | if __name__ == '__main__':
7 | print(calculate_gcd(36, 20)) # Should print 4
8 | print(calculate_gcd(16, 24)) # Should print 8
9 |
--------------------------------------------------------------------------------
/Python/math/GCD_of_two_numbers.py:
--------------------------------------------------------------------------------
1 | """
2 | This is a program written in python for finding GCD of two numbers.
3 | This solution uses recursive approach as implementation.
4 | Recursive approach means a fuction calling itself for which a base condition is given so that the program knows where to terminate.
5 | """
6 |
7 | #definition of functions to find GCD of 2 numbers.
8 | def gcd_of_nums(x,y):
9 | #choose the smaller number
10 | if x > y:
11 | t=x
12 | x=y
13 | y=t
14 |
15 | if(x==0):
16 | return y
17 | else:
18 | return gcd_of_nums(x,y%x)
19 |
20 | def main():
21 | num1 = int(input("Enter 1st number: "))
22 | num2 = int(input("Enter 2nd number: "))
23 |
24 | print("The GCD is: ", gcd_of_nums(num1,num2))
25 |
26 | if __name__ == "__main__":
27 | main()
28 |
29 |
30 | """
31 | Output:
32 |
33 | Enter 1st number: 48
34 | Enter 2nd number: 6
35 | The GCD is: 6
36 |
37 | Enter 1st number: 43
38 | Enter 2nd number: 54
39 | The GCD is: 1
40 | """
41 | print("\n")
42 |
--------------------------------------------------------------------------------
/Python/math/HarshadNumber.py:
--------------------------------------------------------------------------------
1 | """
2 | A number is said to be a Harshad Number if it is divisible by the sum of its digits.
3 | For example: The number 84 is divisible by the sum (12) of its digits (8, 4).
4 |
5 | """
6 |
7 |
8 | def isHarshad(number) :
9 | copy = number
10 |
11 | # Calculating the sum of digits of the number
12 | sum_of_digits = 0
13 | while number != 0 :
14 | digit = number % 10
15 | sum_of_digits += digit
16 | number = number // 10
17 |
18 | # Checking if Number is divisible by sum of digits
19 | if copy % sum_of_digits == 0 :
20 | return True
21 | return False
22 |
23 |
24 | user_input = int(input("Enter a number:"))
25 |
26 | if isHarshad(user_input):
27 | print(user_input, "is a Harshad number")
28 | else:
29 | print(user_input, "is not a Harshad number")
30 |
31 | """
32 | Space Complexity O(1)
33 | Time Complexity O(log(n))
34 |
35 | Sample input/output:
36 | Enter a number:84
37 | 84 is a Harshad number
38 |
39 | Enter a number:123
40 | 123 is not a Harshad number
41 |
42 | """
43 |
--------------------------------------------------------------------------------
/Python/math/Large_number_factorial.py:
--------------------------------------------------------------------------------
1 | # Python Program to compute Large factorial numbers
2 |
3 |
4 | def factorial_range(start, end):
5 | if start+1 < end:
6 | middle = start + ((end - start)//2) # computing the mid element
7 | # recursive function to half the digits
8 | return factorial_range(start, middle) * factorial_range(middle+1, end)
9 | if start == end:
10 | return start
11 | return start*end
12 |
13 |
14 | def factorialtree(n): # function to divide the factorial in trees
15 | if n < 2:
16 | return 1
17 | return factorial_range(1, n)
18 |
19 |
20 | # Driver Code
21 | n = int(input())
22 | print(factorialtree(n))
23 |
24 | '''
25 | Sample I/O:
26 | input:
27 | 12
28 | Output:
29 | 479001600
30 | Time Complexity: O(logN)
31 | Space Complexity: O(1)
32 | '''
33 |
--------------------------------------------------------------------------------
/Python/math/Least_common_multiple.py:
--------------------------------------------------------------------------------
1 | # Python program to find LCM of two numbers
2 |
3 | # using euclid method to find gcd of two numbers
4 |
5 |
6 | def euclidGCD(number1, number2):
7 | if number2 == 0:
8 | return number1
9 | return euclidGCD(number2, number1 % number2)
10 |
11 | # Calculating lcm of two numbers using GCD
12 |
13 |
14 | def lcm(number1, number2):
15 | return (number1 * number2) // euclidGCD(number1, number2)
16 |
17 | number1, number2 = [int(x) for x in input().split()]
18 | print(lcm(number1, number2))
19 |
20 | '''
21 | Sample I/O:
22 |
23 | Sample 1:
24 | Input:761457 614573
25 | Output:467970912861
26 |
27 | Sample 2:
28 | Input:6 8
29 | Output:24
30 |
31 | Time Complexity :O(logn)
32 | Space Complexity:O(1)
33 | '''
34 |
--------------------------------------------------------------------------------
/Python/math/Next_Palindrome.py:
--------------------------------------------------------------------------------
1 | '''
2 | Python Program to get the next nth palindrome of a given number.
3 | An integer is a palindrome if the reverse of that number is
4 | equal to the original number.
5 | '''
6 |
7 |
8 | def isPalindrome(num):
9 | return str(num) == str(num)[::-1]
10 |
11 |
12 | def getNthPalindrome(n, start):
13 | if n < 1:
14 | return start
15 |
16 | while not isPalindrome(start + 1):
17 | start += 1
18 |
19 | return getNthPalindrome(n - 1, start + 1)
20 |
21 |
22 | if __name__ == '__main__':
23 | num = int(input('Enter a Number: '))
24 | n = int(input('Enter nth position: '))
25 | print(getNthPalindrome(n, num))
26 |
27 |
28 | '''
29 | Sample Case:
30 | Example 1:
31 | Enter a number: 12021
32 | Enter nth position: 10
33 | 13031
34 |
35 | Example 2:
36 | Enter a number: 141
37 | Enter nth position: 5
38 | 191
39 |
40 | Time Complexity: O(10^k)
41 | Space Complexity: O(1)
42 | where k = no of digits in given number
43 | '''
44 |
--------------------------------------------------------------------------------
/Python/math/Next_Prime_Number.py:
--------------------------------------------------------------------------------
1 | '''
2 | INTRODUCTION
3 |
4 | The code below calculates and returns the next prime number from the number given by user.
5 | It takes a number n from user and returns a number x such that
6 | 1. x is greater than n
7 | 2. x is a prime number and
8 | 3. there are no prime numbers between n and x
9 |
10 | '''
11 |
12 | def next_prime(n):
13 | # looping from next number to find if it prime or not
14 | x = n+1
15 | while True:
16 | flag = False
17 | # checking whether x is divisible by numbers from 2 to it's half
18 | for y in range(2,x//2+1):
19 | if x%y==0:
20 | x+=1
21 | flag = True
22 | break
23 | if flag==False:
24 | return(x)
25 |
26 | n = int(input("Enter a number : "))
27 | print('Next prime number is ', next_prime(n))
28 |
29 | '''
30 | OUTPUT
31 |
32 | Enter a number : 23
33 | Next prime number is 29
34 |
35 |
36 | TIME COMPLEXITY : O(n²)
37 | SPACE COMPLEXITY : O(1)
38 | '''
39 |
--------------------------------------------------------------------------------
/Python/math/Noble_Integer.py:
--------------------------------------------------------------------------------
1 | ''' An integer x is said to be Noble given an array
2 | if the number of integers greater than x are equal to x.
3 | If noble integer is not found output is -1.
4 | '''
5 | # To find the noble integer from the given list
6 | def nobleint():
7 | x = 0
8 | lst.sort()
9 | for i in range(0, num - 1):
10 | if lst[i] == lst[i + 1]:
11 | continue
12 | if lst[i] == num - i - 1:
13 | x = 1
14 | return num - i - 1
15 | if x == 0:
16 | return -1
17 |
18 | if __name__ == '__main__':
19 | num = int(input('Enter the number of elements:'))
20 | lst = list(map(int, input('Enter the elements:').split()))
21 | print nobleint(lst, num)
22 |
23 | '''
24 | Sample Output
25 |
26 | Enter the number of elements:4
27 | Enter the elements:7 3 9 81
28 | 3
29 | Enter the number of elements:3
30 | Enter the elements:2 2 2
31 | -1
32 |
33 | Complexities
34 | Time Complexity:O(nlogn)
35 | Space Complexity:O(1)
36 | '''
37 |
38 |
--------------------------------------------------------------------------------
/Python/math/Palindrome.py:
--------------------------------------------------------------------------------
1 | """
2 | Python Program to check whether a number is Palindrome or not
3 | An integer is a palindrome if the reverse of that number is equal to the original number.
4 | Example of Palindromes are 11,44,101,121.
5 |
6 | """
7 |
8 | def palindrome(n):
9 | temp = n
10 | sum = 0
11 | remainder = 0
12 | while n > 0:
13 | remainder = n % 10
14 | sum = sum * 10 + remainder
15 | n = n // 10
16 | if sum == temp:
17 | print (temp, 'is a palindrome')
18 | else:
19 | print (temp, 'is not a palindrome')
20 | if __name__ == '__main__':
21 | n = eval(input('Enter No '))
22 | palindrome(n)
23 |
24 | """
25 | Sample Case:
26 | Example 1:
27 | Enter a number: 121
28 | 121 is a palindrome
29 |
30 | Example 2:
31 | Enter a number: 123
32 | 123 is not a palindrome
33 |
34 | Time Complexity: O(n)
35 | Space Complexity: O(1)
36 |
37 | """
38 |
--------------------------------------------------------------------------------
/Python/math/README.md:
--------------------------------------------------------------------------------
1 |
2 | - a
3 |
--------------------------------------------------------------------------------
/Python/math/Squares_in_2n_Chessboard.py:
--------------------------------------------------------------------------------
1 | #Find total number of Squares in a N*N cheesboard.
2 |
3 | class Solution:
4 | # using mathematical logic
5 | def squares(self, N):
6 |
7 | sum=0
8 | for i in range(1,N+1):
9 | s=i*i
10 | sum+=s
11 | return sum
12 |
13 | #taking input
14 | num = int(input("Enter the number :"))
15 | obj = Solution()
16 | print("The square : ")
17 | print(obj.squares(num))
18 |
19 | '''
20 | Time complexity : O(N)
21 | Space complexity : O(1)
22 |
23 | Input :
24 | Enter the number : 1
25 | Output :
26 | The square is : 1
27 | '''
--------------------------------------------------------------------------------
/Python/math/UglyNumber.py:
--------------------------------------------------------------------------------
1 | '''
2 | Ugly numbers are numbers whose only prime factors are 2, 3 or 5.
3 | The sequence 1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15, …
4 | shows the first 11 ugly numbers.
5 | '''
6 |
7 |
8 | def Divide(a, b):
9 | while a % b == 0:
10 | a = a / b
11 | return a
12 |
13 |
14 | def isUgly(num):
15 | num = Divide(num, 2)
16 | num = Divide(num, 3)
17 | num = Divide(num, 5)
18 | return 1 if num == 1 else 0
19 |
20 |
21 | def getUglyNo(num):
22 | i = 1
23 | count = 1
24 | while num > count:
25 | i += 1
26 | if isUgly(i):
27 | count += 1
28 | return i
29 |
30 | num = int(input("Enter Number: "))
31 | ugly = getUglyNo(num)
32 | print("Ugly number is ", ugly)
33 |
34 | '''
35 | Time Complexity:O(n)
36 | Space Complexity: O(1)
37 |
38 | Example 1:
39 | Input:
40 | Enter Number: 10
41 | Output:
42 | Ugly number is 12
43 |
44 | Example 2:
45 | Input:
46 | Enter Number: 4
47 | Output:
48 | Ugly number is 4
49 | '''
50 |
--------------------------------------------------------------------------------
/Python/math/double_factorial.py:
--------------------------------------------------------------------------------
1 | # Double Factorial.
2 |
3 |
4 | def double_fact_i(n): # iterative implementation
5 | ans = 1
6 | for i in range(n, 1, -2):
7 | ans *= i
8 | return ans
9 |
10 |
11 | def double_fact_r(n): # recursive implementation
12 | if n == 0 or n == 1: # checking for 1 or 0
13 | return 1
14 | return n * double_fact_r(n - 2)
15 |
16 |
17 | if __name__ == "__main__":
18 | n = input("enter number")
19 | print("Answer using Iterative method: " + str(double_fact_i(n)))
20 | print("Answer using recursive method: " + str(double_fact_r(n)))
21 |
22 | '''
23 | output:
24 | enter number4
25 | Answer using Iterative method: 8
26 | Answer using recursive method: 8
27 | enter number5
28 | Answer using Iterative method: 15
29 | Answer using recursive method: 15
30 | Time complexity : O(n) '''
31 |
--------------------------------------------------------------------------------
/Python/math/factorial.py:
--------------------------------------------------------------------------------
1 | # Calculate factorial using iterative approach
2 | def fact(x):
3 | result = 1
4 | for i in range(1,x):
5 | result = result * (i+1)
6 | return result
7 |
8 | # Calculate factorial using recursion
9 | def fact_rec(x):
10 | if x == 0 or x == 1:
11 | return 1
12 | else:
13 | return x * fact_rec(x-1)
14 |
15 |
16 | if __name__ == "__main__":
17 | n = int(input("Enter the number: "))
18 | print("The factorial of {} is: {} ".format(n, fact(n)))
19 |
--------------------------------------------------------------------------------
/Python/math/fibonacci_recursion.py:
--------------------------------------------------------------------------------
1 | # Fibonacci Sequence Using Recursion
2 |
3 | def fibo_rec(x):
4 | """
5 | >>fibo_rec(6)
6 | 0 1 1 2 3 5
7 |
8 | >>fibo_rec(10)
9 | 0 1 1 2 3 5 8 13 21 34
10 |
11 | """
12 | if x == 0:
13 | return 0
14 | elif x == 1:
15 | return 1
16 | else:
17 | return fibo_rec(x-1) + fibo_rec(x-2)
18 |
19 | if __name__ == "__main__":
20 | n = int(input("Enter the number of terms: "))
21 | for i in range(n):
22 | print(fibo_rec(i), end=" ")
23 |
--------------------------------------------------------------------------------
/Python/math/min_max_sum.py:
--------------------------------------------------------------------------------
1 | '''
2 | Given five positive integers, the aim is to find the minimum and maximum values that can be calculated by summing exactly four of the five integers.
3 |
4 | '''
5 |
6 | def MMSum(a):
7 | # sorting the array so that it becomes easier to find the min and max set of values
8 | a.sort()
9 | minn=0
10 | maxx=0
11 | for i in range(0,4):
12 | # summing up all minimum values
13 | minn+=a[i]
14 | for i in range(1,5):
15 | # summing up all maximum values
16 | maxx+=a[i]
17 | print(minn,maxx)
18 |
19 | # getting the input
20 | user_input = (input().strip().split())
21 | array = []
22 | for i in user_input:
23 | array.append(int(i))
24 | # calling the Min-Max-Sum function
25 | MMSum(array)
26 |
27 | '''
28 |
29 | COMPLEXITY:
30 |
31 | Time Complexity -> O(N)
32 | Space Complexity -> O(N)
33 |
34 | Sample Input:
35 | 1 2 3 4 5
36 |
37 | Sample Output:
38 | 10 14
39 |
40 | '''
41 |
--------------------------------------------------------------------------------
/Python/math/perfect_square.py:
--------------------------------------------------------------------------------
1 | '''
2 | A program that returns the count of perfect squares less than or equal to a given number.
3 | It also displays those numbers which are perfect squares within the range of that number.
4 | The number should be greater than or equal to 1
5 | '''
6 | #importing math function as it will be used for square root
7 | import math
8 | #count function
9 | def countsq(n):
10 | c=0
11 | for i in range(1,n+1):
12 | x=int(math.sqrt(i))
13 | #Checks whether the number is perfect square or not
14 | if((x*x)==i):
15 | c=c+1
16 | print(i)
17 | return c
18 | #Driver's code
19 | def main():
20 | n1=int(input("Enter a number"))
21 | c1=countsq(n1)
22 | print("The number of perfect squares are",c1)
23 | if __name__=="__main__":
24 | main()
25 |
26 |
27 | '''
28 | Time Complexity:O(n)
29 | Space Complexity:O(1)
30 |
31 | Input/Output
32 | Enter a number 55
33 | 1
34 | 4
35 | 9
36 | 16
37 | 25
38 | 36
39 | 49
40 | The number of perfect squares are 7
41 | '''
42 |
--------------------------------------------------------------------------------
/Python/math/positive_decimal_to_binary.py:
--------------------------------------------------------------------------------
1 | #Function to convert a positive decimal number into its binary equivalent
2 | '''
3 | By using the double dabble method, append the remainder
4 | to the list and divide the number by 2 till it is not
5 | equal to zero
6 | '''
7 | def DecimalToBinary(num):
8 | #the binary equivalent of 0 is 0000
9 | if num == 0:
10 | print('0000')
11 | return
12 | else:
13 | binary = []
14 | while num != 0:
15 | rem = num % 2
16 | binary.append(rem)
17 | num = num // 2
18 | #reverse the list and print it
19 | binary.reverse()
20 | for bit in binary:
21 | print(bit, end="")
22 |
23 | #executable code
24 | decimal = int(input("Enter a decimal number to be converted to binary : "))
25 | print("Binary number : ")
26 | DecimalToBinary(decimal)
27 |
28 | '''
29 | Sample I/O :
30 | Input :
31 | Enter a decimal number to be converted into binary: 8
32 |
33 | Output:
34 | Binary number:
35 | 1000
36 |
37 | Time Complexity : O(n)
38 | Space Complexity : O(1)
39 | '''
40 |
--------------------------------------------------------------------------------
/Python/math/prime_number_using_sieve_of_Eratosthenes.py:
--------------------------------------------------------------------------------
1 | def sieve_of_Eratosthenes(num):
2 |
3 | not_prime_num = set()
4 | prime_nums = []
5 |
6 | for i in range(2, num+1):
7 | # checks if the number is in the not_prime_num list
8 | if i in not_prime_num:
9 | continue
10 |
11 | # if number absent in not_prime_num then add that number to prime_num list
12 | # and every multiple of that number to the not_prime_num list
13 | for f in range(i*2, num+1, i):
14 | not_prime_num.add(f)
15 |
16 | prime_nums.append(i)
17 |
18 | # returns a list of prime numbers less then the given number
19 | return prime_nums
20 |
21 |
22 | if __name__ == "__main__":
23 | user_input = int(input("Enter a sequence of comma seprated numbers: "))
24 |
25 | # calling the sieve_of_Eratosthenes function
26 | prime_numbers = sieve_of_Eratosthenes(user_input)
27 | print(prime_numbers)
28 |
--------------------------------------------------------------------------------
/Python/math/reverse_a_number.py:
--------------------------------------------------------------------------------
1 | """
2 | Python program to reverse a number.
3 | The reverse of a number is a number that is obtained when a number is traversed from right to left.
4 | """
5 |
6 | # Function to do reverse
7 |
8 | def reverse(n):
9 | # Initializing rev as 0
10 |
11 | rev = 0
12 | while True:
13 | if n == 0:
14 | break
15 | # Adding the last digit
16 |
17 | rev = rev * 10 + n % 10
18 | # Removing the last digit
19 |
20 | n = n // 10
21 | return rev
22 |
23 | if __name__ == '__main__':
24 | # Taking input from user
25 |
26 | n = int(input('Enter the number :'))
27 | # Printing the output
28 |
29 | print ("The reverse of the given number is: {} ".format(reverse(n)))
30 |
31 | """
32 | Time Complexity - O(n), where 'n' is the number of digits in the number.
33 | Space Complexity - O(1)
34 |
35 | SAMPLE INPUT AND OUTPUT
36 | SAMPLE I
37 |
38 | INPUT
39 | Enter the number: 1234
40 |
41 | OUTPUT
42 | The reverse of the given number is: 4321
43 |
44 | """
45 |
46 |
--------------------------------------------------------------------------------
/Python/math/sum_of_digits.py:
--------------------------------------------------------------------------------
1 | # Python program to Find the Sum of Digits of a Number
2 |
3 |
4 | def sum_of_digits(num):
5 | # Extracting Each digits
6 | # and compute thier sum in 's'
7 | s = 0
8 | while num != 0:
9 | s = s + (num % 10)
10 | num = num // 10
11 | return s
12 |
13 |
14 | if __name__ == '__main__':
15 | # Input the number And
16 | # Call the function
17 | print("Enter the number: ", end="")
18 | n = int(input())
19 | S = sum_of_digits(abs(n))
20 | print("The sum of digits of the given number is {}.".format(S))
21 |
22 | '''
23 | Time Complexity: O(log(num)), where "num" is the length of the given number
24 | Space Complexity: O(1)
25 |
26 | SAMPLE INPUT AND OUTPUT
27 |
28 | SAMPLE 1
29 |
30 | Enter the number: -12
31 | The sum of digits of the given number is 3.
32 |
33 | SAMPLE 2
34 |
35 | Enter the number: 43258
36 | The sum of digits of the given number is 22.
37 | '''
38 |
--------------------------------------------------------------------------------
/Python/other/CountTriplets.py:
--------------------------------------------------------------------------------
1 | # Count all triplets such that sum of two elements equals the third element.
2 | def find_triplets(arr):
3 | arr.sort()
4 | count = 0
5 | ptr_1 = len(arr) - 1
6 | while ptr_1 >= 2:
7 | ptr_2 = 0
8 | ptr_3 = ptr_1 - 1
9 | while ptr_2 < ptr_3:
10 | if arr[ptr_1] == arr[ptr_2] + arr[ptr_3]:
11 | count += 1
12 | ptr_2 += 1
13 | ptr_3 -= 1
14 | elif arr[ptr_1] > arr[ptr_2] + arr[ptr_3]:
15 | ptr_2 += 1
16 | else:
17 | ptr_3 -= 1
18 | ptr_1 -= 1
19 | return count
20 |
21 | # Driver code
22 | arr = [int(item) for item in input("Enter the list elements : ").split()]
23 | print('Total number of found triplets : {}'.format(find_triplets(arr)))
24 |
25 | '''
26 | SAMPLE I/O:
27 |
28 | Input: Enter the array elements : 1 4 3 5 7
29 | Output: Total number of found triplets : 3
30 |
31 | Time Complexity : O(n^2)
32 | '''
33 |
--------------------------------------------------------------------------------
/Python/other/Count_Articles.py:
--------------------------------------------------------------------------------
1 | /* Write a Python program to count the number of articles in a given text. */
2 |
3 | CODE:
4 |
5 | s=input("ENTER TEXT HERE")
6 | y=s.split()
7 | a=0
8 | an=0
9 | the=0
10 | for i in range(len(y)):
11 | if (y[i]=="a" or y[i]=="A"):
12 | a=a+1
13 | if (y[i]=="an" or y[i]=="An"):
14 | an=an+1
15 | if (y[i]=="the" or y[i]=="The"):
16 | the=the+1
17 | print("a:",a)
18 | print("an:",an)
19 | print("the:",the)
20 | print("Total Articles:",a+an+the)
21 |
22 | ---------------------------------------------------------------------------------------------
23 | TIME COMPLEXITY: O(N) (Where N is length)
24 | SPACE COMPLEXITY: O(N)
25 | ------------------------------------------------------------------------------------------
26 | OUTPUT:
27 |
28 | ENTER TEXT HERE A was the an I am a the she was this that the an a the
29 | a: 3
30 | an: 2
31 | the: 4
32 | Total Articles: 9
33 |
--------------------------------------------------------------------------------
/Python/other/HappyNumber.py:
--------------------------------------------------------------------------------
1 | def numSquareSum(num):
2 | squareSum = 0;
3 | while(num):
4 | squareSum += (num % 10) * (num % 10);
5 | num = int(num / 10);
6 | return squareSum;
7 |
8 | def isHappynumber(num):
9 |
10 | slow = num
11 | fast = num
12 | while(True):
13 |
14 | slow = numSquareSum(slow)
15 | fast = numSquareSum(numSquareSum(fast));
16 | if(slow != fast):
17 | continue
18 | else:
19 | break
20 | return (slow == 1)
21 |
22 | # Driver Code
23 | num = int(input("Enter a number: "))
24 | if (isHappynumber(num)):
25 | print(num , "is a Happy number")
26 | else:
27 | print(num , "is not a Happy number")
28 |
29 | """
30 | Time Complexity: O(logN)
31 | Space Complexity: O(logN)
32 |
33 | Sample Input:
34 | Enter a number: 13
35 | Sample Output:
36 | 13 is a Happy number
37 | """
38 |
--------------------------------------------------------------------------------
/Python/other/Kadanes_Algorithm.py:
--------------------------------------------------------------------------------
1 | # To find the contiguous sub-array with the largest sum in
2 | # a one-dimensional array of numbers
3 |
4 |
5 | def kadane(nums):
6 |
7 | current_max = global_max = nums[0]
8 |
9 | for i in range(1, len(nums)):
10 |
11 | current_max = max(nums[i], nums[i] + current_max)
12 |
13 | if current_max > global_max:
14 | global_max = current_max
15 | return global_max
16 |
17 | if __name__ == '__main__':
18 | print(kadane([-2, -3, -1, -5])) # Output: -1
19 | print(kadane([-2, 1, -3, 4, -1, 2, 1, -5, 4])) # Output: 6
20 |
--------------------------------------------------------------------------------
/Python/other/Program_to_rotation_array.py:
--------------------------------------------------------------------------------
1 | def array_rotation():
2 | save = []
3 | rest_arr = []
4 | for i in arr:
5 | if i == Start_element or i < Start_element:
6 | save.append(i)
7 | else:
8 | rest_arr.append(i)
9 |
10 | rest_arr.extend(save)
11 | print('rest arry =', rest_arr)
12 |
13 | arr = list(input("Enter the no. elements:\n").split())
14 | Start_element = input("Stating from which element:\n")
15 | ending_element = input("Enter the ending element:\n")
16 | array_rotation()
17 |
18 | '''
19 | >>Time & Space Complexity is O(n)
20 |
21 | INPUT
22 |
23 | >>Enter the no. elements:
24 | 1 2 3 4 5 6 7
25 | >>Stating from which element:
26 | 2
27 | >>Enter the ending element:
28 | 7
29 |
30 | OUTPUT
31 | >>rest arry = ['3', '4', '5', '6', '7', '1', '2']
32 |
33 |
34 | '''
--------------------------------------------------------------------------------
/Python/other/Reverse_string_using_stack.py:
--------------------------------------------------------------------------------
1 | #class of stack
2 | class stack:
3 | def __init__(self):
4 | self.items=[]
5 | def push(self,item):
6 | self.items.append(item)
7 | def pop(self):
8 | return self.items.pop()
9 | def is_empty(self):
10 | return self.items==[]
11 |
12 |
13 | #function to reverse a function
14 | def reverse(string):
15 |
16 | """
17 | >>Input:ziuQ
18 | >>Output:Quiz
19 |
20 | """
21 | x=len(string)
22 | l=0
23 | while l> 4)
8 |
9 | number = int(input("Enter Number: "))
10 | print("After swapping the nibbles:")
11 | print(swapNibbles(number))
12 |
13 | '''
14 | Sample I/O:
15 | Input
16 | Enter Number: 100
17 |
18 | Output:
19 | After swapping the nibbles:
20 | 70
21 |
22 | Time Complexity: O(1)
23 | Space Complexity: O(1)
24 |
25 | '''
26 |
--------------------------------------------------------------------------------
/Python/other/Unique_number_III.py:
--------------------------------------------------------------------------------
1 | # Unique_Number_III
2 | # Given an array that contains all elements occurring 3 times, but one
3 | # occurs only once. Find that unique element.
4 |
5 |
6 | def unique_element(array, size):
7 | for i in range(size):
8 | j = 0
9 | while(j < size):
10 | if (i != j and array[i] == array[j]):
11 | break
12 | j += 1
13 | if (j == size):
14 | return array[i]
15 |
16 | return -1
17 |
18 |
19 | print("Enter Elements:")
20 | array = input().split()
21 | size = len(array)
22 | print("Unique element:")
23 | print(unique_element(array, size))
24 |
25 | '''
26 | Sample I/O:
27 | Input:
28 | Enter Elements:
29 | 1 1 1 4 2 2 2 3 3 3
30 |
31 | Output:
32 | Unique element:
33 | 4
34 |
35 | Time Complexity: O(size*size)
36 | Space Complexity:O(1)
37 | '''
38 |
--------------------------------------------------------------------------------
/Python/other/Wave_Array.py:
--------------------------------------------------------------------------------
1 | """
2 | Sorting the array into a wave-like array.
3 | For eg: arr[] = {1,2,3,4,5}
4 | Output: 2 1 4 3 5
5 | """
6 |
7 |
8 | def convertToWave(length,array):
9 | for i in range(0, length - length%2, 2): #swapping alternatively
10 | temp=array[i]
11 | array[i]=array[i+1]
12 | array[i+1]=temp
13 | return array
14 |
15 | arr = list(map(int,input("Enter the elements of the array : ").split()))
16 | N = len(arr) # length of the array
17 |
18 | arr = convertToWave(N,arr)
19 |
20 | print("Wave Array: ")
21 | for el in arr:
22 | print(el, end=" ")
23 |
24 |
25 | """
26 | Time complexity : O(1)
27 | Space complexity : O(1)
28 |
29 | INPUT:-
30 | Enter the elements of the array : 1 2 3 4 5 6 7
31 | OUTPUT:-
32 | Wave Array: 2 1 4 3 6 5 7
33 |
34 | """
35 |
--------------------------------------------------------------------------------
/Python/other/find_the_numbers.py:
--------------------------------------------------------------------------------
1 | # Python program to find the unique numbers in an array out
2 | # of which two numbers occur exactly once and are distinct.
3 | # You need to find the other two numbers and print them in ascending order.
4 |
5 | if __name__ == '__main__':
6 | n = int(input("Enter the number of elements: "))
7 | arr = list(map(int, input().split(' ')[:n]))
8 | xors = 0
9 | for i in range(0, n):
10 | xors = xors ^ arr[i]
11 | xors = xors & ~(xors - 1)
12 | x = 0
13 | y = 0
14 | for i in range(0, n):
15 | if arr[i] & xors > 0:
16 | x = x ^ arr[i]
17 | else:
18 | y = y ^ arr[i]
19 | if x > y:
20 | swap(x, y)
21 | print("The distinct numbers are ", x, " and ", y)
22 |
23 | # Time Complexity: O(N)
24 | # Space Complexity: O(1)
25 |
26 | # Input
27 | # Enter the number of elements: 6
28 | # 2 3 1 4 2 1
29 |
30 | # Ouput
31 | # The distinct numbers are 3 and 4
32 |
--------------------------------------------------------------------------------
/Python/other/remove_outermost_parenthesis.py:
--------------------------------------------------------------------------------
1 | def removeOuterParentheses(S):
2 | res, opened = [], 0
3 | for c in S:
4 | if c == '(' and opened > 0:
5 | res.append(c)
6 | if c == ')' and opened > 1:
7 | res.append(c)
8 | opened += 1 if c == '(' else -1
9 | return "".join(res)
10 |
11 | str = input("Enter string: ")
12 | result = removeOuterParentheses(str)
13 | print(result)
14 |
15 |
16 | """
17 | Time complexity: O(n)
18 | Space complexity: O(n)
19 | Sample Input 1:
20 | Enter string: (()())(())
21 | Output: ()()()
22 |
23 | Sample Input 2:
24 | Enter string: ()()
25 | Output: ""
26 |
27 | """
28 |
--------------------------------------------------------------------------------
/Python/other/stringkth.py:
--------------------------------------------------------------------------------
1 | '''
2 | A program to remove the kth index from a string and print the remaining string.In case the value of k
3 | is greater than length of string then return the complete string as it is.
4 | '''
5 | #main function
6 | def main():
7 | s=input("enter a string")
8 | k=int(input("enter the index"))
9 | l=len(s)
10 | #Check whether the value of k is greater than length
11 | if(k>l):
12 | print(s)
13 | #If k is less than length of string then remove the kth index value
14 | else:
15 | s1=''
16 | for i in range(0,l):
17 | if(i!=k):
18 | s1=s1+s[i]
19 | print(s1)
20 | if __name__== "__main__":
21 | main()
22 |
23 | '''
24 | Time Complexity:O(n),n is length of string
25 | Space Complexity:O(1)
26 |
27 | Input/Output:
28 | enter a string python
29 | enter the index 2
30 | pyhon
31 | '''
32 |
--------------------------------------------------------------------------------
/Python/search/Linear_Search.py:
--------------------------------------------------------------------------------
1 | def linearSearch(arr, x):
2 | pos = -1
3 | for i in range(len(arr)):
4 | if arr[i] == x:
5 | pos = i
6 | print("Found at {}".format(pos))
7 |
8 | if pos == -1:
9 | print("Not Found")
--------------------------------------------------------------------------------
/Python/search/bilinear.py:
--------------------------------------------------------------------------------
1 | '''
2 | Bilinear search is searching algorithm where it is search for a element
3 | from the both end. It is a improved version of linear search.
4 | '''
5 |
6 |
7 | def bilinear(x, arr):
8 | siz = len(arr)
9 | p = 0
10 | i = 0
11 | j = siz-1
12 |
13 | while i < j:
14 | if arr[i] != x and arr[j] != x:
15 | i += 1
16 | j -= 1
17 | else:
18 | p = 1
19 | break
20 | if p == 1:
21 | return True
22 | else:
23 | return False
24 |
25 | if __name__ == "__main__":
26 | print('enter the list:')
27 | l = list(map(int, input().split(' ')))
28 |
29 | ele = int(input("enter the element to check:"))
30 |
31 | if bilinear(ele, l):
32 | print('element found')
33 | elif bilinear(ele, l) is False:
34 | print("element not found")
35 |
--------------------------------------------------------------------------------
/Python/sort/Bead_Sort.py:
--------------------------------------------------------------------------------
1 | #Bead sort (a.k.a Abacus sort, or Gravity sort) is a sorting algorithm
2 | # that can sort a list of positive integers .
3 | # We can sort negative numbers too by adding a constant to all the integers and subracting it later
4 | #Bead sort is a natural algorithm
5 | #It uses (imitates) gravity to sort an input list
6 |
7 | def bead_sort(a):
8 | minimum, maximum = min(a), max(a)
9 | n = len(a)
10 |
11 | # Initialize a temporary array filled with minimum
12 | temp = [minimum] * n
13 | for i in range(maximum-1, minimum-1, -1):
14 | k = 0
15 | for j in range(n):
16 | if a[j] > i:
17 | temp[k] += 1
18 | k += 1
19 |
20 | # Copy temp array back into original array
21 | # replacing the array into sorted order
22 | # temp array is reverse sorted, so copy backwards for ascending order
23 | for i in range(n):
24 | a[i] = temp[n-i-1]
25 |
26 | return a
27 |
28 | if __name__ == "__main__":
29 | a=[]
30 | print(bead_sort(a))
--------------------------------------------------------------------------------
/Q-Sharp/blockchain/README.md:
--------------------------------------------------------------------------------
1 | a
2 |
--------------------------------------------------------------------------------
/Q-Sharp/cp/README.md:
--------------------------------------------------------------------------------
1 | a
2 |
--------------------------------------------------------------------------------
/Q-Sharp/cryptography/README.md:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HarshCasper/NeoAlgo/4f1e5bdd6d9d899fa354de94740e0aecf5ecd2be/Q-Sharp/cryptography/README.md
--------------------------------------------------------------------------------
/Q-Sharp/dp/README.md:
--------------------------------------------------------------------------------
1 | a
2 |
--------------------------------------------------------------------------------
/Q-Sharp/ds/README.md:
--------------------------------------------------------------------------------
1 | a
2 |
--------------------------------------------------------------------------------
/Q-Sharp/graphs/README.md:
--------------------------------------------------------------------------------
1 | a
2 |
--------------------------------------------------------------------------------
/Q-Sharp/math/README.md:
--------------------------------------------------------------------------------
1 | a
2 |
--------------------------------------------------------------------------------
/Q-Sharp/other/README.md:
--------------------------------------------------------------------------------
1 | a
2 |
--------------------------------------------------------------------------------
/Q-Sharp/search/README.md:
--------------------------------------------------------------------------------
1 | a
2 |
--------------------------------------------------------------------------------
/Q-Sharp/sort/README.md:
--------------------------------------------------------------------------------
1 | a
2 |
--------------------------------------------------------------------------------
/Resources/README.md:
--------------------------------------------------------------------------------
1 | # Resources
2 |
3 | Everything you need to know to ace Data Structures and Algorithms 🙌
4 |
--------------------------------------------------------------------------------
/Resources/Radix_Sort.md:
--------------------------------------------------------------------------------
1 | # RADIX SORT
2 |
3 | It is a non-comparative sorting algorithm. It is used for sorting the array which contains numbers in the range of 1 to $n^2$. It performs digit by digit sort starting from least significant digit to most significant digit.
4 |
5 | The steps and execution of radix sort are explained briefly with the help of an example.
6 |
7 | ## ANALYSIS
8 |
9 | Input Data: 170, 45, 75, 90, 802, 24, 2, 66
10 | We start sorting from the least significant digit.
11 |
12 | ##### Sorting by one’s place
13 |
14 | [{170, 90}, {02, 802, 02}, {45, 75}, {66}
15 |
16 | ##### Sorting by ten's place
17 |
18 | [{02, 802, 02}, {45}, {66}, {170, 75}, {90}]
19 |
20 | ##### Sorting by hundreds place
21 |
22 | [{002, 002, 045, 066, 075, 090}, {170}, {802}]
23 |
24 | ## Time & Space Complexity of the Algorithm
25 |
26 | #### Worst Case Time Complexity [ Big-O]: O(w.n) where w is the no of bits required to store each value.
27 |
28 | #### Worst Case Space Complexity : O(w+n)
29 |
--------------------------------------------------------------------------------
/SECURITY.md:
--------------------------------------------------------------------------------
1 | # Security Policy
2 |
3 | Since this repo mainly deals with DS and Algos, if you've encountered a security issue,
4 | you should probably wear a tinfoil hat :)
5 |
--------------------------------------------------------------------------------
/_config.yml:
--------------------------------------------------------------------------------
1 | theme: jekyll-theme-architect
2 |
--------------------------------------------------------------------------------
/go.mod:
--------------------------------------------------------------------------------
1 | module github.com/TesseractCoding/NeoAlgo
2 |
3 | go 1.16
4 |
--------------------------------------------------------------------------------
/img/fork.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HarshCasper/NeoAlgo/4f1e5bdd6d9d899fa354de94740e0aecf5ecd2be/img/fork.png
--------------------------------------------------------------------------------
/img/git add.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HarshCasper/NeoAlgo/4f1e5bdd6d9d899fa354de94740e0aecf5ecd2be/img/git add.png
--------------------------------------------------------------------------------
/img/git branch.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HarshCasper/NeoAlgo/4f1e5bdd6d9d899fa354de94740e0aecf5ecd2be/img/git branch.png
--------------------------------------------------------------------------------
/img/git checkout.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HarshCasper/NeoAlgo/4f1e5bdd6d9d899fa354de94740e0aecf5ecd2be/img/git checkout.png
--------------------------------------------------------------------------------
/img/git clone.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HarshCasper/NeoAlgo/4f1e5bdd6d9d899fa354de94740e0aecf5ecd2be/img/git clone.png
--------------------------------------------------------------------------------
/img/git commit.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HarshCasper/NeoAlgo/4f1e5bdd6d9d899fa354de94740e0aecf5ecd2be/img/git commit.png
--------------------------------------------------------------------------------
/img/git push.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HarshCasper/NeoAlgo/4f1e5bdd6d9d899fa354de94740e0aecf5ecd2be/img/git push.png
--------------------------------------------------------------------------------
/img/grover.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HarshCasper/NeoAlgo/4f1e5bdd6d9d899fa354de94740e0aecf5ecd2be/img/grover.png
--------------------------------------------------------------------------------
/img/issue.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HarshCasper/NeoAlgo/4f1e5bdd6d9d899fa354de94740e0aecf5ecd2be/img/issue.png
--------------------------------------------------------------------------------
/img/issue_template_get_started_button.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HarshCasper/NeoAlgo/4f1e5bdd6d9d899fa354de94740e0aecf5ecd2be/img/issue_template_get_started_button.png
--------------------------------------------------------------------------------
/img/neo_algo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HarshCasper/NeoAlgo/4f1e5bdd6d9d899fa354de94740e0aecf5ecd2be/img/neo_algo.png
--------------------------------------------------------------------------------
/img/new_issue.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HarshCasper/NeoAlgo/4f1e5bdd6d9d899fa354de94740e0aecf5ecd2be/img/new_issue.png
--------------------------------------------------------------------------------
/img/pull_2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HarshCasper/NeoAlgo/4f1e5bdd6d9d899fa354de94740e0aecf5ecd2be/img/pull_2.png
--------------------------------------------------------------------------------
/img/pull_request.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HarshCasper/NeoAlgo/4f1e5bdd6d9d899fa354de94740e0aecf5ecd2be/img/pull_request.png
--------------------------------------------------------------------------------