From b66a7e1e74423247bd60f7e9ef9d239301e16f4e Mon Sep 17 00:00:00 2001
From: Lakshyajit Laxmikant <30868587+lakshyajit165@users.noreply.github.com>
Date: Mon, 16 Mar 2020 12:19:37 +0530
Subject: [PATCH 001/265] Karatsuba algorithm (#2490)
* added karatsuba multiplication in python along with readme
* modifications for karatsuba algorithm
---
.../Karatsuba_multiplication_algo.cpp | 0
Karatsuba_Algorithm/Readme.md | 54 +++++++++++++++++++
Karatsuba_Algorithm/karatsuba.py | 29 ++++++++++
3 files changed, 83 insertions(+)
rename {Karatsuba_Algo => Karatsuba_Algorithm}/Karatsuba_multiplication_algo.cpp (100%)
create mode 100644 Karatsuba_Algorithm/Readme.md
create mode 100755 Karatsuba_Algorithm/karatsuba.py
diff --git a/Karatsuba_Algo/Karatsuba_multiplication_algo.cpp b/Karatsuba_Algorithm/Karatsuba_multiplication_algo.cpp
similarity index 100%
rename from Karatsuba_Algo/Karatsuba_multiplication_algo.cpp
rename to Karatsuba_Algorithm/Karatsuba_multiplication_algo.cpp
diff --git a/Karatsuba_Algorithm/Readme.md b/Karatsuba_Algorithm/Readme.md
new file mode 100644
index 000000000..7df095146
--- /dev/null
+++ b/Karatsuba_Algorithm/Readme.md
@@ -0,0 +1,54 @@
+# Karatsuba Multiplication
+Karatsuba multiplication is an effective and efficient way of multiplication, which comes handy when multiplying really large numbers. It is different from the steps followed in conventional multiplication technique due to the fact that, it recursively performs the multiplication, thereby, making it possible to accomodate really large numbers.
+
+#### Consider the following example:
+#### 5678 x 1234 = 7006652
+
+While carrying out traditional multiplication(I mean the method we're usually taught at schools), we first have to multiply 5678 by 4, then by 3...upto 1 and then add all the intermediary products. It turns out that, while implementing this logic in code, we have to make 2n operations(n being the number of digits in the larger number) - (n operations to calculate the intermediary products + n operations to add those products,a long with keeping track of the carry overs). This is a lot of computation.
+
+#### Now let's have a look at how karatsuba multiplication, decreases the computations
+#### Following are the steps for karatsuba multiplication:
+- Consider the above 2 numbers, let x = 5678 and y = 1234
+- Break each number into 2 halves and store them in variables
+- In this case, let a = 56, b = 78, c = 12, d = 34
+- Now we can express x and y as, x = 10 ^ (n/2) * a + b and y = 10 ^ (n/2) * c + d, where a,b,c,d are n/2 digit numbers.
+- Therefore, x * y = 10 ^ n * a * c + 10 ^ (n/2) * (a * d + b * c) + b * d
+- Now, on the first look it may seem that there are 4 recursive calls, to compute ac, ad, bc and bd - but here is the trick:
+- It's also called as Gauss's trick - which requires only 3 recursive calls.
+- If we carefully observe, we have already computed ac and bd in the first 2 steps, so if we subtract this result from the result of (a+b) * (c+d), we reduce 1 recursive call.
+- It may seems strange, but when the computations to be performed are of very high level(multiplying really large digit numbers in this case), reducing even a single recursive call significantly affects performance.
+- Checkout the code in python, to understand the recursive work flow better as well as the base case for the recursive function.
+
+### Pseudo code
+```
+karatsuba(x, y):
+
+ m = ceil(n/2)
+
+ a = floor(x / 10**m)
+ b = x % (10**m)
+
+ c = floor(y / 10**m)
+ d = y % (10**m)
+
+ #recursive steps
+ ac = karatsuba(a,c)
+ bd = karatsuba(b,d)
+ ad_plus_bc = karatsuba(a + b, c + d) - ac - bd
+
+ return int(ac*(10**(m*2)) + ad_plus_bc*(10**m) + bd)
+```
+
+### Complexity
+
+To analyze the complexity of the Karatsuba algorithm, consider the number of multiplications the algorithm performs as a function of n, M(n).
+
+The algorithm multiplies together two nn-bit numbers. If n=2^k for some k then the algorithm recurses three times on n/2-bit number. The recurrence for this is:
+
+M(n) = 3M(n/2)
+
+This takes care of the multiplications required for Karatsuba--now to consider the additions and subtractions. There are O(n)O(n) additions and subtractions required for the algorithm. Therefore, the overall recurrence for the Karatsuba algorithm is:
+
+T(n) = 3T(n/2) + O(n)
+
+Using the master theorem on the above recurrence yields that the running time of the Karatsuba algorithm is: $\Theta$(nlog23)
\ No newline at end of file
diff --git a/Karatsuba_Algorithm/karatsuba.py b/Karatsuba_Algorithm/karatsuba.py
new file mode 100755
index 000000000..1fa796bcb
--- /dev/null
+++ b/Karatsuba_Algorithm/karatsuba.py
@@ -0,0 +1,29 @@
+#!/usr/bin/python3
+from math import ceil, floor
+
+def karatsuba(x,y):
+ # base case
+ if x < 10 and y < 10: # in other words, if x and y are single digits
+ return x*y
+
+ n = max(len(str(x)), len(str(y)))
+ m = ceil(n/2) # Cast n into a float because n might lie outside the representable range of integers.
+
+ a = floor(x / 10**m)
+ b = x % (10**m)
+
+ c = floor(y / 10**m)
+ d = y % (10**m)
+
+ # recursive steps
+ ac = karatsuba(a,c)
+ bd = karatsuba(b,d)
+ ad_plus_bc = karatsuba(a + b, c + d) - ac - bd
+
+ return int(ac*(10**(m*2)) + ad_plus_bc*(10**m) + bd)
+
+# INPUT 123456789, 987654321
+a,b = map(int, input().split(' '))
+
+# OUTPUT 121932631112635269
+print(karatsuba(a, b))
From d6cc947e77cf61595ec9000c28ef0ecbff401ccd Mon Sep 17 00:00:00 2001
From: Hardev Khandhar <54733460+HardevKhandhar@users.noreply.github.com>
Date: Mon, 16 Mar 2020 13:52:51 +0530
Subject: [PATCH 002/265] Menu Driven Circular Doubly Linked List in c++
(#2423)
* Menu Driven Program
* Updated and Renamed File
* Delete Circular-Doubly-Linked-List.cpp
* Menu Driven Program
Updated and Renamed File
* Update Circular_Doubly_Linked_List.cpp
* Delete Circular_Doubly_Linked_List.cpp
* Delete Circular-Doubly-Linked-List.cpp
* all done
* Commited Latest Changes
* Commited Latest Changes
* Commited Latest Changes
* Committed Latest Changes
* Committed Latest Changes
* Committed Latest Changes
* Committed Latest Changes
* Committed Latest Changes
* Committed Latest Changes
* # This is a combination of 6 commits.
# This is the 1st commit message:
Menu Driven Program
Updated and Renamed File
# This is the commit message #2:
Menu Driven Program
# This is the commit message #3:
Updated and Renamed File
# This is the commit message #4:
Delete Circular-Doubly-Linked-List.cpp
# This is the commit message #5:
Update Circular_Doubly_Linked_List.cpp
# This is the commit message #6:
all done
* parent 575de38ca91337ed5420385cf26f76d03460068d
author Hardev_Khandhar 1583005888 +0530
committer Hardev_Khandhar 1583948499 +0530
Menu Driven Program
Updated and Renamed File
Menu Driven Program
Updated and Renamed File
Delete Circular-Doubly-Linked-List.cpp
Update Circular_Doubly_Linked_List.cpp
all done
Commited Latest Changes
Commited Latest Changes
Commited Latest Changes
Committed Latest Changes
Committed Latest Changes
Committed Latest Changes
Committed Latest Changes
Committed Latest Changes
Committed Latest Changes
* Updated Changes
---
.../Circular_Doubly_Linked_List.cpp | 486 ++++++++++++++----
1 file changed, 381 insertions(+), 105 deletions(-)
diff --git a/Circular_Doubly_Linked_List/Circular_Doubly_Linked_List.cpp b/Circular_Doubly_Linked_List/Circular_Doubly_Linked_List.cpp
index 8b6d71ce0..3551c1e33 100644
--- a/Circular_Doubly_Linked_List/Circular_Doubly_Linked_List.cpp
+++ b/Circular_Doubly_Linked_List/Circular_Doubly_Linked_List.cpp
@@ -1,131 +1,407 @@
+/**
+ Code contributed by Hardev Khandhar for GirlScript Summer of Code 2020
+ link: https://github.com/HardevKhandhar
+*/
+
#include
using namespace std;
-class node{
-private:
+
+// Declaring the structure of node
+struct node
+{
int data;
- node *next;
- node *prev;
-public:
- node(int d)
- {
- data=d;
- next=NULL;
- prev=NULL;
- }
- friend class Linked_List;
+ struct node *lptr;
+ struct node *rptr;
};
-class Linked_List
+
+struct node *HEAD = NULL;
+
+// Creating a node
+node *createNode(int value)
{
-private:
- node *head;
-public:
- Linked_List()
+ struct node *ptr;
+ ptr = new(struct node);
+ if(ptr == NULL)
+ {
+ cout << "Memory Not Allocated!" << endl;
+ return 0;
+ }
+ else
{
- head=NULL;
- }
-void insertatbeg(int d)
- {
- node *n=new node(d);
- node*ptr=head;
- if(head==NULL)
- {
- head=n;
- n->next=head;
- n->prev=n;
- }
- else
- {
- head->prev->next=n;
- n->prev=head->prev;
- n->next=head;
- head->prev=n;
- head=n;
-
- }
-
-
- }
- void insertatend(int d)
+ ptr -> data = value;
+ ptr -> lptr = NULL;
+ ptr -> rptr = NULL;
+ return ptr;
+ }
+}
+
+// Insert node at the beginning of circular-doubly-linked-list
+void insertAtFront()
{
- node *n=new node(d);
- head->prev->next=n;
- n->prev=head->prev;
- n->next=head;
+ struct node *newNode;
+ struct node *trav = HEAD;
+ int value;
+ cout << "Enter the value to be inserted: ";
+ cin >> value;
+ newNode = createNode(value);
+ if(HEAD == NULL)
+ {
+ HEAD = newNode;
+ newNode -> rptr = HEAD;
+ }
+ else
+ {
+ newNode -> lptr = NULL;
+ newNode -> rptr = HEAD;
+ while(trav -> rptr != HEAD)
+ {
+ trav = trav -> rptr;
+ }
+ trav -> rptr = newNode;
+ HEAD = newNode;
+ }
+}
+
+// Insert node at the end of circular-doubly-linked-list
+void insertAtLast()
+{
+ struct node *newNode;
+ struct node *trav;
+ trav = HEAD;
+ int value;
+ cout << "Enter the value to be inserted: ";
+ cin >> value;
+ newNode = createNode(value);
+ if(HEAD == NULL)
+ {
+ newNode -> lptr = NULL;
+ HEAD = newNode;
+ newNode -> rptr = HEAD;
+ return;
+ }
+ else {
+ while(trav -> rptr != HEAD)
+ {
+ trav = trav -> rptr;
+ }
+ trav -> rptr = newNode;
+ newNode -> lptr = trav;
+ newNode -> rptr = HEAD;
+ }
}
- void print()
+
+// Insert node after a particular node in the circular-doubly-linked-list
+void insertAtPosition(int x)
+{
+ struct node *trav;
+ struct node *next;
+ struct node *newNode;
+ trav = HEAD;
+ int value;
+ cout << "Enter the value to be inserted: ";
+ cin >> value;
+ newNode = createNode(value);
+ while(trav -> data != x && trav -> rptr != NULL)
{
- node *t=head;
- do
- {
- cout<data<<" ->";
- t=t->next;
+ trav = trav -> rptr;
+ }
+ if(trav == NULL)
+ {
+ cout << "Desired element not found!" << endl;
+ }
+ else
+ {
+ next = trav -> rptr;
+ trav -> rptr = newNode;
+ newNode -> rptr = next;
+ newNode -> lptr = trav;
+ next -> lptr = newNode;
+ }
+}
- }while(t!=head);
- cout< data << " ";
+ ptr = ptr -> rptr;
}
- void insertatK(int d,int k)
+ while(ptr != HEAD);
+ cout << endl;
+}
+
+// Delete front node from the list
+void deleteAtFront()
{
- node *n=new node(d);
- node *t=head;
- node *temp=NULL;
- int cnt=1;
- while(head==NULL || k==1)
+ struct node *trav = HEAD;
+ if(HEAD == NULL)
{
- insertatbeg(d);
+ cout << "List is Empty!";
+ return;
+ }
+ if(HEAD -> rptr == HEAD){
+ cout << "Element " << HEAD -> data << " is removed." << endl;
+ HEAD = NULL;
+ }
+ else {
+ cout << "Element " << HEAD -> data << " is removed." << endl;
+ while(trav -> rptr != HEAD){
+ trav = trav -> rptr;
+ }
+ HEAD = HEAD -> rptr;
+ HEAD -> lptr = NULL;
+ trav -> rptr = HEAD;
+ }
+}
+
+// Delete last node from the list
+void deleteAtLast()
+{
+ struct node *trav;
+ struct node *previous;
+ trav = HEAD;
+ if(HEAD == NULL){
+ cout << "List is Empty!";
return;
}
- while(t->next!=NULL && cnt rptr == HEAD)
{
- temp=t;
- t=t->next;
- cnt++;
- }
- n->prev=temp;
- n->next=temp->next;
- temp->next=n;
- t->prev=n;
+ HEAD = NULL;
+ }
+ else {
+ while(trav -> rptr != HEAD)
+ {
+ previous = trav;
+ trav = trav -> rptr;
+ }
+ cout << "Element " << trav -> data << " is removed." << endl;
+ previous = trav -> lptr;
+ previous -> rptr = HEAD;
+ }
}
-void delatbeg()
+
+// Delete node from a particular position in the list
+void deleteAtPosition(int x)
{
- node *t=head;
- head->prev->next=head->next;
- head->next->prev=head->prev;
- head=head->next;
- t->next=NULL;
- delete t;
+ struct node *trav;
+ struct node *previous;
+ struct node *next;
+ trav = HEAD;
+ while(trav -> data != x && trav -> rptr != NULL)
+ {
+ previous = trav;
+ trav = trav -> rptr;
+ }
+ if(trav == NULL)
+ {
+ cout << "Desired element not found!" << endl;
+ }
+ else
+ {
+ next = trav -> rptr;
+ previous -> rptr = trav -> rptr;
+ next -> lptr = previous;
+ }
}
-void delatend()
+
+// Menu driven program
+int main()
{
- node *t;
- t=head->prev;
- t->prev->next=head;
- head->prev=t->prev;
- t->next=NULL;
- delete t;
+ int choice, nodes, position, element, i;
+ cout << "**************************************" << endl;
+ cout << "* Circular Doubly Linked List *" << endl;
+ cout << "**************************************\n" << endl;
+ while(1)
+ {
+ cout << "1. Insert node at the beginning" << endl;
+ cout << "2. Insert node at the end" << endl;
+ cout << "3. Insert node at given position" << endl;
+ cout << "4. Delete node at front" << endl;
+ cout << "5. Delete node at last" << endl;
+ cout << "6. Delete node at given position" << endl;
+ cout << "7. Display elements of linked list" << endl;
+ cout << "8. Exit" << endl;
+ cout << "\nEnter your choice: ";
+ cin >> choice;
+ switch(choice)
+ {
+ case 1:
+ insertAtFront();
+ cout << endl;
+ break;
+ case 2:
+ insertAtLast();
+ cout << endl;
+ break;
+ case 3:
+ int x;
+ cout << "Enter the node information: ";
+ cin >> x;
+ insertAtPosition(x);
+ cout << endl;
+ break;
+ case 4:
+ deleteAtFront();
+ cout << endl;
+ break;
+
+ case 5:
+ deleteAtLast();
+ cout << endl;
+ break;
+
+ case 6:
+ int y;
+ cout << "Enter the node information: ";
+ cin >> y;
+ deleteAtPosition(y);
+ cout << endl;
+ break;
+
+ case 7:
+ display();
+ cout << endl;
+ break;
+
+ case 8:
+ cout << "Exit" << endl;
+ return 0;
+ break;
+
+ default:
+ cout << "Invalid Choice!" << endl;
+ break;
+ }
+ }
+ return 0;
}
-};
-int main()
-{
- Linked_List ll;
- int d,c;
- char choice;
- ll.insertatbeg(1);
- ll.insertatbeg(2);
- ll.insertatbeg(3);
- ll.print();
- ll.insertatend(4);
- ll.print();
- // ll.insertatK(10,3);
- //ll.print();
- ll.delatend();
- ll.print();
- ll.delatend();
- ll.print();
- // ll.delatend();
- //ll.print();
-}
+
+/**
+
+**************************************
+* Circular Doubly Linked List *
+**************************************
+
+1. Insert node at the beginning
+2. Insert node at the end
+3. Insert node at given position
+4. Delete node at front
+5. Delete node at last
+6. Delete node at given position
+7. Display elements of linked list
+8. Exit
+
+Enter your choice: 1
+Enter the value to be inserted: 21
+
+1. Insert node at the beginning
+2. Insert node at the end
+3. Insert node at given position
+4. Delete node at front
+5. Delete node at last
+6. Delete node at given position
+7. Display elements of linked list
+8. Exit
+
+Enter your choice: 1
+Enter the value to be inserted: 52
+
+1. Insert node at the beginning
+2. Insert node at the end
+3. Insert node at given position
+4. Delete node at front
+5. Delete node at last
+6. Delete node at given position
+7. Display elements of linked list
+8. Exit
+
+Enter your choice: 7
+Elements of Doubly Linked List are: 52 21
+
+1. Insert node at the beginning
+2. Insert node at the end
+3. Insert node at given position
+4. Delete node at front
+5. Delete node at last
+6. Delete node at given position
+7. Display elements of linked list
+8. Exit
+
+Enter your choice: 2
+Enter the value to be inserted: 99
+
+1. Insert node at the beginning
+2. Insert node at the end
+3. Insert node at given position
+4. Delete node at front
+5. Delete node at last
+6. Delete node at given position
+7. Display elements of linked list
+8. Exit
+
+Enter your choice: 3
+Enter the node information: 21
+Enter the value to be inserted: 45
+
+1. Insert node at the beginning
+2. Insert node at the end
+3. Insert node at given position
+4. Delete node at front
+5. Delete node at last
+6. Delete node at given position
+7. Display elements of linked list
+8. Exit
+
+Enter your choice: 7
+Elements of Doubly Linked List are: 52 21 45 99
+
+1. Insert node at the beginning
+2. Insert node at the end
+3. Insert node at given position
+4. Delete node at front
+5. Delete node at last
+6. Delete node at given position
+7. Display elements of linked list
+8. Exit
+
+Enter your choice: 4
+Element 52 is removed.
+
+1. Insert node at the beginning
+2. Insert node at the end
+3. Insert node at given position
+4. Delete node at front
+5. Delete node at last
+6. Delete node at given position
+7. Display elements of linked list
+8. Exit
+
+Enter your choice: 5
+Element 99 is removed.
+
+1. Insert node at the beginning
+2. Insert node at the end
+3. Insert node at given position
+4. Delete node at front
+5. Delete node at last
+6. Delete node at given position
+7. Display elements of linked list
+8. Exit
+
+Enter your choice: 7
+Elements of Doubly Linked List are: 21 45
+
+*/
From af6cc495e5147d3e8281ebb0a7468ea08ffcd50d Mon Sep 17 00:00:00 2001
From: Aman-Codes <54680709+Aman-Codes@users.noreply.github.com>
Date: Mon, 16 Mar 2020 15:57:28 +0530
Subject: [PATCH 003/265] Adding ASCII_Subsequence in C, Python and JavaScript
(Closes issue #1703) (#2290)
* Add files via upload
* Improved Indentation
Improved Indentation
* Update ASCII_Subsequences.c
* Update ASCII_Subsequences.c
* Update ASCII_Subsequences.js
* Update ASCII_Subsequences.py
* Update ASCII_Subsequences.js
* Update ASCII_Subsequences.py
---
Ascii_Subsequences/ASCII_Subsequences.c | 110 +++++++++++++++++++++++
Ascii_Subsequences/ASCII_Subsequences.js | 46 ++++++++++
Ascii_Subsequences/ASCII_Subsequences.py | 36 ++++++++
3 files changed, 192 insertions(+)
create mode 100644 Ascii_Subsequences/ASCII_Subsequences.c
create mode 100644 Ascii_Subsequences/ASCII_Subsequences.js
create mode 100644 Ascii_Subsequences/ASCII_Subsequences.py
diff --git a/Ascii_Subsequences/ASCII_Subsequences.c b/Ascii_Subsequences/ASCII_Subsequences.c
new file mode 100644
index 000000000..69d4c5a9e
--- /dev/null
+++ b/Ascii_Subsequences/ASCII_Subsequences.c
@@ -0,0 +1,110 @@
+/*ASCII SUBSEQUENCES PROBLEM
+This problem is same as the "Subsequences" question just instead of two function calls, three function calls will be made :
+- One with the same string.
+- One with a letter added.
+- One with the ASCII code of the letter added to the string.
+*/
+
+#include
+#include
+#include
+#include
+
+char str[100];
+
+void subseq(char s[], int i, char str[])
+{
+ if(i == strlen(str))
+ {
+ printf("%s\n", s);
+ return;
+ }
+
+ // The 3 function calls in the same order as explained above.
+ // First function call
+ subseq(s, i + 1, str);
+
+ int i1;
+ char s2[strlen(s) + 2];
+
+ for(i1 = 0; i1 < strlen(s); i1++)
+ {
+ // Copy string from s to s2
+ s2[i1] = s[i1];
+ }
+
+ // Concatinate ith character of string str to s2
+ s2[i1++] = str[i];
+ s2[i1] = '\0';
+
+ // Second function call
+ subseq(s2, i + 1, str);
+
+ // Integer n stores the ASCII value of the ith character of string str
+ int i2, n = (int)str[i];
+ char s3[strlen(s) + 2];
+
+ // Create AsciiString to store the ASCII value of the ith character of string str
+ char AsciiString[5];
+
+ if(n < 10)
+ {
+ AsciiString[0] = (char)(n + 48);
+ AsciiString[1] = '\0';
+ }
+ else if(n<100)
+ {
+ AsciiString[0] = (char)(((n - (n % 10)) / 10) + 48);
+ AsciiString[1] = (char)((n % 10) + 48);
+ AsciiString[2] = '\0';
+ }
+ else
+ {
+ AsciiString[0] = (char)(((n - (n % 100)) / 100) + 48);
+ AsciiString[1] = (char)((((n - (n % 10)) / 10) % 10) + 48);
+ AsciiString[2] = (char)((n % 10) + 48);
+ AsciiString[3] = '\0';
+ }
+
+ for(i2 = 0; i2 < strlen(s); i2++)
+ {
+ // Copy string from s to s3
+ s3[i2] = s[i2];
+ }
+
+ int i3 = i2;
+
+ for(; i2 < strlen(AsciiString) + strlen(s); i2++)
+ {
+ // Concatinate AsciiString into s3
+ s3[i2] = AsciiString[i2 - i3];
+ }
+
+ s3[i2] = '\0';
+ // Third function call
+ subseq(s3, i + 1, str);
+}
+
+int main()
+{
+ printf("Enter the string\n");
+ scanf("%s", str);
+ printf("Number of Subsequences : %d\n", (int)pow(3, strlen(str)));
+ subseq("", 0, str);
+ return 0;
+}
+
+/*Sample Input: Enter the string:
+ab
+Sample Output:
+Number of Subsequences : 9
+
+b
+98
+a
+ab
+a98
+97
+97b
+9798
+*/
diff --git a/Ascii_Subsequences/ASCII_Subsequences.js b/Ascii_Subsequences/ASCII_Subsequences.js
new file mode 100644
index 000000000..b3ed3fe56
--- /dev/null
+++ b/Ascii_Subsequences/ASCII_Subsequences.js
@@ -0,0 +1,46 @@
+/*ASCII SUBSEQUENCES PROBLEM
+This problem is same as the "Subsequences" question just instead of two function calls, three function calls will be made :
+- One with the same string.
+- One with a letter added.
+- One with the ascii code of the letter added to the string.
+*/
+
+function subseq(s, i, str)
+{
+ if(i === str.length)
+ {
+ console.log(s);
+ return;
+ }
+
+ // The 3 function calls in the same order as explained above.
+ // First function call
+ subseq(s, i + 1, str);
+ // Second function call
+ subseq(s + str[i], i + 1, str);
+ var n = str.charCodeAt(i);
+ // Third function call with the ASCII value of the ith element of the string
+ subseq(s + n.toString(), i + 1, str);
+}
+
+( function IIFE() {
+ var str = prompt("Enter the string");
+ console.log( "Number of Subsequences : ", Math.pow(3, str.length));
+ subseq("", 0, str);
+ return 0;
+})();
+
+/*Sample Input: Enter the string:
+ab
+Sample Output:
+Number of Subsequences : 9
+
+b
+98
+a
+ab
+a98
+97
+97b
+9798
+*/
diff --git a/Ascii_Subsequences/ASCII_Subsequences.py b/Ascii_Subsequences/ASCII_Subsequences.py
new file mode 100644
index 000000000..5981573eb
--- /dev/null
+++ b/Ascii_Subsequences/ASCII_Subsequences.py
@@ -0,0 +1,36 @@
+"""ASCII SUBSEQUENCES PROBLEM
+This problem is same as the "Subsequences" question just instead of two function calls, three function calls will be made :
+- One with the same string.
+- One with a letter added.
+- One with the ASCII code of the letter added to the string."""
+
+def subseq(s, i, string1):
+ if (i == len(string1)):
+ print(s)
+ return
+ #The 3 function calls in the same order as explained above.
+ # First function call
+ subseq(s, i + 1, string1)
+ # Second function call
+ subseq(s + string1[i], i + 1, string1)
+ #Third function call in which ord(string1[i]) gives the ASCII value which is then converted to string for concatenation
+ subseq(s + str(ord(string1[i])),i + 1, string1)
+
+string1 = input("Enter the string")
+print("Number of Subsequences :", pow(3, len(string1)))
+subseq("", 0, string1)
+
+"""Sample Input: Enter the string
+ab
+Sample Output:
+Number of Subsequences : 9
+
+b
+98
+a
+ab
+a98
+97
+97b
+9798
+"""
From 9555f9f18bc6eff87a557e17898495994a6484a0 Mon Sep 17 00:00:00 2001
From: Raksha <57195964+raksha009@users.noreply.github.com>
Date: Mon, 16 Mar 2020 16:13:25 +0530
Subject: [PATCH 004/265] check whether a string is palindrome (#2402)
* pallindrome string python
* Update and rename pallindrome_string.py to palindrome_string.py
Fixed Typo in file name
* Update palindrome_string.py
---
Palindrome/palindrome_string.py | 32 ++++++++++++++++++++++++++++++++
1 file changed, 32 insertions(+)
create mode 100644 Palindrome/palindrome_string.py
diff --git a/Palindrome/palindrome_string.py b/Palindrome/palindrome_string.py
new file mode 100644
index 000000000..3aa4aac24
--- /dev/null
+++ b/Palindrome/palindrome_string.py
@@ -0,0 +1,32 @@
+# Python program to find whether a string is a palindrome or not
+
+# Function to reverse a String
+def reverse(str):
+
+ # Initialize variable
+ rev = ""
+
+ for i in range (len(str)-1, -1, -1):
+ rev = rev + str[i]
+ return rev
+
+
+# --- main ---
+string = raw_input(("Enter a string: ")) #User Input
+
+a = reverse(string) #Function call
+
+if(a == string): #Comparing the reversed String with original String
+ print("String entered is palindrome!")
+else:
+ print("String entered is not a palindrome!")
+
+'''
+TEST CASES
+
+Enter a string: affcffa
+String entered is palindrome!
+
+Enter a string: abbcd
+String entered is not a palindrome!
+'''
From 41591c0ce21c0a3f61b4da969b622ba072a045d3 Mon Sep 17 00:00:00 2001
From: Yashasvi Sinha <59117774+heisastark@users.noreply.github.com>
Date: Mon, 16 Mar 2020 16:16:04 +0530
Subject: [PATCH 005/265] added Power_Of_Two in JS (#2362)
* added Power_Of_Twoin JS
* Added space around minus in line 11
---
Power_Of_Two/Power_Of_Two.js | 33 +++++++++++++++++++++++++++++++++
1 file changed, 33 insertions(+)
create mode 100644 Power_Of_Two/Power_Of_Two.js
diff --git a/Power_Of_Two/Power_Of_Two.js b/Power_Of_Two/Power_Of_Two.js
new file mode 100644
index 000000000..e74f9922c
--- /dev/null
+++ b/Power_Of_Two/Power_Of_Two.js
@@ -0,0 +1,33 @@
+/*
+To check whether a number is a power of two or not,
+we do bitwise "and" of number and number - 1, if the
+result is zero the number is a power of two.
+Example: number = 4, then 4 & 3 i.e 100 && 011 is 0
+16 & 15 i.e 10000 & 01111 = 0
+This is true for all powers of two.
+*/
+
+function isPowerofTwo(n){
+ return n && ( ! ( n & (n - 1) ));
+}
+
+var num = parseInt(prompt("Enter a number to check:"));
+
+if(isPowerofTwo(num)){
+ console.log("The number is a power of two");
+}
+else{
+ console.log("The number is not a power of two");
+}
+
+
+/*
+Input:
+64
+Output:
+The number is a power of two
+Input:
+5
+Output:
+The number is not a power of two
+*/
From 38be455c219b8629fff0f3211e2348fc5540c162 Mon Sep 17 00:00:00 2001
From: Sohel Raja Molla
Date: Mon, 16 Mar 2020 20:47:57 +0530
Subject: [PATCH 006/265] Implementation of Pascal Triangle in Java and Python
Added
---
Pascal_Triangle/Pascal_Triangle.java | 51 ++++++++++++++++++++++++++++
Pascal_Triangle/Pascal_Triangle.py | 30 ++++++++++++++++
2 files changed, 81 insertions(+)
create mode 100644 Pascal_Triangle/Pascal_Triangle.java
create mode 100644 Pascal_Triangle/Pascal_Triangle.py
diff --git a/Pascal_Triangle/Pascal_Triangle.java b/Pascal_Triangle/Pascal_Triangle.java
new file mode 100644
index 000000000..3a0fda487
--- /dev/null
+++ b/Pascal_Triangle/Pascal_Triangle.java
@@ -0,0 +1,51 @@
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.*;
+
+class Pascal_Triangle {
+ public static void main (String[] args) throws IOException{
+ // Taking The Input from User
+ System.out.print("Enter the number of rows to be printed: ");
+ BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
+ // Converting String Into Integer
+ int rows = Integer.parseInt(br.readLine());
+ // Calling the Pascal Class
+ new Pascal(rows);
+ }
+}
+
+class Pascal {
+ Pascal(int n)
+ {
+ for(int row = 1; row <= n; row++)
+ {
+ // Initializing the Initial Value of Pascal Value as 1
+ int pascal_value = 1;
+ // For Pring Blank Space
+ for(int i = 1; i < n - row + 1; i++){
+ System.out.print(" ");
+ }
+ System.out.print(" ");
+ // For calculating the Pascal Value
+ for(int i = 1; i <= row; i++)
+ {
+ // Assigning the Printable string to string s and printing the s
+ String s = " " + pascal_value + " ";
+ System.out.print(s);
+ // Calculating the New Pascal Value
+ pascal_value = pascal_value * (row - i) / i;
+ }
+ System.out.println();
+ }
+ }
+}
+
+//Input:
+//Enter the number of rows to be printed: 5
+
+//Output:
+// 1
+// 1 1
+// 1 2 1
+// 1 3 3 1
+// 1 4 6 4 1
diff --git a/Pascal_Triangle/Pascal_Triangle.py b/Pascal_Triangle/Pascal_Triangle.py
new file mode 100644
index 000000000..532b64c48
--- /dev/null
+++ b/Pascal_Triangle/Pascal_Triangle.py
@@ -0,0 +1,30 @@
+def Pascal_Triangle(n):
+ for row in range(1, n + 1):
+ # Initializing the Initial Value of Pascal Value as 1
+ pascal_value = 1
+ # For printing blank spaces
+ for i in range(1, n - row + 1):
+ print(' ', end=' ')
+ # For calculating the pascal value
+ for i in range(1, row + 1):
+ # Creating the printable string and printing the string
+ s = ' ' + str(pascal_value) + ' '
+ print(s, end = " ")
+ # Calculating the new Pascal Value
+ pascal_value = int(pascal_value * (row - i) / i)
+ print(end = '\n')
+
+# Taking the Input from the user
+rows = int(input("Enter the number of rows to be printed: "))
+# Calling the Function
+Pascal_Triangle(rows)
+
+# Input:
+# Enter the number of rows to be printed: 5
+
+# Output:
+# 1
+# 1 1
+# 1 2 1
+# 1 3 3 1
+# 1 4 6 4 1
From da2f29155413ebe635bca8994111b1d3dcdb843a Mon Sep 17 00:00:00 2001
From: Sukriti Shah
Date: Wed, 18 Mar 2020 14:31:02 +0530
Subject: [PATCH 007/265] Adding Python Implementation for Kosaraju Algorithm
(Issue #2246) (#2488)
* Adding Python implementation for issue #2246
* Update Kosaraju_Algorithm.py
---
Kosaraju_Algorithm/Kosaraju_Algorithm.py | 83 ++++++++++++++++++++++++
1 file changed, 83 insertions(+)
create mode 100644 Kosaraju_Algorithm/Kosaraju_Algorithm.py
diff --git a/Kosaraju_Algorithm/Kosaraju_Algorithm.py b/Kosaraju_Algorithm/Kosaraju_Algorithm.py
new file mode 100644
index 000000000..a7c0bca7b
--- /dev/null
+++ b/Kosaraju_Algorithm/Kosaraju_Algorithm.py
@@ -0,0 +1,83 @@
+# Python implementation of Kosaraju's Algorithm
+# Kosaraju's Algorithm is used to print all Strongly Connected Components (SCCs) in a directed graph
+# A component is said to be strongly connected if there is a path between all pairs of vertices in it.
+
+# Kosaraju’s Algorithm involves two passes of Depth First Search in order to find the number of SCCs
+
+# defaultdict is a useful technique for building graphs.
+from collections import defaultdict
+
+# Function for first DFS pass and to fill vertices in finishStack
+def firstDFS(g, v, visited, finishStack):
+ visited[v] = True
+ for i in g[v]:
+ if visited[i] == False:
+ firstDFS(g, i, visited, finishStack)
+ finishStack = finishStack.append(v)
+
+# Function for second DFS pass
+def secondDFS(gt, v, visited):
+ visited[v] = True
+ print(v, end = " ")
+ for i in gt[v]:
+ if visited[i] == False:
+ secondDFS(gt, i, visited)
+
+# Create Graph
+v = int(input("Enter number of vertices in the graph: "))
+
+# g represents original graph
+g = defaultdict(list)
+
+# gt represents transpose of original graph
+gt = defaultdict(list)
+
+e = int(input("Enter number of edges in the graph: "))
+for i in range(1 , e + 1):
+ print("Edge no. %d - "%(i), end = "")
+ num = list(map(int, input(' ').split()))
+ g[num[0]].append(num[1])
+ gt[num[1]].append(num[0])
+
+# Stack to be filled according to finishing time
+finishStack = []
+
+# Maintaining visited array of size v
+# All vertices are marked False for first DFS pass
+visited = [False] * v
+
+# First DFS on g
+for i in range(v):
+ if visited[i] == False:
+ firstDFS(g, i, visited, finishStack)
+
+print ("Strongly connected components(SCCs) in the graph are: ")
+
+# Maintaining visited array of size v
+# All vertices are marked False for second DFS pass
+visited = [False] * v
+
+# Second DFS on gt
+while finishStack:
+ i = finishStack.pop()
+ if visited[i] == False:
+ secondDFS(gt, i, visited)
+ print()
+
+'''
+Sample Input:
+Enter number of vertices in the graph: 6
+Enter number of edges in the graph: 7
+Edge no. 1 - 0 1
+Edge no. 2 - 1 2
+Edge no. 3 - 2 0
+Edge no. 4 - 2 3
+Edge no. 5 - 3 4
+Edge no. 6 - 4 5
+Edge no. 7 - 5 3
+
+Sample Output:
+Strongly connected components(SCCs) in the graph are:
+0 2 1
+3 5 4
+'''
From d54e5611b03541e5ddb8f541efe0caa2312724a2 Mon Sep 17 00:00:00 2001
From: Swayamprava Satpathy <43417696+Xxoliaxx@users.noreply.github.com>
Date: Wed, 18 Mar 2020 14:39:00 +0530
Subject: [PATCH 008/265] Added code for Round Robin Scheduling (#1928)
* Add files via upload
* Update Readers_Writers_Problem.cpp
* Update Readers_Writers_Problem.cpp
* Add files via upload
* Update Round_Robin_Scheduling.cpp
* Delete Round_Robin_Scheduling.cpp
* Add files via upload
* Delete Readers_Writers_Problem.cpp
* Indentation and space around operators fix
* Update Round_Robin_Scheduling.cpp
* Update Round_Robin_Scheduling.cpp
* Update Round_Robin_Scheduling.cpp
* Update Round_Robin_Scheduling.cpp
* Update Round_Robin_Scheduling.cpp
* Update Round_Robin_Scheduling.cpp
---
.../C++/Preemptive/Round_Robin_Scheduling.cpp | 104 ++++++++++++++++++
1 file changed, 104 insertions(+)
create mode 100644 Scheduling_Algorithm/C++/Preemptive/Round_Robin_Scheduling.cpp
diff --git a/Scheduling_Algorithm/C++/Preemptive/Round_Robin_Scheduling.cpp b/Scheduling_Algorithm/C++/Preemptive/Round_Robin_Scheduling.cpp
new file mode 100644
index 000000000..ae27ba4db
--- /dev/null
+++ b/Scheduling_Algorithm/C++/Preemptive/Round_Robin_Scheduling.cpp
@@ -0,0 +1,104 @@
+/*Round Robin Scheduling is a CPU scheduling algorithm where each process is assigned a fixed time slot in a cyclic way.
+It is preemtive in nature.
+It is cyclic in nature so starvation doesn’t occur
+It is variant of first come, first served scheduling
+No priority given to any process or task
+It is also known as Time slicing scheduling
+-Arrival Time: Time at which the process arrives in the ready queue.
+-Burst Time: Time required by a process for CPU execution.
+-Turn Around Time: Time Difference between completion time and arrival time.
+-Waiting Time: Time Difference between turn around time and burst time. */
+
+#include
+using namespace std;
+
+int main()
+{
+ int i, j, no_of_process, current_time, remaining_time;
+ int f = 0, time_slice, wait_time = 0, turn_time = 0;
+ cout << "Enter number of processes: ";
+ cin >> no_of_process;
+
+ int a[no_of_process]; //Arrival Time
+ int b[no_of_process]; //Burst Time
+ int r[no_of_process];
+ remaining_time = no_of_process;
+
+ for(i = 0; i < no_of_process; i++)
+ {
+ cout << "\nProcess " << i << ": ";
+ cout << "Enter Arrival Time: ";
+ cin >> a[i];
+ cout << "Enter Burst Time: ";
+ cin >> b[i];
+ r[i] = b[i];
+ }
+
+ cout << "Enter Time slice: ";
+ cin >> time_slice;
+
+ cout << "\nProcess\tTurnaround time\t Waiting Time\n";
+ cout << "-------------------------------------------";
+ for(current_time = 0, i = 0; remaining_time != 0;)
+ {
+ //If burst time is less than time slice
+ if(r[i] <= time_slice && r[i] > 0)
+ {
+ current_time += r[i]; //Increase current time by adding burst time
+ r[i] = 0; //Make remaining time zero
+ f = 1;
+ }
+ //If required time is more than time slice
+ else if(r[i] > 0)
+ {
+ r[i] -= time_slice; //Reduce remaining time by time slice
+ current_time += time_slice; //Increase current time by adding time slice
+ }
+
+ if(r[i] == 0 && f == 1)
+ {
+ remaining_time--;
+ cout << "\nProcess " << i << "\t" << current_time - a[i] << "\t\t" << current_time - a[i] - b[i];
+ wait_time += current_time - a[i] - b[i];
+ turn_time += current_time - a[i];
+ f = 0;
+ }
+ if(i >= no_of_process - 1)
+ i = 0;
+ else if(a[i+1] <= current_time)
+ i++;
+ else
+ i = 0;
+ }
+ cout << "\nAverage Waiting Time: " << (wait_time*1.0) / no_of_process;
+ cout << "\nAverage Turnaround Time: " << (turn_time*1.0) / no_of_process;
+ return 0;
+}
+
+/*
+Sample Input/Output:
+
+Enter number of processes: 4
+
+Process 0: Enter Arrival Time: 1
+Enter Burst Time: 5
+
+Process 1: Enter Arrival Time: 3
+Enter Burst Time: 7
+
+Process 2: Enter Arrival Time: 2
+Enter Burst Time: 5
+
+Process 3: Enter Arrival Time: 5
+Enter Burst Time: 8
+Enter Time slice: 3
+
+Process Turnaround time Waiting Time
+-------------------------------------------
+Process 0 13 8
+Process 2 17 12
+Process 1 20 13
+Process 3 20 12
+Average Waiting Time: 11.25
+Average Turnaround Time: 17.5
+*/
From 199ea87e49c6a5d9528b28b8aa015bf5b8599ce3 Mon Sep 17 00:00:00 2001
From: Chanpreet Singh <34856246+chanpreet1999@users.noreply.github.com>
Date: Wed, 18 Mar 2020 18:18:11 +0530
Subject: [PATCH 009/265] Closes Issue #1601 (#1744)
Added Count Frequency Of Elements In Java For issue #1601
---
.../CountFrequencyOfArrayElements.java | 62 +++++++++++++++++++
1 file changed, 62 insertions(+)
create mode 100644 Freq_Of_Elements_Of_Array/CountFrequencyOfArrayElements.java
diff --git a/Freq_Of_Elements_Of_Array/CountFrequencyOfArrayElements.java b/Freq_Of_Elements_Of_Array/CountFrequencyOfArrayElements.java
new file mode 100644
index 000000000..d44303278
--- /dev/null
+++ b/Freq_Of_Elements_Of_Array/CountFrequencyOfArrayElements.java
@@ -0,0 +1,62 @@
+/*Problem Statement
+ * Given an array of elements count the frequency of every element in the array.
+ */
+
+import java.util.HashMap;
+import java.util.Scanner;
+
+public class CountFrequencyOfArrayElements
+{
+
+ public static void main(String[] args)
+ {
+ Scanner sc = new Scanner(System.in);
+
+ // input size of array
+ int n = sc.nextInt();
+ // input array
+ int a[] = new int[n];
+ for(int i = 0; i < n; i++)
+ a[i] = sc.nextInt();
+
+ countFreq(a, n);
+
+ sc.close();
+ }
+
+ // function to count frequency
+ private static void countFreq(int[] a, int n) {
+ // using hashmap to store the freq
+ HashMap hm = new HashMap<>();
+ for(int i = 0; i < n; i++)
+ {
+ if( hm.containsKey(a[i]) )
+ hm.put( a[i], hm.get(a[i]) + 1);
+ else
+ hm.put(a[i], 1);
+ }
+
+ //display the frequencies
+ System.out.println("Element \t Frequency");
+ hm.forEach(
+ (k,v) ->
+ {
+ System.out.println(k + " \t\t " + v);
+ }
+ );
+ }
+
+}
+
+/*
+ * Input :
+5
+2 1 1 6 1
+
+ * Output :
+Element Frequency
+1 3
+2 1
+6 1
+
+ * */
From 4b17a3e9b29225931199b56e84757330edae3304 Mon Sep 17 00:00:00 2001
From: parjanyaacoder <46294122+parjanyaacoder@users.noreply.github.com>
Date: Wed, 18 Mar 2020 18:20:35 +0530
Subject: [PATCH 010/265] Pancake Sorting in Java (#2022)
* Pancake Sorting implemented in Java language For issue #1988
---
Pancake_Sort/Pancake_Sort.java | 73 ++++++++++++++++++++++++++++++++++
1 file changed, 73 insertions(+)
create mode 100644 Pancake_Sort/Pancake_Sort.java
diff --git a/Pancake_Sort/Pancake_Sort.java b/Pancake_Sort/Pancake_Sort.java
new file mode 100644
index 000000000..c26136fe0
--- /dev/null
+++ b/Pancake_Sort/Pancake_Sort.java
@@ -0,0 +1,73 @@
+/* Pancake Sorting is a Sorting Technique in which the array of length n can be sorted only by reversing the array upto an index i where i is in range of 0 to n - 1 */
+
+import java.util.* ;
+class PancakeSorting
+{
+
+ static void reverseArray ( int a [] , int n ) // This functions reverses the array upto index n
+ {
+ int temp[] = new int [ n + 1 ] ; // temp is the temporary array
+ for ( int i = 0 ; i <= n ; i ++ )
+ {
+ temp [ i ] = a [ n - i ] ;
+ }
+ for ( int i = 0 ; i <= n ; i ++ )
+ a [ i ] = temp [ i ] ;
+ }
+
+
+ static int findMax ( int a [] , int n ) // Function to find index of max element upto index n
+ {
+ int max = a [ 0 ] ; int j = 0 ; // j stores the index of max element
+ for ( int i = 1 ; i <= n ; i ++ )
+ {
+ if ( a [ i ] > max )
+ {
+ max = a [ i ] ;
+ j = i ;
+ }
+ }
+
+ return j ;
+
+ }
+
+
+ static void pancakeSort ( int a [ ] , int n )
+ {
+ int currentLength ;
+ for ( currentLength = n ; currentLength > 0 ; -- currentLength )
+ {
+ int j = findmax ( a , currentLength - 1 ) ;
+ if ( j != currentLength )
+ {
+ reverseArray ( a , j ) ;
+ reverseArray ( a , currentLength-1 ) ;
+ }
+ }
+ }
+
+
+ public static void main ( String [] args )
+ {
+ Scanner sc = new Scanner ( System.in ) ;
+ int i , j , k , l , m , n ;
+ n = sc.nextInt () ;
+ int array [ ] = new int [ n ] ;
+ for ( i = 0 ; i < n ;i ++)
+ array [ i ] = sc.nextInt () ;
+ pancakesort ( array , n ) ;
+ for ( i = 0 ; i < n ; i ++)
+ System.out.print ( array [ i ] + " " ) ;
+ System.out.println ( ) ;
+ }
+
+
+}
+
+
+/* Input
+n = 5 array = { 5 , 4 , 3 , 2 , 1 }
+
+ Output
+1 2 3 4 5 */
From e274d7140445a4e27d70d1551f9de7dd26cc9541 Mon Sep 17 00:00:00 2001
From: "Abhushan A. Joshi" <49617450+abhu-A-J@users.noreply.github.com>
Date: Wed, 18 Mar 2020 22:33:29 +0530
Subject: [PATCH 011/265] Implementation of Bucket Sort in JS (#2431)
---
Bucket_Sort/Bucket_Sort.js | 64 ++++++++++++++++++++++++++++++++++++++
1 file changed, 64 insertions(+)
create mode 100644 Bucket_Sort/Bucket_Sort.js
diff --git a/Bucket_Sort/Bucket_Sort.js b/Bucket_Sort/Bucket_Sort.js
new file mode 100644
index 000000000..ee9a8c90e
--- /dev/null
+++ b/Bucket_Sort/Bucket_Sort.js
@@ -0,0 +1,64 @@
+/*
+ Bucket sort is a comparison sort algorithm that operates on elements by dividing
+ them into different buckets and then sorting these buckets individually.
+*/
+
+const insertionSort = arr => {
+ let i, j;
+ for (i = 1; i < arr.length; i++) {
+ let currentVal = arr[i];
+ for (j = i - 1; j >= 0; j--) {
+ if (currentVal > arr[j]) {
+ break;
+ }
+ else {
+ arr[j + 1] = arr[j];
+ }
+ }
+ arr[j + 1] = currentVal;
+ }
+ return arr;
+}
+
+const bucketSort = arr => {
+
+ if (arr.length === 0) {
+ return arr;
+ }
+
+ // finding minimum and maximum value and setting bucket size
+ let minValue = Math.min(...arr);
+ let maxValue = Math.max(...arr);
+ let bucketSize = 10;
+
+ let bucketCount = Math.floor((maxValue - minValue) / bucketSize) + 1;
+
+ let buckets = Array.from({ length: bucketCount }, () => []);
+
+ // Pushing values to buckets
+ for (let i = 0; i < arr.length; i++) {
+ let index = Math.floor((arr[i] - minValue) / bucketSize);
+ buckets[index].push(arr[i]);
+ }
+
+ // reset the input array to store sorted result
+ arr.length = 0;
+
+ // sort individual buckets and put the elements onto the array
+ buckets.forEach(function (bucket) {
+ insertionSort(bucket);
+ bucket.forEach(function (value) {
+ arr.push(value)
+ });
+ });
+
+ return arr;
+}
+
+// I/P and O/P examples
+
+// [ -11, -10, -1, 2, 4 ]
+console.log(bucketSort([-1, 2, 4, -10, -11]));
+
+// [ -11, -10, 4, 100, 200 ]
+console.log(bucketSort([100, 200, 4, -10, -11]));
\ No newline at end of file
From e8f269283a74b0f4eb2c18075927494b3ac7e52f Mon Sep 17 00:00:00 2001
From: shweta gurnani <43384092+shwetagurnani@users.noreply.github.com>
Date: Thu, 19 Mar 2020 00:21:28 +0530
Subject: [PATCH 012/265] Create Readme.md (#2383)
* Create Readme.md
* Update Readme.md
---
Ternary_Search/Readme.md | 46 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 46 insertions(+)
create mode 100644 Ternary_Search/Readme.md
diff --git a/Ternary_Search/Readme.md b/Ternary_Search/Readme.md
new file mode 100644
index 000000000..f2f14dfc4
--- /dev/null
+++ b/Ternary_Search/Readme.md
@@ -0,0 +1,46 @@
+# Ternary Search
+
+Ternary search is a searching technique that is used to search the position of a specific value in an array. Ternary search is a divide-and-conquer algorithm. It is mandatory for the array to be sorted (in which you will search for an element).
+
+The array is divided into three parts and then we determine in which part the element exists. In this search, after each iteration it neglects ⅓ part of the array and repeats the same operations on the remaining ⅔.
+
+## Algorithm
+
+ 1.mid1 = start + (end - start) / 3 and mid2 = mid1 + (end - start) / 3.
+
+ 2.Compare the element to be searched with the element at mid1. If they are equal then return mid1.
+
+ 3.Compare the element to be searched with the element at mid2. If they are equal then return mid2.
+
+ 4.If the element to be searched is less than element at mid1 recur to the first part, otherwise if it is greater than the element at mid2 recur to the third part. If not both, then recur to the second part.
+
+## Pseudo Code
+
+```
+ ternarySearch(array, start, end, searchKey)
+ if start <= end then
+ mid1 = start + (end - start) / 3
+ mid2 = mid1 + (end - start) / 3
+ if array[mid1] = searchKey then
+ return mid1
+ if array[mid2] = searchKey then
+ return mid2
+ if searchKey < array[mid1] then
+ call ternarySearch(array, start, mid1 - 1, searchKey)
+ if searchKey > array[mid2] then
+ call ternarySearch(array, mid2 + 1, end, searchKey)
+ else
+ call ternarySearch(array, mid1 + 1, mid2-1, searchKey)
+```
+
+## Complexity
+ Time Complexity: O(log3 n)
+ Space Complexity: O(1)
+
+ ## Implementation
+ * [C Code](https://github.com/jainaman224/Algo_Ds_Notes/blob/master/Ternary_Search/Ternary_Search.c)
+ * [C++ Code](https://github.com/jainaman224/Algo_Ds_Notes/blob/master/Ternary_Search/Ternary_Search.cpp)
+ * [Java Code](https://github.com/jainaman224/Algo_Ds_Notes/blob/master/Ternary_Search/Ternary_Search.java)
+ * [Coffee Code](https://github.com/jainaman224/Algo_Ds_Notes/blob/master/Ternary_Search/Ternary_Search.coffee)
+ * [Python Code](https://github.com/jainaman224/Algo_Ds_Notes/blob/master/Ternary_Search/Ternary_Search.py)
+ * [JS Code](https://github.com/jainaman224/Algo_Ds_Notes/blob/master/Ternary_Search/Ternary_Search.js)
From fe80d529dabbccd9b5651549819897811e723bf7 Mon Sep 17 00:00:00 2001
From: Arghadip Chakraborty
Date: Thu, 19 Mar 2020 01:26:04 +0530
Subject: [PATCH 013/265] Added KNN algorithm using C (#2074)
Fixed indentation
Fixed indentation
Fixed indentation again
Fixed indentation
Added more comments in the code
Fixed Identaion and few coding conventions
Fixed Identaion
Fixed Identaion and few coding conventions
---
.../K_Nearest_Neighbours.c | 117 ++++++++++++++++++
1 file changed, 117 insertions(+)
create mode 100644 Machine_Learning/K_Nearest_Neighbours/K_Nearest_Neighbours.c
diff --git a/Machine_Learning/K_Nearest_Neighbours/K_Nearest_Neighbours.c b/Machine_Learning/K_Nearest_Neighbours/K_Nearest_Neighbours.c
new file mode 100644
index 000000000..ce0f639d3
--- /dev/null
+++ b/Machine_Learning/K_Nearest_Neighbours/K_Nearest_Neighbours.c
@@ -0,0 +1,117 @@
+#include
+#include
+#include
+
+typedef struct point{
+ float w, x, y, z; // features or co-ordinates of the point
+ float distance; // Distance from test point
+ int op; // label of the point
+}point;
+
+int main() {
+ int i, j, n, k;
+ point p;
+ point temp;
+ printf("Number of data points: ");
+ scanf("%d", &n);
+ point arr[n];
+ printf("\nEnter the dataset values: \n");
+ printf("w\tx\ty\tz\top\n");
+
+ // Taking input data
+ for (i = 0; i < n; i++) {
+ scanf("%f%f%f%f%d", &arr[i].w, &arr[i].x, &arr[i].y, &arr[i].z, &arr[i].op);
+ }
+ printf("w\tx\ty\tz\top\n");
+ for (i = 0; i < n; i++) {
+ printf("%.2f\t%.2f\t%.2f\t%.2f\t%d\n", arr[i].w, arr[i].x, arr[i].y, arr[i].z, arr[i].op);
+ }
+
+ // Taking the feature values or co-ordinates of the unknown data point
+ printf("\nEnter the feature values of the unkown point: \nw\tx\ty\tz\n");
+ scanf("%f%f%f%f", &p.w, &p.x, &p.y, &p.z);
+
+ // Measuring the Euclidean distances
+ for (i = 0; i < n; i++) {
+ arr[i].distance = sqrt((arr[i].w - p.w) * (arr[i].w - p.w) + (arr[i].x - p.x) * (arr[i].x - p.x) + (arr[i].y - p.y) * (arr[i].y - p.y) + (arr[i].z - p.z) * (arr[i].z - p.z));
+ }
+
+ //Sorintg the training data with resptect to the Euclidean distances
+ for (i = 1; i < n; i++) {
+ for (j = 0; j < n - i; j++) {
+ if (arr[j].distance > arr[j + 1].distance) {
+ temp = arr[j];
+ arr[j] = arr[j + 1];
+ arr[j + 1] = temp;
+ }
+ }
+ }
+ printf("w\tx\ty\tz\top\tdistance\n");
+ for (i = 0; i < n; i++) {
+ printf("%.2f\t%.2f\t%.2f\t%.2f\t%d\t%.2f\n", arr[i].w, arr[i].x, arr[i].y, arr[i].z, arr[i].op, arr[i].distance);
+ }
+
+ // Taking the K -nearest neighbors
+ printf("\nNumber of nearest neighbors(k): "); // Value of K
+ scanf("%d", &k);
+
+ // Measuring the frequencies of each label in K nearest neighbors' data
+ int freq1 = 0; // for label 1
+ int freq2 = 0; // for label 2
+ int freq3 = 0; // for label 3
+ int none = 0;
+ for (i = 0; i < k; i++) {
+ if (arr[i].op == 1)
+ freq1++;
+ else if (arr[i].op == 2)
+ freq2++;
+ else if(arr[i].op == 3)
+ freq3++;
+ else
+ none++;
+ }
+
+ // Printing the label of the unknown data
+ if(freq1 >= freq2 && freq1 >= freq3) {
+ printf("\nThe class of unknown point is: 1");
+ }
+ else if(freq2 >= freq1 && freq2 >= freq3 ) {
+ printf("\nThe class of unknown point is: 2");
+ }
+ else {
+ printf("\nThe class of unknown point is: 3");
+ }
+}
+
+/*Sample Input and Output:
+------------------------
+Number of data points: 5
+
+Enter the dataset values:
+w x y z op
+1 2 4 3 1
+1 3 2 1 1
+8 7 6 9 2
+7 8 6 9 2
+6 9 7 5 2
+w x y z op
+1.00 2.00 4.00 3.00 1
+1.00 3.00 2.00 1.00 1
+8.00 7.00 6.00 9.00 2
+7.00 8.00 6.00 9.00 2
+6.00 9.00 7.00 5.00 2
+
+Enter the feature values of the unkown point:
+w x y z
+8 7 5 9
+w x y z op distance
+8.00 7.00 6.00 9.00 2 1.00
+7.00 8.00 6.00 9.00 2 1.73
+6.00 9.00 7.00 5.00 2 5.29
+1.00 2.00 4.00 3.00 1 10.54
+1.00 3.00 2.00 1.00 1 11.75
+
+Number of nearest neighbors(k): 2
+
+The class of unknown point is: 2
+*/
From 691b23a4cd549d095179ae2b418e7daa07029a7c Mon Sep 17 00:00:00 2001
From: Nikhil Patro
Date: Thu, 19 Mar 2020 20:37:55 +0530
Subject: [PATCH 014/265] Added Bisection_Method.cpp (#2458)
---
Bisection_Method/Bisection_Method.cpp | 122 ++++++++++++++++++++++++++
1 file changed, 122 insertions(+)
create mode 100644 Bisection_Method/Bisection_Method.cpp
diff --git a/Bisection_Method/Bisection_Method.cpp b/Bisection_Method/Bisection_Method.cpp
new file mode 100644
index 000000000..92541251d
--- /dev/null
+++ b/Bisection_Method/Bisection_Method.cpp
@@ -0,0 +1,122 @@
+#include
+#include
+using namespace std;
+// approximation limit
+#define error 0.0001
+
+//function of the polynomial is inputted here say f(x) = x*x - 2*x + 1
+float polynomial(float x)
+{
+ return x * x - 4 * x + 3;
+}
+
+float mid(float q, float w)
+{
+ return (q + w) / 2;
+}
+
+int main()
+{
+ int i;
+ float lower_bound, upper_bound, a, b;
+
+ cout << "For the interval (a, b) where the root may lie : " << endl;
+ cout << "Enter the value of a :- " << endl;
+ cin >> lower_bound;
+
+ a = lower_bound;
+
+ cout << "Enter the value of b :- " << endl;
+ cin >> upper_bound;
+
+ b = upper_bound;
+
+ if(polynomial(lower_bound) * polynomial(upper_bound) > 0)
+ {
+ cout << "Invalid interval" << endl;
+ }
+ else
+ {
+ // repeat until the required accuracy is obtained
+ while(abs(polynomial(mid(lower_bound, upper_bound))) > error)
+ {
+ cout << "\nIteration_no = " << i << " , First_no = " << lower_bound
+ << " , Second_no = " << upper_bound << " middle = "
+ << mid(lower_bound, upper_bound) ;
+ cout << " , f(middle) = " << polynomial(mid(lower_bound, upper_bound))
+ << " , f(first_no)*f(middle) = "
+ << polynomial(lower_bound)*polynomial(mid(lower_bound, upper_bound)) << endl;
+ // sign changes in the first interval => root lies in the 1st interval
+ if(polynomial(lower_bound) * polynomial(mid(lower_bound, upper_bound)) < 0)
+ {
+ upper_bound = mid(lower_bound, upper_bound);
+ }
+ else
+ {
+ lower_bound = mid(lower_bound, upper_bound);
+ }
+ i++;
+ }
+ cout << "\nIteration_no = " << i << " , First_no = " << lower_bound
+ << " , Second_no = " << upper_bound << " middle = " << mid(lower_bound, upper_bound) ;
+ cout << " , f(middle) = " << polynomial(mid(lower_bound, upper_bound))
+ << " , f(first_no)*f(middle) = "
+ << polynomial(lower_bound)*polynomial(mid(lower_bound, upper_bound)) << endl;
+ cout << "\nThe approximated root of the given polynomial within the specified interval ("
+ << a << " , " << b << ") = " ;
+ cout << mid(upper_bound, lower_bound) << endl;
+ }
+ return 0;
+}
+
+/* OUTPUT
+For the interval (a, b) where the root may lie :
+Enter the value of a :-
+2.1
+Enter the value of b :-
+4.1
+
+Iteration_no = 0 , First_no = 2.1 , Second_no = 4.1 middle = 3.1 , f(middle) = 0.21 ,
+f(first_no)*f(middle) = -0.2079
+
+Iteration_no = 1 , First_no = 2.1 , Second_no = 3.1 middle = 2.6 , f(middle) = -0.64 ,
+f(first_no)*f(middle) = 0.6336
+
+Iteration_no = 2 , First_no = 2.6 , Second_no = 3.1 middle = 2.85 , f(middle) = -0.2775 ,
+f(first_no)*f(middle) = 0.1776
+
+Iteration_no = 3 , First_no = 2.85 , Second_no = 3.1 middle = 2.975 , f(middle) = -0.0493755 ,
+f(first_no)*f(middle) = 0.0137017
+
+Iteration_no = 4 , First_no = 2.975 , Second_no = 3.1 middle = 3.0375 , f(middle) = 0.0764065 ,
+f(first_no)*f(middle) = -0.00377261
+
+Iteration_no = 5 , First_no = 2.975 , Second_no = 3.0375 middle = 3.00625 , f(middle) = 0.0125389 ,
+f(first_no)*f(middle) = -0.000619115
+
+Iteration_no = 6 , First_no = 2.975 , Second_no = 3.00625 middle = 2.99062 , f(middle) = -0.0186625 ,
+f(first_no)*f(middle) = 0.000921469
+
+Iteration_no = 7 , First_no = 2.99062 , Second_no = 3.00625 middle = 2.99844 , f(middle) = -0.00312233 ,
+f(first_no)*f(middle) = 5.82703e-005
+
+Iteration_no = 8 , First_no = 2.99844 , Second_no = 3.00625 middle = 3.00234 , f(middle) = 0.00469303 ,
+f(first_no)*f(middle) = -1.46532e-005
+
+Iteration_no = 9 , First_no = 2.99844 , Second_no = 3.00234 middle = 3.00039 , f(middle) = 0.000781059 ,
+f(first_no)*f(middle) = -2.43872e-006
+
+Iteration_no = 10 , First_no = 2.99844 , Second_no = 3.00039 middle = 2.99941 , f(middle) = -0.00117207 ,
+f(first_no)*f(middle) = 3.65958e-006
+
+Iteration_no = 11 , First_no = 2.99941 , Second_no = 3.00039 middle = 2.9999 , f(middle) = -0.000195503 ,
+f(first_no)*f(middle) = 2.29143e-007
+
+Iteration_no = 12 , First_no = 2.9999 , Second_no = 3.00039 middle = 3.00015 , f(middle) = 0.000292778 ,
+f(first_no)*f(middle) = -5.7239e-008
+
+Iteration_no = 13 , First_no = 2.9999 , Second_no = 3.00015 middle = 3.00002 , f(middle) = 4.86374e-005 ,
+f(first_no)*f(middle) = -9.50877e-009
+
+The approximated root of the given polynomial within the specified interval (2.1, 4.1) = 3.00002
+*/
\ No newline at end of file
From b4d253ff804166713336d5e162a91b7c2e6e40ac Mon Sep 17 00:00:00 2001
From: PratilipiAich <47985146+PratilipiAich@users.noreply.github.com>
Date: Thu, 19 Mar 2020 22:21:42 +0530
Subject: [PATCH 015/265] Circular Queue in JAVA (#2471)
* Added Circular_Queue.java
* Added Circular_Queue.java
Co-authored-by: pratilipi
---
Circular_Queue/Circular_Queue.java | 248 +++++++++++++++++++++++++++++
1 file changed, 248 insertions(+)
create mode 100644 Circular_Queue/Circular_Queue.java
diff --git a/Circular_Queue/Circular_Queue.java b/Circular_Queue/Circular_Queue.java
new file mode 100644
index 000000000..10c736364
--- /dev/null
+++ b/Circular_Queue/Circular_Queue.java
@@ -0,0 +1,248 @@
+/* Circular Queue works by the process of circular increment
+i.e. when we try to increment any variable and we reach the end of queue,
+we start from the beginning of queue by modulo division with the queue size.*/
+
+import java.util.Scanner;
+
+public class Circular_Queue {
+ int front, rear, size;
+ int[] arr;
+
+ public Circular_Queue(int s) {
+ size = s;
+ arr = new int[s];
+ front = rear = -1;
+ }
+
+ public static void main(String[] args) {
+ int choice, value, s;
+ Scanner in = new Scanner(System.in);
+
+ System.out.println("Enter the size of queue:");
+ s = in.nextInt();
+ Circular_Queue q = new Circular_Queue(s);
+ do {
+ System.out.println("\n1. Insert");
+ System.out.println("2. Delete");
+ System.out.println("3. Display");
+ System.out.println("4. Exit");
+ System.out.println("Enter choice: ");
+ choice = in.nextInt();
+ switch (choice) {
+ case 1:
+ System.out.println("\nEnter the value: ");
+ value = in.nextInt();
+ q.enQueue(value);
+ break;
+ case 2:
+ value = q.deQueue();
+ if(value == -1) {
+ System.out.println("\nUNDERFLOW! Queue is Empty.");
+ break;
+ }
+ System.out.println("\n" + value + " Deleted from queue.");
+ break;
+ case 3:
+ q.display();
+ break;
+ case 4:
+ System.exit(0);
+ default:
+ System.out.println("Invalid choice.");
+
+ }
+ } while (choice != 4);
+
+ }
+
+ /*
+Insertion:
+1) Check whether queue is Full by (front == 0 && rear == size - 1) || (rear == (front - 1) % (size - 1)).
+2) If it is full then display Queue is full. If queue is not full then, check
+ if (front == -1) then set front = rear = 0 and insert the first element.
+3) If (rear == SIZE – 1 && front != 0) if it is true then set rear = 0 and insert element.
+4) Otherwise increment rear by 1 and insert an element.
+*/
+// Inserting the value in the queue
+ public void enQueue(int value) {
+ if ((front == 0 && rear == size - 1) ||
+ (rear == (front - 1) % (size - 1))) {
+ System.out.println("\nOVERFLOW! Queue is Full.");
+ return;
+ } else if (front == -1) /* Insert First Element */ {
+ front = rear = 0;
+ arr[rear] = value;
+ } else if (rear == size - 1 && front != 0) {
+ rear = 0;
+ arr[rear] = value;
+ } else {
+ rear++;
+ arr[rear] = value;
+ }
+ }
+
+ /*
+Deletion:
+1) Check whether queue is Empty with (front==-1).
+2) If it is empty then display Queue is empty.
+3) If queue is not empty then remove the element and Check if (front==rear)
+ if it is true then set front = rear= -1 else set front = (front + 1) % size and return the element.
+*/
+// Deleting from queue
+ public int deQueue() {
+ if (front == -1) {
+ return -1;
+
+ }
+ int element = arr[front];
+ arr[front] = -1;
+ if (front == rear) {
+ front = -1;
+ rear = -1;
+ }
+ else {
+ if (front == size - 1)
+ front = 0;
+ else
+ front = front + 1;
+ }
+ return element;
+ }
+
+ // Displaying the queue
+ public void display() {
+ if (front == -1) {
+ System.out.println("UNDERFLOW! Queue is Empty.");
+ return;
+ }
+ System.out.println("\nElements in Circular Queue are: ");
+ if (rear >= front) {
+ for (int i = front; i <= rear; i++)
+ System.out.print(arr[i] + "\t");
+ } else {
+ for (int i = front; i < size; i++)
+ System.out.println(arr[i] + "\t");
+
+ for (int i = 0; i <= rear; i++)
+ System.out.println(arr[i] + "\t");
+ }
+ }
+
+}
+/*
+Enter the size of queue:
+4
+
+1. Insert
+2. Delete
+3. Display
+4. Exit
+Enter choice:
+1
+
+Enter the value:
+10
+
+1. Insert
+2. Delete
+3. Display
+4. Exit
+Enter choice:
+1
+
+Enter the value:
+20
+
+1. Insert
+2. Delete
+3. Display
+4. Exit
+Enter choice:
+1
+
+Enter the value:
+30
+
+1. Insert
+2. Delete
+3. Display
+4. Exit
+Enter choice:
+1
+
+Enter the value:
+40
+
+1. Insert
+2. Delete
+3. Display
+4. Exit
+Enter choice:
+1
+
+Enter the value:
+50
+
+OVERFLOW! Queue is Full.
+
+1. Insert
+2. Delete
+3. Display
+4. Exit
+Enter choice:
+3
+
+Elements in Circular Queue are:
+10 20 30 40
+1. Insert
+2. Delete
+3. Display
+4. Exit
+Enter choice:
+2
+
+10 Deleted from queue.
+
+1. Insert
+2. Delete
+3. Display
+4. Exit
+Enter choice:
+2
+
+20 Deleted from queue.
+
+1. Insert
+2. Delete
+3. Display
+4. Exit
+Enter choice:
+2
+
+30 Deleted from queue.
+
+1. Insert
+2. Delete
+3. Display
+4. Exit
+Enter choice:
+2
+
+40 Deleted from queue.
+
+1. Insert
+2. Delete
+3. Display
+4. Exit
+Enter choice:
+2
+
+UNDERFLOW! Queue is Empty.
+
+1. Insert
+2. Delete
+3. Display
+4. Exit
+Enter choice:
+4
+ */
From baa09a61ea51195f9dbc9bbbfa7db926c7e7a7ff Mon Sep 17 00:00:00 2001
From: Ravi Kanth Gojur
Date: Thu, 19 Mar 2020 22:45:42 +0530
Subject: [PATCH 016/265] Fibonacci_Number using DP approach added (#2060)
* Fibonacci_Number using DP approach added
indentation corrected
* Indentation Corrected
* Fibonacci number using DP Approach added
---
.../Fibonacci_Number_Using_DP_Approach.c | 53 ++++++++++++++++
.../Fibonacci_Number_Using_DP_Approach.cpp | 51 ++++++++++++++++
.../Fibonacci_Number_Using_DP_Approach.java | 60 +++++++++++++++++++
3 files changed, 164 insertions(+)
create mode 100644 Fibonacci_Number_Using_DP_Approach/Fibonacci_Number_Using_DP_Approach.c
create mode 100644 Fibonacci_Number_Using_DP_Approach/Fibonacci_Number_Using_DP_Approach.cpp
create mode 100644 Fibonacci_Number_Using_DP_Approach/Fibonacci_Number_Using_DP_Approach.java
diff --git a/Fibonacci_Number_Using_DP_Approach/Fibonacci_Number_Using_DP_Approach.c b/Fibonacci_Number_Using_DP_Approach/Fibonacci_Number_Using_DP_Approach.c
new file mode 100644
index 000000000..530cb4c1d
--- /dev/null
+++ b/Fibonacci_Number_Using_DP_Approach/Fibonacci_Number_Using_DP_Approach.c
@@ -0,0 +1,53 @@
+#include
+int dp[100005] = {0};
+
+int fibDP(int n)
+{
+ if(n == 0 || n == 1)
+ {
+ return n;
+ }
+ /* This is used to print the values or series of given fibonacci number
+ if(dp[n] != 0)
+ {
+ return dp[n];
+ }*/
+
+ /* This recursion is to hold the values till cand1 = 1(from 5-4-3-2-1), cand2 = 1(5-3-1) */
+ int cand1 = fibDP(n - 1);
+ int cand2 = fibDP(n - 2);
+
+ /*
+ Later, it will go back to its previous values(2-3), cand1, cand2 values will be updated.
+ after, getting values (1,1), those values get added and updated at 5th index.
+ this will repeat in each iteration,
+ You can check(print) manually the values of cand1, cand2, n and dp[n]
+ at multiple instances to get a proper idea of structure of the program
+ dp[n] = cand1 + cand2; This statement is used to store the fibonacci series in the array
+ here, we will be returning the final values of cand1, cand2. */
+ return (cand1 + cand2);
+}
+
+int main(int argc, char const *argv[])
+{
+ int n, result;
+
+ printf("Enter a Number to find the Fibonacci using DP apporach: ");
+ scanf("%d", &n);
+
+ result = fibDP(n);
+ printf("\n Fibonacci of %d is: %d", n, result);
+
+ return 0;
+}
+
+/*
+TestCase-1:
+Sample Input: 6
+Sample Output: 8
+
+TestCase-2:
+Sample Input: 10
+Sample Output: 55
+*/
+
diff --git a/Fibonacci_Number_Using_DP_Approach/Fibonacci_Number_Using_DP_Approach.cpp b/Fibonacci_Number_Using_DP_Approach/Fibonacci_Number_Using_DP_Approach.cpp
new file mode 100644
index 000000000..c0507595f
--- /dev/null
+++ b/Fibonacci_Number_Using_DP_Approach/Fibonacci_Number_Using_DP_Approach.cpp
@@ -0,0 +1,51 @@
+#include
+using namespace std;
+int dp[100005] = {0};
+
+int fibDP(int n)
+{
+ if(n == 0 or n == 1)
+ {
+ return n;
+ }
+
+ /* This is used to print the values or series of given fibonacci number.
+ if(dp[n] != 0)
+ {
+ return dp[n];
+ }*/
+
+ /* This recursion is to hold the values till cand1 = 1(from 5-4-3-2-1), cand2 = 1(5-3-1) */
+ int cand1 = fibDP(n - 1);
+ int cand2 = fibDP(n - 2);
+
+ /*
+ Later, it will go back to its previous values(2-3), cand1, cand2 values will be updated.
+ after, getting values (1,1), those values get added and updated at 5th index.
+ this will repeat in each iteration,
+ You can check(print) manually the values of cand1, cand2, n and dp[n]
+ at multiple instances to get a proper idea of structure of the program
+ dp[n] = cand1 + cand2; This statement is used to store the fibonacci series in the array
+ here, we will be returning the final values of cand1, cand2. */
+ return (cand1 + cand2);
+}
+
+int main(int argc, char const *argv[])
+{
+ int n;
+ cout << "Enter a Number to find the Fibonacci using DP apporach: ";
+ cin >> n;
+ cout << "Fibonacci of " << n << " is: " << fibDP(n);
+ return 0;
+}
+
+/*
+TestCase-1:
+Sample Input: 6
+Sample Output: 8
+
+TestCase-2:
+Sample Input: 10
+Sample Output: 55
+*/
+
diff --git a/Fibonacci_Number_Using_DP_Approach/Fibonacci_Number_Using_DP_Approach.java b/Fibonacci_Number_Using_DP_Approach/Fibonacci_Number_Using_DP_Approach.java
new file mode 100644
index 000000000..3029aa51e
--- /dev/null
+++ b/Fibonacci_Number_Using_DP_Approach/Fibonacci_Number_Using_DP_Approach.java
@@ -0,0 +1,60 @@
+import java.util.*;
+
+class findingFib
+{
+ int dp[] = new int[100005];
+
+ int fibDP(int n)
+ {
+ if(n == 0 || n == 1)
+ {
+ return n;
+ }
+
+ /* This is used to print the values or series of given fibonacci number.
+ if(dp[n] != 0)
+ {
+ return dp[n];
+ }*/
+
+ /* This recursion is to hold the values till cand1 = 1(from 5-4-3-2-1), cand2 = 1(5-3-1) */
+ int cand1 = fibDP(n-1);
+ int cand2 = fibDP(n-2);
+
+ /* Later, it will go back to its previous values(2-3), cand1, cand2 values will be updated.
+ after, getting values (1,1), those values get added and updated at 5th index.
+ this will repeat in each iteration,
+ You can check(print) manually the values of cand1, cand2, n and dp[n]
+ at multiple instances to get a proper idea of structure of the program
+ dp[n] = cand1 + cand2; This statement is used to store the fibonacci series in the array
+ here, we will be returning the final values of cand1, cand2. */
+ return (cand1 + cand2);
+ }
+}
+
+class Mainer
+{
+ public static void main(String args[])
+ {
+ findingFib ob1 = new findingFib();
+ int n, result;
+
+ Scanner s = new Scanner(System.in);
+ System.out.print("Enter a Number to find the Fibonacci using DP apporach: ");
+ n = s.nextInt();
+
+ result = ob1.fibDP(n);
+ System.out.println("Fibonacci of " + n + " is: " + result);
+ }
+}
+
+/*
+TestCase-1:
+Sample Input: 6
+Sample Output: 8
+
+TestCase-2:
+Sample Input: 10
+Sample Output: 55
+*/
+
From c726b743a5ee99725d804e6187f28d8b35e19682 Mon Sep 17 00:00:00 2001
From: Ravi Kanth Gojur
Date: Thu, 19 Mar 2020 23:05:06 +0530
Subject: [PATCH 017/265] Length of Linked List in C, Java Added
---
Linked_List/Length_of_Linked_List.c | 71 ++++++++++++++++++++++++
Linked_List/Length_of_Linked_List.java | 74 ++++++++++++++++++++++++++
2 files changed, 145 insertions(+)
create mode 100644 Linked_List/Length_of_Linked_List.c
create mode 100644 Linked_List/Length_of_Linked_List.java
diff --git a/Linked_List/Length_of_Linked_List.c b/Linked_List/Length_of_Linked_List.c
new file mode 100644
index 000000000..ec4fb18d1
--- /dev/null
+++ b/Linked_List/Length_of_Linked_List.c
@@ -0,0 +1,71 @@
+// Length of Linked List
+#include
+#include
+
+/*
+This code is written for Char to store in LinkedList, if you want to store numericals or any other datatype,
+just replace relevent data type in place of char in class Node.
+*/
+
+struct Node
+{
+ char data;
+ struct Node* next;
+};
+
+void pushing_data_to_LL(struct Node** headPointer, char newData)
+{
+ struct Node* newNode = (struct Node*)malloc(sizeof(struct Node));
+ newNode -> data = newData;
+ newNode -> next = (*headPointer);
+ (*headPointer) = newNode;
+}
+
+int gettingLength(struct Node* head)
+{
+ int count = 0;
+ struct Node* current = head;
+ while(current != NULL)
+ {
+ count++;
+ current = current -> next;
+ }
+ return count;
+}
+
+int main()
+{
+ struct Node* head = NULL;
+ printf("Currently Length of Linkedlist is: %d", gettingLength(head));
+
+ pushing_data_to_LL(&head, 'G');
+ pushing_data_to_LL(&head, 'S');
+ pushing_data_to_LL(&head, 'S');
+ pushing_data_to_LL(&head, 'O');
+ pushing_data_to_LL(&head, 'C');
+
+ //Intermediate Checking
+ printf("\n Currently Length of Linkedlist is: %d", gettingLength(head));
+
+ pushing_data_to_LL(&head, '-');
+ printf("\n Currently Length of Linkedlist is: %d", gettingLength(head));
+
+ pushing_data_to_LL(&head, '2');
+ pushing_data_to_LL(&head, '0');
+ pushing_data_to_LL(&head, '2');
+ pushing_data_to_LL(&head, '0');
+
+ printf("\n Currently Length of Linkedlist is: %d", gettingLength(head));
+
+ return 0;
+}
+
+/*
+TestCase-1:
+Sample Input: G S S O C 2 0 2 0
+Sample Output: 9 //9 letters
+
+TestCase-2:
+Sample Input: O p e n - S o u r c e
+Sample Output: 11 //11 letters
+*/
diff --git a/Linked_List/Length_of_Linked_List.java b/Linked_List/Length_of_Linked_List.java
new file mode 100644
index 000000000..627cf9145
--- /dev/null
+++ b/Linked_List/Length_of_Linked_List.java
@@ -0,0 +1,74 @@
+import java.util.*;
+
+/*
+This code is written for Strings to store in LinkedList, if you want to store numericals or any other datatype,
+just replace relevent data type in place of string in class Node.
+*/
+
+class Node
+{
+ String data;
+ Node next;
+ Node(String info)
+ {
+ data = info;
+ next = null;
+ }
+}
+
+class LinkedListLength
+{
+ Node head;
+ public void pushing_data_to_LL(String new_data)
+ {
+ Node new_node = new Node(new_data); // Creating the node and assign the data.
+ new_node.next = head; // making the next node as head node
+ head = new_node; // making head to point to new Node
+ }
+ public int gettingLength()
+ {
+ Node temp = head;
+ int count = 0;
+ while(temp != null)
+ {
+ count++;
+ temp = temp.next;
+ }
+ return count;
+ }
+}
+
+class Mainer
+{
+ public static void main(String[] args)
+ {
+ LinkedListLength thisList = new LinkedListLength();
+
+ System.out.println("Currently the Length of the LinkedList is: " + thisList.gettingLength());
+
+ thisList.pushing_data_to_LL("G");
+ thisList.pushing_data_to_LL("S");
+ thisList.pushing_data_to_LL("S");
+ thisList.pushing_data_to_LL("O");
+ thisList.pushing_data_to_LL("C");
+
+ System.out.println("Currently the Length of the LinkedList is: " + thisList.gettingLength());
+
+ thisList.pushing_data_to_LL("2");
+ thisList.pushing_data_to_LL("0");
+ thisList.pushing_data_to_LL("2");
+ thisList.pushing_data_to_LL("0");
+
+ System.out.println("Currently the Length of the LinkedList is: " + thisList.gettingLength());
+ }
+}
+
+/*
+TestCase-1:
+Sample Input: G S S O C 2 0 2 0
+Sample Output: 9 //9 letters
+
+TestCase-2:
+Sample Input: O p e n - S o u r c e
+Sample Output: 11 //11 letters
+*/
\ No newline at end of file
From 33a784f57a173b9c7ac176f27c0b83db1d716c40 Mon Sep 17 00:00:00 2001
From: Sri Manikanta Palakollu
Date: Thu, 19 Mar 2020 23:08:20 +0530
Subject: [PATCH 018/265] Implemented the Gnome Sort Completely. (#2275)
* Implemented the Gnome Sort Completely.
* Implemented the requested Changes.
* Made the requested changes.
* Changes Done.
---
Gnome_Sort/Gnome_Sort.c | 62 ++++++++++++++++++++++++++++++++++++++
Gnome_Sort/Gnome_Sort.cpp | 62 ++++++++++++++++++++++++++++++++++++++
Gnome_Sort/Gnome_Sort.java | 61 +++++++++++++++++++++++++++++++++++++
Gnome_Sort/Gnome_Sort.py | 45 +++++++++++++++++++++++++++
4 files changed, 230 insertions(+)
create mode 100644 Gnome_Sort/Gnome_Sort.c
create mode 100644 Gnome_Sort/Gnome_Sort.cpp
create mode 100644 Gnome_Sort/Gnome_Sort.java
create mode 100644 Gnome_Sort/Gnome_Sort.py
diff --git a/Gnome_Sort/Gnome_Sort.c b/Gnome_Sort/Gnome_Sort.c
new file mode 100644
index 000000000..ee2987699
--- /dev/null
+++ b/Gnome_Sort/Gnome_Sort.c
@@ -0,0 +1,62 @@
+#include
+
+// A function which is used to sort the algorithm using gnome sort
+void gnome_sort(int arr[], int n) {
+
+ int index = 0;
+ while (index < n){
+
+ if (index == 0 || arr[index - 1] <= arr[index]){
+ index++;
+ }
+ else{
+ int temp = arr[index-1];
+ arr[index - 1] = arr[index];
+ arr[index] = temp;
+ index = index - 1;
+
+ }
+
+ }
+
+}
+
+// Main function.
+int main()
+{
+ int n;
+ printf("Enter the size of an Array: ");
+ scanf("%d", &n);
+ int arr[n];
+
+ for(int i = 0; i < n; i++){
+ scanf("%d", &arr[i]);
+ }
+
+ gnome_sort(arr, n);
+
+ for(int i = 0; i < n; i++){
+ printf("%d\n", arr[i]);
+ }
+
+ return 0;
+}
+
+/*
+ Sample Driver Code:
+ INPUT:
+ Enter the size of an Array: 5
+ 3
+ 2
+ 1
+ -5
+ 7
+
+ OUTPUT:
+ -5
+ 1
+ 2
+ 3
+ 7
+
+*/
diff --git a/Gnome_Sort/Gnome_Sort.cpp b/Gnome_Sort/Gnome_Sort.cpp
new file mode 100644
index 000000000..9912482c9
--- /dev/null
+++ b/Gnome_Sort/Gnome_Sort.cpp
@@ -0,0 +1,62 @@
+#include
+
+using namespace std;
+
+// A function that is used to sort the algorithm using gnome sort
+void gnome_sort(int arr[], int n) {
+
+ // Implementation Logic Begins here
+ int index = 0;
+
+ while (index < n) {
+ // Intially Index is set to Zero then It will be incremented to 1
+ if (index == 0)
+ index++;
+ // Checking the values between the array elements
+ if (arr[index] >= arr[index - 1])
+ index++;
+ else {
+ swap(arr[index], arr[index - 1]);
+ index--;
+ }
+ }
+}
+
+// Main function.
+int main()
+{
+
+ int n;
+ cout << "Enter the size of an Array: ";
+ cin >> n;
+ int arr[n];
+ for(int i = 0; i < n; i++){
+ cin >> arr[i];
+ }
+ gnome_sort(arr, n);
+
+ for(int i = 0; i < n; i++){
+ cout << arr[i] <= arr[index - 1])
+ index++;
+ else {
+ int temp = 0;
+ temp = arr[index];
+ arr[index] = arr[index - 1];
+ arr[index - 1] = temp;
+ index--;
+ }
+ }
+ }
+
+ // Sample Input to test above function
+ public static void main(String[] args) {
+
+ Scanner sc = new Scanner(System.in);
+ System.out.print("Enter the Size of an Array: ");
+ int n = sc.nextInt();
+ int arr[] = new int[n];
+ for(int i=0; i= arr[index - 1]:
+ index = index + 1
+ else:
+ arr[index], arr[index-1] = arr[index-1], arr[index]
+ index = index - 1
+
+ return arr
+
+# Test Code
+n = int(input("Enter the size of an Array: "))
+arr = list()
+for i in range(n):
+ val = int(input())
+ arr.append(val)
+# Function Call
+result = gnome_sort(arr,n)
+print(result)
+
+'''
+ Sample Driver Code:
+ INPUT:
+ Enter the size of an Array: 5
+ 3
+ 2
+ 1
+ -5
+ 7
+
+ OUTPUT:
+ -5
+ 1
+ 2
+ 3
+ 7
+
+'''
From b4e89f398a66955b8ae8473f47d850b30e2387ab Mon Sep 17 00:00:00 2001
From: Muskan Goyal <47412347+goyalmuskan@users.noreply.github.com>
Date: Thu, 19 Mar 2020 23:14:24 +0530
Subject: [PATCH 019/265] Merge_Sort.php added (#1820)
* Create Fibonacci_Number.php
* Delete Fibonacci_Number.php
* Create Merge_Sort.php
* Update Merge_Sort.php
* Updated
* Updated
---
Merge_Sort/Merge_Sort.php | 44 +++++++++++++++++++++++++++++++++++++++
1 file changed, 44 insertions(+)
create mode 100644 Merge_Sort/Merge_Sort.php
diff --git a/Merge_Sort/Merge_Sort.php b/Merge_Sort/Merge_Sort.php
new file mode 100644
index 000000000..5fada8473
--- /dev/null
+++ b/Merge_Sort/Merge_Sort.php
@@ -0,0 +1,44 @@
+ 0 && count($right) > 0) {
+ if($left[0] > $right[0]) {
+ $res[] = $right[0];
+ $right = array_slice($right , 1);
+ }
+ else{
+ $res[] = $left[0];
+ $left = array_slice($left, 1);
+ }
+ }
+ while (count($left) > 0) {
+ $res[] = $left[0];
+ $left = array_slice($left, 1);
+ }
+ while (count($right) > 0) {
+ $res[] = $right[0];
+ $right = array_slice($right, 1);
+ }
+ return $res;
+}
+
+$test_array = array(100, 54, 7, 2, 5, 4, 1);
+echo implode(' ', merge_sort($test_array));
+
+/*
+Output :
+1 2 4 5 7 54 100
+*/
+?>
From 0b5d39b91d60d9537c3e2a84d38c0433f4106faa Mon Sep 17 00:00:00 2001
From: "Abhushan A. Joshi" <49617450+abhu-A-J@users.noreply.github.com>
Date: Thu, 19 Mar 2020 23:36:05 +0530
Subject: [PATCH 020/265] Implementation of Karatsuba Algorithm in JS (#2420)
---
Karatsuba_Algorithm/Karatsuba_Algorithm.js | 42 ++++++++++++++++++++++
1 file changed, 42 insertions(+)
create mode 100644 Karatsuba_Algorithm/Karatsuba_Algorithm.js
diff --git a/Karatsuba_Algorithm/Karatsuba_Algorithm.js b/Karatsuba_Algorithm/Karatsuba_Algorithm.js
new file mode 100644
index 000000000..be1d99d8b
--- /dev/null
+++ b/Karatsuba_Algorithm/Karatsuba_Algorithm.js
@@ -0,0 +1,42 @@
+/*
+The Karatsuba Algorithm implements faster multiplication,
+than the traditional approach.
+*/
+
+const karatSuba = (num1, num2) => {
+
+ // for single digit number multiply directly
+ if (num1 < 10 || num2 < 10) {
+ return num1 * num2;
+ }
+
+ let num1Str = num1.toString();
+ let num2Str = num2.toString();
+ let n = Math.min(num1Str.length, num2Str.length);
+ let half = Math.round(n / 2);
+
+ // divide num1 into two halves
+ let num1_H = parseInt(num1Str.substring(0, num1Str.length - half));
+ let num1_L = parseInt(num1Str.substring(num1Str.length - half, num1Str.length));
+
+ // divide num2 into two halves
+ let num2_H = parseInt(num2Str.substring(0, num2Str.length - half));
+ let num2_L = parseInt(num2Str.substring(num2Str.length - half, num2Str.length));
+
+ // using the KaratSuba Definition
+ let s1 = karatSuba(num1_L, num2_L);
+ let s2 = karatSuba(num1_L + num1_H, num2_L + num2_H);
+ let s3 = karatSuba(num1_H, num2_H);
+ let s4 = s2 - s3 - s1;
+
+ // karatsuba formula for finding product
+ let result = s3 * Math.pow(10, 2 * half) + s4 * Math.pow(10, half) + s1;
+
+ return result;
+};
+
+// I/O and O/P Examples
+
+// The result is: 83810205
+console.log(karatSuba(12345, 6789));
+console.log(12345 * 6789);
From feb06a5a02fdf7bbf9222f3d0b27da77ec1f64cf Mon Sep 17 00:00:00 2001
From: Hari Krishnan U
Date: Thu, 19 Mar 2020 23:45:35 +0530
Subject: [PATCH 021/265] Create Shell_Sort.cs (#2457)
Update Shell_Sort.cs
Update Shell_Sort.cs
Update Shell_Sort.cs
---
Shell_Sort/Shell_Sort.cs | 66 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 66 insertions(+)
create mode 100644 Shell_Sort/Shell_Sort.cs
diff --git a/Shell_Sort/Shell_Sort.cs b/Shell_Sort/Shell_Sort.cs
new file mode 100644
index 000000000..b41a7962a
--- /dev/null
+++ b/Shell_Sort/Shell_Sort.cs
@@ -0,0 +1,66 @@
+// C# program implementation of the ShellSort algorithm
+using System;
+
+class ShellSort
+{
+ //function to implement ShellSort
+ void shellsort(int []array, int size)
+ {
+ // Beginning with a big gap, and then keep on reducing it.
+ for (int g = size/2; g >= 1; g /= 2)
+ {
+ // Performing an insertion sort
+ for (int i = g; i < size; i += 1)
+ {
+ int j, temp = array[i];
+
+ //Shift other elements until the correct position of a[i] is found
+ for (j = i; array[j - g] > temp && j >= g ; j -= g)
+ array[j] = array[j - g];
+
+ // put the element a[i] in its correct position
+ array[j] = temp;
+ }
+ }
+ }
+
+ public static void Main()
+ {
+
+ int size;
+ Console.Write("How many numbers do you want to sort : ");
+ size = Convert.ToInt32(Console.ReadLine());
+ int[] array = new int[size];
+ Console.Write("\nEnter the numbers : ");
+ for (int i = 0; i < size; i++)
+ array[i] = Convert.ToInt32(Console.ReadLine());
+ ShellSort ob = new ShellSort();
+ ob.shellsort(array, size);
+ Console.Write("\nAfter sorting : ");
+ for (int i = 0; i < size; i++)
+ Console.Write(array[i] + " ");
+ }
+}
+
+/*SAMPLE INPUT AND OUTPUT
+SAMPLE 1
+How many numbers do you want to sort : 7
+Enter the numbers :
+ 4
+ 9
+ 3
+ 9
+ 4
+ 7
+ 5
+After sorting : 3 4 4 5 7 9 9
+SAMPLE 2
+How many numbers do you want to sort : 5
+Enter the numbers :
+ 5
+ 1
+ 7
+ 3
+ 2
+After sorting : 1 2 3 5 7
+*/
From 850074720e2bc39d28cd6f51dfb20519638c71bf Mon Sep 17 00:00:00 2001
From: RedEye00 <55008117+RedEye00@users.noreply.github.com>
Date: Thu, 19 Mar 2020 23:50:42 +0530
Subject: [PATCH 022/265] Finding last digit of nth term in squares of
fibonacci number (#2285)
* Add files via upload
* Delete fib.cpp
* Create a.txt
* Delete a.txt
* Issue Resolved and file is added
* Issues Resolved please review
* Issue of comment resolved
* commited changes in issues
---
...igit_of_Square_of_Nth_Fibonacci_Number.cpp | 43 +++++++++++++++++++
1 file changed, 43 insertions(+)
create mode 100644 Last_Digit_of_Square_of_Nth_Fibonacci_Number/Last_Digit_of_Square_of_Nth_Fibonacci_Number.cpp
diff --git a/Last_Digit_of_Square_of_Nth_Fibonacci_Number/Last_Digit_of_Square_of_Nth_Fibonacci_Number.cpp b/Last_Digit_of_Square_of_Nth_Fibonacci_Number/Last_Digit_of_Square_of_Nth_Fibonacci_Number.cpp
new file mode 100644
index 000000000..e5211db4e
--- /dev/null
+++ b/Last_Digit_of_Square_of_Nth_Fibonacci_Number/Last_Digit_of_Square_of_Nth_Fibonacci_Number.cpp
@@ -0,0 +1,43 @@
+//C++ Program to find last digit of square of nth fibonacci numbers
+#include
+using namespace std;
+
+int main(){
+ int a[60], n, i, c, b[60], j;
+ a[0] = 0;
+ a[1] = 1;
+ b[0] = 0;
+ b[1] = 1;
+
+ /*Using the concept that after 60 numbers in a fibonacci
+ numbers the last digit repeats itself again and again*/
+
+ /*In this loop we store the last digits of squares of first 60 fibonacci number and
+ we will store last digits in new array and their index as position in fibonacci series*/
+
+ for(i = 2 ; i < 60 ; i++){
+ a[i] = (a[i - 1] + a[i - 2]) % 10;
+ c = a[i];
+ b[i] = (c * c) % 10;
+ }
+ cin>> n ;
+
+ //print the last digit given in that position
+
+ cout<< " \n The Last Digit of Square of this Number : " << b[ n % 60] ;
+
+ return 0;
+}
+/*
+Sample Input 1:
+2344
+
+Sample Output 1:
+The Last Digit of Square of this Number : 9
+
+Sample Input 2:
+267
+
+Sample Output 2:
+The Last Digit of Square of this Number : 4
+*/
From 564d1fd09894b96790fea9fadb8139704f9270bc Mon Sep 17 00:00:00 2001
From: Chandrika Deb
Date: Fri, 20 Mar 2020 00:27:03 +0530
Subject: [PATCH 023/265] Added minesweeper implementation in C++ (#2541)
---
Minesweeper/minesweeper.cpp | 399 ++++++++++++++++++++++++++++++++++++
1 file changed, 399 insertions(+)
create mode 100644 Minesweeper/minesweeper.cpp
diff --git a/Minesweeper/minesweeper.cpp b/Minesweeper/minesweeper.cpp
new file mode 100644
index 000000000..5f4265333
--- /dev/null
+++ b/Minesweeper/minesweeper.cpp
@@ -0,0 +1,399 @@
+#include
+using namespace std;
+
+#define max_mine 99
+#define max_side 25
+#define max_move 526 // 25*25-99
+int SIDE;
+int MINES;
+
+void clrscr()
+{
+ std::cout << "\33[2J\33[1;1H" << std::flush;
+}
+
+bool isvalid(int row, int col)
+{
+ return (row >= 0) && (row < SIDE) && (col >= 0) && (col < SIDE);
+}
+
+bool ismine(int row, int col, char board[][max_side])
+{
+ if(board[row][col] == 'B')
+ return (true);
+ else
+ return (false);
+}
+
+void move(int *x, int *y)
+{
+ printf("\nEnter your move as (row col) -> ");
+ scanf("%d %d", x, y);
+ return;
+}
+
+void board(char myboard[][max_side])
+{
+ clrscr();
+ printf("\n\n\t\t\t ");
+ for(int i = 0; i < SIDE; i++)
+ {
+ if (i > 9)
+ printf(" %d ", i / 10);
+ else
+ printf(" ");
+ }
+ printf("\n\t\t\t ");
+ for(int i = 0; i < SIDE; i++)
+ printf(" %d ", i % 10);
+ printf("\n\n");
+ for(int i = 0; i < SIDE; i++)
+ {
+ printf("\t\t\t ");
+ for(int j = 0; j < SIDE; j++)
+ {
+ printf("%c ", myboard[i][j]);
+ }
+ printf(" %2d", i);
+ printf("\n");
+ }
+ return;
+}
+
+int countadjacent(int row, int col, int mines[][2], char realboard[][max_side])
+{
+ int count = 0;
+ if(isvalid(row - 1, col) == true)
+ {
+ if(ismine(row - 1, col, realboard) == true)
+ count++;
+ }
+ if(isvalid(row + 1, col) == true)
+ {
+ if(ismine(row + 1, col, realboard) == true)
+ count++;
+ }
+ if(isvalid(row, col + 1) == true)
+ {
+ if(ismine(row, col + 1, realboard) == true)
+ count++;
+ }
+ if(isvalid(row, col - 1) == true)
+ {
+ if(ismine(row, col - 1, realboard) == true)
+ count++;
+ }
+ if(isvalid(row - 1, col - 1) == true)
+ {
+ if(ismine(row - 1, col - 1, realboard) == true)
+ count++;
+ }
+ if(isvalid(row - 1, col + 1) == true)
+ {
+ if(ismine(row - 1, col + 1, realboard) == true)
+ count++;
+ }
+ if(isvalid(row + 1, col - 1) == true)
+ {
+ if(ismine(row + 1, col - 1, realboard) == true)
+ count++;
+ }
+ if(isvalid(row + 1, col + 1) == true)
+ {
+ if(ismine(row + 1, col + 1, realboard) == true)
+ count++;
+ }
+ return (count);
+}
+
+bool playuntil(char myboard[][max_side], char realboard[][max_side], int mines[][2], int row, int col, int *moves_left)
+{
+ if(myboard[row][col] != '-')
+ return false;
+ int i, j;
+ if(realboard[row][col] == 'B')
+ {
+ myboard[row][col] = 'B';
+ for(i = 0; i < MINES; i++)
+ myboard[mines[i][0]][mines[i][1]] = 'B';
+ board(myboard);
+ printf ("\nYou lost!\n");
+ return (true);
+ }
+ else
+ {
+ int count = countadjacent(row, col, mines, realboard);
+ (*moves_left)--;
+ myboard[row][col] = count + '0';
+ if(!count)
+ {
+ if(isvalid(row - 1, col) == true)
+ {
+ if(ismine(row - 1, col, realboard) == false)
+ playuntil(myboard, realboard, mines, row - 1, col, moves_left);
+ }
+ if (isvalid (row + 1, col) == true)
+ {
+ if (ismine (row + 1, col, realboard) == false)
+ playuntil(myboard, realboard, mines, row + 1, col, moves_left);
+ }
+ if (isvalid (row, col + 1) == true)
+ {
+ if (ismine (row, col + 1, realboard) == false)
+ playuntil(myboard, realboard, mines, row, col + 1, moves_left);
+ }
+ if (isvalid (row, col - 1) == true)
+ {
+ if (ismine (row, col - 1, realboard) == false)
+ playuntil(myboard, realboard, mines, row, col - 1, moves_left);
+ }
+ if (isvalid (row - 1, col + 1) == true)
+ {
+ if (ismine (row - 1, col + 1, realboard) == false)
+ playuntil(myboard, realboard, mines, row - 1, col + 1, moves_left);
+ }
+ if (isvalid (row - 1, col - 1) == true)
+ {
+ if (ismine (row - 1, col - 1, realboard) == false)
+ playuntil(myboard, realboard, mines, row - 1, col - 1, moves_left);
+ }
+ if (isvalid (row + 1, col + 1) == true)
+ {
+ if (ismine (row + 1, col + 1, realboard) == false)
+ playuntil(myboard, realboard, mines, row + 1, col + 1, moves_left);
+ }
+ if (isvalid (row + 1, col - 1) == true)
+ {
+ if (ismine (row + 1, col - 1, realboard) == false)
+ playuntil(myboard, realboard, mines, row + 1, col - 1, moves_left);
+ }
+ }
+ return (false);
+ }
+}
+
+void placemines(int mines[][2],char realboard[][max_side])
+{
+ bool mark[max_side*max_side];
+ memset(mark, false, sizeof(mark));
+ for(int i = 0; i < MINES;)
+ {
+ int random = rand() % (SIDE * SIDE);
+ int x = random / SIDE;
+ int y = random % SIDE;
+ if(mark[random] == false) //add mine if not present at position random
+ {
+ mines[i][0] = x;
+ mines[i][1] = y;
+ realboard[mines[i][0]][mines[i][1]] = 'B';
+ mark[random] = true;
+ i++;
+ }
+ }
+}
+
+void initialise(char realboard[][max_side], char myboard[][max_side])
+{
+ srand(time(NULL)); //initalising random so that same config doesn't arise
+ int i, j;
+ for(i = 0; i < SIDE; i++)
+ for(j = 0; j < SIDE; j++)
+ {
+ myboard[i][j] = realboard[i][j] = '-';
+ }
+ return;
+}
+
+void cheatmines (char realboard[][max_side])
+{
+ printf ("The mines locations are-\n");
+ board (realboard);
+ return;
+}
+
+void replacemine(int row, int col, char board[][max_side])
+{
+ for(int i = 0; i < SIDE; i++)
+ {
+ for(int j = 0; j < SIDE; j++)
+ {
+ if(board[i][j] != 'B')
+ {
+ board[i][j] = 'B';
+ board[row][col] = '-';
+ return;
+ }
+ }
+ }
+}
+
+void play()
+{
+ bool gameover = false;
+ char realboard[max_side][max_side],myboard[max_side][max_side];
+ int moves_left = SIDE*SIDE-MINES;
+ int x,y;
+ int mines[max_mine][2]; //stores (x,y) of all mines
+ initialise(realboard, myboard);
+ placemines(mines, realboard);
+ //if you want cheat and win
+ //cheatmines(realboard);
+ int currentmoveindex = 0;
+ while(gameover == false)
+ {
+ printf ("Current Status of Board : \n");
+ board(myboard);
+ move(&x, &y);
+ //if first move is mine
+ if(currentmoveindex == 0)
+ {
+ if(ismine(x, y, realboard) == true) //first attempt is a mine
+ replacemine(x, y, realboard); //replace the mine at that location
+ }
+ currentmoveindex++;
+ gameover = playuntil(myboard, realboard, mines, x, y, &moves_left);
+ if((gameover == false) && (moves_left == 0))
+ {
+ printf ("\nYou won !\n");
+ gameover = true;
+ }
+ }
+}
+
+void chdiff()
+{
+ clrscr();
+ cout << "\nMINESWEEPER GAME";
+ cout << "\n\nCHOOSE YOUR DIFFICULTY LEVEL : ";
+ cout << "\n\n0.BEGINNER\n1.MEDIUM\n2.HARD";
+ cout << "\n\nENTER YOUR LEVEL (0-2) : ";
+ int ch;
+ cin >> ch;
+ if(ch == 0)
+ {
+ SIDE = 9;
+ MINES = 10;
+ }
+ else if(ch == 1)
+ {
+ SIDE = 16;
+ MINES = 40;
+ }
+ else if(ch == 2)
+ {
+ SIDE = 24;
+ MINES = 99;
+ }
+ else
+ exit(0);
+}
+
+int main()
+{
+ chdiff();
+ play();
+ return 0;
+}
+
+/*
+ Input:
+ MINESWEEPER GAME
+CHOOSE YOUR DIFFICULTY LEVEL :
+0.BEGINNER
+1.MEDIUM
+2.HARD
+ENTER YOUR LEVEL (0-2) :0
+Output:
+ 0 1 2 3 4 5 6 7 8
+
+ - - - - - - - - - 0
+ - - - - - - - - - 1
+ - - - - - - - - - 2
+ - - - - - - - - - 3
+ - - - - - - - - - 4
+ - - - - - - - - - 5
+ - - - - - - - - - 6
+ - - - - - - - - - 7
+ - - - - - - - - - 8
+
+EnteEnter your move as (row col) -> 4 6
+ 0 1 2 3 4 5 6 7 8
+
+ - - - - 1 0 0 0 0 0
+ - - 1 1 2 1 1 0 0 1
+ - - 1 0 1 - 1 0 0 2
+ - - 1 0 1 1 1 0 0 3
+ - - 2 1 0 0 0 1 1 4
+ - - - 2 1 1 0 1 - 5
+ - - - - - 1 0 1 - 6
+ - - - - - 1 1 2 - 7
+ - - - - - - - - - 8
+
+Enter your move as (row col) -> 7 3
+ 0 1 2 3 4 5 6 7 8
+
+ - - - - 1 0 0 0 0 0
+ - - 1 1 2 1 1 0 0 1
+ - - 1 0 1 - 1 0 0 2
+ - - 1 0 1 1 1 0 0 3
+ - - 2 1 0 0 0 1 1 4
+ - - - 2 1 1 0 1 - 5
+ - - - - - 1 0 1 - 6
+ - - - 1 - 1 1 2 - 7
+ - - - - - - - - - 8
+Enter your move as (row col) -> 8 6
+ 0 1 2 3 4 5 6 7 8
+
+ - - - - 1 0 0 0 0 0
+ - - 1 1 2 1 1 0 0 1
+ - - 1 0 1 - 1 0 0 2
+ - - 1 0 1 1 1 0 0 3
+ - - 2 1 0 0 0 1 1 4
+ - - - 2 1 1 0 1 - 5
+ - - - - - 1 0 1 - 6
+ - - - 1 - 1 1 2 - 7
+ - - - - - - 1 - - 8
+
+Enter your move as (row col) -> 6 1
+
+ 0 1 2 3 4 5 6 7 8
+
+ - - - - 1 0 0 0 0 0
+ - - 1 1 2 1 1 0 0 1
+ - - 1 0 1 - 1 0 0 2
+ - - 1 0 1 1 1 0 0 3
+ - - 2 1 0 0 0 1 1 4
+ - - - 2 1 1 0 1 - 5
+ - 1 - - - 1 0 1 - 6
+ - - - 1 - 1 1 2 - 7
+ - - - - - - 1 - - 8
+ Enter your move as (row col) -> 8 3
+ 0 1 2 3 4 5 6 7 8
+
+ - - - - 1 0 0 0 0 0
+ - - 1 1 2 1 1 0 0 1
+ - - 1 0 1 - 1 0 0 2
+ - - 1 0 1 1 1 0 0 3
+ 2 3 2 1 0 0 0 1 1 4
+ 0 1 - 2 1 1 0 1 - 5
+ 0 1 1 2 - 1 0 1 - 6
+ 0 0 0 1 1 1 1 2 - 7
+ 0 0 0 0 0 0 1 - - 8
+
+
+ Enter your move as (row col) -> 8 8
+
+ 0 1 2 3 4 5 6 7 8
+
+ - - - B 1 0 0 0 0 0
+ - - 1 1 2 1 1 0 0 1
+ B - 1 0 1 B 1 0 0 2
+ B B 1 0 1 1 1 0 0 3
+ 2 3 2 1 0 0 0 1 1 4
+ 0 1 B 2 1 1 0 1 B 5
+ 0 1 1 2 B 1 0 1 - 6
+ 0 0 0 1 1 1 1 2 - 7
+ 0 0 0 0 0 0 1 B B 8
+
+You lost!
+*/
From fa99a7809527b0900014dcefdfcdd1d48cc7ba05 Mon Sep 17 00:00:00 2001
From: Ritish Singh <54978105+ritish099@users.noreply.github.com>
Date: Fri, 20 Mar 2020 01:18:34 +0530
Subject: [PATCH 024/265] LCM of N elements of an array
---
.../Largest_Common_Multiple_1-DArray.c | 47 ++++++++++++++++
.../Largest_Common_Multiple_1-DArray.cpp | 53 ++++++++++++++++++
.../Largest_Common_Multiple_1-DArray.java | 54 +++++++++++++++++++
3 files changed, 154 insertions(+)
create mode 100644 Largest_Common_Multiple/Largest_Common_Multiple_1-DArray.c
create mode 100644 Largest_Common_Multiple/Largest_Common_Multiple_1-DArray.cpp
create mode 100644 Largest_Common_Multiple/Largest_Common_Multiple_1-DArray.java
diff --git a/Largest_Common_Multiple/Largest_Common_Multiple_1-DArray.c b/Largest_Common_Multiple/Largest_Common_Multiple_1-DArray.c
new file mode 100644
index 000000000..e25fcfbc9
--- /dev/null
+++ b/Largest_Common_Multiple/Largest_Common_Multiple_1-DArray.c
@@ -0,0 +1,47 @@
+// C program to find Largest_common_multiple of n elements
+#include
+#include
+
+// GCD of 'a' and 'b'
+int gcd(int a, int b)
+{
+ if (b == 0)
+ return a;
+ return gcd(b, a % b);
+}
+
+// Returns LCM of array elements
+long long int findlcm(int arr[], int n)
+{
+ // Initialize result
+ long long int ans = arr[0];
+
+ // ans contains LCM of arr[0], ..arr[i]
+ // after i'th iteration,
+ int i;
+ for (i = 1; i < n; i++)
+ ans = (((arr[i] * ans)) / (gcd(arr[i], ans)));
+
+ return ans;
+}
+
+// Driver Code
+int main()
+{
+ int n, i;
+ printf("Enter the no of elements of the array\n");
+ scanf("%d", & n);
+ int arr[n];
+ printf("Enter the elements of the array\n");
+ for (i = 0; i < n; i++) {
+ scanf("%d", & arr[i]);
+ }
+ printf("LCM : %lld", findlcm(arr, n));
+ return 0;
+}
+
+/*Enter the no of elements of the array
+5
+Enter the elements of the array
+4 6 12 24 30
+LCM : 120*/
diff --git a/Largest_Common_Multiple/Largest_Common_Multiple_1-DArray.cpp b/Largest_Common_Multiple/Largest_Common_Multiple_1-DArray.cpp
new file mode 100644
index 000000000..f6a75e43b
--- /dev/null
+++ b/Largest_Common_Multiple/Largest_Common_Multiple_1-DArray.cpp
@@ -0,0 +1,53 @@
+/*This code is to find the Largest__common_multiple of an given array of elements*/
+
+#include
+
+using namespace std;
+
+int getLCM(int a, int b)
+{
+ int m;
+ m = (a > b) ? a : b;
+ while (true) {
+ if (m % a == 0 && m % b == 0)
+ // returns the value to getLCMArray function
+ return m;
+ m++;
+ }
+}
+
+int getLCMArray(int arr[], int n)
+{
+ int lcm = getLCM(arr[0], arr[1]);
+ for (int i = 2; i < n; i++)
+ {
+ // calls function getLCM to compute the LCM of two numbers
+ lcm = getLCM(lcm, arr[i]);
+ }
+ // returns LCM to main.
+ return lcm;
+}
+
+int main()
+{
+ int n, i;
+ cout << "Enter the no. of elements of array\n";
+ cin >> n;
+ int a[n];
+ cout << "Enter the elements of array\n";
+ for (i = 0; i < n; i++)
+ {
+ cin >> a[i];
+ }
+ cout << "LCM of array elements: " << getLCMArray(a, n);
+}
+
+/*Enter the no. of elements of array
+5
+Enter the elements of array
+4
+6
+12
+24
+30
+LCM of array elements: 120*/
diff --git a/Largest_Common_Multiple/Largest_Common_Multiple_1-DArray.java b/Largest_Common_Multiple/Largest_Common_Multiple_1-DArray.java
new file mode 100644
index 000000000..cfc3cc5a4
--- /dev/null
+++ b/Largest_Common_Multiple/Largest_Common_Multiple_1-DArray.java
@@ -0,0 +1,54 @@
+// JAVA code to find Largest_common_multiple of n elements of the array
+
+import java.util.Scanner;
+import java.util.Arrays;
+
+class LCM
+{
+ public static void main(String args[])
+ {
+ int n;
+ Scanner s = new Scanner(System.in);
+ System.out.println("Enter no. of elements in array:");
+ n = s.nextInt();
+ int a[] = new int[n];
+ System.out.println("Enter all the elements:");
+ for (int i = 0; i < n; i++)
+ {
+ // Taking input from the user
+ a[i] = s.nextInt();
+ }
+ int lcm = 1;
+ for (int each: a)
+ {
+ lcm = calculateLcm(lcm, each);
+ }
+ System.out.println("LCM for " + Arrays.toString(a) + " is : " + lcm);
+ }
+
+ // Calculating LCM by using GCD
+ private static int calculateLcm(int lcm, int each)
+ {
+ return lcm * each / gcd(lcm, each);
+ }
+
+ // Calculating GCD
+ private static int gcd(int val1, int val2)
+ {
+ if (val1 == 0 || val2 == 0)
+ return 0;
+
+ if (val1 == val2)
+ return val1;
+
+ if (val1 > val2)
+ return gcd(val1 - val2, val2);
+ return gcd(val1, val2 - val1);
+ }
+}
+
+/*Enter no. of elements in array:
+6
+Enter all the elements:
+1 2 3 4 5 6
+LCM for [1, 2, 3, 4, 5, 6] is : 60*/
From b13b244b5a39117af5ed8ef6d55107b1dfe3dda4 Mon Sep 17 00:00:00 2001
From: jedi-starlord <46528937+jedi-starlord@users.noreply.github.com>
Date: Fri, 20 Mar 2020 17:18:45 +0530
Subject: [PATCH 025/265] Added Longest Increasing Subsequence code in Go
(#2493)
* Longest Increasing Subsequence code in Go
* Longest Increasing Subsequence code in Go
* Updated problem description
* No more than 80 chars per line
---
Longest_Increasing_Subsequence/LIS.go | 67 +++++++++++++++++++++++++++
1 file changed, 67 insertions(+)
create mode 100644 Longest_Increasing_Subsequence/LIS.go
diff --git a/Longest_Increasing_Subsequence/LIS.go b/Longest_Increasing_Subsequence/LIS.go
new file mode 100644
index 000000000..ee84d0246
--- /dev/null
+++ b/Longest_Increasing_Subsequence/LIS.go
@@ -0,0 +1,67 @@
+/* Problem Statement :
+To find the length of the Longest Increasing
+Subsequence of a given sequence, that is all the
+elements of the subsequence are in increasing sorted order.
+*/
+package main
+
+import "fmt"
+
+func Max(lis []int) (max int) {
+ max = lis[0]
+ for i := 1; i < len(lis); i++ {
+ if lis[i] > max {
+ max = lis[i]
+ }
+ }
+ return
+}
+
+func LIS(arr []int) {
+ length := len(arr)
+
+ if length == 0 {
+ return
+ }
+
+ // Slice to store the length of the LIS til some index
+ lis_arr := make([]int, length)
+ lis_arr[0] = 1
+
+ for i := 1; i < length; i++ {
+ lis_arr[i] = 1
+
+ // Computing LIS value in DP Bottom-up
+ for j := 0; j < i; j++ {
+ if ( arr[i] > arr[j] && lis_arr[i] < lis_arr[j] + 1) {
+ lis_arr[i] = lis_arr[j] + 1
+ }
+ }
+ }
+
+ fmt.Printf("Length of the Longest Increasing Subsequence : %d\n", Max(lis_arr))
+}
+
+func main() {
+ var n int
+ fmt.Println("Enter the size of the array : ")
+ fmt.Scan(&n)
+ fmt.Println("Enter the array elements : ")
+ arr := make([]int, n)
+
+ for i := 0; i < n; i++ {
+ fmt.Scan(&arr[i])
+ }
+
+ LIS(arr)
+}
+
+/* Sample Input :
+Enter the size of the array :
+8
+Enter the array elements :
+15 26 13 38 26 52 43 62
+
+Sample Output :
+Length of the Longest Increasing Subsequence : 5
+*/
From 6d249f8d93ed85df4d2a01f845d938fd7196a71b Mon Sep 17 00:00:00 2001
From: Debojyoti Chakraborty <50295688+darkdebo@users.noreply.github.com>
Date: Fri, 20 Mar 2020 17:26:01 +0530
Subject: [PATCH 026/265] added ruby implementation of Armstrong number (#2501)
* this is a ruby implementation of the armstrong number.
On branch master
Changes to be committed:
new file: Armstrong_Number/Armstrong_Number.rb
* Update Armstrong_Number.rb
ruby implementation of armstrong number.
* On branch master
Your branch is up to date with 'origin/master'.
Changes to be committed:
modified: Armstrong_Number.rb
checked with 153,370
* Changes to be committed:
modified: Armstrong_Number.rb
* Added 4 space indent
Done with indentation across the file.
* Taking input dynamically
* Changes to be committed:
new file: Bead_Sort.rb
* Changes to be committed:
new file: Bead_Sort.rb
* Revert " Changes to be committed:"
* Delete Bead_Sort.rb
* Delete Armstrong_Number.rb
* Create Armstrong_Number.rb
* added Armstrong_Number.rb
* Changes to be committed:
modified: Armstrong_Number/Armstrong_Number.rb
* modified: Armstrong_Number/Armstrong_Number.rb
---
Armstrong_Number/Armstrong_Number.rb | 44 ++++++++++++++++++++++++++++
1 file changed, 44 insertions(+)
create mode 100644 Armstrong_Number/Armstrong_Number.rb
diff --git a/Armstrong_Number/Armstrong_Number.rb b/Armstrong_Number/Armstrong_Number.rb
new file mode 100644
index 000000000..fb0e193e6
--- /dev/null
+++ b/Armstrong_Number/Armstrong_Number.rb
@@ -0,0 +1,44 @@
+# A positive integer of n digits is called an Armstrong number of order n (order is number of digits) if
+# abcd... = pow(a,n) + pow(b,n) + pow(c,n) + pow(d,n) + ....
+
+# To calculate the order of the number
+def order(num)
+ # variable to store of the number
+ count = 0
+ while (num != 0)
+ count = count + 1
+ num = num / 10
+ end
+ return count
+end
+
+# Function to check whether the given number is
+# Armstrong number or not
+def Armstrong(num)
+ count = order(num)
+ temp = num
+ sum = 0
+ boolean = false
+ while (temp != 0)
+ d = temp % 10
+ sum = sum + d ** count
+ temp = temp / 10
+ end
+ return num == sum
+end
+
+# Driver Program
+num = gets.chomp.to_i
+print(Armstrong(num))
+
+#True
+
+#num = 134
+#print(Armstrong(num))
+
+#False
+
+#num = 370
+#print(Armstrong(num))
+
+#True
From 81efff3eb365f1b9222928e9b070c4df2bfa36f0 Mon Sep 17 00:00:00 2001
From: HariniJeyaraman <58400069+HariniJeyaraman@users.noreply.github.com>
Date: Sat, 21 Mar 2020 02:02:31 +0530
Subject: [PATCH 027/265] Postfix Evaluation in C
---
Postfix_Evaluation/Postfix _Evaluation.c | 86 ++++++++++++++++++++++++
1 file changed, 86 insertions(+)
create mode 100644 Postfix_Evaluation/Postfix _Evaluation.c
diff --git a/Postfix_Evaluation/Postfix _Evaluation.c b/Postfix_Evaluation/Postfix _Evaluation.c
new file mode 100644
index 000000000..c64c510b9
--- /dev/null
+++ b/Postfix_Evaluation/Postfix _Evaluation.c
@@ -0,0 +1,86 @@
+//Postfix Evaluation
+#include
+#include
+#include
+
+struct stack
+{
+ char A[100];
+ int Top;
+};
+
+void push(struct stack *ps, char x)
+{
+ if(ps -> Top == 99)
+ printf("\nStack is Full\n");
+ else
+ {
+ ps -> Top = ps -> Top + 1;
+ ps -> A[ps -> Top] = x;
+ }
+}
+
+int evaluate(int op1, int op2, char c)
+{
+ if(c == '+')
+ return op1 + op2;
+ else if(c == '-')
+ return op1 - op2;
+ else if(c == '*')
+ return op1 * op2;
+ else if(c == '/')
+ return op1 / op2;
+}
+
+void print(struct stack s)
+{
+ int i;
+ for(i = 0 ; i <= s.Top ; i++)
+ printf("%d\t", s.A[i]);
+}
+
+int pop(struct stack *ps)
+{
+ int x;
+ if(ps -> Top == -1)
+ printf("Stack is empty!Element cant be deleted\n");
+ else
+ {
+ x = ps -> A[ps -> Top];
+ ps -> Top = ps -> Top - 1;
+ return x;
+ }
+}
+
+int main()
+{
+ int op1, op2, x, i;
+ char optr;
+ struct stack s;
+ s.Top = -1;
+ printf("Enter the postfix exp to be evaluated \n");
+ gets(s.A);
+ for(i = 0; i < strlen(s.A); i++)
+ {
+ if(isdigit(s.A[i]))
+ push(&s, s.A[i] - '0');
+ else if(s.A[i] == '+' || s.A[i] == '-' || s.A[i] == '*' || s.A[i] == '/')
+ {
+ op1 = pop(&s);
+ op2 = pop(&s);
+ optr = s.A[i];
+ x = evaluate(op2, op1, optr);
+ push(&s, x);
+ }
+ }
+
+ printf("The result is : ");
+ print(s);
+ printf("\n");
+}
+
+/*Input - Output Sample
+Enter the postfix exp to be evaluated
+2 3 1 * + 9 -
+The result is : -4
+*/
From a771bf161703c49672add6563562eb2ef0801879 Mon Sep 17 00:00:00 2001
From: Md Akdas Ahmad <43089126+MdAkdas@users.noreply.github.com>
Date: Sat, 21 Mar 2020 13:04:06 +0530
Subject: [PATCH 028/265] Max_circular_sum_added (#2354)
---
.../max_circular_subArray_sum.c | 77 +++++++++++++++++++
.../max_circular_subarray_sum.cpp | 70 +++++++++++++++++
2 files changed, 147 insertions(+)
create mode 100644 Max_Circular_SubArray_Sum/max_circular_subArray_sum.c
create mode 100644 Max_Circular_SubArray_Sum/max_circular_subarray_sum.cpp
diff --git a/Max_Circular_SubArray_Sum/max_circular_subArray_sum.c b/Max_Circular_SubArray_Sum/max_circular_subArray_sum.c
new file mode 100644
index 000000000..fde1120d3
--- /dev/null
+++ b/Max_Circular_SubArray_Sum/max_circular_subArray_sum.c
@@ -0,0 +1,77 @@
+/*
+Question- Given n numbers (both +ve and -ve), arranged in a circle, find the maximum sum of consecutive number.
+Solution- There are two cases for this problem
+Case-1 The elements that contribute to the maximum sum are arranged such that no wrapping is there.Kadane will simply work.
+Case-2 The elements which contribute to the maximum sum are arranged such that wrapping is there.
+*/
+
+#include
+
+//Returns maximum of two numbers.
+int max(int num1, int num2)
+{
+ return (num1 > num2 ) ? num1 : num2;
+}
+
+/*Function to find contiguous sub-array with the largest sum
+in given set of integers*/
+int kadaneAlgo(int a[], int n)
+{
+ int max_so_far = 0, max_ending_here = 0;
+
+ for(int i = 0; i < n ; i++)
+ {
+ max_ending_here += a[i];
+
+ if(max_ending_here < 0)
+ {
+ max_ending_here = 0;
+ }
+
+ max_so_far = max(max_ending_here, max_so_far);
+ }
+
+ return max_so_far;
+}
+
+int circular_subarray_sum(int a[], int n)
+{
+ //answer for case 1
+ int kadane_max = kadaneAlgo(a, n);
+
+ //find total sum and negate all elements of the array
+ int total_sum = 0;
+ for(int i = 0; i < n ; i++)
+ {
+ total_sum + = a[i];
+ a[i] = -a[i];
+
+ }
+
+/*find out the sum of non contributing elements and subtract this sum from the
+total sum.*/
+total_sum = total_sum + kadaneAlgo(a, n);
+return max(kadane_max, total_sum);
+}
+
+int main()
+{
+ int n;
+ scanf("%d", &n);
+ int a[n];
+
+ for(int i = 0; i < n ; i++)
+ {
+ scanf("%d", &a[i]);
+ }
+ printf("The sum of subarray with the largest sum is: %d", circular_subarray_sum(a, n));
+ return 0;
+}
+
+/*
+Input-
+9
+2 1 -8 4 -5 1 -7 4 -1
+Output-
+The sum of subarray with the largest sum is 6
+*/
\ No newline at end of file
diff --git a/Max_Circular_SubArray_Sum/max_circular_subarray_sum.cpp b/Max_Circular_SubArray_Sum/max_circular_subarray_sum.cpp
new file mode 100644
index 000000000..3e82c555b
--- /dev/null
+++ b/Max_Circular_SubArray_Sum/max_circular_subarray_sum.cpp
@@ -0,0 +1,70 @@
+/*
+Question- Given n numbers (both +ve and -ve), arranged in a circle, find the maximum sum of consecutive number.
+Solution- There are two cases for this problem.
+Case-1 The elements that contribute to the maximum sum are arranged such that no wrapping is there.Kadane will simply work.
+Case-2 The elements which contribute to the maximum sum are arranged such that wrapping is there.
+*/
+
+#include
+using namespace std;
+
+/* Function to find contiguous sub-array with the largest sum
+in given set of integers*/
+int kadaneAlgo(int a[], int n)
+{
+ int max_so_far=0, max_ending_here = 0;
+
+ for(int i = 0; i < n; i++)
+ {
+ max_ending_here += a[i];
+ if(max_ending_here < 0)
+ {
+ max_ending_here = 0;
+ }
+
+ max_so_far = max(max_ending_here, max_so_far);
+ }
+ return max_so_far;
+}
+
+int circular_subarray_sum(int a[], int n)
+{
+ //answer for case 1.
+ int kadane_max = kadaneAlgo(a, n);
+
+ //Find total sum and negate all elements of the array.
+ int total_sum = 0;
+ for(int i = 0; i < n; i++)
+ {
+ total_sum += a[i];
+ a[i] = -a[i];
+
+ }
+ /*Ans for test case 2.
+ Find out the sum of non contributing elements and subtract this sum from the Total sum.*/
+ total_sum = total_sum + kadaneAlgo(a, n);
+ return max(kadane_max, total_sum);
+}
+
+int main()
+{
+ int n;
+ cin >> n;
+ int a[n];
+
+ for(int i = 0; i < n; i++)
+ {
+ cin >> a[i];
+ }
+
+ cout << "The sum of subarray with the largest sum is: " << circular_subarray_sum(a, n) << endl;
+ return 0;
+}
+
+/*
+Input-
+9
+2 1 -8 4 -5 1 -7 4 -1
+Output-
+The sum of subarray with the largest sum is 6
+*/
\ No newline at end of file
From 3ec54dbf97e4c123a1a2cee6939d2c94dbdce545 Mon Sep 17 00:00:00 2001
From: Soham Pal <49874099+p-soham11@users.noreply.github.com>
Date: Sun, 22 Mar 2020 03:04:16 +0530
Subject: [PATCH 029/265] Ternary Search in C# (#2176) (#2494)
---
Ternary_Search/Ternary_Search.cs | 103 +++++++++++++++++++++++++++++++
1 file changed, 103 insertions(+)
create mode 100644 Ternary_Search/Ternary_Search.cs
diff --git a/Ternary_Search/Ternary_Search.cs b/Ternary_Search/Ternary_Search.cs
new file mode 100644
index 000000000..5d4212197
--- /dev/null
+++ b/Ternary_Search/Ternary_Search.cs
@@ -0,0 +1,103 @@
+using System;
+
+public class ternarysrc {
+
+ // Function to perform Ternary Search
+ static int ternarySearch(int l, int r, int key, int[] ar)
+ {
+ while (r >= l)
+ {
+
+ // Finding the mid1 and mid2
+ int mid1 = l + (r - l) / 3;
+ int mid2 = r - (r - l) / 3;
+
+ // To check if key is present at any mid
+ if (ar[mid1] == key)
+ {
+ return mid1;
+ }
+ if (ar[mid2] == key)
+ {
+ return mid2;
+ }
+
+ // Checking region where KEY might be present
+ if (key < ar[mid1])
+ {
+ r = mid1 - 1;
+ }
+ else if (key > ar[mid2])
+ {
+ l = mid2 + 1;
+ }
+ else
+ {
+ l = mid1 + 1;
+ r = mid2 - 1;
+ }
+ }
+
+ // If the KEY is not found
+ return -1;
+ }
+
+ // Main Function to Execute
+ public static void Main(String[] args)
+ {
+ int l, r, p, i, key = 0, len = 0;
+
+ // Taking the input of Array Length from user
+ Console.WriteLine("Enter Length of Array : ");
+ len = Convert.ToInt32(Console.ReadLine());
+
+ int[] ar = new int[len];
+
+ Console.WriteLine("Enter Array Elements in Ascending Order : ");
+
+ for(i = 0; i < len; i++ ) // Array input
+ {
+ ar[i] = Convert.ToInt32(Console.ReadLine());
+ }
+
+ // Starting index
+ l = 0;
+
+ // Ending Index
+ r = len - 1;
+
+ Console.WriteLine("\nEnter the Number to be Searched : ");
+ // KEY to be searched in the array
+ key = Convert.ToInt32(Console.ReadLine());
+
+ // Searching the KEY using ternarySearch function
+ p = ternarySearch(l, r, key, ar);
+
+
+ // Checking if the KEY is present or not
+ if(p == -1)
+ Console.WriteLine("\nNumber Not Found");
+ else
+ Console.WriteLine("\n The Index of " + key + " is " + p);
+ Console.ReadKey();
+
+
+ }
+}
+
+// Sample Input/Output:
+/*
+ Enter Length of Array : 5
+ Enter Array Elements in Ascending Order :
+ 10
+ 20
+ 30
+ 40
+ 50
+
+ Enter the Number to be Searched :
+ 50
+
+ The Index of 50 is 4
+
+*/
From 03077e5ac8ce372ecf618f64a3b10a90ac743823 Mon Sep 17 00:00:00 2001
From: Simran Koul
Date: Sun, 22 Mar 2020 15:51:24 +0530
Subject: [PATCH 030/265] Create arrayList.java (#2230)
Update arrayList.java
Modifications after Review
Update arrayList.java
Made changes as suggested
---
Collections/arrayList.java | 228 +++++++++++++++++++++++++++++++++++++
1 file changed, 228 insertions(+)
create mode 100644 Collections/arrayList.java
diff --git a/Collections/arrayList.java b/Collections/arrayList.java
new file mode 100644
index 000000000..868a686a4
--- /dev/null
+++ b/Collections/arrayList.java
@@ -0,0 +1,228 @@
+import java.util.*;
+public class arrayList {
+ public static void main(String[] args) {
+
+ // Creating a Scanner Object
+ Scanner scan = new Scanner(System.in);
+
+ // Creating the ArrayList
+ List li = new ArrayList();
+
+ char choice='y';
+ int value, index;
+ System.out.println("Enter 1 to add Objects to the list");
+ System.out.println("Enter 2 to add Object at a particular index to a list");
+ System.out.println("Enter 3 to check size of the list");
+ System.out.println("Enter 4 to remove an element from particular index");
+ System.out.println("Enter 5 to get an element at a particular index");
+ System.out.println("Enter 6 to replace an element at a particular index");
+ System.out.println("Enter 7 to find the index of an element");
+ System.out.println("Enter 8 to search for the last occurence index of element in the list");
+ System.out.println("Enter 9 to check whether an element exists in the list");
+ System.out.println("Enter 10 to clear the list");
+ System.out.println("Enter 11 to check whether the list is empty or not");
+ System.out.println("Enter 12 to create a sublist from the list");
+ System.out.println("Enter 13 to print the list");
+ while(choice=='y')
+ {
+ System.out.println("Enter your choice");
+ int input = scan.nextInt();
+ switch(input)
+ {
+ case 1: System.out.println("Enter value to be added");
+ value=scan.nextInt();
+ li.add(value);
+ break;
+ case 2: System.out.println("Enter the index and value of element to be added");
+ index=scan.nextInt();
+ value=scan.nextInt();
+ li.add(index,value);
+ break;
+ case 3: System.out.println("Size of list: "+li.size());
+ break;
+ case 4: System.out.println("Enter index of element to be removed");
+ index=scan.nextInt();
+ li.remove(index);
+ System.out.println("Element removed successfully!");
+ System.out.println("After Deletion: "+li);
+ break;
+ case 5: System.out.println("Enter index of element");
+ index=scan.nextInt();
+ System.out.println("Element is: "+li.get(index));
+ break;
+ case 6: System.out.println("Enter index and value of element to be replaced");
+ index=scan.nextInt();
+ value=scan.nextInt();
+ li.set(index,value);
+ System.out.println("After replacing: "+li);
+ break;
+ case 7: System.out.println("Enter value of element whose index to be found");
+ value=scan.nextInt();
+ System.out.println("Value is: "+li.indexOf(value));
+
+ break;
+ case 8: System.out.println("Enter the value of element whose last occurence index is to be found");
+ value=scan.nextInt();
+ System.out.println("Value is:"+li.lastIndexOf(value));
+ break;
+ case 9: // Check if an element exists in the Array List
+ System.out.println("Enter value of element");
+ value=scan.nextInt();
+ boolean find = li.contains(value);
+ if(find) {
+ System.out.println("Element is in the list");
+ }
+ else
+ {
+ System.out.println("Element is not in the list");
+ }
+ break;
+ case 10: // To clear all elements in array
+ li.clear();
+ break;
+ case 11: // To check whether the list is empty or not.
+ System.out.println("Is the list empty? "+li.isEmpty());
+ break;
+ case 12: // To print sublist
+ int start,end;
+ System.out.println("Enter starting and ending index");
+ start=scan.nextInt();
+ end=scan.nextInt();
+ List sublist = new ArrayList();
+ sublist = li.subList(start,end);
+ System.out.println(sublist);
+ break;
+ case 13: // Creating an Iterator to traverse the arraylist.
+ Iterator itr = li.iterator();
+ while(itr.hasNext())
+ {
+ System.out.println(itr.next());
+ }
+ break;
+ default: System.out.println("Invalid option entered");
+ break;
+
+ }
+ System.out.println("Do you want to continue? Enter 'y' for more inputs or 'n' to stop");
+ choice=scan.next().charAt(0);
+ }
+ }
+}
+
+/*
+Sample Input
+Enter 1 to add Objects to the list
+Enter 2 to add Object at a particular index to a list
+Enter 3 to check size of the list
+Enter 4 to remove an element from particular index
+Enter 5 to get an element at a particular index
+Enter 6 to replace an element at a particular index
+Enter 7 to find the index of an element
+Enter 8 to search for the last occurence index of element in the list
+Enter 9 to check whether an element exists in the list
+Enter 10 to clear the list
+Enter 11 to check whether the list is empty or not
+Enter 12 to create a sublist from the list
+Enter 13 to print the list
+Enter your choice
+1
+Enter value to be added
+100
+Do you want to continue? Enter 'y' for more inputs or 'n' to stop
+y
+Enter your choice
+1
+Enter value to be added
+200
+Do you want to continue? Enter 'y' for more inputs or 'n' to stop
+y
+Enter your choice
+1
+Enter value to be added
+300
+Do you want to continue? Enter 'y' for more inputs or 'n' to stop
+y
+Enter your choice
+2
+Enter the index and value of element to be added
+2
+1000
+Do you want to continue? Enter 'y' for more inputs or 'n' to stop
+y
+Enter your choice
+3
+Size of list: 4
+Do you want to continue? Enter 'y' for more inputs or 'n' to stop
+y
+Enter your choice
+4
+Enter index of element to be removed
+2
+Element removed successfully!
+After Deletion: [100, 200, 300]
+Do you want to continue? Enter 'y' for more inputs or 'n' to stop
+y
+Enter your choice
+5
+Enter index of element
+2
+Element is: 300
+Do you want to continue? Enter 'y' for more inputs or 'n' to stop
+y
+Enter your choice
+6
+Enter index and value of element to be replaced
+1
+200
+After replacing: [100, 200, 300]
+Do you want to continue? Enter 'y' for more inputs or 'n' to stop
+y
+Enter your choice
+7
+Enter value of element whose index to be found
+100
+Value is: 0
+Do you want to continue? Enter 'y' for more inputs or 'n' to stop
+y
+Enter your choice
+8
+Enter the value of element whose last occurence index is to be found
+200
+Value is:1
+Do you want to continue? Enter 'y' for more inputs or 'n' to stop
+y
+Enter your choice
+9
+Enter value of element
+100
+Element is in the list
+Do you want to continue? Enter 'y' for more inputs or 'n' to stop
+y
+Enter your choice
+11
+Is the list empty? false
+Do you want to continue? Enter 'y' for more inputs or 'n' to stop
+y
+Enter your choice
+12
+Enter starting and ending index
+1
+2
+[200]
+Do you want to continue? Enter 'y' for more inputs or 'n' to stop
+y
+Enter your choice
+13
+100
+200
+300
+Do you want to continue? Enter 'y' for more inputs or 'n' to stop
+y
+Enter your choice
+9
+Enter value of element
+12
+Element is not in the list
+Do you want to continue? Enter 'y' for more inputs or 'n' to stop
+n
+*/
\ No newline at end of file
From 4d56308e85f7e2d4f34a18eb2c4488cbdebe8b38 Mon Sep 17 00:00:00 2001
From: Md Akdas Ahmad <43089126+MdAkdas@users.noreply.github.com>
Date: Mon, 23 Mar 2020 15:40:19 +0530
Subject: [PATCH 031/265] palindromic_string_added 2, indentation fixed C/C++
(#2356)
---
palindromic_string/palindromic_string.c | 54 ++++++++++++++++++++++
palindromic_string/palindromic_string.cpp | 55 +++++++++++++++++++++++
2 files changed, 109 insertions(+)
create mode 100644 palindromic_string/palindromic_string.c
create mode 100644 palindromic_string/palindromic_string.cpp
diff --git a/palindromic_string/palindromic_string.c b/palindromic_string/palindromic_string.c
new file mode 100644
index 000000000..1984bbde4
--- /dev/null
+++ b/palindromic_string/palindromic_string.c
@@ -0,0 +1,54 @@
+/*
+C Programme to check palindromic string.
+A Palindromic String is a sequence of characters which is
+the same when read both forward and backward.
+*/
+
+#include
+#include
+
+// Driver function
+int main()
+{
+ char string1[20];
+ int i, length;
+ bool flag = false;
+
+ printf("Enter a string: ");
+ scanf("%s", string1);
+
+ length = strlen(string1);
+
+ for(i = 0; i < length/2; i++)
+ {
+ if(string1[i] != string1[length - i - 1])
+ {
+ flag = true;
+ break;
+ }
+ }
+
+ if (flag)
+ {
+ printf("%s is not a palindrome", string1);
+ }
+ else
+ {
+ printf("%s is a palindrome", string1);
+ }
+ return 0;
+}
+
+/*
+Input:
+radar
+
+Output:
+radar is a palindrome
+
+Input:
+Enter a string: india
+
+Output:
+india is not a palindrome
+*/
diff --git a/palindromic_string/palindromic_string.cpp b/palindromic_string/palindromic_string.cpp
new file mode 100644
index 000000000..11720adbe
--- /dev/null
+++ b/palindromic_string/palindromic_string.cpp
@@ -0,0 +1,55 @@
+/*
+C++ Programme to check palindromic string.
+A Palindromic String is a sequence of characters which is
+the same when read both forward and backward.
+*/
+
+#include
+#include
+using namespace std;
+
+// Driver function
+int main()
+{
+ char string1[20];
+ int i, length;
+ bool flag = false;
+
+ cout << "Enter a string: ";
+ cin >> string1;
+
+ length = strlen(string1);
+
+ for(i = 0; i < length/2; i++)
+ {
+ if(string1[i] != string1[length - i - 1])
+ {
+ flag = true;
+ break;
+ }
+ }
+
+ if (flag)
+ {
+ cout << string1 << " is not a palindrome" << endl;
+ }
+ else
+ {
+ cout << string1 << " is a palindrome" << endl;
+ }
+
+ return 0;
+}
+
+/*Input:
+radar
+
+Output:
+radar is a palindrome
+
+Input:
+Enter a string: india
+
+Output:
+india is not a palindrome
+*/
\ No newline at end of file
From cda804925c437422227d2752dfe3c23908b1c8d9 Mon Sep 17 00:00:00 2001
From: Raksha <57195964+raksha009@users.noreply.github.com>
Date: Tue, 24 Mar 2020 22:31:29 +0530
Subject: [PATCH 032/265] check palindrome in a number in Java (#2492)
updated with changes
updated
updated changes
---
Palindrome/palindrome_no.java | 47 +++++++++++++++++++++++++++++++++++
1 file changed, 47 insertions(+)
create mode 100644 Palindrome/palindrome_no.java
diff --git a/Palindrome/palindrome_no.java b/Palindrome/palindrome_no.java
new file mode 100644
index 000000000..b3b5e0e06
--- /dev/null
+++ b/Palindrome/palindrome_no.java
@@ -0,0 +1,47 @@
+// Java program to check if a number entered is a palindrome
+
+import java.util.*;
+
+public class palindrome_no {
+
+ // Find reverse of a number
+ public static int reverse(int number) {
+ int reverseno = 0 ;
+
+ while (number > 0) {
+ reverseno = (int) (reverseno * Math.pow(10, 1) + number % Math.pow(10, 1));
+ number = (int) (number / Math.pow(10, 1));
+ }
+ return reverseno;
+ }
+
+ public static void main(String[] args) {
+ Scanner s = new Scanner(System.in);
+ System.out.println(" Hey, Enter any number ");
+ int enter_number = s.nextInt();
+ int reverseno = reverse(enter_number);
+
+ // Check whether the number entered is equal to reversed number or not
+ if (reverseno == enter_number) {
+ System.out.println("Number is a PALINDROME");
+ return ;
+ }
+ System.out.println("Number is not a PALINDROME");
+ return;
+ }
+}
+
+/*
+Test cases
+INPUT
+ Hey, Enter any number
+1223
+OUTPUT
+Number is not a PALINDROME
+
+INPUT
+ Hey, Enter any number
+1223221
+OUTPUT
+Number is a PALINDROME
+*/
From b02279f7cfe58e0de64b76fd3aa91de50e560f0e Mon Sep 17 00:00:00 2001
From: Raksha <57195964+raksha009@users.noreply.github.com>
Date: Tue, 24 Mar 2020 22:34:05 +0530
Subject: [PATCH 033/265] check palindrome in a string in Java (#2491)
updated
---
Palindrome/palindrome_string.java | 50 +++++++++++++++++++++++++++++++
1 file changed, 50 insertions(+)
create mode 100644 Palindrome/palindrome_string.java
diff --git a/Palindrome/palindrome_string.java b/Palindrome/palindrome_string.java
new file mode 100644
index 000000000..175e380e1
--- /dev/null
+++ b/Palindrome/palindrome_string.java
@@ -0,0 +1,50 @@
+//Java program to check if a string is a Palindrome
+
+import java.util.*;
+
+public class reverse_string {
+
+ // Reverse a given string
+ public static String palindrome(String string_entered) {
+ String str_reversed = "";
+ int length_of_String = string_entered.length()-1;
+ int len = 0;
+
+ for (len = length_of_String; len >= 0 ; len --)
+ str_reversed = str_reversed + string_entered.charAt(len);
+ return str_reversed;
+ }
+
+ public static void main(String[] args) {
+
+ Scanner s = new Scanner(System.in);
+ System.out.println(" Hey,Enter any string ");
+ String string_entered = s.nextLine();
+ String str_reversed = palindrome(string_entered);
+
+ // Comparing 2 strings to find if input string is palindrome or not
+ if(string_entered.equals(str_reversed)) {
+ System.out.println(" String is a PALINDROME ");
+ }
+ else {
+ System.out.println(" String is not a PALINDROME ");
+ }
+ }
+}
+
+/*
+Test cases
+
+INPUT
+ Hey,Enter any string
+hello
+OUTPUT
+ String is not a PALINDROME
+
+INPUT
+ Hey,Enter any string
+metem
+OUTPUT
+ String is a PALINDROME
+*/
+
From c91c9a89f86b13e391e35673c50e838c279947af Mon Sep 17 00:00:00 2001
From: Ramchandra Joshi <60807704+rbjoshi1309@users.noreply.github.com>
Date: Wed, 25 Mar 2020 12:20:54 +0530
Subject: [PATCH 034/265] Added code for Tower Of Hanoi in Go language (#2562)
Added code for Tower Of Hanoi in Go language
---
Tower_Of_Hanoi/Tower_Of_Hanoi.go | 36 ++++++++++++++++++++++++++++++++
1 file changed, 36 insertions(+)
create mode 100644 Tower_Of_Hanoi/Tower_Of_Hanoi.go
diff --git a/Tower_Of_Hanoi/Tower_Of_Hanoi.go b/Tower_Of_Hanoi/Tower_Of_Hanoi.go
new file mode 100644
index 000000000..939013a59
--- /dev/null
+++ b/Tower_Of_Hanoi/Tower_Of_Hanoi.go
@@ -0,0 +1,36 @@
+// Tower of Hanoi problem using recursion
+
+package main
+import "fmt"
+
+func TowerOfHanoi(n int, source byte, destination byte, auxillary byte) {
+ if (n == 1) {
+ fmt.Printf("Move disk 1 from rod %c to rod %c \n", source, destination)
+ return
+ }
+ TowerOfHanoi(n - 1, source, auxillary, destination)
+ fmt.Printf("Move disk %d from rod %c to rod %c \n", n, source, destination)
+ TowerOfHanoi(n - 1, auxillary, destination, source)
+}
+
+func main() {
+ var n int
+ fmt.Print("Enter number of disks: ")
+ fmt.Scan(&n)
+ // n = Number of disks
+
+ TowerOfHanoi(n, 'A', 'C', 'B')
+ // A, B and C are names of rods
+ // A is source rod, B is auxillary rod, C is destination rod
+}
+
+/*
+Enter number of disks: 3
+Move disk 1 from rod A to rod C
+Move disk 2 from rod A to rod B
+Move disk 1 from rod C to rod B
+Move disk 3 from rod A to rod C
+Move disk 1 from rod B to rod A
+Move disk 2 from rod B to rod C
+Move disk 1 from rod A to rod C
+*/
From 1a7ceec1fe07ea03f4daecf61df8a42b57393338 Mon Sep 17 00:00:00 2001
From: abhinash_giri <56127409+abhinashgiri@users.noreply.github.com>
Date: Wed, 25 Mar 2020 12:25:17 +0530
Subject: [PATCH 035/265] Merge-sort-3-way-with-reuested-changes (#2505)
---
Merge_Sort_3_Way/Merge_Sort_3_Way.cpp | 204 ++++++++++++++++++++++++++
1 file changed, 204 insertions(+)
create mode 100644 Merge_Sort_3_Way/Merge_Sort_3_Way.cpp
diff --git a/Merge_Sort_3_Way/Merge_Sort_3_Way.cpp b/Merge_Sort_3_Way/Merge_Sort_3_Way.cpp
new file mode 100644
index 000000000..b1092a74e
--- /dev/null
+++ b/Merge_Sort_3_Way/Merge_Sort_3_Way.cpp
@@ -0,0 +1,204 @@
+#include "iostream"
+#include
+using namespace std;
+
+//function for storing elements from three vectors(left,mid,right) in sorted manner in vector named sorted
+// sorted vector must be passed by reference to see the effect of changes made by the function
+// other vectors are passed as reference to avoid copying of elements repeatedly
+
+void mergeVersion3(vector &sorted,vector &left,vector &mid,vector &right)
+{
+ int i = 0; //index pointer variable for left vector
+ int j = 0; //index pointer variable for mid vector
+ int k = 0; //index pointer variable for right vector
+ int l = 0; //index pointer variable for sorted vector
+ // selecting the minimum element of from the three vectors when all are non-empty
+ while( (i < left.size()) && (j mergeSort3ways(vector &input)
+{
+ if( input.size() == 1 )
+ {
+ return input;
+ }
+ else if( input.size() == 2 )
+ {
+
+ //two different vectors (element1 and element2) of size 1 to store one element each and no_element vector of size 0
+
+ vectorelement1,element2,no_element(0);
+ element1.emplace_back(input.at(0));
+ element2.emplace_back(input.at(1));
+
+ //call merging of three vectors and then return sorted vector
+
+ mergeVersion3(input,element1,element2,no_element);
+ return input;
+ }
+ else
+ { int left_size {0}, right_size {0}, mid_size {0};
+ if( input.size() % 3 == 0 )
+ {
+ left_size = int(input.size() / 3);
+ mid_size = int(input.size() / 3);
+ right_size = int(input.size() / 3);
+ }
+ else if( input.size() % 3 == 1 )
+ {
+ left_size = int(input.size() / 3) + 1;
+ mid_size = int(input.size() / 3);
+ right_size = int(input.size() / 3);
+ }
+ else if( input.size() % 3 == 2 )
+ {
+ left_size = int(input.size() / 3) + 1;
+ mid_size = int(input.size() / 3);
+ right_size = int(input.size() / 3) + 1;
+ }
+
+ // dividing original vector into three vectors left_vec,mid_vec,right_vec
+
+ vector left_vec,right_vec,mid_vec;
+ for (int i = 0; i < left_size ; ++i)
+ {
+ left_vec.emplace_back(input[i]);
+ }
+ for (int i = 0; i < mid_size ; ++i)
+ {
+ mid_vec.emplace_back(input[i + left_size]);
+ }
+ for (int i = 0; i < right_size ; ++i)
+ {
+ right_vec.emplace_back(input[i + left_size + mid_size]);
+ }
+
+ //dividing the three vectors recursively
+
+ mergeSort3ways(left_vec);
+ mergeSort3ways(mid_vec);
+ mergeSort3ways(right_vec);
+
+ // sorting the vector
+
+ mergeVersion3(input,left_vec,mid_vec,right_vec);
+ return input;
+ }
+
+}
+
+// Driver Code
+
+int main()
+{
+ int n {0} , temp {0}; //initializes the variables n and temp to zero just after creation , it is not assignment
+ cin >> n; //input for number of elements in input array/vector
+ vector input , result; //vector to take input of all elements
+
+ // taking input of n elements in a vector
+
+ for (int i = 0; i < n ; ++i) {
+ cin >> temp;
+ input.emplace_back(temp); //emplace_back is more efficient than push_back
+ }
+
+ // sorted vector is returned to result vector
+
+ result = mergeSort3ways(input);
+
+ // Displaying the sorted Vector
+
+ for(auto c : result)
+ {
+ cout << c << " ";
+ }
+ return 0;
+}
+// Sample Test Cases
+// Input
+// 5
+// 78 8 6 5 7
+// Output
+// 5 6 7 8 78
+// input
+// 10
+// -8 45 -9 47 34 2 5 21 987 -3
+// Output
+// -9 -8 -3 2 5 21 34 45 47 987
From 3bb864cc7503482ce456c0d40b76409a4dd994f7 Mon Sep 17 00:00:00 2001
From: Ishaan Ahuja <59371101+ishaan2908@users.noreply.github.com>
Date: Wed, 25 Mar 2020 23:59:11 +0530
Subject: [PATCH 036/265] Created Count_Rotations.java (#1804)
Added method to find how many times a sorted array is rotated using Binary Search
---
Count_Rotations/Count_Rotations.java | 70 ++++++++++++++++++++++++++++
1 file changed, 70 insertions(+)
create mode 100644 Count_Rotations/Count_Rotations.java
diff --git a/Count_Rotations/Count_Rotations.java b/Count_Rotations/Count_Rotations.java
new file mode 100644
index 000000000..6b1accc83
--- /dev/null
+++ b/Count_Rotations/Count_Rotations.java
@@ -0,0 +1,70 @@
+/**
+ * A sorted array has been rotated in clockwise direction.
+ * Find how many times it was rotated.
+ */
+
+import java.util.Scanner;
+
+class CountRotations
+{
+ static int findRotations(int[] arr)
+ {
+ /**
+ * returns no. of times a sorted array was rotated.
+ */
+ int size = arr.length;
+ int left = 0, right = size - 1;
+
+ while(left <= right)
+ {
+ int middle = (right + left) / 2;
+ int previous = (middle + size - 1) % size, next = (middle + 1) % size;
+
+ // next is index of element after middle
+ // previous is index of element before middle
+
+ if(arr[left] <= arr[right])
+ return left;
+
+ if(arr[middle] <= arr[next] && arr[middle] <= arr[previous])
+ return middle;
+
+ if(arr[middle] <= arr[right])
+ right = middle - 1;
+
+ else if(arr[middle] >= arr[left])
+ left = middle + 1;
+ }
+ return 0;
+ }
+
+ public static void main(String[] args)
+ {
+ Scanner scan = new Scanner(System.in);
+
+ System.out.println("Enter size of the array: ");
+ int size = scan.nextInt();
+
+ int[] arr = new int[size];
+
+ System.out.println("Enter " + size + " elements: ");
+ for(int i = 0; i < size; i++)
+ arr[i] = scan.nextInt();
+
+ int count = findRotations(arr);
+ // count variable stores no. of rotations in the array.
+
+ System.out.println("The array is rotated " + count + " times.");
+ }
+}
+
+/**
+ * Sample Input
+ * size = 6
+ * arr = 5, 6, 1, 2, 3, 4
+ */
+
+/**
+ * Sample Output
+ * The array is rotated 2 times.
+ */
From b5a3f734ef0da069d1380dfa1c6f865d1bc8552b Mon Sep 17 00:00:00 2001
From: jalajdorai <53962833+jalajdorai@users.noreply.github.com>
Date: Thu, 26 Mar 2020 00:22:06 +0530
Subject: [PATCH 037/265] Integer to Roman Program (#2216)
---
Integer_to_Roman/Integer_to_Roman.cpp | 67 +++++++++++++++++++++++++++
1 file changed, 67 insertions(+)
create mode 100644 Integer_to_Roman/Integer_to_Roman.cpp
diff --git a/Integer_to_Roman/Integer_to_Roman.cpp b/Integer_to_Roman/Integer_to_Roman.cpp
new file mode 100644
index 000000000..2b08ff0af
--- /dev/null
+++ b/Integer_to_Roman/Integer_to_Roman.cpp
@@ -0,0 +1,67 @@
+/*
+Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M.
+Symbol Value
+I 1
+V 5
+X 10
+L 50
+C 100
+D 500
+M 1000
+For example, two is written as II in Roman numeral, just two one's added together.
+Twelve is written as, XII, which is simply X + II.
+The number twenty seven is written as XXVII, which is XX + V + II.
+Roman numerals are usually written largest to smallest from left to right.
+However, the numeral for four is not IIII. Instead, the number four is written as IV.
+Because the one is before the five we subtract it making four.
+The same principle applies to the number nine, which is written as IX.
+There are six instances where subtraction is used:
+I can be placed before V (5) and X (10) to make 4 and 9.
+X can be placed before L (50) and C (100) to make 40 and 90.
+C can be placed before D (500) and M (1000) to make 400 and 900.
+Given an integer, convert it to a roman numeral.
+ Input is guaranteed to be within the range from 1 to 3999.
+*/
+
+#include
+using namespace std;
+class Solution {
+public:
+ string intToRoman(int num) {
+ int a[] = {1, 4, 5, 9, 10, 40, 50, 90, 100, 400, 500, 900, 1000};
+ string s[] = {"I", "IV", "V", "IX", "X", "XL", "L", "XC", "C", "CD", "D", "CM", "M"};
+ string ans = "";
+ int i = 12;
+ while(num > 0)
+ {
+ int d = num / a[i];
+ num = num % a[i];
+ while(d--)
+ {
+ ans = ans + s[i];
+ }
+ i--;
+ }
+ return ans;
+ }
+};
+
+int stringToInteger(string input) {
+ return stoi(input);
+}
+
+int main() {
+ string line;
+ while (getline(cin, line)) {
+ int num = stringToInteger(line);
+ string ret = Solution().intToRoman(num);
+ string out = (ret);
+ cout << out << endl;
+ }
+ return 0;
+}
+/*
+Input: 58
+Output: "LVIII"
+Explanation: L = 50, V = 5, III = 3.
+*/
From 0cfac2b7503607b22aacdfdda7f172abcf7d3a94 Mon Sep 17 00:00:00 2001
From: Rukmini Meda <44504940+Rukmini-Meda@users.noreply.github.com>
Date: Fri, 27 Mar 2020 13:13:13 +0530
Subject: [PATCH 038/265] Depth First Search in Dart (#2561)
---
Depth_First_Search/Depth_First_Search.dart | 100 +++++++++++++++++++++
1 file changed, 100 insertions(+)
create mode 100644 Depth_First_Search/Depth_First_Search.dart
diff --git a/Depth_First_Search/Depth_First_Search.dart b/Depth_First_Search/Depth_First_Search.dart
new file mode 100644
index 000000000..c5224896f
--- /dev/null
+++ b/Depth_First_Search/Depth_First_Search.dart
@@ -0,0 +1,100 @@
+// Required library to use inbuilt queue in LIFO manner in Dart
+import 'dart:collection';
+// Required library to use standard output facility of dart
+import 'dart:io';
+
+// Function to find the depth first search of a graph
+void Depth_First_Search ( var graph, int source, int no_vertices ) {
+ // Queue is used in LIFO manner to obtain stack functionality.
+ var queue = Queue();
+ // A list to keep track of visited nodes
+ var visited = new List(no_vertices);
+ // Initializing the list
+ for(int i = 0; i < no_vertices; i ++ ) {
+ visited[i] = 0;
+ }
+ // Adding the source node to LIFO queue ( stack )
+ queue.add(source);
+ // Marking the node visited
+ visited[source] = 1;
+ int val;
+
+ while(queue.isNotEmpty){
+ val = queue.removeLast();
+ stdout.write("$val ");
+
+ //Visiting neighbours of the popped node
+ for(int i = 0; i < no_vertices; i ++ ){
+ if(graph[val][i] == 1 && visited[i] == 0){
+ queue.add(i);
+ visited[i] = 1;
+ }
+ }
+ }
+}
+
+// Driver method of the program
+void main(){
+
+ // Reading from the standard input
+ print("Which graph do you want to enter ( directed/ undirected ):");
+ String mode = stdin.readLineSync().toString();
+
+ print("Enter number of vertices:");
+ var input = stdin.readLineSync();
+ int no_vertices = int.parse(input);
+
+ // Graph is implemented as adjacency matrix.
+ var graph = new List.generate(no_vertices, (_) => new List(no_vertices));
+ for(int i = 0; i < no_vertices; i++){
+ for(int j = 0; j < no_vertices; j++){
+ graph[i][j] = 0;
+ }
+ }
+
+ print("Enter number of edges:");
+ var input1 = stdin.readLineSync();
+ int no_edges = int.parse(input);
+ print("Enter source and destination vertices of edges:\n");
+ print("Note: Enter source and destination vertices as 0,1,2,...");
+
+ for(int i = 1; i <= no_edges; i++){
+
+ print("Edge #$i:");
+
+ print("Enter source vertex:");
+ int source = int.parse(stdin.readLineSync());
+
+ print("Enter destination vertex:");
+ int destination = int.parse(stdin.readLineSync());
+
+ if(mode == "undirected"){
+ graph[source][destination] = 1;
+ graph[destination][source] = 1;
+ }
+ else{
+ graph[source][destination] = 1;
+ }
+
+ }
+
+ print("Enter the source vertex from which DFS should begin:");
+ int source1 = int.parse(stdin.readLineSync());
+
+ // Sample input graph
+ // 0 - 1 - 2
+ // | /
+ // 3 - 4
+
+ print("Vertices in Depth First Search of the graph in sample input is: ");
+
+ // Depth First Search of the above graph
+ Depth_First_Search(graph,source1,no_vertices);
+
+ // Sample Output
+ // Vertices in Depth First Search of the graph in sample input is:
+ // 0 3 4 2 1
+
+}
+
+
From d3a2320a5025b9e3df714c0d288e892b81e607fe Mon Sep 17 00:00:00 2001
From: Rukmini Meda <44504940+Rukmini-Meda@users.noreply.github.com>
Date: Fri, 27 Mar 2020 13:13:33 +0530
Subject: [PATCH 039/265] Breadth first search using dart (#2560)
---
.../Breadth_First_Search.dart | 99 +++++++++++++++++++
1 file changed, 99 insertions(+)
create mode 100644 Breadth_First_Search/Breadth_First_Search.dart
diff --git a/Breadth_First_Search/Breadth_First_Search.dart b/Breadth_First_Search/Breadth_First_Search.dart
new file mode 100644
index 000000000..895b1f5f3
--- /dev/null
+++ b/Breadth_First_Search/Breadth_First_Search.dart
@@ -0,0 +1,99 @@
+// Required library to use inbuilt queues in Dart
+import 'dart:collection';
+// Required library to use standard output facility of dart
+import 'dart:io';
+
+// Function to find the breadth first search of a graph
+void Breadth_First_Search( var graph, int source, int no_vertices ) {
+ // Queue to order nodes levelwise or breadthwise
+ var queue = Queue();
+ // A list to keep track of visited nodes
+ var visited = new List(no_vertices);
+ // Initializing the list
+ for(int i = 0; i < no_vertices; i++){
+ visited[i] = 0;
+ }
+ // Adding the source node to queue
+ queue.add(source);
+ // Marking the node visited
+ visited[source] = 1;
+ int val;
+
+ while(queue.isNotEmpty){
+ val = queue.removeFirst();
+ stdout.write("$val ");
+
+ //Visiting neighbours of the dequed node
+ for(int i = 0; i < no_vertices; i++){
+ if(graph[val][i] == 1 && visited[i] == 0){
+ queue.add(i);
+ visited[i] = 1;
+ }
+ }
+ }
+}
+
+// Driver method of the program
+void main() {
+
+ // Reading from the standard input
+ print("Which graph do you want to enter ( directed/ undirected ):");
+ String mode = stdin.readLineSync().toString();
+
+ print("Enter number of vertices:");
+ var input = stdin.readLineSync();
+ int no_vertices = int.parse(input);
+
+ // Graph is implemented as adjacency matrix.
+ var graph = new List.generate(no_vertices, (_) => new List(no_vertices));
+ for(int i = 0; i < no_vertices; i++){
+ for(int j = 0; j < no_vertices; j++){
+ graph[i][j] = 0;
+ }
+ }
+
+ print("Enter number of edges:");
+ var input1 = stdin.readLineSync();
+ int no_edges = int.parse(input);
+ print("Enter source and destination vertices of edges:\n");
+ print("Note: Enter source and destination vertices as 0,1,2,...");
+
+ for(int i = 1; i <= no_edges; i++){
+
+ print("Edge #$i:");
+
+ print("Enter source vertex:");
+ int source = int.parse(stdin.readLineSync());
+
+ print("Enter destination vertex:");
+ int destination = int.parse(stdin.readLineSync());
+
+ if(mode == "undirected"){
+ graph[source][destination] = 1;
+ graph[destination][source] = 1;
+ }
+ else {
+ graph[source][destination] = 1;
+ }
+
+ }
+
+ print("Enter the source vertex from which BFS should begin:");
+ int source1 = int.parse(stdin.readLineSync());
+
+ // Sample input graph
+ // 0 - 1 - 2
+ // | /
+ // 3 - 4
+
+ print("Vertices in Breadth First Search of the graph in sample input is: ");
+
+ // Breadth First Search of the above graph
+ Breadth_First_Search(graph,source1,no_vertices);
+
+ // Sample Output
+ // 0 1 3 2 4
+
+}
+
+
From e492e1adab74c05ea4380975362256a5fd291ae5 Mon Sep 17 00:00:00 2001
From: Ritish Singh <54978105+ritish099@users.noreply.github.com>
Date: Fri, 27 Mar 2020 13:55:05 +0530
Subject: [PATCH 040/265] Postman Sort in C# (#2511)
---
Postman_Sort/Postman_Sort.cs | 112 +++++++++++++++++++++++++++++++++++
1 file changed, 112 insertions(+)
create mode 100644 Postman_Sort/Postman_Sort.cs
diff --git a/Postman_Sort/Postman_Sort.cs b/Postman_Sort/Postman_Sort.cs
new file mode 100644
index 000000000..e44363c54
--- /dev/null
+++ b/Postman_Sort/Postman_Sort.cs
@@ -0,0 +1,112 @@
+//Program to Sort the array using Postman Sort
+
+using System;
+namespace Declaring_Method
+{
+ public class Postman_Sort
+ {
+ public static int[] arr = new int[100];
+ public static int[] arr1 = new int[100];
+ public int temp, max, count, maxdigits = 0, c = 0;
+ public static void Main(string[] args)
+ {
+
+ Postman_Sort p = new Postman_Sort();
+ int t1, t, n = 1, i, j;
+ Console.WriteLine("Enter the Size of the array ");
+ p.count = Convert.ToInt32(Console.ReadLine());
+ Console.WriteLine("Enter the elements of the array :-");
+ for (i = 0; i < p.count; i++)
+ {
+ Console.Write("Element - {0} : ", i);
+ arr[i] = Convert.ToInt32(Console.ReadLine());
+ arr1[i] = arr[i];
+ }
+
+ //Finding the longest digits in the array and no of elements in that digit
+ for (i = 0; i < p.count; i++)
+ {
+ t = arr[i];
+ while (t > 0)
+ {
+ p.c++; //Counting the no of elements of a digit
+ t = t / 10;
+ }
+ if (p.maxdigits < p.c)
+ p.maxdigits = p.c; //Storing the length of longest digit
+ p.c = 0;
+ }
+ for (i = 1; i < p.maxdigits; i++)
+ {
+ n = n * 10;
+ }
+
+ for (i = 0; i < p.count; i++)
+ {
+ p.max = arr[i] / n; //Dividing by a particular base
+ t = i;
+ for (j = i + 1; j < p.count; j++)
+ {
+ if (p.max > (arr[j] / n))
+ {
+ p.max = arr[j] / n;
+ t = j;
+ }
+ }
+ p.temp = arr1[t];
+ arr1[t] = arr1[i];
+ arr1[i] = p.temp;
+ p.temp = arr[t];
+ arr[t] = arr[i];
+ arr[i] = p.temp;
+ }
+ while (n >= 1)
+ {
+ for (i = 0; i < p.count;)
+ {
+ t1 = arr[i] / n;
+ for (j = i + 1; t1 == (arr[j] / n); j++);
+ arrange(i, j);
+ i = j;
+ }
+ n = n / 10;
+ }
+ Console.WriteLine("Sorted Array");
+ for (i = 0; i < p.count; i++)
+ Console.Write("{0} ", arr1[i]); //Displaying the Sorted array
+ }
+
+ //Arranging the elements
+ public static void arrange(int k, int n)
+ {
+ Postman_Sort p = new Postman_Sort();
+ int i, j;
+ for (i = k; i < (n - 1); i++)
+ {
+ for (j = i + 1; j < n; j++)
+ {
+ if (arr1[i] > arr1[j])
+ {
+ p.temp = arr1[i];
+ arr1[i] = arr1[j];
+ arr1[j] = p.temp;
+ p.temp = (arr[i] % 10);
+ arr[i] = (arr[j] % 10);
+ arr[j] = p.temp;
+ }
+ }
+ }
+ }
+ }
+}
+/* Enter the Size of the array
+6
+Enter the elements of the array :-
+Element - 0 : 43
+Element - 1 : 35
+Element - 2 : 75
+Element - 3 : 1
+Element - 4 : 68
+Element - 5 : 453
+Sorted Array
+1 35 43 68 75 453 */
From 5730c44353f43c16ad2dd1d47a29059c6f3f1d09 Mon Sep 17 00:00:00 2001
From: Anuj Singh <43649349+myselfanuj@users.noreply.github.com>
Date: Fri, 27 Mar 2020 23:35:30 +0530
Subject: [PATCH 041/265] CircleSort Algo in Kotlin (#2460)
* CircleSort in Kotlin
* Arranged Code
* Update Circle_Sort.kts
---
Circle_Sort/Circle_Sort.kts | 55 +++++++++++++++++++++++++++++++++++++
1 file changed, 55 insertions(+)
create mode 100644 Circle_Sort/Circle_Sort.kts
diff --git a/Circle_Sort/Circle_Sort.kts b/Circle_Sort/Circle_Sort.kts
new file mode 100644
index 000000000..382c01749
--- /dev/null
+++ b/Circle_Sort/Circle_Sort.kts
@@ -0,0 +1,55 @@
+fun> circleSort(array: Array, lo: Int, hi: Int, nSwaps: Int): Int {
+ if (lo == hi) return nSwaps
+
+ fun swap(array: Array, i: Int, j: Int) {
+ val temp = array[i]
+ array[i] = array[j]
+ array[j] = temp
+ }
+
+ var high = hi
+ var low = lo
+ val mid = (hi - lo) / 2
+ var swaps = nSwaps
+
+ while (low < high) {
+ if (array[low] > array[high]) {
+ swap(array, low, high)
+ swaps++
+ }
+ low++
+ high--
+ }
+ if (low == high)
+ if (array[low] > array[high + 1]) {
+ swap(array, low, high + 1)
+ swaps++
+ }
+
+ swaps = circleSort(array, lo, lo + mid, swaps)
+ swaps = circleSort(array, lo + mid + 1, hi, swaps)
+ return swaps
+}
+
+fun main(args: Array) {
+ // -- ExampleArray1 --
+ val array = arrayOf(6, 7, 8, 9, 2, 5, 3, 4, 1)
+ println("Unsorted Array: ${array.asList()}")
+ while (circleSort(array, 0, array.size - 1, 0) != 0) ;
+ println("Sorted Array : ${array.asList()}") //Sorted Array
+ println()
+
+ // -- ExampleArray2 --
+ val array2 = arrayOf("the", "quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog")
+ println("Unsorted Array : ${array2.asList()}")
+ while (circleSort(array2, 0, array2.size - 1, 0) != 0) ;
+ println("Sorted Array : ${array2.asList()}") //Sorted Array
+}
+
+
+//output
+Unsorted Array: [6, 7, 8, 9, 2, 5, 3, 4, 1]
+Sorted Array : [1, 2, 3, 4, 5, 6, 7, 8, 9]
+
+Unsorted Array : [the, quick, brown, fox, jumps, over, the, lazy, dog]
+Sorted Array : [brown, dog, fox, jumps, lazy, over, quick, the, the]
From 8c338af13daeec1317945a4502a15910afc67a84 Mon Sep 17 00:00:00 2001
From: Bishal Kumar Chanda <60260604+BishalKrChanda@users.noreply.github.com>
Date: Fri, 27 Mar 2020 23:39:58 +0530
Subject: [PATCH 042/265] added armstrong in c#
added armstrong in c#
---
Armstrong_Number/Armstrong_Number.cs | 38 ++++++++++++++++++++++++++++
1 file changed, 38 insertions(+)
create mode 100644 Armstrong_Number/Armstrong_Number.cs
diff --git a/Armstrong_Number/Armstrong_Number.cs b/Armstrong_Number/Armstrong_Number.cs
new file mode 100644
index 000000000..4ba4bed30
--- /dev/null
+++ b/Armstrong_Number/Armstrong_Number.cs
@@ -0,0 +1,38 @@
+using System;
+public class Armstrong
+{
+ public static void Main(string[] args)
+ {
+ // initialising variables
+ int n, r, sum = 0, temp;
+ // asking for user input for the number to be checked
+ Console.Write("Enter the Number = ");
+ // storing the number in variable n
+ n = int.Parse(Console.ReadLine());
+ // storing the number in a temporary variable
+ temp = n;
+ // running while loop to get the condition number
+ while(n > 0)
+ {
+ r = n % 10;
+ sum = sum + (r * r * r);
+ n = n / 10;
+ }
+ // checking if the number found using the condition of finding armstrong number is equal to the given number
+ // printing the statement according to the result of the condition
+ if(temp == sum)
+ Console.Write("The Entered Number is an Armstrong Number.");
+ else
+ Console.Write("The Entered number is not an Armstrong Number.");
+ }
+}
+
+/*
+Sample inputs and outputs:
+
+Enter the Number = 153
+The Entered Number is an Armstrong Number.
+
+Enter the Number = 121
+The Entered number is not an Armstrong Number.
+*/
From 32a22374add884d44f0f2abf67193a197b2e860d Mon Sep 17 00:00:00 2001
From: Aman-Codes <54680709+Aman-Codes@users.noreply.github.com>
Date: Fri, 27 Mar 2020 23:41:05 +0530
Subject: [PATCH 043/265] Implemented KNN algorithm using C++ (Closes issue
#1789) (#2546)
* Added the KNN Algorithm implemented using C++
* Added Tree_Inorder_Traversal.js
* Delete Tree_Inorder_Traversal.js
---
.../K_Nearest_Neighbors.cpp | 111 ++++++++++++++++++
1 file changed, 111 insertions(+)
create mode 100644 Machine_Learning/K_Nearest_Neighbours/K_Nearest_Neighbors.cpp
diff --git a/Machine_Learning/K_Nearest_Neighbours/K_Nearest_Neighbors.cpp b/Machine_Learning/K_Nearest_Neighbours/K_Nearest_Neighbors.cpp
new file mode 100644
index 000000000..296a0ed85
--- /dev/null
+++ b/Machine_Learning/K_Nearest_Neighbours/K_Nearest_Neighbors.cpp
@@ -0,0 +1,111 @@
+#include
+using namespace std;
+
+struct point {
+ float w, x, y, z; // w, x, y and z are the values of the dataset
+ float distance; // distance will store the distance of dataset point from the unknown test point
+ int op; // op will store the class of the point
+};
+
+int main() {
+ int i, j, n, k;
+ struct point p;
+ struct point temp;
+ cout << "Number of data points: ";
+ cin >> n;
+ struct point arr[n];
+ cout << "\nEnter the dataset values: \n";
+ cout << "w\tx\ty\tz\top\n";
+
+ // Taking dataset
+ for (i = 0; i < n; i++) {
+ cin >> arr[i].w >> arr[i].x >> arr[i].y >> arr[i].z >> arr[i].op;
+ }
+
+ cout << "\nw\tx\ty\tz\top\n";
+
+ for (i = 0; i < n; i++) {
+ cout << fixed << setprecision(2) << arr[i].w << '\t' << arr[i].x << '\t' << arr[i].y << '\t' << arr[i].z << '\t' << arr[i].op << '\n';
+ }
+
+ cout << "\nEnter the feature values of the unknown point: \nw\tx\ty\tz\n";
+ cin >> p.w >> p.x >> p.y >> p.z;
+
+ // Measuring the Euclidean distance
+ for (i = 0; i < n; i++) {
+ arr[i].distance = sqrt(((arr[i].w - p.w) * (arr[i].w - p.w)) + ((arr[i].x - p.x) * (arr[i].x - p.x)) + ((arr[i].y - p.y) * (arr[i].y - p.y)) + ((arr[i].z - p.z) * (arr[i].z - p.z)));
+ }
+
+ // Sorting the training data with respect to distance
+ for (i = 1; i < n; i++) {
+ for (j = 0; j < n - i; j++) {
+ if (arr[j].distance > arr[j + 1].distance) {
+ temp = arr[j];
+ arr[j] = arr[j + 1];
+ arr[j + 1] = temp;
+ }
+ }
+ }
+
+ cout << "\nw\tx\ty\tz\top\tdistance\n";
+ for (i = 0; i < n; i++) {
+ cout << fixed << setprecision(2) << arr[i].w << '\t' << arr[i].x << '\t' << arr[i].y << '\t' << arr[i].z << '\t' << arr[i].op << '\t' << arr[i].distance << '\n';
+ }
+
+ // Taking the K nearest neighbors
+ cout << "\nNumber of nearest neighbors(k): ";
+ cin >> k;
+
+ int freq[1000] = {0};
+ int index = 0, maxfreq = 0;
+
+ // Creating frequency array of the class of k nearest neighbors
+ for (int i = 0; i < k; i++) {
+ freq[arr[i].op]++;
+ }
+
+ // Finding the most frequent occurring class
+ for (int i = 0; i < 1000; i++) {
+ if(freq[i] > maxfreq) {
+ maxfreq = freq[i];
+ index = i;
+ }
+ }
+
+ cout << "The class of unknown point is " << index;
+ return 0;
+}
+
+// Sample Output
+/*
+Number of data points: 5
+
+Enter the dataset values:
+w x y z op
+1 2 3 4 5
+10 20 30 40 50
+5 2 40 7 10
+40 30 100 28 3
+20 57 98 46 8
+
+w x y z op
+1.00 2.00 3.00 4.00 5
+10.00 20.00 30.00 40.00 50
+5.00 2.00 40.00 7.00 10
+40.00 30.00 100.00 28.00 3
+20.00 57.00 98.00 46.00 8
+
+Enter the feature values of the unknown point:
+w x y z
+40 30 80 30
+
+w x y z op distance
+40.00 30.00 100.00 28.00 3 20.10
+20.00 57.00 98.00 46.00 8 41.34
+10.00 20.00 30.00 40.00 50 60.00
+5.00 2.00 40.00 7.00 10 64.33
+1.00 2.00 3.00 4.00 5 94.39
+
+Number of nearest neighbors(k): 3
+The class of unknown point is 3
+*/
From db7a66f2ac601d73cab2ee538cb69c5a425f8256 Mon Sep 17 00:00:00 2001
From: AkanshaKamboj <42874293+AkanshaKamboj@users.noreply.github.com>
Date: Sat, 28 Mar 2020 00:01:06 +0530
Subject: [PATCH 044/265] Binary Tree Bottom View, Top View and Right View in C
#1577 (#2396)
* Binary Tree Bottom View in C
* Update BinaryTree_Bottom_View.c
* Update BinaryTree_Bottom_View.c
* Create Binary_Tree_Right_View.c
* Create Binary_Tree_Top_View.c
* Rename BinaryTree_Bottom_View.c to Binary_Tree_Bottom_View.c
* Update Binary_Tree_Bottom_View.c
* Update Binary_Tree_Right_View.c
* Update Binary_Tree_Top_View.c
---
.../Binary_Tree_Bottom_View.c | 124 ++++++++++++++++++
.../Binary_Tree_Right_View.c | 105 +++++++++++++++
Binary_Tree_Top_View/Binary_Tree_Top_View.c | 124 ++++++++++++++++++
3 files changed, 353 insertions(+)
create mode 100644 Binary_Tree_Bottom_View/Binary_Tree_Bottom_View.c
create mode 100644 Binary_Tree_Right_View/Binary_Tree_Right_View.c
create mode 100644 Binary_Tree_Top_View/Binary_Tree_Top_View.c
diff --git a/Binary_Tree_Bottom_View/Binary_Tree_Bottom_View.c b/Binary_Tree_Bottom_View/Binary_Tree_Bottom_View.c
new file mode 100644
index 000000000..18e63540e
--- /dev/null
+++ b/Binary_Tree_Bottom_View/Binary_Tree_Bottom_View.c
@@ -0,0 +1,124 @@
+/* C program to print bottom view of the binary tree*/
+
+#include
+#include
+#include
+
+// A binary tree node has data, pointer to left child and a pointer to right child
+struct Node
+{
+ int data;
+ struct Node* left;
+ struct Node* right;
+};
+
+/* Inserting elements into Binary Tree*/
+struct Node *create()
+{
+ Node *ptr;
+ int x;
+ printf("Enter data(-1 for no node):");
+ scanf("%d", &x);
+
+ if(x == -1)
+ return NULL;
+
+ ptr = (struct Node*)malloc(sizeof(struct Node));
+ ptr -> data = x;
+
+ printf("Enter left child of %d:\n", x);
+ ptr -> left = create();
+
+ printf("Enter right child of %d:\n", x);
+ ptr -> right = create();
+
+ return ptr;
+}
+
+// Calculating the level and the vertical distance of the node and finding the nodes that appear as the top view
+void findBottomView(struct Node *root, int *a, int *b, int level, int dist)
+{
+ if(root == NULL)
+ return;
+
+ if(level > a[50 + dist])
+ {
+ a[50 + dist] = level;
+ b[50 + dist] = root -> data;
+ }
+
+ # Recursively calling the right and the left child to get the bottom view
+
+ findBottomView(root -> right, a, b, level + 1, dist + 1);
+ findBottomView(root -> left, a, b, level + 1, dist - 1);
+}
+
+int *bottomView(struct Node* root, int *len) {
+
+ int i, o = 0;
+
+ // a stores level of the node
+ // b stores vertical distance of the node from root
+
+ int *a = (int *)calloc(100, sizeof(int));
+ int *b = (int *)calloc(100, sizeof(int));
+ int *c = (int *)calloc(100, sizeof(int));
+
+ // Initialising a and b as INT_MIN as we need to print bottom most elements
+ for(i = 0; i < 100; i++)
+ {
+ a[i] = INT_MIN;
+ b[i] = INT_MIN;
+ }
+
+ findBottomView(root, a, b, 0, 0);
+
+ for(i = 0; i < 100; i++)
+ {
+ if(b[i] != INT_MIN)
+ c[o++] = b[i];
+ }
+
+ *len = o;
+ return c;
+}
+
+int main()
+{
+ struct Node *root = create();
+ int len = 0;
+ int *res = bottomView(root, &len);
+
+ for(int i = 0; i < len; i++)
+ printf("%d ", res[i]);
+}
+
+
+/* Sample Input
+Enter data(-1 for no node: 1
+Enter left child of 1:
+Enter data(-1 for no node: 2
+Enter left child of 2:
+Enter data(-1 for no node: 6
+Enter left child of 6:
+Enter data(-1 for no node: -1
+Enter right child of 6:
+Enter data(-1 for no node: -1
+Enter right child of 2:
+Enter data(-1 for no node: -1
+Enter right child of 1:
+Enter data(-1 for no node: 3
+Enter left child of 3:
+Enter data(-1 for no node: -1
+Enter right child of 3:
+Enter data(-1 for no node: -1
+
+ 1
+ / \
+ 2 3
+ /
+ 6
+
+Output :- 6 2 1 3
+*/
+
diff --git a/Binary_Tree_Right_View/Binary_Tree_Right_View.c b/Binary_Tree_Right_View/Binary_Tree_Right_View.c
new file mode 100644
index 000000000..5f58ab287
--- /dev/null
+++ b/Binary_Tree_Right_View/Binary_Tree_Right_View.c
@@ -0,0 +1,105 @@
+/* C program to print right view of the binary tree*/
+
+#include
+#include
+
+/* A binary tree node has data, pointer to left child and a pointer to right child */
+struct Node
+{
+ int data;
+ struct Node* left;
+ struct Node* right;
+};
+
+/* Inserting elements into Binary Tree*/
+struct Node *create()
+{
+ Node *ptr;
+ int x;
+
+ printf("Enter data(-1 for no node):");
+ scanf("%d", &x);
+
+ if(x == -1)
+ return NULL;
+
+ ptr = (struct Node*)malloc(sizeof(struct Node));
+ ptr -> data = x;
+
+ printf("Enter left child of %d:\n",x);
+ ptr -> left = create();
+
+ printf("Enter right child of %d:\n",x);
+ ptr -> right = create();
+
+ return ptr;
+}
+
+/*Recursive solution for priniting right view of Binary Tree*/
+void findRightView(struct Node *root, int *ans, int *size, int index)
+{
+ if(root == NULL)
+ return;
+
+ index++;
+
+ // Increasing the level of the tree every time a node with the same level appears
+ if(index > *size)
+ ans[(*size)++] = root -> data;
+
+ // Recursively calling the nodes down the tree
+ findRightView(root -> right, ans, size, index);
+
+ findRightView(root -> left, and, size, index);
+}
+
+// Function for intializing the level of the root node and size of the array
+int *rightView(struct Node *root, int *size)
+{
+ int *ans = malloc(sizeof(int) * 100);
+ *size = 0;
+
+ findRightView(root, ans, size, 0);
+
+ return ans;
+}
+
+int main()
+{
+ struct Node *root = create();
+
+ int size = 0;
+ int *res = rightView(root, &size);
+
+ for(int i = 0; i < size; i++)
+ printf("%d", res[i]);
+}
+
+/* Sample Input
+Enter data(-1 for no node: 1
+Enter left child of 1:
+Enter data(-1 for no node: 2
+Enter left child of 2:
+Enter data(-1 for no node: 6
+Enter left child of 6:
+Enter data(-1 for no node: -1
+Enter right child of 6:
+Enter data(-1 for no node: -1
+Enter right child of 2:
+Enter data(-1 for no node: -1
+Enter right child of 1:
+Enter data(-1 for no node: 3
+Enter left child of 3:
+Enter data(-1 for no node: -1
+Enter right child of 3:
+Enter data(-1 for no node: -1
+
+ 1
+ / \
+ 2 3
+ /
+ 6
+
+Output :- 1 3 6
+*/
+
diff --git a/Binary_Tree_Top_View/Binary_Tree_Top_View.c b/Binary_Tree_Top_View/Binary_Tree_Top_View.c
new file mode 100644
index 000000000..be8940cbd
--- /dev/null
+++ b/Binary_Tree_Top_View/Binary_Tree_Top_View.c
@@ -0,0 +1,124 @@
+
+/* C program to print top view of Binary tree*/
+
+#include
+#include
+#include
+
+/* A binary tree node has data, pointer to left child and a pointer to right child */
+struct Node
+{
+ int data;
+ struct Node* left;
+ struct Node* right;
+};
+
+// Inserting elements into Binary Tree
+struct Node *create()
+{
+ Node *ptr;
+ int x;
+
+ printf("Enter data(-1 for no node):");
+ scanf("%d",&x);
+
+ if(x == -1)
+ return NULL;
+
+ ptr = (struct Node*)malloc(sizeof(struct Node));
+ ptr -> data = x;
+
+ printf("Enter left child of %d:\n",x);
+ ptr -> left = create();
+
+ printf("Enter right child of %d:\n",x);
+ ptr -> right = create();
+
+ return ptr;
+}
+
+// Calculating the level and the vertical distance of the node and finding the nodes that appear as the top view
+void findTopView(struct Node *root, int *a, int *b, int level, int dist)
+{
+ if(root == NULL)
+ return;
+
+ if(level < a[50 + dist])
+ {
+ a[50 + dist] = level;
+ b[50 + dist] = root->data;
+ }
+
+ # Recursively calling the left and the right child to get the bottom view
+ findTopView(root->left, a, b, level+1, dist-1);
+
+ findTopView(root->right, a, b, level+1, dist+1);
+}
+
+int *topView(struct Node* root, int *len) {
+
+ int i,o = 0;
+
+ // a stores the level of the node
+ // b stores the Vertical distance of the node from root
+ int *a = (int *)calloc(100, sizeof(int));
+ int *b = (int *)calloc(100, sizeof(int));
+ int *c = (int *)calloc(100, sizeof(int));
+
+ // Initialising a and b as INT_MAX as we need to print top most elements
+ for(i = 0; i < 100; i++)
+ {
+ a[i] = INT_MAX;
+ b[i] = INT_MAX;
+ }
+
+ findTopView(root, a, b, 0, 0);
+
+ for(i = 0; i < 100; i++)
+ {
+ if(b[i] != INT_MAX)
+ c[o++] = b[i];
+ }
+
+ *len = o;
+ return c;
+}
+
+int main()
+{
+ struct Node *root = create();
+ int len = 0;
+ int *res = topView(root, &len);
+
+ for(int i = 0; i < len; i++)
+ printf("%d ", res[i]);
+}
+
+/* Sample Input
+Enter data(-1 for no node: 1
+Enter left child of 1:
+Enter data(-1 for no node: 2
+Enter left child of 2:
+Enter data(-1 for no node: 6
+Enter left child of 6:
+Enter data(-1 for no node: -1
+Enter right child of 6:
+Enter data(-1 for no node: -1
+Enter right child of 2:
+Enter data(-1 for no node: -1
+Enter right child of 1:
+Enter data(-1 for no node: 3
+Enter left child of 3:
+Enter data(-1 for no node: -1
+Enter right child of 3:
+Enter data(-1 for no node: -1
+
+ 1
+ / \
+ 2 3
+ /
+ 6
+
+Output :- 6 2 1 3
+*/
+
From e3e7af5642f7886247345ae7ecae834ab1c3ba2e Mon Sep 17 00:00:00 2001
From: Chand Bud <47664980+chandbud5@users.noreply.github.com>
Date: Sat, 28 Mar 2020 16:26:59 +0530
Subject: [PATCH 045/265] Tower of Hanoi in Kotlin (#2531)
* Add files via upload
* Update Tower_Of_Hanoi.kt
* Update Tower_Of_Hanoi.kt
* Update Tower_Of_Hanoi.kt
* Update Tower_Of_Hanoi.kt
---
Tower_Of_Hanoi/Tower_Of_Hanoi.kt | 44 ++++++++++++++++++++++++++++++++
1 file changed, 44 insertions(+)
create mode 100644 Tower_Of_Hanoi/Tower_Of_Hanoi.kt
diff --git a/Tower_Of_Hanoi/Tower_Of_Hanoi.kt b/Tower_Of_Hanoi/Tower_Of_Hanoi.kt
new file mode 100644
index 000000000..cd1422331
--- /dev/null
+++ b/Tower_Of_Hanoi/Tower_Of_Hanoi.kt
@@ -0,0 +1,44 @@
+/*
+ This is the solution for tower of hanoi problem using recursion implemented in Kotlin
+ Tower of Hanoi is an application of recursion
+ In this our aim is to shift n disks from source tower(peg) to destination tower(peg)
+ We can use third tower as auxilary tower. In it's solution we first try to shift n-1 disks.
+ Minimum number of steps required for this are 2^n-1 where n is number of disks.
+*/
+import java.util.Scanner
+
+fun main() {
+
+ val reader = Scanner(System.`in`)
+ var n:Int = reader.nextInt()
+ solveHanoi(n, 'A', 'C', 'B')
+}
+
+/*
+ n - Number of disks
+ src - Source pole
+ dest - Destination pole
+ aux - Auxiliary pole
+*/
+
+fun solveHanoi(n: Int,src: Char, dest: Char, aux: Char)
+{
+ if(n >= 1)
+ {
+ solveHanoi(n - 1, src, dest, aux)
+ println("Move disk $n from $src to $dest")
+ solveHanoi(n - 1, aux, dest, src)
+ }
+}
+
+/*
+Output:
+ for 3 disks
+ Move disk 1 from A to C
+ Move disk 2 from A to C
+ Move disk 1 from B to C
+ Move disk 3 from A to C
+ Move disk 1 from B to C
+ Move disk 2 from B to C
+ Move disk 1 from A to C
+*/
From a9e22d6f8d8a2b408a82eb4098e6c56a8dcac50b Mon Sep 17 00:00:00 2001
From: Chandrika Deb
Date: Sat, 28 Mar 2020 16:29:37 +0530
Subject: [PATCH 046/265] Added Tower Of Hanoi in PHP (#2577)
* Added Tower Of Hanoi in PHP
* Update Tower_Of_Hanoi.php
---
Tower_Of_Hanoi/Tower_Of_Hanoi.php | 43 +++++++++++++++++++++++++++++++
1 file changed, 43 insertions(+)
create mode 100644 Tower_Of_Hanoi/Tower_Of_Hanoi.php
diff --git a/Tower_Of_Hanoi/Tower_Of_Hanoi.php b/Tower_Of_Hanoi/Tower_Of_Hanoi.php
new file mode 100644
index 000000000..4a28a5272
--- /dev/null
+++ b/Tower_Of_Hanoi/Tower_Of_Hanoi.php
@@ -0,0 +1,43 @@
+/* This is an implementation of Tower Of Hanoi problem in PHP.
+ We have considered 4 disks in this case.
+*/
+
+
+
+/* Sample Output
+
+Move disk 1 from rod A to rod B
+Move disk 2 from rod A to rod C
+Move disk 1 from rod B to rod C
+Move disk 3 from rod A to rod B
+Move disk 1 from rod C to rod A
+Move disk 2 from rod C to rod B
+Move disk 1 from rod A to rod B
+Move disk 4 from rod A to rod C
+Move disk 1 from rod B to rod C
+Move disk 2 from rod B to rod A
+Move disk 1 from rod C to rod A
+Move disk 3 from rod B to rod C
+Move disk 1 from rod A to rod B
+Move disk 2 from rod A to rod C
+Move disk 1 from rod B to rod C
+
+*/
From 51b497cf277fc7f5e68605c2f7d46306805c3034 Mon Sep 17 00:00:00 2001
From: Disha Sinha <42354197+disha2sinha@users.noreply.github.com>
Date: Sat, 28 Mar 2020 16:32:21 +0530
Subject: [PATCH 047/265] Tower of Hanoi in Dart (#2513)
* Tower of Hanoi in Dart
* Update Tower_of_Hanoi.dart
* Update Tower_of_Hanoi.dart
* Update Tower_of_Hanoi.dart
* Add files via upload
* Update Tower_of_Hanoi.dart
* Update Tower_of_Hanoi.dart
* Update Tower_of_Hanoi.dart
---
Tower_Of_Hanoi/Tower_of_Hanoi.dart | 49 ++++++++++++++++++++++++++++++
1 file changed, 49 insertions(+)
create mode 100644 Tower_Of_Hanoi/Tower_of_Hanoi.dart
diff --git a/Tower_Of_Hanoi/Tower_of_Hanoi.dart b/Tower_Of_Hanoi/Tower_of_Hanoi.dart
new file mode 100644
index 000000000..03a2085e1
--- /dev/null
+++ b/Tower_Of_Hanoi/Tower_of_Hanoi.dart
@@ -0,0 +1,49 @@
+/* Tower of Hanoi is a mathematical problem where we have three rods A, B and C and n
+number of disks where n is taken from user in this code.
+The goal of the problem is to transfer the entire stack of disks to another rod,
+obeying the conditions as follows:
+1) Only one disk can be moved at a time.
+2) Each move consists of taking the top disk from one of the stacks and placing
+it on top of another stack.
+3) No disk can be placed on top of a smaller disk. */
+
+import 'dart:io';
+
+void tower (int disks, String beg, String aux, String end)
+{
+ if (disks == 1)
+ {
+ print ("\nMove disk 1 from $beg ---> $end \n") ;
+ return ;
+ }
+ tower (disks - 1, beg, end, aux) ;
+ print ("\nMove disk $disks from $beg ---> $end \n") ;
+ tower (disks - 1, aux, beg, end) ;
+ return ;
+}
+
+main()
+{
+ print ("ENTER NUMBER OF DISCS :\n") ;
+ int disks = int.parse (stdin.readLineSync()) ;
+ tower (disks, "A", "B", "C") ;
+}
+
+/*OUTPUT:
+ENTER NUMBER OF DISCS:
+4
+Move disk 1 from A ---> B
+Move disk 2 from A ---> C
+Move disk 1 from B ---> C
+Move disk 3 from A ---> B
+Move disk 1 from C ---> A
+Move disk 2 from C ---> B
+Move disk 1 from A ---> B
+Move disk 4 from A ---> C
+Move disk 1 from B ---> C
+Move disk 2 from B ---> A
+Move disk 1 from C ---> A
+Move disk 3 from B ---> C
+Move disk 1 from A ---> B
+Move disk 2 from A ---> C
+Move disk 1 from B ---> C */
From 775b4ae122c77584f21fc0800b8f15b3d96d9d67 Mon Sep 17 00:00:00 2001
From: Yashasvi Sinha <59117774+heisastark@users.noreply.github.com>
Date: Sat, 28 Mar 2020 16:35:17 +0530
Subject: [PATCH 048/265] added kadane algo in dart (#2517)
* added kadane algo in dart
* Dynamic Inputs, Comments position changed
1. Code changed to take dynamic inputs
2. Added comments before the code
* Added sample input/output at the end of the file
* Indented return statements properly
* Added Karatsuba Algo in Dart
* Added spaces between operators and Sample I/O
* Deleting mistakenly added file
Karatsuba_Algorithm.dart was accidentally pushed to the my branch that sent for PR. I have removed it now.
---
Kadane_Algorithm/Kandane_Algorithm.dart | 85 +++++++++++++++++++++++++
1 file changed, 85 insertions(+)
create mode 100755 Kadane_Algorithm/Kandane_Algorithm.dart
diff --git a/Kadane_Algorithm/Kandane_Algorithm.dart b/Kadane_Algorithm/Kandane_Algorithm.dart
new file mode 100755
index 000000000..bda39c82e
--- /dev/null
+++ b/Kadane_Algorithm/Kandane_Algorithm.dart
@@ -0,0 +1,85 @@
+/* Dart implementation of Kadane's Algorithm to find the Maximum Subarray Sum
+including the extra phase required when all the numbers in array are negative */
+
+import 'dart:io';
+
+// Function that returns maximum between Two Numbers
+int max(a, b){
+ if(a > b)
+ return a;
+ else
+ return b;
+}
+
+
+// Function implementing Kadane's Algorithm (array contains at least one positive number)
+int kadane( input , n ){
+ int currentmax = 0, maxsofar = 0;
+
+ for( int i = 0; i < n; i++ )
+ {
+ currentmax = max( 0 , currentmax + input[i] );
+ maxsofar = max( maxsofar, currentmax );
+ }
+ return maxsofar;
+}
+
+void main() {
+
+ int maxsubarraysum, size;
+
+ // Input array
+ stdout.write("Enter the number of elements in the array:");
+ String input = stdin.readLineSync();
+ size = int.parse(input);
+ List array = [];
+ for( int i = 0; i < size; i++ )
+ {
+ String x1 = stdin.readLineSync();
+ int x2 = int.parse(x1);
+ array.add(x2);
+ }
+
+ // Size of array
+ int n = array.length;
+
+ // Flag variable to check if all the numbers in array are negative or not
+ int flag = 0;
+
+ // Smallest_negative variable will store the maximum subarray sum if all the numbers are negative in array
+ int largestinnegative = array[0];
+
+ // Scanning each element in array
+ for( int i = 0; i < n; i++ )
+ {
+ // If any element is positive, kadane's algo can be applied
+ if(array[i] >= 0)
+ {
+ flag = 1;
+ break;
+ }
+ else
+ { // If all the elements are negative, find the largest in them
+ if( array[i] > largestinnegative )
+ {
+ largestinnegative = array[i];
+ }
+ }
+ }
+
+ // Kadane's algo applicable
+ if(flag == 1)
+ {
+ maxsubarraysum = kadane( array , n );
+ }
+ else
+ { // Kadane 's algo not applicable,
+ maxsubarraysum = largestinnegative;
+ }
+
+ // hence the max_subarray_sum will be the largest number in array itself
+ print("Maximum Subarray Sum is: $maxsubarraysum");
+}
+
+// sample input = [-2, 1, -6, 4, -1, 2, 1, -5, 4]
+// sample output = Maximum Subarray Sum is: 6
From c2aa357b88156fe35238e66dcb355077cc0f4836 Mon Sep 17 00:00:00 2001
From: Raksha <57195964+raksha009@users.noreply.github.com>
Date: Sat, 28 Mar 2020 22:31:41 +0530
Subject: [PATCH 049/265] Find whether a number is Palindrome or not (#2327)
* EvenOdd Python
* EvenODD python
* pallindrome of string in python
* pallindrome number in python
* Update and rename pallindrome_no.py to palindrome_no.py
Fixed the all the typos
* Delete EvenOdd.py
* Delete pallindrome_string.py
* Update palindrome_no.py
* Update palindrome_no.py
* Update palindrome_no.py
Co-authored-by: samjain2001
---
Palindrome/palindrome_no.py | 34 ++++++++++++++++++++++++++++++++++
1 file changed, 34 insertions(+)
create mode 100644 Palindrome/palindrome_no.py
diff --git a/Palindrome/palindrome_no.py b/Palindrome/palindrome_no.py
new file mode 100644
index 000000000..0f341d47c
--- /dev/null
+++ b/Palindrome/palindrome_no.py
@@ -0,0 +1,34 @@
+# Python program to find whether a number is a palindrome or not
+
+# Function to reverse a number
+def reverse(num):
+ # Initialize variable
+ rev = 0
+
+ while ( num > 0 ) :
+ dig = num % 10
+ rev = rev * 10 + dig
+ num = num // 10
+ # Returning reversed number
+ return rev
+
+# --- main ---
+num = int(input("Enter a number:"))
+a = reverse(num)
+
+# Comparing the reversed number with original number
+if(a == num):
+ print("Number entered is palindrome!")
+else:
+ print("Number entered is not a palindrome!")
+
+'''
+TEST CASES
+INPUT
+Enter a number:3445443
+Number entered is palindrome!
+
+OUTPUT
+Enter a number:234
+Number entered is not a palindrome!
+'''
From 8f170a6b38ae7b19a1a409b46d004c89d59a509d Mon Sep 17 00:00:00 2001
From: Ritish Singh <54978105+ritish099@users.noreply.github.com>
Date: Sun, 29 Mar 2020 15:03:46 +0530
Subject: [PATCH 050/265] Jhonson Algorithm in C# (#2626)
* Jhonson Algorithm in C#
* Update Jhonson.cs
---
Jhonson_Algoritm/Jhonson.cs | 76 +++++++++++++++++++++++++++++++++++++
1 file changed, 76 insertions(+)
create mode 100644 Jhonson_Algoritm/Jhonson.cs
diff --git a/Jhonson_Algoritm/Jhonson.cs b/Jhonson_Algoritm/Jhonson.cs
new file mode 100644
index 000000000..b5a41b194
--- /dev/null
+++ b/Jhonson_Algoritm/Jhonson.cs
@@ -0,0 +1,76 @@
+// C# Program Implementing Jhonson Algorithm.
+
+using System;
+
+namespace ConsoleApp1
+{
+ class Jhonson_Algorithm
+ {
+ public static void Main(String[] args)
+ {
+ int vert, edge, i, j, k, c;
+ int INF = 999999;
+ int[,] cost = new int[10, 10];
+ int[,] adj = new int[10, 10];
+
+ Console.WriteLine("Enter no of vertices: ");
+ vert = Convert.ToInt32(Console.ReadLine());
+ Console.WriteLine("Enter no of Edges: ");
+ edge = Convert.ToInt32(Console.ReadLine());
+ Console.WriteLine("Enter the EDGE cost: ");
+
+ for (k = 1; k <= edge; k++)
+ {
+ //take the input and store it into adj and cost matrix
+ i = Convert.ToInt32(Console.ReadLine());
+ j = Convert.ToInt32(Console.ReadLine());
+ c = Convert.ToInt32(Console.ReadLine());
+ adj[i, j] = cost[i, j] = c;
+ }
+
+ for (i = 1; i <= vert; i++)
+ for (j = 1; j <= vert; j++)
+ {
+ if (adj[i, j] == 0 && i != j)
+ //If its not a edge put infinity
+ adj[i, j] = INF;
+ }
+ for (k = 1; k <= vert; k++)
+ for (i = 1; i <= vert; i++)
+ for (j = 1; j <= vert; j++)
+ //Finding the minimum
+ //find minimum path from i to j through k
+ adj[i, j] = (adj[i, k] + adj[k, j]) > adj[i, j] ? adj[i, j] : (adj[i, k] + adj[k, j]) ;
+ Console.WriteLine("The distance matrix of the graph.\n");
+ // Output the resultant matrix
+ for (i = 1; i <= vert; i++)
+ {
+ for (j = 1; j <= vert; j++)
+ {
+ if (adj[i, j] != INF)
+ Console.Write("{0} ", adj[i,j]);
+ }
+ Console.WriteLine(" ");
+ }
+ }
+ }
+}
+/*Enter no of vertices:
+3
+Enter no of Edges:
+5
+Enter the EDGE cost:
+1 2 8
+
+2 1 12
+
+1 3 22
+
+3 1 6
+
+2 3 4
+The distance matrix of the graph.
+
+0 8 12
+10 0 4
+6 14 0*/
From df04554ca1e8a7347218a521cb09db73bb05ebb2 Mon Sep 17 00:00:00 2001
From: Sabuj Jana
Date: Sun, 29 Mar 2020 15:21:13 +0530
Subject: [PATCH 051/265] Added Topological_Sort.js (Fixes #2159) (#2369)
* Added Topological_Sort.js
* Added Topological_Sort.js
---
Topological_Sort/Topological_Sort.js | 92 ++++++++++++++++++++++++++++
1 file changed, 92 insertions(+)
create mode 100644 Topological_Sort/Topological_Sort.js
diff --git a/Topological_Sort/Topological_Sort.js b/Topological_Sort/Topological_Sort.js
new file mode 100644
index 000000000..b76dfcc1f
--- /dev/null
+++ b/Topological_Sort/Topological_Sort.js
@@ -0,0 +1,92 @@
+// Program to implement Topological Sort
+class Graph {
+ constructor(nodes) {
+ //2 class variables
+ this.nodes = nodes; // no of vertices
+ this.adj = new Array(nodes); // adjacency list
+ for (let i = 0; i < nodes; i++) {
+ this.adj[i] = new Array();
+ }
+ this.stack = []; // a stack for storing the ending times of dfs
+ }
+
+ showGraph = () => {
+ const {
+ nodes,
+ adj
+ } = this; // destructuring for clarity
+
+ for (let i = 0; i < nodes; i++) {
+ // show graph in readable format
+ console.log(`Vertex ${i} is connected to verices `, adj[i]);
+ }
+ };
+
+ addEdge = (x, y) => {
+ const {
+ nodes,
+ adj
+ } = this;
+ // x is connected to y
+ adj[x].push(y);
+ };
+
+ topoSort = () => {
+ const {
+ nodes,
+ adj
+ } = this;
+
+ let visited = new Array(nodes); // visited array
+ for (let i = 0; i < nodes; i++) visited[i] = false;
+
+ for (let i = 0; i < nodes; i++)
+ if (!visited[i]) this.topoUtil(i, visited);
+ };
+
+ topoUtil = (start, visited) => {
+ // utility function of topoSort
+ const {
+ nodes,
+ adj
+ } = this;
+
+ visited[start] = true;
+
+ for (let x of adj[start]) {
+ if (!visited[x]) {
+ this.topoUtil(x, visited);
+ }
+ }
+
+ this.stack.push(start); // push the node when we have completed it
+ };
+}
+
+// implement
+let n = 6; // 6 vertices
+let graph = new Graph(n); // initialise the graph
+
+// add edges
+graph.addEdge(5, 2);
+graph.addEdge(5, 0);
+graph.addEdge(4, 0);
+graph.addEdge(4, 1);
+graph.addEdge(2, 3);
+graph.addEdge(3, 1);
+
+console.log("The Graph is:");
+graph.showGraph();
+
+graph.topoSort();
+console.log(`The Topological sort is `, graph.stack.reverse());
+
+// Output:
+// The Graph is:
+// Vertex 0 is connected to verices []
+// Vertex 1 is connected to verices []
+// Vertex 2 is connected to verices [ 3 ]
+// Vertex 3 is connected to verices [ 1 ]
+// Vertex 4 is connected to verices [ 0, 1 ]
+// Vertex 5 is connected to verices [ 2, 0 ]
+// The topological sort is [ 5, 4, 2, 3, 1, 0 ]
From 49d53689f40edc8d26c5ac9694311b8525c4c947 Mon Sep 17 00:00:00 2001
From: Raksha <57195964+raksha009@users.noreply.github.com>
Date: Sun, 29 Mar 2020 17:42:22 +0530
Subject: [PATCH 052/265] Addition of matrix in java (#2527)
updated
---
Matrix_Operations/Java/Matrix_Addition.java | 108 ++++++++++++++++++++
1 file changed, 108 insertions(+)
create mode 100644 Matrix_Operations/Java/Matrix_Addition.java
diff --git a/Matrix_Operations/Java/Matrix_Addition.java b/Matrix_Operations/Java/Matrix_Addition.java
new file mode 100644
index 000000000..63c9d71ed
--- /dev/null
+++ b/Matrix_Operations/Java/Matrix_Addition.java
@@ -0,0 +1,108 @@
+// Java Program to calculation sum of 2 matrices (2D Array)
+import java.util.*;
+
+public class Matrix_Addition {
+ // Find sum of 2 Matrices and store it in matrix3
+ public static void add_matrices(int[][] matrix1, int[][] matrix2) {
+
+ int index1, index2 = 0;
+ int[][] matrix3 = new int[matrix1.length][matrix1[0].length];
+
+ for ( index1 = 0; index1 < matrix1.length ; index1 ++) {
+ for ( index2 = 0; index2 < matrix1[0].length; index2++ ) {
+ matrix3[index1][index2] = matrix1[index1][index2] + matrix2[index1][index2];
+ }
+ }
+
+ // Print the calculated matrix
+ for ( index1 = 0; index1 < matrix3.length ; index1 ++) {
+ for ( index2 = 0; index2 < matrix3[0].length; index2++ ) {
+ System.out.print( matrix3[index1][index2] + " ");
+ }
+ System.out.println();
+ }
+ }
+
+ public static void main(String args[]) {
+ Scanner s = new Scanner(System.in);
+
+ System.out.println("Of First Matrix");
+ System.out.println(" Enter number of rows ");
+ int rows_first = s.nextInt();
+
+ System.out.println(" Enter number of columns ");
+ int columns_first = s.nextInt();
+ int[][] matrix1 = new int[rows_first][columns_first];
+
+ System.out.println("Of Second Matrix");
+ System.out.println(" Enter number of rows ");
+ int rows_second = s.nextInt();
+
+ System.out.println(" Enter number of columns ");
+ int columns_second = s.nextInt();
+ int[][] matrix2 = new int[rows_second][columns_second];
+
+ if (columns_first != columns_second || rows_first != rows_second) {
+ System.out.println(" Addition of matrix is not possible ");
+ }
+ else {
+
+ System.out.println(" Enter elements of 1st matrix ");
+ for (int i = 0 ; i < rows_first; i++) {
+ for (int j = 0 ; j< columns_first; j++) {
+ matrix1[i][j] = s.nextInt();
+ }
+ }
+
+ System.out.println(" Enter elements of 2nd matrix ");
+ for (int i = 0 ; i < rows_first; i++) {
+ for (int j = 0 ; j< columns_first; j++) {
+ matrix2[i][j] = s.nextInt();
+ }
+ }
+ add_matrices(matrix1, matrix2);
+ }
+ }
+}
+
+/*
+TEST CASES
+INPUT
+Of First Matrix
+Enter number of rows
+2
+Enter number of columns
+3
+Of Second Matrix
+Enter number of rows
+2
+Enter number of columns
+4
+OUTPUT
+Addition of matrix is not possible
+INPUT
+Of First Matrix
+Enter number of rows
+2
+Enter number of columns
+2
+Of Second Matrix
+Enter number of rows
+2
+Enter number of columns
+2
+Enter elements of 1st matrix
+1
+2
+3
+4
+Enter elements of 2nd matrix
+1
+1
+1
+1
+OUTPUT
+2 3
+4 5
+*/
+
From 39bbc04246cc62e5ce6f3f6bc229c14afd9587f7 Mon Sep 17 00:00:00 2001
From: VIJAY07102 <44638395+VIJAY07102@users.noreply.github.com>
Date: Mon, 30 Mar 2020 19:45:04 +0530
Subject: [PATCH 053/265] Priority_Queue.py
Priority_Queue
---
Priority_Queue/Priority_Queue.py | 65 ++++++++++++++++++++++++++++++++
1 file changed, 65 insertions(+)
create mode 100644 Priority_Queue/Priority_Queue.py
diff --git a/Priority_Queue/Priority_Queue.py b/Priority_Queue/Priority_Queue.py
new file mode 100644
index 000000000..eff1b80fd
--- /dev/null
+++ b/Priority_Queue/Priority_Queue.py
@@ -0,0 +1,65 @@
+queue = []
+
+def insert(data): # To insert values into the Queue
+ queue.append(data)
+
+def delete(): # TO remove value from the Priority Queue
+ try: # Here highest value will be deleted first
+ max = 0
+ for i in range(len(queue)):
+ if queue[i] > queue[max]:
+ max = i
+
+ item = queue[max]
+ del queue[max]
+
+ return item
+
+ except IndexError: # Instead of giving error for empty queue
+ print("Queue is empty!!") # Displays that 'Queue is empty'
+
+while 1:
+
+ print("\t1. Insert value in queue\n\t2. Delete value in queue\n\t3. Print Queue\n\t4. Exit")
+
+ opt = int(input("Enter your option:"))
+
+ if opt == 1:
+ value = int(input("Enter the value:"))
+ insert(value)
+
+ elif opt == 2:
+ del_value = delete()
+ print("\n" + str(del_value) + " is deleted")
+
+ elif opt == 3:
+ print(queue)
+
+ elif opt == 4:
+ break
+
+ else:
+ print("\tInvalid option!\n\tTry Again!!")
+
+# The program is made of user choice
+'''
+Example:
+ 1. Insert value in queue
+ 2. Delete value in queue
+ 3. Print Queue
+ 4. Exit
+Enter your option: 1 # Here you have to give value to be inserted in the queue
+Enter the value: 12
+ 1. Insert value in queue
+ 2. Delete value in queue
+ 3. Print Queue
+ 4. Exit
+Enter your option:2 # To delete the value of highest priority(here highest value)
+14 is deleted
+Enter your option:3 # display the queue
+[12, 1, 7]
+Enter your option:4 #to exit
+If you enter any other value other than (1,2,3,4), You will be shown:
+ Invalid option!
+ Try Again!!
+'''
From f47d1b73611295bd2727a978d3078a194855a0fb Mon Sep 17 00:00:00 2001
From: "Abhushan A. Joshi" <49617450+abhu-A-J@users.noreply.github.com>
Date: Wed, 1 Apr 2020 00:26:18 +0530
Subject: [PATCH 054/265] Added implementation of Z-Algorithm in JS (#2607)
---
Z_Algorithm/Z_Algorithm.js | 102 +++++++++++++++++++++++++++++++++++++
1 file changed, 102 insertions(+)
create mode 100644 Z_Algorithm/Z_Algorithm.js
diff --git a/Z_Algorithm/Z_Algorithm.js b/Z_Algorithm/Z_Algorithm.js
new file mode 100644
index 000000000..351dca2a5
--- /dev/null
+++ b/Z_Algorithm/Z_Algorithm.js
@@ -0,0 +1,102 @@
+/*
+Z algorithm is a linear time string matching algorithm which runs in complexity.
+It is used to find all occurrence of a pattern in a string , which is common
+string searching problem.
+*/
+
+const setZArray = combined => {
+
+ // Initiate zArray and fill it with zeros.
+ const zArray = Array.from({ length: combined.length }, () => 0);
+
+ // Z box boundaries.
+ let leftIndex = 0, rightIndex = 0, shift = 0;
+
+ // Go through all characters of the zString.
+ for (let i = 1; i < combined.length; i += 1) {
+
+ if (i > rightIndex) {
+
+ leftIndex = i;
+ rightIndex = i;
+
+ while (
+ rightIndex < combined.length
+ && combined[rightIndex - leftIndex] === combined[rightIndex]
+ ) {
+
+ // Expanding Z box right boundary.
+ rightIndex += 1;
+ }
+
+
+ zArray[i] = rightIndex - leftIndex;
+ rightIndex -= 1;
+
+ }
+
+ else {
+
+ // Calculate corresponding Z box shift.
+ shift = i - leftIndex;
+
+ // Check if the value that has been already calculated before
+ if (zArray[shift] < (rightIndex - i) + 1) {
+
+ zArray[i] = zArray[shift];
+ }
+ else {
+
+ // shift left boundary of Z box to current position.
+ leftIndex = i;
+
+ // And start comparing characters one by one as we normally do for the case
+ while (
+ rightIndex < combined.length
+ && combined[rightIndex - leftIndex] === combined[rightIndex]
+ ) {
+ rightIndex += 1;
+ }
+
+ zArray[i] = rightIndex - leftIndex;
+
+ rightIndex -= 1;
+ }
+ }
+ }
+
+ // Return generated zArray.
+ return zArray;
+}
+
+
+zAlgorithm = (text, word) => {
+
+ const wordPositions = [];
+
+ // Concatenate word and text. Word will be a prefix to a text.
+ const zString = `${word}$${text}`;
+
+ // Generate Z-array for concatenated string.
+ const zArray = setZArray(zString);
+
+ for (let i = 1; i < zArray.length; i += 1) {
+ if (zArray[i] === word.length) {
+
+ const wordPosition = i - word.length - 1;
+ wordPositions.push(wordPosition);
+ }
+ }
+
+ // Return the list of word positions.
+ return wordPositions;
+}
+
+
+// I/O and O/P Examples:
+
+// The postions are: [0,10,16]
+console.log(zAlgorithm("omgawesomeomgsftomg", "omg"));
+
+// The positions are: [3,12]
+console.log(zAlgorithm("ohelloworldello", "llo"));
From faf814b4081e7aaba2ab884464bdbcb521410cae Mon Sep 17 00:00:00 2001
From: HIMANSHU SHARMA
Date: Wed, 1 Apr 2020 22:04:44 +0530
Subject: [PATCH 055/265] Created Pancake Sort in C# (#2309)
* Create Pancake_Sort.cs
* Update Pancake_Sort.cs
* Update Pancake_Sort.cs
* Update Pancake_Sort.cs
* Update Pancake_Sort.cs
* Update Pancake_Sort.cs
* Update Pancake_Sort.cs
* Update Pancake_Sort.cs
* Update Pancake_Sort.cs
* Update Pancake_Sort.cs
* Update Pancake_Sort.cs
* Update Pancake_Sort.cs
---
Pancake_Sort/Pancake_Sort.cs | 78 ++++++++++++++++++++++++++++++++++++
1 file changed, 78 insertions(+)
create mode 100644 Pancake_Sort/Pancake_Sort.cs
diff --git a/Pancake_Sort/Pancake_Sort.cs b/Pancake_Sort/Pancake_Sort.cs
new file mode 100644
index 000000000..14fcf9212
--- /dev/null
+++ b/Pancake_Sort/Pancake_Sort.cs
@@ -0,0 +1,78 @@
+using System;
+
+class pancakeSortProgram {
+ // function swapping adjacent integer in array till from index 0 toindex i
+ static void flip(int []arr, int i)
+ {
+ int temp, start = 0;
+ while (start < i)
+ {
+ temp = arr[start];
+ arr[start] = arr[i];
+ arr[i] = temp;
+ start++;
+ i--;
+ }
+ }
+ // function returning index of max value till index curr_size
+ static int findMax(int []arr, int n)
+ {
+ int mi, i;
+ for (mi = 0, i = 0; i < n; ++i)
+ if (arr[i] > arr[mi])
+ mi = i;
+ return mi;
+ }
+
+ static int pancakeSort(int []arr, int n)
+ {
+ for (int curr_size = n; curr_size > 1; --curr_size)
+ {
+ // function calling for finding index of max integer
+ // till the index curr_size
+ int mi = findMax(arr, curr_size);
+ // call function flip for swapping if index of max integer
+ // till the index curr_size is not equal to curr_size-1
+ if (mi != curr_size - 1)
+ {
+ flip(arr, mi);
+ flip(arr, curr_size - 1);
+ }
+ }
+ return 0;
+ }
+ // function for printing sorted array
+ static void printArray(int []arr, int arr_size)
+ {
+ for (int i = 0; i < arr_size; i++)
+ Console.Write(arr[i] + " ");
+ Console.Write("");
+ }
+
+ public static void Main (string [] args)
+ {
+ int n = Convert.ToInt32(Console.ReadLine());//input size of array
+ int []arr = new int[n];//initializing array of size n
+
+ for(int i = 0; i < n; i++)
+ arr[i] = Convert.ToInt32(Console.ReadLine());//input value in array
+
+ pancakeSort(arr, n);// call function which is sorting the input array
+ Console.Write("Sorted Array: ");
+ printArray(arr, n);// call fubction which print the sorted array
+ }
+}
+/*
+Input:
+6
+23
+10
+20
+11
+12
+6
+7
+
+Output:
+Sorted Array: 6 7 10 11 12 20 23
+*/
From 23261ceda1e6c15dd947b201a795d025c54d687e Mon Sep 17 00:00:00 2001
From: PrachieNaik <42534757+PrachieNaik@users.noreply.github.com>
Date: Wed, 1 Apr 2020 22:27:45 +0530
Subject: [PATCH 056/265] Create Tree_Preorder_Traversal.kt (#2585)
* Create Tree_Preorder_Traversal.kt
* Update Tree_Preorder_Traversal.kt
Taking dynamic input
---
.../Tree_Preorder_Traversal.kt | 50 +++++++++++++++++++
1 file changed, 50 insertions(+)
create mode 100644 Tree_Preorder_Traversal/Tree_Preorder_Traversal.kt
diff --git a/Tree_Preorder_Traversal/Tree_Preorder_Traversal.kt b/Tree_Preorder_Traversal/Tree_Preorder_Traversal.kt
new file mode 100644
index 000000000..18bef0bd6
--- /dev/null
+++ b/Tree_Preorder_Traversal/Tree_Preorder_Traversal.kt
@@ -0,0 +1,50 @@
+import java.util.*
+class Node(
+ var key:Int,
+ var left:Node? = null,
+ var right:Node? = null
+)
+{
+ fun preorderTraversal()
+ {
+ print("$key ")
+ left?.preorderTraversal()
+ right?.preorderTraversal()
+ }
+}
+
+fun main() {
+ var read = Scanner(System.`in`)
+ println("Enter the size of Array:")
+ val arrSize = read.nextLine().toInt()
+ var arr = IntArray(arrSize)
+ val nodes = mutableListOf>()
+ println("Enter the array respresentaion of binary tree")
+ for(i in 0 until arrSize)
+ {
+ arr[i] = read.nextLine().toInt()
+ nodes.add(Node(arr[i]))
+ }
+ for(i in 0..arrSize-2)
+ {
+ if((i*2)+1
Date: Wed, 1 Apr 2020 22:52:02 +0530
Subject: [PATCH 057/265] add kosaraju algorithm in cpp (#2672)
* add kosaraju algorithm in cpp
* Update kosaraju_algorithm.cpp
---
kosaraju_algorithm/kosaraju_algorithm.cpp | 105 ++++++++++++++++++++++
1 file changed, 105 insertions(+)
create mode 100644 kosaraju_algorithm/kosaraju_algorithm.cpp
diff --git a/kosaraju_algorithm/kosaraju_algorithm.cpp b/kosaraju_algorithm/kosaraju_algorithm.cpp
new file mode 100644
index 000000000..8b969d461
--- /dev/null
+++ b/kosaraju_algorithm/kosaraju_algorithm.cpp
@@ -0,0 +1,105 @@
+//Strongly connected components(KOSARAJU ALGORITHM)
+#include
+#include
+#include
+#include
+using namespace std;
+
+//dfs to store vertices in a stack as per their finish time
+void dfs(vector* edges, int start, unordered_set &visited, stack &finishStack) {
+ visited.insert(start);
+ for (int i = 0; i < edges[start].size(); i++) {
+ int adjacent = edges[start][i];
+ if (visited.count(adjacent) == 0) {
+ dfs(edges, adjacent, visited, finishStack);
+ }
+ }
+ finishStack.push(start);
+}
+
+//dfs of a transpose graph
+void dfs2(vector* edges, int start, unordered_set* component, unordered_set & visited) {
+ visited.insert(start);
+ component->insert(start);
+ for (int i = 0; i < edges[start].size(); i++) {
+ int adjacent = edges[start][i];
+ if (visited.count(adjacent) == 0) {
+ dfs2(edges, adjacent, component, visited);
+ }
+ }
+}
+
+unordered_set*>* getSCC(vector* edges, vector* edgesT, int n) {
+ unordered_set visited;
+ stack finishedVertices;
+ for (int i = 0; i < n; i++) {
+ if (visited.count(i) == 0) {
+ dfs(edges, i, visited, finishedVertices);
+ }
+ }
+ unordered_set*>* output = new unordered_set*>();
+ visited.clear();
+ while (finishedVertices.size() != 0) {
+ int element = finishedVertices.top();
+ finishedVertices.pop();
+ if (visited.count(element) != 0) {
+ continue;
+ }
+ unordered_set* component = new unordered_set();
+ dfs2(edgesT, element, component, visited);
+ output->insert(component);
+ }
+ return output;
+}
+
+int main() {
+ int n; //no.of vertices
+ cout<<"Enter the no. of vertices : "<> n;
+ vector* edges = new vector[n]; //using a adjacency list to implement
+ vector* edgesT = new vector[n]; //transpose of a graph
+ int m; // no.of edges
+ cout<<"Enter the no. of edges : "<> m;
+
+ for (int i = 0; i < m; i++) {
+ int j, k;
+ cin >> j >> k;
+ edges[j - 1].push_back(k - 1);
+ edgesT[k - 1].push_back(j - 1);
+ }
+
+ unordered_set*>* components = getSCC(edges, edgesT, n);
+ unordered_set*>::iterator it = components->begin();
+
+ while (it != components->end()) {
+ unordered_set* component = *it;
+ unordered_set::iterator it2 = component->begin();
+ while (it2 != component->end()) {
+ cout <<*it2 + 1<< " ";
+ it2++;
+ }
+ cout << endl;
+ delete component;
+ it++;
+ }
+
+ delete components;
+ delete [] edges;
+ delete [] edgesT;
+}
+
+/*INPUTS
+Enter the no. of vertices : 6
+Enter the no. of edges :7
+1 2
+2 3
+3 4
+4 1
+3 5
+5 6
+6 5
+
+OUTPUT
+6 5
+2 3 4 1 */
From 2e9f2ac3386740ef3693cae6211e9a9f81adb526 Mon Sep 17 00:00:00 2001
From: j-shreya <53999364+j-shreya@users.noreply.github.com>
Date: Wed, 1 Apr 2020 23:28:08 +0530
Subject: [PATCH 058/265] Aggressive cows (#2543)
* Create GENERIC_TREE_LOTRAVERSAL.java
* Update GENERIC_TREE_LOTRAVERSAL.java
* Revert "Update GENERIC_TREE_LOTRAVERSAL.java"
This reverts commit dfdd3095201cbf35c1ee673a6332a0eaf4960a88.
* Revert "Create GENERIC_TREE_LOTRAVERSAL.java"
This reverts commit 2c87bbb08c1e7f312d3e9410b7ff5423d25f1458.
* Create Aggressive_Cows.java
* Update Aggressive_Cows.java
1. Multi comments made
2. Extra spaces and lines removed
3. Indentation corrected
---
Aggressive_Cows/Aggressive_Cows.java | 76 ++++++++++++++++++++++++++++
1 file changed, 76 insertions(+)
create mode 100644 Aggressive_Cows/Aggressive_Cows.java
diff --git a/Aggressive_Cows/Aggressive_Cows.java b/Aggressive_Cows/Aggressive_Cows.java
new file mode 100644
index 000000000..1cdb49723
--- /dev/null
+++ b/Aggressive_Cows/Aggressive_Cows.java
@@ -0,0 +1,76 @@
+import java.util.Arrays;
+import java.util.Scanner;
+
+public class Aggressive_Cows {
+
+ public static void main(String[] args) {
+
+ /* in this problem we have to maximise the minimum distance between the
+ * cows since minimum distance is being linearly checked we apply
+ * binary search on minimum distance */
+
+ Scanner scn = new Scanner(System.in);
+ int nos = scn.nextInt(); // input for no. of stalls
+ int noc = scn.nextInt(); // input for no. of cows
+
+ int[] arr = new int[nos]; // storing the position of stalls in an array
+
+ for (int i = 0; i < arr.length; i++) {
+ arr[i] = scn.nextInt();
+ }
+
+ Arrays.sort(arr); // to sort the positions of stalls in ascending order
+
+ int finalAns = 0;
+
+ int lo = 0;
+ int hi = arr[arr.length - 1] - arr[0];
+
+ while (lo <= hi) {
+
+ int mid = (lo + hi) / 2;
+
+ if (isItPossible(nos, noc, arr, mid)) {
+
+ finalAns = mid;
+ lo = mid + 1;
+
+ }else{
+ hi = mid - 1;
+ }
+ }
+
+ System.out.println(finalAns);
+
+ }
+
+ // function to check if a particular arrangement of cows is possible or not
+ private static boolean isItPossible(int nos, int noc, int[] arr, int mid) {
+
+ int cowsPlaced = 1;
+ int lastCowPos = arr[0]; // position at which cow is placed
+
+ for (int i = 1; i < arr.length; i++) {
+
+ if (arr[i] - lastCowPos >= mid) {
+ cowsPlaced++;
+ lastCowPos = arr[i];
+
+ if (cowsPlaced == noc) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+}
+
+// SAMPLE INPUT: 5 3
+// 1
+// 2
+// 8
+// 4
+// 9
+//
+// Output:
+// 3
From 4a4737dd8a6ecb9301fb2394b6b6a588e46c7949 Mon Sep 17 00:00:00 2001
From: shreya kapoor <31164665+shreyakapoor08@users.noreply.github.com>
Date: Thu, 2 Apr 2020 16:40:17 +0530
Subject: [PATCH 059/265] Logistic Regression in Python (#2636)
---
.../Logistic_Regression.ipynb | 418 ++++++++++++++++++
1 file changed, 418 insertions(+)
create mode 100644 Machine_Learning/Logistic_Regression/Logistic_Regression.ipynb
diff --git a/Machine_Learning/Logistic_Regression/Logistic_Regression.ipynb b/Machine_Learning/Logistic_Regression/Logistic_Regression.ipynb
new file mode 100644
index 000000000..669cfdb7f
--- /dev/null
+++ b/Machine_Learning/Logistic_Regression/Logistic_Regression.ipynb
@@ -0,0 +1,418 @@
+{
+ "cells": [
+ {
+ "cell_type": "code",
+ "execution_count": 1,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "import numpy as np\n",
+ "import matplotlib.pyplot as plt\n",
+ "import pandas as pd\n",
+ "%matplotlib inline"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 2,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "plt.style.use('seaborn')"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 3,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "(500, 2)\n",
+ "(500, 2)\n"
+ ]
+ }
+ ],
+ "source": [
+ "mean_01 = np.array([1,0.5])\n",
+ "cov_01 = np.array([[1,0.1],[0.1,1.2]])\n",
+ "\n",
+ "mean_02 = np.array([4,5])\n",
+ "cov_02 = np.array([[1.21,0.1],[0.1,1.3]])\n",
+ "\n",
+ "\n",
+ "# Normal Distribution\n",
+ "dist_01 = np.random.multivariate_normal(mean_01,cov_01,500)\n",
+ "dist_02 = np.random.multivariate_normal(mean_02,cov_02,500)\n",
+ "\n",
+ "print(dist_01.shape)\n",
+ "print(dist_02.shape)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 4,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "image/png": "iVBORw0KGgoAAAANSUhEUgAAAfIAAAFcCAYAAAAzhzxOAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjAsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+17YcXAAAgAElEQVR4nOydeXgUZdb27+7q6iUbSSCAJCxhdRsdXnVwxwW3mXdGHRccRhREYWSU0c/XmWGUccFxRsQwBgUlSFAgbGFVlE0goAQUiCgRCLuyKNk7W2/V/f1RXZWqrqXXdLbzu65c2lXVTz1V3fSpc55z7mPw+Xw+EARBEATRLjG29gQIgiAIgogcMuQEQRAE0Y4hQ04QBEEQ7Rgy5ARBEATRjiFDThAEQRDtGDLkBEEQBNGOaVFDXlZWhhEjRmDhwoUAgHPnzmH06NEYNWoU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ZyIiIiFePUOhERkYoxkBMREakYAzkREZGKMZATERGpGAM5ERGRijGQExERqRgDORERkYoxkBMREanY/wf3vEcdEwZ9KAAAAABJRU5ErkJggg==\n",
+ "text/plain": [
+ ""
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ }
+ ],
+ "source": [
+ "plt.figure(0)\n",
+ "\n",
+ "plt.scatter(dist_01[:,0],dist_01[:,1],label='Class 0')\n",
+ "plt.scatter(dist_02[:,0],dist_02[:,1],color='r',marker='^',label='Class 1')\n",
+ "plt.xlim(-5,10)\n",
+ "plt.ylim(-5,10)\n",
+ "plt.xlabel('x1')\n",
+ "plt.ylabel('x2')\n",
+ "plt.legend()\n",
+ "plt.show()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 5,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "(500, 1)\n",
+ "(500, 1)\n",
+ "(1000, 3)\n"
+ ]
+ }
+ ],
+ "source": [
+ "y1 = np.zeros((500,1))\n",
+ "print(y1.shape)\n",
+ "\n",
+ "y2 = np.ones((500,1))\n",
+ "print(y2.shape)\n",
+ "\n",
+ "data1 = np.hstack((dist_01,y1))\n",
+ "data2 = np.hstack((dist_02,y2))\n",
+ "data = np.vstack((data1,data2))\n",
+ "\n",
+ "print(data.shape)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 6,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "[[ 4.61546313 2.66193635 1. ]\n",
+ " [ 4.14312954 4.21854945 1. ]\n",
+ " [ 3.5360558 5.44785463 1. ]\n",
+ " [-0.30283189 1.49333376 0. ]\n",
+ " [ 3.78745303 6.42600424 1. ]\n",
+ " [ 1.88347777 4.75120101 1. ]\n",
+ " [ 4.62331128 4.57041199 1. ]\n",
+ " [ 3.25889833 6.95708425 1. ]\n",
+ " [ 0.8891156 -1.34359916 0. ]\n",
+ " [ 3.17329477 3.51864788 1. ]]\n"
+ ]
+ }
+ ],
+ "source": [
+ "np.random.shuffle(data)\n",
+ "print(data[:10])"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 7,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "split = int(0.8*data.shape[0])"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 8,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "(800, 2) (200, 2)\n",
+ "(800,) (200,)\n"
+ ]
+ }
+ ],
+ "source": [
+ "X_train = data[:split,:-1]\n",
+ "X_test = data[split:,:-1]\n",
+ "\n",
+ "Y_train = data[:split,-1]\n",
+ "Y_test = data[split:,-1]\n",
+ "\n",
+ "print(X_train.shape,X_test.shape)\n",
+ "print(Y_train.shape,Y_test.shape)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 9,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "def hypothesis(x,w,b):\n",
+ " '''accepts input vector x, input weight vector w and bias b'''\n",
+ " \n",
+ " h = np.dot(x,w) + b\n",
+ " return sigmoid(h)\n",
+ "\n",
+ "def sigmoid(z):\n",
+ " return 1.0/(1.0 + np.exp(-1.0*z))\n",
+ "\n",
+ "def error(y_true,x,w,b):\n",
+ " \n",
+ " m = x.shape[0]\n",
+ " \n",
+ " err = 0.0\n",
+ " \n",
+ " for i in range(m):\n",
+ " hx = hypothesis(x[i],w,b) \n",
+ " err += y_true[i]*np.log2(hx) + (1-y_true[i])*np.log2(1-hx)\n",
+ " \n",
+ " \n",
+ " return -err/m\n",
+ "\n",
+ "\n",
+ "def get_grads(y_true,x,w,b):\n",
+ " \n",
+ " grad_w = np.zeros(w.shape)\n",
+ " grad_b = 0.0\n",
+ " \n",
+ " m = x.shape[0]\n",
+ " \n",
+ " for i in range(m):\n",
+ " hx = hypothesis(x[i],w,b)\n",
+ " \n",
+ " grad_w += -1*(y_true[i] - hx)*x[i]\n",
+ " grad_b += -1*(y_true[i]-hx)\n",
+ " \n",
+ " \n",
+ " grad_w /= m\n",
+ " grad_b /= m\n",
+ " \n",
+ " return [grad_w,grad_b] #returning python list\n",
+ "\n",
+ "\n",
+ "# One Iteration of Gradient Descent\n",
+ "def grad_descent(x,y_true,w,b,learning_rate=0.1):\n",
+ " \n",
+ " err = error(y_true,x,w,b)\n",
+ " [grad_w,grad_b] = get_grads(y_true,x,w,b)\n",
+ " \n",
+ " w = w - learning_rate*grad_w\n",
+ " b = b - learning_rate*grad_b\n",
+ " \n",
+ " return err,w,b\n",
+ " \n",
+ "def predict(x,w,b):\n",
+ " \n",
+ " confidence = hypothesis(x,w,b)\n",
+ " if confidence<0.5:\n",
+ " return 0\n",
+ " else:\n",
+ " return 1\n",
+ " \n",
+ "def accuracy(x_tst,y_tst,w,b):\n",
+ " \n",
+ " y_pred = []\n",
+ " \n",
+ " for i in range(y_tst.shape[0]):\n",
+ " p = predict(x_tst[i],w,b)\n",
+ " y_pred.append(p)\n",
+ " \n",
+ " y_pred = np.array(y_pred)\n",
+ " \n",
+ " return float((y_pred==y_tst).sum())/y_tst.shape[0]\n",
+ " \n",
+ " \n",
+ " "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 10,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "loss = []\n",
+ "acc = []\n",
+ "\n",
+ "W = 2*np.random.random((X_train.shape[1],))\n",
+ "b = 5*np.random.random()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 11,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "for i in range(300):\n",
+ " l,W,b = grad_descent(X_train,Y_train,W,b,learning_rate=0.5)\n",
+ " acc.append(accuracy(X_test,Y_test,W,b))\n",
+ " loss.append(l)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 12,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "image/png": "iVBORw0KGgoAAAANSUhEUgAAAe8AAAFYCAYAAAB6R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b78FAHz11Vfo1q0bOnTogMuXL+PixYsAgIyMDPTt2xcxMTGIjo7GsWPHAAAbNmzApk2blPlCRBrGnjeRRvTu3Ru//OUvMWXKFJhMJsTFxeHuu++G3W7H1q1b8eKLL0KSJLz88ssICwvDsmXL8OSTT8JoNMJisWDZsmUAgFWrVmH58uXQ6/WwWq1YtWoVPv30U4W/HZG28K5iRBqWnZ2NyZMnY8+ePUqXQkS3gMPmREREKsOeNxERkcqw501ERKQyDG8iIiKVYXgTERGpDMObiIhIZRjeREREKsPwJiIiUpn/D2VphtOdPEZHAAAAAElFTkSuQmCC\n",
+ "text/plain": [
+ ""
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ }
+ ],
+ "source": [
+ "plt.plot(loss)\n",
+ "plt.ylabel(\"negative of log likelihood\")\n",
+ "plt.xlabel(\"epoch\")\n",
+ "plt.show()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 13,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "image/png": "iVBORw0KGgoAAAANSUhEUgAAAe8AAAFYCAYAAAB6RnQAAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjAsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+17YcXAAAgAElEQVR4nO3df3RU9Z3/8ddkJr9/T5gJQsAEhAYCuEbEpVRUCmyL2x/a1Wa71B/4q8cf6+lKtxo9S9UCWrHaY/fsiivneBAwR0tP9Wst1lZriylY0QhBRdBAAkhm8mPIJJOfc79/BKaMJGGAuXNnMs/HOZ6TO7/yzptrXvncz733YzMMwxAAAEgYKVYXAAAATg/hDQBAgiG8AQBIMIQ3AAAJhvAGACDBEN4AACQYh5kfvmfPHt122226/vrrtXTp0rDn3n77bf385z+X3W7X/Pnzdfvtt4/4WR5PR1RrKyzMUltbV1Q/M5HRj3D0Ixz9CEc/wtGPcNHsh8uVO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3OoygKRBeAMAkGCS/t7mQDJZv369Xn31VQ0MDGjSpEm66aabdOutt2r+/Pn66KOPJEmPP/64iouL9eabb+q///u/lZGRoczMTD300EMqLi5WXV2dVq1apdTUVOXn5+uRRx6R9Peb/+zbt0/jxo3TL3/5S9lsNit/XGDUYuQNJIkPPvhAv//977VhwwbV1NQoNzdXb7/9thobG3XVVVdp48aNmjNnjtatW6dAIKD7779fTz75pNavX6/58+friSeekCT96Ec/0kMPPaTnnntOF110kf70pz9JGlyp7qGHHtLmzZv1ySefqL6+3sofFxjVGHkDSWLbtm06cOCArr32WklSV1eXjhw5ooKCAs2YMUOSVFlZqWeffVYNDQ0qKirS2LFjJUlz5szR888/r9bWVh09elRTp06VJF1//fWSBue8Z86cqczMTEmDi990dHTE+CcEkgfhDSSJtLQ0LViwQP/1X/8VeqypqUlXXXVVaNswDNlstpMOd5/4+HB3VLbb7Se9B4A5OGwOJInKykq99dZb6uzslCRt2LBBHo9HPp9Pu3fvliTt2LFDX/rSl1RaWqqWlhYdOnRIklRbW6vzzz9fhYWFKigo0AcffCBJWrdunTZs2GDNDwQkMUbeQJKYOXOm/u3f/k3f//73lZ6eLrfbrYsvvljFxcXavHmzHn74YRmGoZ///OfKyMjQypUr9cMf/lBpaWnKysrSypUrJUmPPvqoVq1aJYfDodzcXD366KN67bXXLP7pgOTCqmJAEmtqatL3vvc9vfXWW1aXAuA0cNgcAIAEw8gbAIAEw8gbAIAEQ3gDAJBgCG8AABIM4Q0AQIIhvAEASDD/H0oQ082/kubpAAAAAElFTkSuQmCC\n",
+ "text/plain": [
+ ""
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "0.98\n"
+ ]
+ }
+ ],
+ "source": [
+ "plt.plot(acc)\n",
+ "plt.ylabel(\"accuracy\")\n",
+ "plt.xlabel(\"epoch\")\n",
+ "plt.show()\n",
+ "print(acc[-1])"
+ ]
+ },
+ {
+ "cell_type":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7G4sXL8b8+fNhMpmwbNkyfzfJ486dO4e33noLN27cgEwmw44dO/CXv/wFL730EnJzc5GUlITMzEzea9AxpoQQQkgQC82vcYQQQkiYoEBOCCGEBDEK5IQQQkgQo0BOCCGEBDEK5IQQQkgQo0BOCGH1+eefY+TIkTh8+LC/m0II4UGBnBDSSUFBAc6dO4ehQ4f6uymEEBcokBMS5v7973/jlVdeAQBcvnwZ06dPx9SpU/GnP/0pJMv1EhJqKJATEuYee+wx/PTTTzh+/DheffVVvPbaayFdm52QUEOBnJAwxzAMVqxYgWeffRaDBw/G7bff7u8mEUJEoEBOCEFdXR0iIyNx8+ZNfzeFECISBXJCwpzBYMDSpUuxevVqyOVyFBQU+LtJhBAR6NAUQsLcypUrERUVhd///veoqqpCdnY2srKycPToUfz4449ISkpCt27dsGrVKmg0Gn83lxDihAI5IYQQEsRoap0QQggJYhTICSGEkCBGgZwQQggJYhTICSGEkCBGgZwQQggJYhTICSGEkCBGgZwQQggJYhTICSGEkCD2/wHbdW2wZOUCLgAAAABJRU5ErkJggg==\n",
+ "text/plain": [
+ ""
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ }
+ ],
+ "source": [
+ "plt.figure(0)\n",
+ "\n",
+ "plt.scatter(dist_01[:,0],dist_01[:,1],label='Class 0')\n",
+ "plt.scatter(dist_02[:,0],dist_02[:,1],color='r',marker='^',label='Class 1')\n",
+ "plt.xlim(-5,10)\n",
+ "plt.ylim(-5,10)\n",
+ "plt.xlabel('x1')\n",
+ "plt.ylabel('x2')\n",
+ "\n",
+ "x = np.linspace(-4,8,10)\n",
+ "y = -(W[0]*x + b)/W[1]\n",
+ "plt.plot(x,y,color='k')\n",
+ "\n",
+ "plt.legend()\n",
+ "plt.show()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 15,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "[0.76604691 1.49267387]\n",
+ "-5.424920453033558\n"
+ ]
+ }
+ ],
+ "source": [
+ "print(W)\n",
+ "print(b)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": []
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 3",
+ "language": "python",
+ "name": "python3"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 3
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython3",
+ "version": "3.6.8"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 2
+}
From fb37ab4be2ad207dbd1a115d65127f6f561f9422 Mon Sep 17 00:00:00 2001
From: SWARNIMA SHUKLA
Date: Fri, 3 Apr 2020 00:13:00 +0530
Subject: [PATCH 060/265] Johnson Algorithm Implementation in Dart (#2567)
---
Johnson_Algorithm/Johnson_Algorithm.dart | 180 +++++++++++++++++++++++
1 file changed, 180 insertions(+)
create mode 100644 Johnson_Algorithm/Johnson_Algorithm.dart
diff --git a/Johnson_Algorithm/Johnson_Algorithm.dart b/Johnson_Algorithm/Johnson_Algorithm.dart
new file mode 100644
index 000000000..e1cbc70f9
--- /dev/null
+++ b/Johnson_Algorithm/Johnson_Algorithm.dart
@@ -0,0 +1,180 @@
+/*
+Johnson’s algorithm for All-pairs shortest paths
+
+Given a weighted Directed Graph where the weights may be negative,
+find the shortest path between every pair of vertices in the Graph using
+Johnson’s Algorithm.
+ */
+
+int MAX_INT = 9223372036854775807;
+
+int minDistance(distance, visited)
+{
+ var minimum = MAX_INT;
+ var minVertex = 0;
+
+ var v = distance.length;
+
+ for(var vertex = 0; vertex < v; vertex++)
+ {
+ if( (minimum > distance[vertex]) && (visited[vertex] == false) )
+ {
+ minimum = distance[vertex];
+ minVertex = vertex;
+ }
+ }
+ return minVertex;
+}
+
+void Dijkstra(graph, modified, src)
+{
+ var num_vertices = graph.length;
+ var distance = new List(num_vertices);
+
+ var visited = new List(num_vertices);
+
+ for (var i = 0; i < num_vertices; i++)
+ {
+ distance[i] = MAX_INT;
+ visited[i] = false;
+ }
+
+ distance[src] = 0;
+
+ for(var count = 0; count < num_vertices; count++)
+ {
+ var curVertex = minDistance(distance, visited);
+ visited[curVertex] = true;
+ for(var vertex = 0; vertex < num_vertices; vertex++)
+ {
+ if ((visited[vertex] == false) && (distance[vertex] > (distance[curVertex] +
+ modified[curVertex][vertex])) && (graph[curVertex][vertex] != 0))
+ {
+ distance[vertex] = (distance[curVertex] + modified[curVertex][vertex]);
+ }
+ }
+ }
+
+ for(var vertex = 0; vertex < num_vertices; vertex++)
+ {
+ print('Vertex ${vertex} : ${distance[vertex]}');
+ }
+}
+
+List BellmanFord(edges, graph, num_vertices)
+{
+ var distance = new List(num_vertices+1);
+
+ for(var i = 0; i <= num_vertices; i++)
+ {
+ distance[i]=MAX_INT;
+ }
+
+ distance[num_vertices] = 0;
+
+ for(var i = 0; i < num_vertices; i++)
+ {
+ edges.add([num_vertices, i, 0]);
+ }
+
+ for(var i = 0; i < num_vertices; i++)
+ {
+ for(var j in edges)
+ {
+
+ if((distance[j[0]] != MAX_INT) && (distance[j[0]] + j[2] < distance[j[1]]) )
+ {
+ distance[j[1]] = distance[j[0]] + j[2];
+ }
+ }
+ }
+
+ return distance;
+}
+
+
+void JohnsonAlgorithm(graph)
+{
+ var edges = new List();
+
+ for(var i = 0; i < graph.length ; i++)
+ {
+ for(var j = 0; j < graph[i].length; j++)
+ {
+ if(graph[i][j] != 0)
+ {
+ edges.add([i, j, graph[i][j]]);
+ }
+ }
+ }
+
+ var modifiedwei = BellmanFord(edges, graph, graph.length);
+
+ var modified = [[0,0,0,0],
+ [0,0,0,0],
+ [0,0,0,0],
+ [0,0,0,0]];
+
+ for(var i = 0; i < graph.length; i++)
+ {
+ for(var j = 0; j < graph[i].length; j++)
+ {
+ if(graph[i][j] != 0)
+ {
+ modified[i][j] = (graph[i][j] +
+ modifiedwei[i] - modifiedwei[j]);
+ }
+ }
+ }
+
+ print ('Modified Graph: ${modified}');
+
+ for(var src = 0; src < graph.length; src++)
+ {
+ print ('\nShortest Distance with vertex ${src} as the source:\n');
+ Dijkstra(graph, modified, src);
+ }
+}
+
+void main() {
+
+ var graph = [[0, -8, 2, 4],
+ [0, 0, 2, 6],
+ [0, 0, 0, 2],
+ [0, 0, 0, 0]];
+
+ JohnsonAlgorithm(graph);
+}
+
+/*
+Modified Graph: [[0, 0, 8, 8], [0, 0, 0, 2], [0, 0, 0, 0], [0, 0, 0, 0]]
+
+Shortest Distance with vertex 0 as the source:
+
+Vertex 0 : 0
+Vertex 1 : 0
+Vertex 2 : 0
+Vertex 3 : 0
+
+Shortest Distance with vertex 1 as the source:
+
+Vertex 0 : 9223372036854775807
+Vertex 1 : 0
+Vertex 2 : 0
+Vertex 3 : 0
+
+Shortest Distance with vertex 2 as the source:
+
+Vertex 0 : 9223372036854775807
+Vertex 1 : 9223372036854775807
+Vertex 2 : 0
+Vertex 3 : 0
+
+Shortest Distance with vertex 3 as the source:
+
+Vertex 0 : 9223372036854775807
+Vertex 1 : 9223372036854775807
+Vertex 2 : -9223372036854775801
+Vertex 3 : 0
+
+ */
From 4e6909438b449fa055040539a288f7dfb178133b Mon Sep 17 00:00:00 2001
From: Hardev Khandhar <54733460+HardevKhandhar@users.noreply.github.com>
Date: Fri, 3 Apr 2020 00:34:45 +0530
Subject: [PATCH 061/265] Boyer Moore Algorithm in C# (#2604)
* Boyer Moore Algorithm in C#
* Updated Changes
---
Boyer_Moore_Algorithm/Boyer_Moore.cs | 110 +++++++++++++++++++++++++++
1 file changed, 110 insertions(+)
create mode 100644 Boyer_Moore_Algorithm/Boyer_Moore.cs
diff --git a/Boyer_Moore_Algorithm/Boyer_Moore.cs b/Boyer_Moore_Algorithm/Boyer_Moore.cs
new file mode 100644
index 000000000..391afe81a
--- /dev/null
+++ b/Boyer_Moore_Algorithm/Boyer_Moore.cs
@@ -0,0 +1,110 @@
+// C# Program for Boyer Moore String Matching Algorithm
+
+using System;
+
+public class Algorithm
+{
+ static int CHARACTERS = 256;
+
+ // Getting maximum of two integers
+ static int max (int a, int b) { return (a > b)? a: b; }
+
+ // Bad Character Pre-Processing Function
+ static void badChar( char []str, int size,int []badCharacter)
+ {
+ int i;
+
+ // Initializing all occurences to -1
+ for (i = 0; i < CHARACTERS; i++)
+ badCharacter[i] = -1;
+
+ // Filling the Actual Value
+ for (i = 0; i < size; i++)
+ badCharacter[(int) str[i]] = i;
+ }
+
+ // Pattern Searching Function
+ static void search( char []txt, char []pat)
+ {
+ int m = pat.Length;
+ int n = txt.Length;
+
+ int []Character = new int[CHARACTERS];
+ badChar(pat, m, Character);
+
+ /*
+ s is used to keep track of
+ pattern shifting with respect to text
+ */
+
+ int s = 0;
+
+ while(s <= (n - m))
+ {
+ int j = m - 1;
+
+ while(j >= 0 && pat[j] == txt[s+j])
+ j--;
+
+ /*
+ If the pattern is present at current
+ shift, then index j will become -1 after
+ the above loop
+ */
+
+ if (j < 0)
+ {
+ Console.WriteLine("Pattern occurs at index: " + s);
+ s += (s+m < n)? m-Character[txt[s+m]] : 1;
+ }
+
+ else
+ s += max(1, j - Character[txt[s+j]]);
+
+ }
+ }
+
+ public static void Main()
+ {
+ Console.WriteLine("Enter The String Value: ");
+ String valueEntered = Console.ReadLine();
+ Console.WriteLine("Enter The Pattern To Search: ");
+ String pattern = Console.ReadLine();
+ Console.WriteLine();
+
+ char []txt = valueEntered.ToCharArray();
+ char []pat = pattern.ToCharArray();
+ search(txt, pat);
+ }
+}
+
+/**
+
+Enter The String Value:
+ABAAABCD
+Enter The Pattern To Search:
+ABC
+
+Pattern occurs at index: 4
+
+--------------------------------------------------
+
+Enter The String Value:
+AABAACAADAABAABA
+Enter The Pattern To Search:
+AABA
+
+Pattern occurs at index: 0
+Pattern occurs at index: 9
+Pattern occurs at index: 12
+
+--------------------------------------------------
+
+Enter The String Value:
+THIS IS A TEST TEXT
+Enter The Pattern To Search:
+TEST
+
+Pattern occurs at index: 10
+
+*/
From f231d7fba6dcdfb9a9612c1206a5431782f3b19d Mon Sep 17 00:00:00 2001
From: Sukriti Shah
Date: Fri, 3 Apr 2020 16:38:33 +0530
Subject: [PATCH 062/265] Adding PHP Implementation for Chinese Rem. Th.
(#2685)
---
.../Chinese_Remainder_Theorem.php | 57 +++++++++++++++++++
1 file changed, 57 insertions(+)
create mode 100644 Chinese_Remainder_Theorem/Chinese_Remainder_Theorem.php
diff --git a/Chinese_Remainder_Theorem/Chinese_Remainder_Theorem.php b/Chinese_Remainder_Theorem/Chinese_Remainder_Theorem.php
new file mode 100644
index 000000000..0275718e9
--- /dev/null
+++ b/Chinese_Remainder_Theorem/Chinese_Remainder_Theorem.php
@@ -0,0 +1,57 @@
+
+
From 50193d01daaaba6477d881911c7089a594fa22a7 Mon Sep 17 00:00:00 2001
From: Apoorva <51367534+apoorvam25@users.noreply.github.com>
Date: Fri, 3 Apr 2020 22:35:53 +0530
Subject: [PATCH 063/265] Added Minimum Absolute Difference in Array Problem[C
and C++] (#1845)
---
.../Minimum_Absolute_Difference_In_Array.c | 42 +++++++++++++++++++
.../Minimum_Absolute_Difference_In_Array.cpp | 38 +++++++++++++++++
2 files changed, 80 insertions(+)
create mode 100644 Minimum_Absolute_Difference_In_Array/Minimum_Absolute_Difference_In_Array.c
create mode 100644 Minimum_Absolute_Difference_In_Array/Minimum_Absolute_Difference_In_Array.cpp
diff --git a/Minimum_Absolute_Difference_In_Array/Minimum_Absolute_Difference_In_Array.c b/Minimum_Absolute_Difference_In_Array/Minimum_Absolute_Difference_In_Array.c
new file mode 100644
index 000000000..8739a9751
--- /dev/null
+++ b/Minimum_Absolute_Difference_In_Array/Minimum_Absolute_Difference_In_Array.c
@@ -0,0 +1,42 @@
+/*Given an integer array A of size N, find and return
+the minimum absolute difference between any two elements in the array.
+The absolute difference between two elements ai, and aj (where i != j ) is |ai - aj|*/
+
+#include
+#include
+#include
+
+int cmpfunc (const void * a, const void * b)
+{
+ return (*(int*)a - *(int*)b);
+}
+
+int minAbsoluteDiff(int arr[], int n)
+{
+ qsort(arr, n, sizeof(int), cmpfunc);
+ int mindiff = INT_MAX;
+ for(int i = 0; i < n - 1; i++)
+ {
+ if(abs(arr[i] - arr[i + 1]) < mindiff)
+ mindiff = abs(arr[i] - arr[i + 1]);
+ }
+ return mindiff;
+}
+
+int main()
+{
+ int size, i;
+ scanf("%d", &size);
+ int input[size];
+ for(i = 0; i < size; i++)
+ scanf("%d", &input[i]);
+
+ printf("%d", minAbsoluteDiff(input,size));
+ return 0;
+}
+
+/* Input : 12
+ 922 192 651 200 865 174 798 481 510 863 150 520
+
+ Output : 2
+*/
diff --git a/Minimum_Absolute_Difference_In_Array/Minimum_Absolute_Difference_In_Array.cpp b/Minimum_Absolute_Difference_In_Array/Minimum_Absolute_Difference_In_Array.cpp
new file mode 100644
index 000000000..ab13f120d
--- /dev/null
+++ b/Minimum_Absolute_Difference_In_Array/Minimum_Absolute_Difference_In_Array.cpp
@@ -0,0 +1,38 @@
+/*Given an integer array A of size N,find and return
+the minimum absolute difference between any two elements in the array.
+The absolute difference between two elements ai, and aj (where i != j ) is |ai - aj|*/
+
+#include
+#include
+#include
+using namespace std;
+
+int minAbsoluteDiff(int arr[], int n)
+{
+ std::sort(arr, arr + n);
+ int mindiff = INT_MAX;
+ for(int i = 0; i < n - 1; i++)
+ {
+ if(abs(arr[i] - arr[i + 1] ) < mindiff)
+ mindiff = abs(arr[i] - arr[i + 1]);
+ }
+ return mindiff;
+}
+
+int main()
+{
+ int size;
+ cin >> size;
+ int *input = new int[1 + size];
+
+ for(int i = 0; i < size; i++)
+ cin >> input[i];
+ cout << minAbsoluteDiff(input, size) << endl;
+ return 0;
+}
+
+/* Input : 5
+ 2 9 0 4 5
+
+ Output : 1
+*/
From 67a6b6bc9bf2306c837189616c563f0e6819d99c Mon Sep 17 00:00:00 2001
From: Mansi Agrawal <46123053+mansikagrawal@users.noreply.github.com>
Date: Fri, 3 Apr 2020 22:59:12 +0530
Subject: [PATCH 064/265] Count_Inversion.cpp (#2625)
---
Count_Inversion/Count_Inversion.cpp | 85 +++++++++++++++++++++++++++++
1 file changed, 85 insertions(+)
create mode 100644 Count_Inversion/Count_Inversion.cpp
diff --git a/Count_Inversion/Count_Inversion.cpp b/Count_Inversion/Count_Inversion.cpp
new file mode 100644
index 000000000..3f4c1601e
--- /dev/null
+++ b/Count_Inversion/Count_Inversion.cpp
@@ -0,0 +1,85 @@
+// Count inversion using merge sort
+
+#include
+using namespace std;
+
+//merge two sorted arrays such that resultant array is also sorted
+int merge(int array[], int aux[], int low, int mid, int high)
+{
+ int x = low, y = mid, z = low, count = 0;
+
+ // checking till left and right half of merge sort
+ while ((x <= mid-1) && (y <= high))
+ {
+ if (array[x] <= array[y])
+ {
+ aux[z++] = array[x++];
+ }
+ else
+ {
+ aux[z++] = array[y++];
+ count += mid-x;
+ }
+ }
+
+ // Copy remaining elements
+ while (x <= mid-1)
+ {
+ aux[z++] = array[x++];
+ }
+
+ while (y <= high)
+ {
+ aux[z++] = array[y++];
+ }
+
+ // Sorting the original array with the help of aux array
+ for (int i = low; i <= high; i++)
+ {
+ array[i] = aux[i];
+ }
+ return count;
+}
+
+//merge sort to find inversion count
+int mergeSort(int array[], int aux[], int low, int high)
+{
+ int count = 0;
+ if (high > low)
+ {
+ int mid = (low + high) / 2;
+
+ // merge sort on Left half of the array
+ count = mergeSort(array, aux, low, mid);
+ // merge sort on Right half of the array
+ count += mergeSort(array, aux, mid + 1, high);
+ // Merge the two half
+ count += merge(array, aux, low, mid + 1, high);
+ }
+ return count;
+}
+
+//wrapper function that returns number of inversions
+int inversions_count(int array[], int n)
+{
+ int aux[n];
+ return mergeSort(array, aux, 0, n-1);
+}
+
+int main ()
+{
+ int n;
+ cin >> n;
+ int arr[n];
+ for(int i = 0; i < n; i++)
+ cin >> arr[i];
+ cout << (inversions_count(arr, n)) << endl;
+ return 0;
+}
+
+/* Sample input
+5
+1 20 6 4 5
+
+Sample Output
+5 */
From 34d8d3b7b3aaa518751bb053eb314d844c381ba0 Mon Sep 17 00:00:00 2001
From: Aman-Codes <54680709+Aman-Codes@users.noreply.github.com>
Date: Sun, 5 Apr 2020 16:38:02 +0530
Subject: [PATCH 065/265] Added Tree Inorder Traversal in JS (#2586)
* Create Tree_Inorder_Traversal.js
* Update Tree_Inorder_Traversal.js
---
.../Tree_Inorder_Traversal.js | 38 +++++++++++++++++++
1 file changed, 38 insertions(+)
create mode 100644 Tree_Inorder_Traversal/Tree_Inorder_Traversal.js
diff --git a/Tree_Inorder_Traversal/Tree_Inorder_Traversal.js b/Tree_Inorder_Traversal/Tree_Inorder_Traversal.js
new file mode 100644
index 000000000..37ea90ebd
--- /dev/null
+++ b/Tree_Inorder_Traversal/Tree_Inorder_Traversal.js
@@ -0,0 +1,38 @@
+/*
+ * Program to traverse a tree in Inorder.
+ */
+
+// Creates a Tree Node with input value
+class Node {
+ constructor(value) {
+ this.value = value;
+ this.left = null;
+ this.right = null;
+ }
+}
+
+// Function for In Order Tree Transversal
+function InOrder(root) {
+ if (root) {
+ InOrder(root.left);
+ console.log(root.value);
+ InOrder(root.right);
+ }
+}
+
+// Sample Input
+var root = new Node(1);
+root.left = new Node(2);
+root.right = new Node(3);
+root.left.left = new Node(4);
+root.left.right = new Node(5);
+root.right.left = new Node(6);
+root.right.right = new Node(7);
+
+// Sample Output
+console.log("In Order traversal of tree is:-");
+InOrder(root);
+
+/* Output
+In Order traversal of tree is:- 4 2 5 1 6 3 7
+ */
From 3aa645770be5789598b671bc820791a80c2fa1e0 Mon Sep 17 00:00:00 2001
From: prince-09 <52371330+prince-09@users.noreply.github.com>
Date: Sun, 5 Apr 2020 16:45:00 +0530
Subject: [PATCH 066/265] Floyd warshal js (#2468)
* floyd Warshall in javascript
* floyd warshall in java script
* floyd warshall in java script
* Update Floyd_Warshall.js
* Update Floyd_Warshall.js
* Update Floyd_Warshall.js
* Update Floyd_Warshall.js
* Update Floyd_Warshall.js
* Update Floyd_Warshall.js
* Update Floyd_Warshall.js
* Update Floyd_Warshall.js
* Update Floyd_Warshall.js
* Update Floyd_Warshall.js
---
Floyd_Warshall_Algorithm/Floyd_Warshall.js | 88 ++++++++++++++++++++++
1 file changed, 88 insertions(+)
create mode 100644 Floyd_Warshall_Algorithm/Floyd_Warshall.js
diff --git a/Floyd_Warshall_Algorithm/Floyd_Warshall.js b/Floyd_Warshall_Algorithm/Floyd_Warshall.js
new file mode 100644
index 000000000..5af0847ed
--- /dev/null
+++ b/Floyd_Warshall_Algorithm/Floyd_Warshall.js
@@ -0,0 +1,88 @@
+/*The Floyd Warshall Algorithm is for solving the All Pairs Shortest Path problem.
+The problem is to find shortest distances between every pair of vertices in a given
+edge weighted directed Graph.This is Floyd Warshall algorithm in java script.*/
+
+class Graph {
+ constructor() {
+ this.edges = {};
+ this.nodes = [];
+ }
+
+ addNode(node) {
+ this.nodes.push(node);
+ this.edges[node] = [];
+ }
+
+ addEdge(node1, node2, weight =1) {
+ this.edges[node1].push({node:node2, weight:weight });
+ this.edges[node2].push({node:node1, weight:weight });
+ }
+
+ floydWarshallAlgorithm() {
+ let dist = {};
+ for (let i = 0; i < this.nodes.length; i++) {
+ dist[this.nodes[i]] = {};
+
+ // For existing edges assign the dist to be same as weight
+ this.edges[this.nodes[i]].forEach(e = > (dist[this.nodes[i]][e.node] = e.weight));
+
+ this.nodes.forEach(n = > {
+ // For all other nodes assign it to infinity
+ if (dist[this.nodes[i]][n] == undefined)
+ dist[this.nodes[i]][n] = Infinity;
+ // For self edge assign dist to be 0
+ if (this.nodes[i] == = n) dist[this.nodes[i]][n] = 0;
+ });
+ }
+
+ this.nodes.forEach(i = > {
+ this.nodes.forEach(j = > {
+ this.nodes.forEach(k = > {
+ // Check if going from i to k then from k to j is better
+ // than directly going from i to j. If yes then update
+ // i to j value to the new value
+ if (dist[i][k] + dist[k][j] < dist[i][j])
+ dist[i][j] = dist[i][k] + dist[k][j];
+ });
+ });
+ });
+ return dist;
+ }
+}
+
+ let g = new Graph();
+
+ var edges = prompt("Please enter number of edges", "5");
+
+ var vertices = prompt("Please enter number of vertices", "5");
+
+ for(let i=0;i
Date: Mon, 6 Apr 2020 03:19:36 +0530
Subject: [PATCH 067/265] Added a Number conversion(Decimal to Binary) code in
java (#2524)
Number conversion (decimal to binary)
---
Number_Conversion/Java/Decimal_to_binary.java | 30 +++++++++++++++++++
1 file changed, 30 insertions(+)
create mode 100644 Number_Conversion/Java/Decimal_to_binary.java
diff --git a/Number_Conversion/Java/Decimal_to_binary.java b/Number_Conversion/Java/Decimal_to_binary.java
new file mode 100644
index 000000000..24a179f0b
--- /dev/null
+++ b/Number_Conversion/Java/Decimal_to_binary.java
@@ -0,0 +1,30 @@
+//JAVA program to convert Decimal integer to it's Binary form
+
+import java.util.Scanner;
+
+public class Decimal_to_binary {
+
+ //Driver Code
+ public static void main(String[] args){
+ int n, rem;
+ String Bin = ""; //String to store the binary number
+ Scanner sc = new Scanner(System.in);
+ System.out.println("Enter any decimal number:");
+ n = sc.nextInt(); //Taking the decimal input
+
+ if (n == 0){
+ Bin = "0";
+ }
+
+ //Simultaneously storing the remainder when number divided by 2 in the string in reverse order
+ while (n > 0){
+ rem = n % 2;
+ Bin = rem + Bin;
+ n = n / 2;
+ }
+ System.out.println("Binary number:"+Bin); //output
+ }
+}
+//Input : 10
+//Output : 1010
+
From 51ad0a118a32aa7cea0cad0846d3c007bf5880b0 Mon Sep 17 00:00:00 2001
From: AkanshaKamboj <42874293+AkanshaKamboj@users.noreply.github.com>
Date: Mon, 6 Apr 2020 03:21:05 +0530
Subject: [PATCH 068/265] Linked list merge sort in C, C++, Java, Python #1578
(#2395)
* Create Linked_List_Merge_Sort.c
* Add files via upload
* Update Linked_List_Merge_Sort.c
* Update Linked_List_Merge_Sort.c
* Update Linked_List_MergeSort.cpp
* Update Linked_List_MergeSort.java
* Update Linked_List_MergeSort.java
* Update Linked_List_MergeSort.py
* Update Linked_List_MergeSort.cpp
* Update Linked_List_MergeSort.java
* Update Linked_List_Merge_Sort.c
* Rename Linked_List_MergeSort.cpp to Linked_List_Merge_Sort.cpp
* Rename Linked_List_MergeSort.py to Linked_List_Merge_Sort.py
* Rename Linked_List_MergeSort.java to Linked_List_Merge_Sort.java
---
.../Linked_List_Merge_Sort.c | 157 +++++++++++++++++
.../Linked_List_Merge_Sort.cpp | 156 +++++++++++++++++
.../Linked_List_Merge_Sort.java | 165 ++++++++++++++++++
.../Linked_List_Merge_Sort.py | 149 ++++++++++++++++
4 files changed, 627 insertions(+)
create mode 100644 Linked_List_Merge_Sort/Linked_List_Merge_Sort.c
create mode 100644 Linked_List_Merge_Sort/Linked_List_Merge_Sort.cpp
create mode 100644 Linked_List_Merge_Sort/Linked_List_Merge_Sort.java
create mode 100644 Linked_List_Merge_Sort/Linked_List_Merge_Sort.py
diff --git a/Linked_List_Merge_Sort/Linked_List_Merge_Sort.c b/Linked_List_Merge_Sort/Linked_List_Merge_Sort.c
new file mode 100644
index 000000000..fa759d249
--- /dev/null
+++ b/Linked_List_Merge_Sort/Linked_List_Merge_Sort.c
@@ -0,0 +1,157 @@
+/*C program for sorting a Single Linked List using Merge Sort technique. Merge Sort uses divide and conquer technique i.e. it
+ divides the input array into two halves, calls itself recursively for the two halves until one element remains and then merges
+ the two halves
+
+ | 6 | 5 | 4 | 3 | 2 | 1 | *
+ / \ *
+ / \ *
+ | 6 | 5 | 4 | | 3 | 2 | 1 | *
+ / \ / \ * DIVIDE
+ / \ / \ *
+ | 6 | 5 | | 4 | | 3 | 2 | | 1 | *
+ / \ | / \ | *
+ |6| |5| | |3| |2| | *
+ \ / | \ / |
+ \ / | \ / |
+ | 5 | 6 | | | 2 | 3 | | *
+ \ | \ | *
+ \ | \ | *
+ | 4 | 5 | 6 | | 1 | 2 | 3 | * MERGE
+ \ / *
+ \ / *
+ | 1 | 2 | 3 | 4 | 5 | 6 | *
+ */
+#include
+#include
+
+struct Node {
+ int data;
+ struct Node* next;
+};
+
+/*Merging the contents of the two linked list*/
+struct Node *merge(struct Node *l1, struct Node *l2)
+{
+ if(!l1)
+ return l2;
+
+ if(!l2)
+ return l1;
+
+ struct Node *head=NULL;
+
+ if(l1->data < l2->data)
+ {
+ head = l1;
+ l1 = l1->next;
+ }
+ else
+ {
+ head = l2;
+ l2 = l2->next;
+ }
+
+ struct Node *ptr = head;
+
+ while(l1 && l2)
+ {
+ if(l1->data < l2->data)
+ {
+ ptr->next = l1;
+ l1 = l1->next;
+ }
+ else
+ {
+ ptr->next = l2;
+ l2 = l2->next;
+ }
+ ptr = ptr->next;
+ }
+
+ if(l1)
+ ptr->next = l1;
+ else
+ ptr->next = l2;
+
+ return head;
+}
+
+/*Dividing the linked list*/
+struct Node* mergeSort(struct Node* head) {
+
+ if(head==NULL || head->next==NULL)
+ return head;
+
+ /*Dividing the linked list into two equal parts as done in merge sort*/
+ struct Node *ptr1 = head;
+ struct Node *ptr2 = head->next;
+
+ while(ptr2 && ptr2->next)
+ {
+ ptr1 = ptr1->next;
+ if(ptr2->next)
+ ptr2 = ptr2->next->next;
+ }
+
+ ptr2 = ptr1->next;
+ ptr1->next = NULL;
+
+ return merge(mergeSort(head),mergeSort(ptr2));
+}
+
+/* Function for printing the Single Linked List*/
+void printList(struct Node* head) {
+
+ while (head != NULL) {
+ printf("%d-->", head->data);
+ head = head->next;
+ }
+
+ printf("NULL");
+}
+
+int main()
+{
+ int test,n,ele;
+ scanf("%d", &test);
+
+ /* Inserting elements into linked list*/
+ while (test--)
+ {
+ struct Node* head = NULL;
+ struct Node *temp = NULL;
+ scanf("%d", &n);
+
+ while(n--)
+ {
+ scanf("%d", &ele);
+
+ struct Node *ptr = (struct Node*)malloc(sizeof(struct Node));
+ ptr->data = ele;
+ ptr->next = NULL;
+
+ if(head==NULL)
+ head = ptr;
+ else
+ temp->next = ptr;
+
+ temp = ptr;
+ }
+
+ head = mergeSort(head);
+ printList(head);
+ }
+ return 0;
+}
+
+/*
+Sample Input
+1 - Test cases
+5 - Total number of elements to be inserted in linked list
+23 2 34 5 1 - Adding the contents of the linked list
+
+Sample Output
+1-->2-->5-->23-->34-->NULL
+*/
+
+
diff --git a/Linked_List_Merge_Sort/Linked_List_Merge_Sort.cpp b/Linked_List_Merge_Sort/Linked_List_Merge_Sort.cpp
new file mode 100644
index 000000000..a5ddf503f
--- /dev/null
+++ b/Linked_List_Merge_Sort/Linked_List_Merge_Sort.cpp
@@ -0,0 +1,156 @@
+/*C++ program for sorting a Single Linked List using Merge Sort technique. Merge Sort uses divide and conquer technique i.e. it
+ divides the input array into two halves, calls itself recursively for the two halves until one element remains and then merges
+ the two halves
+ | 6 | 5 | 4 | 3 | 2 | 1 | *
+ / \ *
+ / \ *
+ | 6 | 5 | 4 | | 3 | 2 | 1 | *
+ / \ / \ * DIVIDE
+ / \ / \ *
+ | 6 | 5 | | 4 | | 3 | 2 | | 1 | *
+ / \ | / \ | *
+ |6| |5| | |3| |2| | *
+ \ / | \ / |
+ \ / | \ / |
+ | 5 | 6 | | | 2 | 3 | | *
+ \ | \ | *
+ \ | \ | *
+ | 4 | 5 | 6 | | 1 | 2 | 3 | * MERGE
+ \ / *
+ \ / *
+ | 1 | 2 | 3 | 4 | 5 | 6 | *
+ */
+
+#include
+using namespace std;
+
+struct Node {
+ int data;
+ struct Node* next;
+ Node(int x) {
+ data = x;
+ next = NULL;
+ }
+};
+
+/*Merging the contents of the two linked list*/
+struct Node *merge(struct Node *l1, struct Node *l2)
+{
+ if(!l1)
+ return l2;
+
+ if(!l2)
+ return l1;
+
+ struct Node *head = NULL;
+
+ if(l1->data < l2->data)
+ {
+ head = l1;
+ l1 = l1->next;
+ }
+ else
+ {
+ head = l2;
+ l2 = l2->next;
+ }
+
+ struct Node *ptr = head;
+
+ while(l1 && l2)
+ {
+ if(l1->data < l2->data)
+ {
+ ptr->next = l1;
+ l1 = l1->next;
+ }
+ else
+ {
+ ptr->next = l2;
+ l2 = l2->next;
+ }
+ ptr = ptr->next;
+ }
+
+ if(l1)
+ ptr->next = l1;
+ else
+ ptr->next = l2;
+
+ return head;
+}
+
+/*Dividing the linked list*/
+struct Node* mergeSort(struct Node* head) {
+
+ if(head == NULL || head->next == NULL)
+ return head;
+
+ /*Dividing the linked list into two equal parts as done in merge sort*/
+ struct Node *ptr1 = head;
+ struct Node *ptr2 = head->next;
+
+ while(ptr2 && ptr2->next)
+ {
+ ptr1 = ptr1->next;
+ if(ptr2->next)
+ ptr2 = ptr2->next->next;
+ }
+
+ ptr2 = ptr1->next;
+ ptr1->next = NULL;
+
+ return merge(mergeSort(head),mergeSort(ptr2));
+}
+
+void printList(struct Node* head) {
+
+ while (head != NULL) {
+ printf("%d-->", head->data);
+ head = head->next;
+ }
+
+ printf("NULL");
+}
+
+int main() {
+ int test,n,ele;
+ cin >> test;
+
+ while (test--)
+ {
+ struct Node *head = NULL;
+ struct Node *temp = NULL;
+ cin>>n;
+
+ while(n--)
+ {
+ cin>>ele;
+
+ struct Node *ptr = new Node(ele);
+
+ if(head == NULL)
+ head = ptr;
+ else
+ temp->next = ptr;
+
+ temp = ptr;
+ }
+
+ head = mergeSort(head);
+ printList(head);
+ }
+ return 0;
+}
+
+/*
+Sample Input
+1 - Test cases
+5 - Total number of elements to be inserted in linked list
+23 2 34 5 1 - Adding the contents of the linked list
+
+Sample Output
+1-->2-->5-->23-->34-->NULL
+*/
+
+
diff --git a/Linked_List_Merge_Sort/Linked_List_Merge_Sort.java b/Linked_List_Merge_Sort/Linked_List_Merge_Sort.java
new file mode 100644
index 000000000..1021a2c0d
--- /dev/null
+++ b/Linked_List_Merge_Sort/Linked_List_Merge_Sort.java
@@ -0,0 +1,165 @@
+/*JAVA program for sorting a Single Linked List using Merge Sort technique. Merge Sort uses divide and conquer technique i.e.
+ it divides the input array into two halves, calls itself recursively for the two halves until one element remains and then
+ merges the two halves
+
+ | 6 | 5 | 4 | 3 | 2 | 1 | *
+ / \ *
+ / \ *
+ | 6 | 5 | 4 | | 3 | 2 | 1 | *
+ / \ / \ * DIVIDE
+ / \ / \ *
+ | 6 | 5 | | 4 | | 3 | 2 | | 1 | *
+ / \ | / \ | *
+ |6| |5| | |3| |2| | *
+ \ / | \ / |
+ \ / | \ / |
+ | 5 | 6 | | | 2 | 3 | | *
+ \ | \ | *
+ \ | \ | *
+ | 4 | 5 | 6 | | 1 | 2 | 3 | * MERGE
+ \ / *
+ \ / *
+ | 1 | 2 | 3 | 4 | 5 | 6 | *
+ */
+
+import java.util.*;
+import java.lang.*;
+import java.io.*;
+
+class Node
+{
+ int data;
+ Node next;
+ Node(int key)
+ {
+ data = key;
+ next = null;
+ }
+}
+
+class LinkedList
+{
+ /*Merging the contents of the two linked list*/
+
+ public static Node merge(Node l1, Node l2)
+ {
+ if(l1 == null)
+ return l2;
+
+ if(l2 == null)
+ return l1;
+
+ Node head = null;
+
+ if(l1.data < l2.data)
+ {
+ head = l1;
+ l1 = l1.next;
+ }
+ else
+ {
+ head = l2;
+ l2 = l2.next;
+ }
+
+ Node ptr = head;
+
+ while(l1 != null && l2 != null)
+ {
+ if(l1.data < l2.data)
+ {
+ ptr.next = l1;
+ l1 = l1.next;
+ }
+ else
+ {
+ ptr.next = l2;
+ l2 = l2.next;
+ }
+ ptr = ptr.next;
+ }
+
+ if(l1 != null)
+ ptr.next = l1;
+ else
+ ptr.next = l2;
+
+ return head;
+ }
+
+ /*Dividing the linked list*/
+ public static Node mergeSort(Node head)
+ {
+
+ if(head == null || head.next == null)
+ return head;
+
+ Node ptr1 = head;
+ Node ptr2 = head.next;
+
+ /*Dividing the linked list into two equal parts as done in merge sort*/
+ while(ptr2 !=null && ptr2.next != null)
+ {
+ ptr1 = ptr1.next;
+ if(ptr2.next != null)
+ ptr2 = ptr2.next.next;
+ }
+
+ ptr2 = ptr1.next;
+ ptr1.next = null;
+
+ return merge(mergeSort(head),mergeSort(ptr2));
+ }
+
+ public static void printList(Node head)
+ {
+ if(head == null)
+ return;
+
+ Node temp = head;
+ while(temp != null)
+ {
+ System.out.print(temp.data + "-->");
+ temp = temp.next;
+ }
+ System.out.print("NULL");
+ }
+
+ public static void main (String[] args)
+ {
+ Scanner sc= new Scanner(System.in);
+ int t = sc.nextInt();
+
+ LinkedList l = new LinkedList();
+
+ while(t!=0)
+ {
+ int n = sc.nextInt();
+ Node head = new Node(sc.nextInt());
+ Node temp = head;
+
+ n--;
+
+ while(n!=0){
+ temp.next = new Node(sc.nextInt());
+ temp = temp.next;
+ n--;
+ }
+
+ head = l.mergeSort(head);
+ l.printList(head);
+ t--;
+ }
+ }
+}
+
+/*
+ Sample Input
+ 1 - Test cases
+ 5 - Total number of elements to be inserted in linked list
+ 23 2 34 5 1 - Adding the contents of the linked list
+
+ Sample Output
+ 1-->2-->5-->23-->34-->NULL
+*/
+
diff --git a/Linked_List_Merge_Sort/Linked_List_Merge_Sort.py b/Linked_List_Merge_Sort/Linked_List_Merge_Sort.py
new file mode 100644
index 000000000..5ed23598f
--- /dev/null
+++ b/Linked_List_Merge_Sort/Linked_List_Merge_Sort.py
@@ -0,0 +1,149 @@
+'''
+ PYTHON program for sorting a Single Linked List using Merge Sort technique. Merge Sort uses divide and conquer technique i.e.
+ it divides the input array into two halves, calls itself recursively for the two halves until one element remains and then
+ merges the two halves
+
+ | 6 | 5 | 4 | 3 | 2 | 1 | *
+ / \ *
+ / \ *
+ | 6 | 5 | 4 | | 3 | 2 | 1 | *
+ / \ / \ * DIVIDE
+ / \ / \ *
+ | 6 | 5 | | 4 | | 3 | 2 | | 1 | *
+ / \ | / \ | *
+ |6| |5| | |3| |2| | *
+ \ / | \ / |
+ \ / | \ / |
+ | 5 | 6 | | | 2 | 3 | | *
+ \ | \ | *
+ \ | \ | *
+ | 4 | 5 | 6 | | 1 | 2 | 3 | * MERGE
+ \ / *
+ \ / *
+ | 1 | 2 | 3 | 4 | 5 | 6 | *
+'''
+
+import atexit
+import io
+import sys
+
+class Node:
+
+ def __init__(self, data):
+ self.data = data
+ self.next = None
+
+# Linked List Class
+class LinkedList:
+ def __init__(self):
+ self.head = None
+
+ # creates a new node with given value and appends it at the end of the linked list
+
+ def merge(self, l1, l2):
+ head = None
+
+ # Base cases
+ if l1 == None:
+ return l2
+
+ if l2 == None:
+ return l1
+
+ # pick either l1 or l2 and recurse
+ if l1.data <= l2.data:
+ head = l1
+ l1 = l1.next
+ else:
+ head = l2
+ l2 = l2.next
+
+ ptr=head
+
+ while l1!=None and l2!=None:
+
+ if l1.data < l2.data:
+ ptr.next = l1
+ l1 = l1.next
+ else:
+ ptr.next = l2
+ l2 = l2.next
+
+ ptr = ptr.next
+
+ if l1 != None:
+ ptr.next = l1
+ else:
+ ptr.next = l2
+
+ return head
+
+
+ def mergeSort(self, head):
+
+ if head == None or head.next == None:
+ return head
+
+ ptr1 = head
+ ptr2 = head.next
+
+ while(ptr2 != None and ptr2.next != None):
+ ptr1 = ptr1.next
+ if ptr2.next != None:
+ ptr2 = ptr2.next.next
+
+ ptr2 = ptr1.next
+ ptr1.next = None
+
+ return self.merge(self.mergeSort(head), self.mergeSort(ptr2))
+
+
+# prints the elements of linked list starting with head
+def printList(head):
+
+ if head is None:
+ return
+
+ temp = head
+
+ while temp:
+ print(temp.data,end="-->")
+ temp = temp.next
+
+ print("NULL")
+
+
+if __name__ == '__main__':
+ t=int(input())
+
+ for cases in range(t):
+ n = int(input())
+ li = LinkedList()
+
+ temp = li.head
+
+ while n!=0:
+ ele = int(input())
+ ptr = Node(ele)
+
+ if li.head is None:
+ li.head = ptr
+ else
+ temp.next = ptr
+
+ temp = ptr
+ n -= 1
+
+ li.head = li.mergeSort(li.head)
+ printList(li.head)
+
+ '''
+ Sample Input
+ 1 - Test cases
+ 5 - Total number of elements to be inserted in linked list
+ 23 2 34 5 1 - Adding the contents of the linked list
+
+ Sample Output
+ 1-->2-->5-->23-->34-->NULL
+'''
+
From b973bac2270615b9f0007828449b91a38a10997c Mon Sep 17 00:00:00 2001
From: jedicakelord <46528937+jedicakelord@users.noreply.github.com>
Date: Mon, 6 Apr 2020 03:26:55 +0530
Subject: [PATCH 069/265] Chinese Remainder Theorem in Go (#2675)
* Chinese Remainder Theorem in Go
* Added comments
---
.../Chinese_Remainder_Theorem.go | 93 +++++++++++++++++++
1 file changed, 93 insertions(+)
create mode 100644 Chinese_Remainder_Theorem/Chinese_Remainder_Theorem.go
diff --git a/Chinese_Remainder_Theorem/Chinese_Remainder_Theorem.go b/Chinese_Remainder_Theorem/Chinese_Remainder_Theorem.go
new file mode 100644
index 000000000..389734a93
--- /dev/null
+++ b/Chinese_Remainder_Theorem/Chinese_Remainder_Theorem.go
@@ -0,0 +1,93 @@
+/* Chinese Remainder Theorem :
+* Given two arrays number[0..n-1] and remainder[0..n-1]
+* Find the minimum possible value of x
+* that produces given remainders, i.e
+* x % number[0] = remainder[0]
+* x % number[1] = remainder[1] and so on.
+*/
+
+package main
+
+import "fmt"
+
+//Extended Euclid Algorithm
+func inverse(a int, m int) (x1 int) {
+ var m0 int = m
+ x0 := 0
+ x1 = 1
+ var quotient int
+ var next int
+
+ if m == 1 {
+ return 0
+ }
+
+ // while the number is greater than 1
+ // keep on making (a,m) = (m,a%m)
+ // Go on reverse to find out x0 and x1 from there.
+ // where x1 will be the inverse modulo
+ for a > 1 {
+ quotient = a / m; next = m
+ m = a % m
+ a = next; next = x0
+ x0 = x1 - quotient * x0
+ x1 = next
+ }
+
+ if x1 < 0 {
+ x1 = x1 + m0
+ }
+
+ return x1
+}
+
+func CRT(number []int, rem []int, k int) int {
+ var prod int = 1
+ var prod_exp int
+
+ for i := 0; i < k; i++ {
+ prod = prod * number[i]
+ }
+
+ var result int = 0
+
+ // Optimized CRT formula
+ for i := 0; i < k; i++ {
+ prod_exp = prod / number[i]
+ result = result + rem[i] * inverse(prod_exp, number[i]) * prod_exp
+ }
+
+ return result % prod
+}
+
+func main() {
+ var n int
+ fmt.Println("Enter the size of the array : ")
+ fmt.Scan(&n)
+ fmt.Println("Enter the number array : ")
+ num := make([]int, n)
+
+ for i := 0; i < n; i++ {
+ fmt.Scan(&num[i])
+ }
+
+ fmt.Println("Enter the remainder array : ")
+ rem := make([]int, n)
+
+ for i := 0; i < n; i++ {
+ fmt.Scan(&rem[i])
+ }
+
+ fmt.Printf("Minimum positive number x is : %d\n", CRT(num, rem, n))
+}
+
+/* Input :
+Enter the size of the array :
+3
+Enter the number array :
+4 11 9
+Enter the remainder array :
+1 2 4
+Output :
+Minimum positive number x is : 13
+*/
From 16da63304c5080f5310d391b95510fe41ba50da6 Mon Sep 17 00:00:00 2001
From: HariniJeyaraman <58400069+HariniJeyaraman@users.noreply.github.com>
Date: Mon, 6 Apr 2020 21:06:06 +0530
Subject: [PATCH 070/265] 1st commit (#2605)
---
Quicksort_3_way/quick_sort_3_way.rb | 71 +++++++++++++++++++++++++++++
1 file changed, 71 insertions(+)
create mode 100644 Quicksort_3_way/quick_sort_3_way.rb
diff --git a/Quicksort_3_way/quick_sort_3_way.rb b/Quicksort_3_way/quick_sort_3_way.rb
new file mode 100644
index 000000000..ce52deb6f
--- /dev/null
+++ b/Quicksort_3_way/quick_sort_3_way.rb
@@ -0,0 +1,71 @@
+#3 way Quick Sort in Ruby
+
+def quick_sort(a, lo, hi)
+ if lo < hi
+ temp = partition(a, lo, hi)
+ l = temp[0]
+ r = temp[1]
+ quick_sort(a, lo, l - 1)
+ quick_sort(a, r + 1, hi)
+ end
+end
+
+def partition(a, lo, hi)
+ pivot = a[lo]
+ i = lo + 1
+ lt = lo
+ gt = hi
+
+ while(i <= gt)
+
+ if a[i] < pivot
+ temp = a[lt]
+ a[lt] = a[i]
+ a[i] = temp
+ lt += 1
+ i += 1
+ elsif a[i] > pivot
+ temp = a[i]
+ a[i] = a[gt]
+ a[gt] = temp
+ gt -= 1
+ else
+ i += 1
+ end
+ end
+ return lt, gt
+end
+
+puts "Enter the size of array : "
+n = gets
+puts "Enter the values for the array : "
+$i = 0
+$num = Integer(n)
+arr = Array.new
+
+while $i < $num do
+
+ arr[$i] = gets
+ $i +=1
+end
+$num2 = Integer(n) - 1
+puts quick_sort(arr, 0, $num2)
+puts "After sorting : "
+puts arr
+
+=begin
+Sample Input-Output
+Enter the size of array :
+4
+Enter the values for the array :
+10
+14
+12
+13
+
+After sorting :
+10
+12
+13
+14
+=end
From 983c5d3364928dc38feafe2a83ec8578311485fd Mon Sep 17 00:00:00 2001
From: SWARNIMA SHUKLA
Date: Mon, 6 Apr 2020 22:58:00 +0530
Subject: [PATCH 071/265] Dijkstra Algorithm implementation in dart (#2617)
Update Dijkstra_Algorithm.dart
---
Dijkstra_Algorithm/Dijkstra_Algorithm.dart | 152 +++++++++++++++++++++
1 file changed, 152 insertions(+)
create mode 100644 Dijkstra_Algorithm/Dijkstra_Algorithm.dart
diff --git a/Dijkstra_Algorithm/Dijkstra_Algorithm.dart b/Dijkstra_Algorithm/Dijkstra_Algorithm.dart
new file mode 100644
index 000000000..283a735be
--- /dev/null
+++ b/Dijkstra_Algorithm/Dijkstra_Algorithm.dart
@@ -0,0 +1,152 @@
+/*
+ Djikstra's algorithm (named after its discover, E.W. Dijkstra) solves the
+ problem of finding the shortest path from a point in a graph (the source)
+ to a destination.
+ It turns out that one can find the shortest paths from a given source to all
+ points in a graph in the same time, hence this problem is sometimes called
+ the single-source shortest paths problem.
+*/
+import 'dart:io';
+
+var INT_MAX = 9223372036854775807;
+
+int minDistance(dist, visited, n)
+{
+ int min = INT_MAX, min_index;
+
+ for (var v = 0; v < n + 1; v++)
+ {
+ if (( visited[v] == false ) && ( dist[v] <= min ))
+ {
+ min = dist[v];
+ min_index = v;
+ }
+ }
+
+ return min_index;
+}
+
+void printsol(dist, n)
+{
+ print('Vertex \t\t Distance from Source\n');
+
+ for (var i = 0; i < n + 1; i++)
+ {
+ print('${i} \t\t ${dist[i]}\n');
+ }
+}
+
+void dijkstra(graph, src, n)
+{
+ var dist = new List(n + 1);
+
+ var visited = new List(n + 1);
+
+ for (var i = 0; i < n + 1; i++)
+ {
+ dist[i] = INT_MAX;
+ visited[i] = false;
+ }
+
+ dist[src] = 0;
+
+ for (var count = 0; count < n; count++)
+ {
+ var u = minDistance(dist, visited, n);
+
+ visited[u] = true;
+
+ for (var v = 0; v < n + 1; v++)
+ {
+ if ( !visited[v] && graph[u][v] > 0 && dist[u] != INT_MAX
+ && dist[u] + graph[u][v] < dist[v] )
+ {
+ dist[v] = dist[u] + graph[u][v];
+ }
+ }
+ }
+
+ printsol(dist, n);
+}
+
+void main()
+{
+ print('Enter number of nodes 0 to ?');
+
+ int n = int.parse(stdin.readLineSync());
+
+ var max_edges = (n + 1) * (n);
+
+ var adjmat = new List.generate(n + 1, (_) => new List(n + 1));
+
+ for(var i = 0; i <= n; i++)
+ {
+ for(var j = 0; j <= n; j++)
+ {
+ adjmat[i][j] = 0;
+ }
+ }
+
+ print('Enter in the following format\nsrc\ndest\nweight\n');
+ for(var i = 0; i < max_edges; i++)
+ {
+ var src = int.parse(stdin.readLineSync());
+ var dest = int.parse(stdin.readLineSync());
+ var weight = int.parse(stdin.readLineSync());
+
+ print('*' * 20);
+
+ if( (src == -1) && (dest == -1) )
+ {
+ break;
+ }
+
+ if( src > n || dest > n || src < 0 || dest < 0 )
+ {
+ print('Invalid edge!\n');
+ i--;
+ }
+ else
+ {
+ adjmat[src][dest] = weight;
+ }
+ }
+
+ dijkstra(adjmat, 0, n);
+}
+
+/*
+Input:
+Enter number of nodes 0 to ?
+9
+Enter in the following format
+Source
+Destination
+Weight
+*******************************************************
+The adjacency matrix will look like this
+admat=[[0, 14, 0, 7, 0, 0, 0, 8, 0, 10],
+ [14, 0, 8, 0, 0, 0, 0, 11, 0, 0],
+ [0, 8, 0, 7, 0, 4, 0, 0, 2, 0],
+ [7, 0, 7, 0, 9, 12, 0, 0, 0, 5],
+ [0, 0, 0, 9, 0, 0, 0, 0, 0, 0],
+ [0, 0, 4, 0, 0, 0, 2, 0, 0, 11],
+ [0, 0, 0, 12, 0, 2, 0, 1, 6, 15],
+ [8, 11, 0, 0, 0, 0, 1, 0, 7, 0],
+ [0, 0, 2, 0, 0, 0, 6, 7, 0, 0],
+ [10, 0, 0, 5, 0, 11, 15, 0, 0, 0]];
+*******************************************************
+Output:
+Distance from Source:
+Vertex Distance
+0 0
+1 14
+2 14
+3 7
+4 16
+5 11
+6 9
+7 8
+8 15
+9 10
+*/
From c45f20be73e5dba0d36fe491dc5f03c7e5d4dd5f Mon Sep 17 00:00:00 2001
From: Lakshyajit Laxmikant <30868587+lakshyajit165@users.noreply.github.com>
Date: Mon, 6 Apr 2020 23:02:10 +0530
Subject: [PATCH 072/265] added selection sort logic in typescript (#2693)
---
Selection_Sort/Selection_Sort.ts | 35 ++++++++++++++++++++++++++++++++
1 file changed, 35 insertions(+)
create mode 100644 Selection_Sort/Selection_Sort.ts
diff --git a/Selection_Sort/Selection_Sort.ts b/Selection_Sort/Selection_Sort.ts
new file mode 100644
index 000000000..1c77907e8
--- /dev/null
+++ b/Selection_Sort/Selection_Sort.ts
@@ -0,0 +1,35 @@
+// function for selection sort logic
+function Selection_Sort(numbers: number[]) : number[]{
+
+ let i: number;
+ let j: number;
+ let min: number;
+ let temp: number;
+
+ // outer loop to traverse through each element
+ for(i = 0; i < numbers.length - 1; i++){
+ min = i;
+
+ // inner loop finds the minimum element and puts it in the beginning.
+ for(j = i + 1; j < numbers.length; j++){
+ if(numbers[j] < numbers[min]){
+ min = j;
+ }
+ } // inner loop ends
+
+ if(i !== min){
+ temp = numbers[i];
+ numbers[i] = numbers[min];
+ numbers[min] = temp;
+ }
+ } // outer loop ends
+
+ return numbers;
+}
+
+const numbers: number[] = [10, 9, 8, 1, 5, 2, 4, 7, 3];
+
+console.log(Selection_Sort(numbers));
+
+// INPUT [10, 9, 8, 1, 5, 2, 4, 7, 3]
+// OUTPUT [ 1, 2, 3, 4, 5, 7, 8, 9, 10 ]
From 3140991882297f12f0592c8f0a48e9bc97e62d92 Mon Sep 17 00:00:00 2001
From: Hardev Khandhar <54733460+HardevKhandhar@users.noreply.github.com>
Date: Tue, 7 Apr 2020 11:16:36 +0530
Subject: [PATCH 073/265] Tower Of Hanoi In Ruby (#2701)
---
Tower_Of_Hanoi/Tower_Of_Hanoi.rb | 37 ++++++++++++++++++++++++++++++++
1 file changed, 37 insertions(+)
create mode 100644 Tower_Of_Hanoi/Tower_Of_Hanoi.rb
diff --git a/Tower_Of_Hanoi/Tower_Of_Hanoi.rb b/Tower_Of_Hanoi/Tower_Of_Hanoi.rb
new file mode 100644
index 000000000..1165b804c
--- /dev/null
+++ b/Tower_Of_Hanoi/Tower_Of_Hanoi.rb
@@ -0,0 +1,37 @@
+## Tower Of Hanoi In Ruby
+
+## Recursive Function
+def tower(disk, source, auxilary, destination)
+ if disk == 1
+ puts "Disk #{disk} moves from #{source} to #{destination}"
+ return
+ end
+
+ tower(disk - 1, source, destination, auxilary)
+ puts "Disk #{disk} moves from #{source} to #{destination}"
+ tower(disk - 1, auxilary, source, destination)
+ nil
+
+end
+
+## Taking User Input For Number Of disks
+puts "Enter the number of disks: "
+disk = gets.to_i
+puts
+
+## Fucntion Call
+tower(disk, 'source', 'auxiliary', 'destination')
+
+=begin
+
+Enter the number of disks: 3
+
+Disk 1 moves from Source to Destination
+Disk 2 moves from Source to Auxiliary
+Disk 1 moves from Destination to Auxiliary
+Disk 3 moves from Source to Destination
+Disk 1 moves from Auxiliary to Source
+Disk 2 moves from Auxiliary to Destination
+Disk 1 moves from Source to Destination
+
+=end
From 971acfb0d7b75c433dbaed6b4b6b1c49c0af588a Mon Sep 17 00:00:00 2001
From: sandhyabhan <52604131+sandhyabhan@users.noreply.github.com>
Date: Thu, 9 Apr 2020 15:08:15 +0530
Subject: [PATCH 074/265] Add Inorder Traversal in Kotlin (#2657)
Updated inorder
---
Tree_Inorder_Traversal/Inorder_Traversal.kt | 62 +++++++++++++++++++++
1 file changed, 62 insertions(+)
create mode 100644 Tree_Inorder_Traversal/Inorder_Traversal.kt
diff --git a/Tree_Inorder_Traversal/Inorder_Traversal.kt b/Tree_Inorder_Traversal/Inorder_Traversal.kt
new file mode 100644
index 000000000..5acd29580
--- /dev/null
+++ b/Tree_Inorder_Traversal/Inorder_Traversal.kt
@@ -0,0 +1,62 @@
+//Code for printing inorder traversal in kotlin
+
+class Node
+{
+ //Structure of Binary tree node
+ int num;
+ Node left, right;
+ public node(int num)
+ {
+ key = item;
+ left = right = null;
+ }
+}
+
+class BinaryTree
+{
+ Node root;
+ BinaryTree()
+ {
+ root = null;
+ }
+ //function to print inorder traversal
+ fun printInorder(Node: node):void
+ {
+ if (node == null)
+ return;
+ printInorder(node.left);
+ //printing val of node
+ println(node.num);
+ printInorder(node.right);
+ }
+
+ fun printInorder():void
+ {
+ printInorder(root);
+ }
+}
+
+ //Main function
+fun main()
+{
+ BinaryTree tree = new BinaryTree();
+ var read = Scanner(System.`in`)
+ println("Enter the size of Array:")
+ val arrSize = read.nextLine().toInt()
+ var arr = IntArray(arrSize)
+ println("Enter data of binary tree")
+
+ for(i in 0 until arrSize)
+ {
+ arr[i] = read.nextLine().toInt()
+ tree.root = new Node(arr[i]);
+ }
+
+ println("Inorder traversal of binary tree is");
+ tree.printInorder();//function call
+}
+
+/*
+Input: 10 8 3 30 5 19 4 5 1
+Output:5 3 1 2 8 10 19 30 4
+*/
From 6019d81ec1c2daff0257428d42479eb28863daa5 Mon Sep 17 00:00:00 2001
From: reeha <56428237+syedareehaquasar@users.noreply.github.com>
Date: Thu, 9 Apr 2020 19:39:59 +0530
Subject: [PATCH 075/265] README FOR FORD FULKERSON METHOD (#2589)
---
Ford_Fulkerson_Method/README.md | 70 +++++++++++++++++++++++++++++++++
1 file changed, 70 insertions(+)
create mode 100644 Ford_Fulkerson_Method/README.md
diff --git a/Ford_Fulkerson_Method/README.md b/Ford_Fulkerson_Method/README.md
new file mode 100644
index 000000000..74c1fddd7
--- /dev/null
+++ b/Ford_Fulkerson_Method/README.md
@@ -0,0 +1,70 @@
+# Ford-Fulkerson Algorithm
+
+The Ford-Fulkerson algorithm is an algorithm that tackles the max-flow min-cut problem. That is, given a network with vertices and edges between those vertices that have certain weights, how much "flow" can the network process at a time? Flow can mean anything, but typically it means data through a computer network.
+
+It was discovered in 1956 by Ford and Fulkerson. This algorithm is sometimes referred to as a method because parts of its protocol are not fully specified and can vary from implementation to implementation. An algorithm typically refers to a specific protocol for solving a problem, whereas a method is a more general approach to a problem.
+
+The Ford-Fulkerson algorithm assumes that the input will be a graph, GG, along with a source vertex, ss, and a sink vertex, tt. The graph is any representation of a weighted graph where vertices are connected by edges of specified weights. There must also be a source vertex and sink vertex to understand the beginning and end of the flow network.
+
+Ford-Fulkerson has a complexity of O\big(|E| \cdot f^{*}\big),O(∣E∣⋅f
+∗
+ ), where f^{*}f
+∗
+ is the maximum flow of the network. The Ford-Fulkerson algorithm was eventually improved upon by the Edmonds-Karp algorithm, which does the same thing in O\big(V^2 \cdot E\big)O(V
+2
+ ⋅E) time, independent of the maximum flow value.
+
+## ALGORITHM
+Follow 3 basic steps:
+1. Find augmented path
+2. Complete the bottle neck capacity
+3. Augment each edge and total flow
+Repeat these steps until the augmented path is reached
+
+### Example:
+
+here only 2 spaces are there in DT so taking 2
+
+Similarly another path
+
+Similarly another path
+
+Similarly another path
+
+Here paths SA and CD are full but we require 2 in AC but place of only 1 in CD so we have reached our answer ->19
+
+
+## PSEUDOCODE
+
+The pseudo-code for this method is quite short; however, there are some functions that bear further discussion. The simple pseudo-code is below.
+This pseudo-code is not written in any specific computer language. Instead, it is an informal, high-level description of the algorithm.
+
+Ford-Fulkerson Algorithm ((Graph GG, source ss, sink t):t):
+```
+initialize flow to 0
+path = findAugmentingPath(G, s, t)
+while path exists:
+ augment flow along path #This is purposefully ambiguous for now
+ G_f = createResidualGraph()
+ path = findAugmentingPath(G_f, s, t)
+return flow
+```
+
+# Time Complexity
+O(max_flow * E)
+Time complexity of the above algorithm is O(max_flow * E). We run a loop while there is an augmenting path. In worst case, we may add 1 unit flow in every iteration. Therefore the time complexity becomes O(max_flow * E)
+
+
+# Implementation
+
+ - [c code](https://github.com/jainaman224/Algo_Ds_Notes/blob/master/Ford_Fulkerson_Method/Ford_Fulkerson_Method.c)
+ - [coffee code]
+ - [cpp code](https://github.com/jainaman224/Algo_Ds_Notes/blob/master/Ford_Fulkerson_Method/Ford-Fulkerson.cpp)
+ - [c# code]
+ - [go code]
+ - [java code](https://github.com/jainaman224/Algo_Ds_Notes/blob/master/Ford_Fulkerson_Method/Ford_Fulkerson_Method.java)
+ - [javaScript code]
+ - [kotlin code]
+ - [python code](https://github.com/jainaman224/Algo_Ds_Notes/blob/master/Ford_Fulkerson_Method/Ford_Fulkerson_Method.py)
+ - [ruby code]
+ - [dart code]
From 8d30245d30d75f888614623ef88b8f9cecaf608f Mon Sep 17 00:00:00 2001
From: kushagra-anand <52084821+kushagra-anand@users.noreply.github.com>
Date: Fri, 10 Apr 2020 15:02:42 +0530
Subject: [PATCH 076/265] Kadane Algorithm (#2534)
* Create Kadane Algorithm in GO
---
Kadane_Algorithm/Kadane_Algorithm.go | 55 ++++++++++++++++++++++++++++
1 file changed, 55 insertions(+)
create mode 100644 Kadane_Algorithm/Kadane_Algorithm.go
diff --git a/Kadane_Algorithm/Kadane_Algorithm.go b/Kadane_Algorithm/Kadane_Algorithm.go
new file mode 100644
index 000000000..d9bf09646
--- /dev/null
+++ b/Kadane_Algorithm/Kadane_Algorithm.go
@@ -0,0 +1,55 @@
+// Go program to print largest contiguous array sum
+
+package main
+
+import "fmt"
+
+func KAlgo(a []int, n int) int {
+ var max int
+ var check_max int
+ max = 0
+ check_max = 0
+
+ for i := 0; i < n; i++ {
+ check_max = check_max + a[i]
+
+ // Minimum sum will be 0
+ if check_max < 0 {
+ check_max = 0
+ }
+ if max < check_max {
+ max = check_max
+ }
+ }
+ return max
+}
+
+//Main Function
+func main() {
+ var n int
+ fmt.Print("Enter number of Elements ")
+ fmt.Scan(&n)
+ ope(n)
+}
+
+func ope(n int) {
+ fmt.Print("\nEnter Elements ")
+ a := make([]int, n)
+
+ // Array input
+ for i := 0; i < n; i++ {
+ fmt.Scan(&a[i])
+ }
+
+ var output int
+
+ // Function Calling for the Algo
+ output = KAlgo(a, n)
+ fmt.Println("\nSum of the sub array: ", output)
+}
+
+/*
+Enter Number of Elements 6
+Enter Elements 2 -4 -5 -6 8 10
+Sum of the sub array: 18
+*/
From d3d50a9e92669ae4af0d027c1e72e5ba09e8ca73 Mon Sep 17 00:00:00 2001
From: Ravi Kanth Gojur
Date: Fri, 10 Apr 2020 22:01:49 +0530
Subject: [PATCH 077/265] Boyer Moore Algo in c added (#2644)
---
Boyer_Moore_Algorithm/Boyer_Moore.c | 63 +++++++++++++++++++++++++++++
1 file changed, 63 insertions(+)
create mode 100644 Boyer_Moore_Algorithm/Boyer_Moore.c
diff --git a/Boyer_Moore_Algorithm/Boyer_Moore.c b/Boyer_Moore_Algorithm/Boyer_Moore.c
new file mode 100644
index 000000000..ec88ef89d
--- /dev/null
+++ b/Boyer_Moore_Algorithm/Boyer_Moore.c
@@ -0,0 +1,63 @@
+#include
+#define MAX 256
+
+int findmax(int a, int b)
+{
+ return (a > b) ? a : b;
+}
+
+void searchwrongchar(char *str, int size, int extra[MAX])
+{
+ for (int i = 0; i < MAX; ++i)
+ extra[i] = -1;
+
+ for (int i = 0; i < size; ++i)
+ extra[(int)str[i]] = i;
+}
+
+void search(char *text, char *pattern)
+{
+ int patLen = strlen(pattern);
+ int txtLen = strlen(text);
+
+ int extra[MAX];
+
+ searchwrongchar(pattern, patLen, extra);
+
+ int s = 0;
+ while (s <= (txtLen - patLen))
+ {
+ int j = patLen - 1;
+
+ while (j >= 0 && pattern[j] == text[s + j])
+ j--;
+
+ if (j < 0)
+ {
+ printf("\n\nPattern Matches at shift of = %d.", s);
+ s += (s + patLen < txtLen) ? patLen - extra[text[s + patLen]] : 1;
+ }
+ else
+ s += findmax(1, j - extra[text[s + j]]);
+ }
+}
+
+int main()
+{
+ char text[MAX], pattern[MAX];
+ printf("Enter the Text: ");
+ scanf("%s", &text);
+ printf("\nEnter the Pattern to Match: ");
+ scanf("%s", &pattern);
+ search(text, pattern);
+ return 0;
+}
+
+/*
+INPUT:
+Enter the Text: ABAAABCD
+Enter the Pattern to Match: ABC
+
+OUTPUT:
+Pattern match at shift = 4
+*/
From fe9be768da741dd8f0d1edd68f8d996c9b308300 Mon Sep 17 00:00:00 2001
From: jedicakelord <46528937+jedicakelord@users.noreply.github.com>
Date: Fri, 10 Apr 2020 23:10:12 +0530
Subject: [PATCH 078/265] Boyer Moore in Go (#2687)
---
Boyer_Moore_Algorithm/Boyer_Moore.go | 78 ++++++++++++++++++++++++++++
1 file changed, 78 insertions(+)
create mode 100644 Boyer_Moore_Algorithm/Boyer_Moore.go
diff --git a/Boyer_Moore_Algorithm/Boyer_Moore.go b/Boyer_Moore_Algorithm/Boyer_Moore.go
new file mode 100644
index 000000000..092766194
--- /dev/null
+++ b/Boyer_Moore_Algorithm/Boyer_Moore.go
@@ -0,0 +1,78 @@
+/*Boyer Moore Algorithm for Pattern Search*/
+package main
+
+import "fmt"
+
+func max(a, b int) int {
+ if a > b {
+ return a
+ }
+ return b
+}
+
+//Using Bad Character Heuristic method
+func preprocess(str string, length int, chars []int) {
+
+ for i,_:=range(chars) {chars[i] = 1}
+
+ //The last occurrence of the char
+ for k := 0; k < length; k++ {
+ chars[int(str[k])] = k;
+ }
+}
+
+func boyreMoore(text string, pattern string) {
+ var lenStr int = len(text)
+ var lenPattern int = len(pattern)
+
+ chars := make([]int, 128)
+
+ preprocess(pattern, lenPattern, chars)
+
+ //shift of the pattern with respect to text
+ var shift int = 0
+
+ for shift <= lenStr - lenPattern {
+ match := lenPattern - 1
+
+ for (match >= 0 && pattern[match] == text[shift + match]) {
+ match = match - 1
+ }
+
+ // If pattern found, match = -1
+ if match < 0 {
+ fmt.Printf("Pattern found at : %d\n", shift)
+
+ // Shift the pattern so that the next character in text
+ //aligns with the last occurrence of it in pattern.
+ if shift + lenPattern < lenStr {
+ shift = shift + lenPattern - chars[text[shift + lenPattern]]
+ } else {
+ shift = 1
+ }
+ } else {
+ shift = shift + max(1, match - chars[text[shift + match]]);
+ }
+ }
+}
+
+func main() {
+ var text string
+ var pattern string
+ fmt.Println("Enter the text : ")
+ fmt.Scan(&text)
+ fmt.Println("Enter the pattern to search : ")
+ fmt.Scan(&pattern)
+
+ boyreMoore(text, pattern)
+
+}
+
+/*Input :
+* Enter the text :
+* therethenthat
+* Enter the pattern :
+* the
+* Pattern found at : 0
+* Pattern found at : 8
+*/
From 7e653099d6b670124e6238c4c6e494e1c0b5f6a0 Mon Sep 17 00:00:00 2001
From: coderprasukj <60914425+coderprasukj@users.noreply.github.com>
Date: Sun, 12 Apr 2020 20:30:20 +0530
Subject: [PATCH 079/265] Kruskal Algo in C (#2255)
---
Kruskal_Algorithm/Kruskal_Algorithm.c | 153 ++++++++++++++++++++++++++
1 file changed, 153 insertions(+)
create mode 100644 Kruskal_Algorithm/Kruskal_Algorithm.c
diff --git a/Kruskal_Algorithm/Kruskal_Algorithm.c b/Kruskal_Algorithm/Kruskal_Algorithm.c
new file mode 100644
index 000000000..4f7692296
--- /dev/null
+++ b/Kruskal_Algorithm/Kruskal_Algorithm.c
@@ -0,0 +1,153 @@
+// Kruskal Algorithm in C
+#include
+#define NUM 20
+
+// Creating the edge
+typedef struct edge
+{
+ int p; // Variable to contain all the first node of the edge
+ int q; // Variable to contain all the second node of the edge
+ int weight; // Variable to contain the weight of the edge
+} edge;
+
+// Creating the Edgelist
+typedef struct edgelist
+{
+ edge data[NUM];
+ int n;
+} edgelist;
+
+edgelist list;
+int weights[NUM][NUM]; // Array for weights in the graph
+int n;
+edgelist listSpan;
+
+void kruskal_algo();
+void print();
+int find(int contain[], int vertexno);
+void union1(int contain[], int c1, int c2);
+void sort();
+
+// Driver Program
+int main()
+{
+ int total_cost;
+ printf("\nEnter number of vertices : ");
+ scanf("%d", &n); // Number of Vertices
+
+ printf("\nEnter the adjacency matrix : \n");
+
+ for(int i = 0; i < n; i++) // Enter the Adjacency Matrix
+ for(int j = 0; j < n; j++)
+ scanf("%d", &weights[i][j]);
+
+ kruskal_algo();
+ print();
+ return 0;
+}
+
+// Function performing Kruskal's algorithm
+void kruskal_algo()
+{
+ int contain[NUM], x, y;
+ list.n = 0;
+
+ for(int i = 1; i < n; i++)
+ for(int j = 0; j < i; j++)
+ {
+ if(weights[i][j] != 0)
+ {
+ // Containing all the first node of the edges
+ list.data[list.n].p = i;
+ // Containing all the second node of the edges
+ list.data[list.n].q = j;
+ // Containing the weight of the edges
+ list.data[list.n].weight = weights[i][j];
+ list.n++;
+ }
+ }
+
+ // Sorting the edges according to their weight.
+ sort();
+
+ for(int i = 0; i < n; i++)
+ contain[i] = i; // Intializing the array with first node
+
+ listSpan.n = 0;
+
+ for(int i = 0; i < list.n; i++)
+ {
+ x = find(contain, list.data[i].p); // x is the first node of the edge
+ y = find(contain, list.data[i].q); // y is the second node of the edge
+ if(x != y)
+ {
+ listSpan.data[listSpan.n] = list.data[i];
+ listSpan.n = listSpan.n+1;
+ union1(contain, x, y);
+ }
+ }
+}
+
+// Returns the value present at k[vertex_number]
+int find(int contain[], int vertex_number)
+{
+ return(contain[vertex_number]);
+}
+
+void union1(int contain[], int c1, int c2)
+{
+ for(int i = 0; i < n; i++)
+ if(contain[i] == c2)
+ contain[i] = c1;
+}
+
+// Sorting all the edges in increasing order
+// according to their weight.
+void sort()
+{
+ edge temp;
+ for(int i = 1; i < list.n; i++)
+ {
+ for(int j = 0; j < list.n-1; j++)
+ {
+ if(list.data[j].weight > list.data[j+1].weight)
+ {
+ temp = list.data[j];
+ list.data[j] = list.data[j+1];
+ list.data[j+1] = temp;
+ }
+ }
+ }
+}
+
+// Printing the Output
+void print()
+{
+ int cost = 0;
+ for(int i = 0; i < listSpan.n; i++)
+ {
+ printf("\n%d\t%d\t%d", listSpan.data[i].p, listSpan.data[i].q, listSpan.data[i].weight);
+ cost = cost + listSpan.data[i].weight;
+ }
+ printf("\nCost of the spanning tree = %d\n", cost);
+}
+
+/*
+INPUT :
+Enter number of vertices : 6
+Enter the Adjacency Matrix :
+ 0 3 0 0 6 5
+ 3 0 1 0 0 4
+ 0 1 0 6 0 4
+ 0 0 6 0 8 5
+ 6 0 0 8 0 2
+ 5 4 4 5 2 0
+
+OUTPUT :
+
+ 2 1 1
+ 5 4 2
+ 1 0 3
+ 5 1 4
+Cost of the spanning tree = 15
+*/
From 0f3e0fbbef557c44cfba9c229f688a5a315bf7b4 Mon Sep 17 00:00:00 2001
From: Hardev Khandhar <54733460+HardevKhandhar@users.noreply.github.com>
Date: Mon, 13 Apr 2020 01:39:25 +0530
Subject: [PATCH 080/265] Breadth First Search in Ruby (#2635)
* BFS in Ruby
* Updated Changes
---
Breadth_First_Search/Breadth_First_Search.rb | 92 ++++++++++++++++++++
1 file changed, 92 insertions(+)
create mode 100644 Breadth_First_Search/Breadth_First_Search.rb
diff --git a/Breadth_First_Search/Breadth_First_Search.rb b/Breadth_First_Search/Breadth_First_Search.rb
new file mode 100644
index 000000000..e2548423c
--- /dev/null
+++ b/Breadth_First_Search/Breadth_First_Search.rb
@@ -0,0 +1,92 @@
+## Breadth First Search algorithm in Ruby.
+
+def breadth_first_search(adj_matrix, source, destination)
+ node_array = [source]
+ path = []
+ ## puts "\nThe initial NODE ARRAY is #{node_array}."
+
+ loop do
+ curr_node = node_array.pop
+ path << curr_node
+ ## puts "The next node to be checked is #{curr_node}."
+
+ if curr_node.nil?
+ puts 'Destination Node Not Found!'
+ return false
+
+ elsif curr_node == destination
+ puts "\nDestination Node #{curr_node} Found!"
+ puts "\nThe path between Source Node #{source} and Destination Node #{destination} is:\n #{path}."
+ return true
+
+ end
+
+ ## puts "\nIterating through the following array:\n #{adj_matrix[curr_node]}"
+ children = (0..adj_matrix.length - 1).to_a.select do |i|
+ ## puts "Checking index #{i} whose value is #{adj_matrix[curr_node][i]}"
+ adj_matrix[curr_node][i] == 1
+
+ end
+
+ ## puts "\nCHILD ARRAY returned: #{children}"
+ node_array = children + node_array
+ ## puts "\nAfter appending CHILD ARRAY, NODE ARRAY is: #{node_array}"
+
+ end
+
+end
+
+## Defining Adjacency Matrix by taking user input
+
+puts "Enter Size of Adjacency Matrix: "
+size = gets.to_i
+
+adj_matrix = Array.new(size) { [] }
+
+i = 0
+counter = 0
+
+while(counter != size)
+ i = 0
+ puts "\nEnter the values of row #{counter + 1}: "
+ while(i != size)
+ adj_matrix[counter][i] = gets.to_i
+ i += 1
+ end
+ counter += 1
+end
+
+## User input for Source Node and Destination Node
+
+puts "\nEnter Source Node: "
+source = gets.to_i
+
+puts "\nEnter Destination Node: "
+destination = gets.to_i
+
+## Passing the adjacent matrix, source and destination as arguments to the algorithm.
+
+breadth_first_search(adj_matrix, source, destination)
+
+=begin
+
+Enter Size of Adjacency Matrix: 4
+
+Enter the values of row 1: 0 1 1 0
+
+Enter the values of row 2: 1 0 0 0
+
+Enter the values of row 3: 1 0 1 0
+
+Enter the values of row 4: 0 1 0 0
+
+Enter Source Node: 0
+
+Enter Destination Node: 2
+
+Destination Node 2 Found!
+
+The path between Source Node 0 and Destination Node 2 is:
+ [0, 2].
+
+=end
From b21a0eaebdf2362cb8077456c794c17a603e76ae Mon Sep 17 00:00:00 2001
From: Hardev Khandhar <54733460+HardevKhandhar@users.noreply.github.com>
Date: Mon, 13 Apr 2020 23:13:22 +0530
Subject: [PATCH 081/265] Tree Inorder Traversal In C# (#2723)
---
.../Tree_Inorder_Traversal.cs | 173 ++++++++++++++++++
1 file changed, 173 insertions(+)
create mode 100644 Tree_Inorder_Traversal/Tree_Inorder_Traversal.cs
diff --git a/Tree_Inorder_Traversal/Tree_Inorder_Traversal.cs b/Tree_Inorder_Traversal/Tree_Inorder_Traversal.cs
new file mode 100644
index 000000000..0ef48879e
--- /dev/null
+++ b/Tree_Inorder_Traversal/Tree_Inorder_Traversal.cs
@@ -0,0 +1,173 @@
+/**
+ Tree Inorder Traversal In C#
+*/
+
+using System;
+
+// Node Class To Declare Nodes Of The Tree
+class Node
+{
+ public int data;
+ public Node left;
+ public Node right;
+
+ public void display()
+ {
+ Console.Write(" [");
+ Console.Write(data);
+ Console.Write("] ");
+ }
+}
+
+// Tree Class To Declare Binary Search Tree
+class Tree
+{
+ public Node root;
+
+ // Constructor
+ public Tree()
+ {
+ root = null;
+ }
+
+ public Node ReturnRoot()
+ {
+ return root;
+ }
+
+ // Function To Insert Node Into BST
+ public void Insert(int id)
+ {
+ Node newNode = new Node();
+ newNode.data = id;
+
+ if (root == null)
+ root = newNode;
+ else
+ {
+ Node current = root;
+ Node parent;
+
+ while (true)
+ {
+ parent = current;
+ if (id < current.data)
+ {
+ current = current.left;
+ if (current == null)
+ {
+ parent.left = newNode;
+ return;
+ }
+ }
+
+ else
+ {
+ current = current.right;
+ if (current == null)
+ {
+ parent.right = newNode;
+ return;
+ }
+ }
+ }
+ }
+ }
+
+ // Inorder Traversal Function
+ public void Inorder(Node Root)
+ {
+ if (Root != null)
+ {
+ Inorder(Root.left);
+ Console.Write(Root.data + " ");
+ Inorder(Root.right);
+ }
+ }
+}
+
+class InorderTreeProgram
+{
+ public static void Main(string[] args)
+ {
+ // Declaring the Object Of Tree Class
+ Tree BST = new Tree();
+ Console.WriteLine("1. Insert Node");
+ Console.WriteLine("2. Display InOrder Traversal");
+ Console.WriteLine("3. Exit");
+
+ while(true)
+ {
+ Console.WriteLine("\nEnter your choice: ");
+ String choice = Console.ReadLine();
+ int Choice = int.Parse(choice);
+
+ switch(Choice)
+ {
+ case 1:
+ {
+ Console.WriteLine("Enter the value to insert node: ");
+ String val = Console.ReadLine();
+ int data = int.Parse(val);
+ BST.Insert(data);
+ break;
+ }
+
+ case 2:
+ {
+ Console.WriteLine("\nTree Inorder Traversal: ");
+ BST.Inorder(BST.ReturnRoot());
+ Console.WriteLine(" ");
+ break;
+ }
+
+ case 3:
+ {
+ Console.WriteLine("Exit");
+ System.Environment.Exit(0);
+ break;
+ }
+ }
+ }
+ }
+}
+
+/**
+
+1. Insert Node
+2. Display InOrder Traversal
+3. Exit
+
+Enter your choice: 1
+Enter the value to insert node: 30
+
+Enter your choice: 1
+Enter the value to insert node: 35
+
+Enter your choice: 1
+Enter the value to insert node: 57
+
+Enter your choice: 1
+Enter the value to insert node: 15
+
+Enter your choice: 1
+Enter the value to insert node: 63
+
+Enter your choice: 1
+Enter the value to insert node: 49
+
+Enter your choice: 1
+Enter the value to insert node: 77
+
+Enter your choice: 1
+Enter the value to insert node: 98
+
+Enter your choice: 2
+
+Tree Inorder Traversal:
+15 30 35 49 57 63 77 98
+
+Enter your choice: 3
+Exit
+
+*/
From 5f10bda91547599631ab7c9fc248f6e8b7d8e756 Mon Sep 17 00:00:00 2001
From: riajha02 <32812168+RiaJha02@users.noreply.github.com>
Date: Mon, 13 Apr 2020 11:14:13 -0700
Subject: [PATCH 082/265] Adding Backtracking Using Bitmasking (#2583)
Squashing Files
---
.../Backtrack_using_bitmask.cpp | 48 +++++++++++++++
.../Backtrack_using_bitmask.java | 59 +++++++++++++++++++
.../Backtrack_using_bitmask.py | 46 +++++++++++++++
3 files changed, 153 insertions(+)
create mode 100644 Backtracking_using_bitmask/Backtrack_using_bitmask.cpp
create mode 100644 Backtracking_using_bitmask/Backtrack_using_bitmask.java
create mode 100644 Backtracking_using_bitmask/Backtrack_using_bitmask.py
diff --git a/Backtracking_using_bitmask/Backtrack_using_bitmask.cpp b/Backtracking_using_bitmask/Backtrack_using_bitmask.cpp
new file mode 100644
index 000000000..430594811
--- /dev/null
+++ b/Backtracking_using_bitmask/Backtrack_using_bitmask.cpp
@@ -0,0 +1,48 @@
+#include
+using namespace std;
+
+#define d (1 << n) - 1
+int cnt = 0;
+
+/*This is an optimised approach than the normal backtracking approach.
+Here we don’t need to write is Safe Position Function
+which works in linear time instead we use bitsets which work in O(1) time.*/
+
+void solve(int row, int left, int right, int n)
+{
+ //All rows are occupied,so the solution must be complete
+ if(row == d)
+ {
+ cnt++;
+ return;
+ }
+
+ //Gets a bit sequence with "1"s whereever there is an open "slot"
+ int pos = d & ~(left | row | right);
+
+ //Loops as long as there is a valid place to put another queen.
+ while(pos > 0)
+ {
+ int bit = pos & (-pos);
+ pos -= bit;
+ solve(row | bit, (left | bit) << 1, (right | bit) >> 1, n);
+ }
+}
+
+int main() {
+ int n;
+ cin >> n;
+ solve(0, 0, 0, n);
+ cout << cnt;
+}
+
+/*
+Sample Input:
+4
+Sample Output:
+2
+Sample Input:
+5
+Sample Output:
+10
+*/
\ No newline at end of file
diff --git a/Backtracking_using_bitmask/Backtrack_using_bitmask.java b/Backtracking_using_bitmask/Backtrack_using_bitmask.java
new file mode 100644
index 000000000..20c064bfb
--- /dev/null
+++ b/Backtracking_using_bitmask/Backtrack_using_bitmask.java
@@ -0,0 +1,59 @@
+import java.util.*;
+class Solution
+{
+ //Keeps track of the # of valid solutions
+ static int ans = 0;
+
+ public static int power(int x, int y)
+ {
+ if(y == 0)
+ return 1;
+ int result = power(x,y / 2);
+ if(y % 2 == 0)
+ return result * result;
+ else
+ return x * result * result;
+ }
+ //Checks all possible board configurations
+ public static void solveNQueens(int left, int col, int right, int n, int done)
+ {
+ //All columns are occupied, so the solution must be complete
+ if(col == done)
+ {
+ ans++;
+ return;
+ }
+
+ //Gets a bit sequence with "1"s where ever there is an open "slot"
+ int pos = ~(left | col | right) & done;
+
+ //Loops as long as there is a valid place to put another queen.
+ while(pos > 0)
+ {
+ int bit = pos & (-pos);
+ pos = pos - bit;
+ solveNQueens((left | bit) >> 1, col | bit, (right | bit) << 1, n, done);
+ }
+ }
+ public static void main(String[] args)
+ {
+ Scanner input = new Scanner(System.in);
+ int n = input.nextInt();
+ //Helps identify valid solutions
+ int done = power(2, n) - 1;
+ solveNQueens(0, 0, 0, n, done);
+ System.out.print(ans);
+ input.close();
+ }
+};
+
+/*
+Sample Input:
+4
+Sample Output:
+2
+Sample Input:
+5
+Sample Output:
+10
+*/
\ No newline at end of file
diff --git a/Backtracking_using_bitmask/Backtrack_using_bitmask.py b/Backtracking_using_bitmask/Backtrack_using_bitmask.py
new file mode 100644
index 000000000..c43de7811
--- /dev/null
+++ b/Backtracking_using_bitmask/Backtrack_using_bitmask.py
@@ -0,0 +1,46 @@
+# Here we use bit patterns to keep track of queen placements
+# for the columns, left diagonals and right diagonals.
+
+def totalNQueens(n):
+ #Helps identify valid solutions
+ all_ones = 2 ** n - 1
+
+ #Keeps track of the # of valid solutions
+ count = 0
+
+ #Checks all possible board configurations
+ def helper(ld, column, rd):
+ nonlocal count
+ #All columns are occupied,so the solution must be complete
+ if column == all_ones:
+ count += 1
+ return
+
+ #Gets a bit sequence with "1"s whereever there is an open "slot"
+ possible_slots = ~(ld | column | rd) & all_ones
+
+ #Loops as long as there is a valid place to put another queen.
+ while possible_slots:
+ current_bit = possible_slots & -possible_slots
+ possible_slots -= current_bit
+ helper( (ld | current_bit) >> 1, column | current_bit, (rd | current_bit) << 1)
+
+ helper(0, 0, 0)
+ return count
+
+if __name__ == '__main__':
+ n = int(input())
+ d = (1 << n) - 1
+ cnt = totalNQueens(n)
+ print(cnt)
+
+'''
+Sample Input:
+4
+Sample Output:
+2
+Sample Input:
+5
+Sample Output:
+10
+'''
\ No newline at end of file
From 9dbe42b4989276a7285d430a3d8d6fc89ae540e3 Mon Sep 17 00:00:00 2001
From: Raksha <57195964+raksha009@users.noreply.github.com>
Date: Tue, 14 Apr 2020 21:52:54 +0530
Subject: [PATCH 083/265] Transpose of matrix in java (#2529)
changes made
---
Matrix_Operations/Java/Matrix_transpose.java | 63 ++++++++++++++++++++
1 file changed, 63 insertions(+)
create mode 100644 Matrix_Operations/Java/Matrix_transpose.java
diff --git a/Matrix_Operations/Java/Matrix_transpose.java b/Matrix_Operations/Java/Matrix_transpose.java
new file mode 100644
index 000000000..f24dacd1d
--- /dev/null
+++ b/Matrix_Operations/Java/Matrix_transpose.java
@@ -0,0 +1,63 @@
+// Java Program to calculation transpose of a matrix (2D Array)
+import java.util.Scanner;
+
+public class Matrix_transpose {
+
+ // Find transpose of matrix
+ public static void transpose_matrices(int[][] matrix) {
+
+ int index1, index2;
+ int[][] matrix_ans = new int[matrix.length][matrix[0].length];
+ for ( index1 = 0; index1 < matrix.length; index1 ++) {
+ for ( index2 = 0; index2 < matrix[0].length; index2++ ) {
+ matrix_ans[index2][index1] = matrix[index1][index2];
+ }
+ }
+
+ // Print the calculated matrix
+ for ( index1 = 0; index1 < matrix_ans.length; index1 ++) {
+ for ( index2 = 0; index2 < matrix_ans[0].length; index2++ ) {
+ System.out.print( matrix_ans[index1][index2] + " ");
+ }
+ System.out.println();
+ }
+ }
+
+ public static void main(String args[]) {
+ Scanner s = new Scanner(System.in);
+
+ System.out.println(" Enter number of rows ");
+ int rows = s.nextInt();
+
+ System.out.println(" Enter number of columns ");
+ int columns = s.nextInt();
+ int[][] matrix = new int[rows][columns];
+
+
+ System.out.println(" Enter elements of matrix ");
+ for (int i = 0; i < rows; i++) {
+ for (int j = 0 ; j < columns; j++) {
+ matrix[i][j] = s.nextInt();
+ }
+ }
+ transpose_matrices(matrix);
+ }
+}
+/*
+TEST CASES
+
+INPUT
+ Enter number of rows
+2
+ Enter number of columns
+2
+ Enter elements of matrix
+2 3
+4 5
+
+OUTPUT
+2 4
+3 5
+
+*/
+
From 335ca72ad25fb16d86d02b933b5417b63835ffc0 Mon Sep 17 00:00:00 2001
From: Manish Choudhary <53442020+Manish-cloud@users.noreply.github.com>
Date: Tue, 14 Apr 2020 21:58:22 +0530
Subject: [PATCH 084/265] Kruskal Algorithm Implementation in python (#2682)
Used disjoint set data structure for Algorithm implementation.
---
Kruskal_Algorithm/Kruskal_Algorithm.py | 93 ++++++++++++++++++++++++++
1 file changed, 93 insertions(+)
create mode 100644 Kruskal_Algorithm/Kruskal_Algorithm.py
diff --git a/Kruskal_Algorithm/Kruskal_Algorithm.py b/Kruskal_Algorithm/Kruskal_Algorithm.py
new file mode 100644
index 000000000..973909899
--- /dev/null
+++ b/Kruskal_Algorithm/Kruskal_Algorithm.py
@@ -0,0 +1,93 @@
+#Implementation of Kruskal Algorithm using Disjoint
+
+graphData = []
+vertices = []
+
+class Disjoint:
+ def __init__(self):
+ self.sets = []
+
+ def createSet(self, val):
+ self.sets.append([val])
+
+ def getSets(self):
+ return self.sets
+
+ def findSet(self, val):
+ for oneSet in self.sets:
+ if val in oneSet:
+ return oneSet
+
+ def mergeSets(self, val1, val2):
+ set1 = self.findSet(val1)
+ set2 = self.findSet(val2)
+ if set1 != set2:
+ set1.extend(set2)
+ self.sets.remove(set2)
+
+def kruskalAlgorithm(vertices, graphData):
+ MST = []
+ minimumWeight = 0
+
+ adisjointSet = Disjoint() # Creating object of disjoint set
+ for vertex in vertices:
+ adisjointSet.createSet(vertex)
+
+ graphData.sort() # Sort weights in increasing order
+
+ for weight, vertex1, vertex2 in graphData:
+ if (adisjointSet.findSet(vertex1) != adisjointSet.findSet(vertex2)):
+ minimumWeight += weight
+ MST.append((weight, vertex1, vertex2))
+ adisjointSet.mergeSets(vertex1, vertex2)
+ # To improve efficiency
+ # when length of disjoint set becomes 1 we can break loop
+ if (len(adisjointSet.sets) == 1):
+ break
+
+ print("Minimum Weight : ", minimumWeight)
+ # To display in which order edges are added
+ for path in MST:
+ print((path[1], path[2]), "=>", path[0])
+
+if __name__ == "__main__":
+ numberOfVertices = int(input("Enter number of vertices in graph : "))
+ print("Enter vertices")
+ for _ in range(numberOfVertices):
+ vertex = input()
+ vertices.append(vertex)
+
+ numberOfEdges = int(input("Enter number of edges in graph : "))
+ print("Note :=> Enter graph data in following format weight vertex1 vertex2")
+ for _ in range(numberOfEdges):
+ weights, vertex1, vertex2 = input().split()
+ weights = int(weights)
+ graphData.append((weights, vertex1, vertex2))
+
+ kruskalAlgorithm(vertices, graphData)
+
+"""
+Input/Output
+
+Enter number of vertices in graph : 5
+Enter vertices
+a
+b
+c
+d
+e
+Enter number of edges in graph : 7
+Note :=> Enter graph data in following format weight vertex1 vertex2
+1 a c
+4 a b
+2 c b
+3 b d
+7 c d
+5 c e
+6 d e
+Minimum Weight : 11
+('a', 'c') => 1
+('c', 'b') => 2
+('b', 'd') => 3
+('c', 'e') => 5
+"""
From 1d8912a78ac23096a948407ba3dd3bdf6bc364cf Mon Sep 17 00:00:00 2001
From: Rukmini Meda <44504940+Rukmini-Meda@users.noreply.github.com>
Date: Tue, 14 Apr 2020 22:03:55 +0530
Subject: [PATCH 085/265] Tree Preorder Traversal in Dart (#2720)
---
.../Tree_Preorder_Traversal.dart | 139 ++++++++++++++++++
1 file changed, 139 insertions(+)
create mode 100644 Tree_Preorder_Traversal/Tree_Preorder_Traversal.dart
diff --git a/Tree_Preorder_Traversal/Tree_Preorder_Traversal.dart b/Tree_Preorder_Traversal/Tree_Preorder_Traversal.dart
new file mode 100644
index 000000000..81898f6cf
--- /dev/null
+++ b/Tree_Preorder_Traversal/Tree_Preorder_Traversal.dart
@@ -0,0 +1,139 @@
+import 'dart:io';
+
+// Class to define the node of a binary tree.
+class Node {
+
+ int value;
+ Node left;
+ Node right;
+
+ Node(int value) {
+
+ this.value = value;
+ this.left = null;
+ this.right = null;
+
+ }
+
+}
+
+// Class to define a binary tree.
+class Tree {
+
+ // The tree's root.
+ Node root;
+
+ // Constructor
+ Tree(Node root) {
+ this.root = root;
+ }
+
+ // Insert method to build the tree using recursion.
+ Node insert(Node root, int val) {
+
+ if (root != null){
+
+ // Inserting in the left side if value is less than root.
+ if (val < root.value) {
+ root.left = insert(root.left, val);
+ }
+ else {
+ // Inserting in the right side if value is greater than root.
+ if (val > root.value) {
+ root.right = insert(root.right, val);
+ }
+ // Informing user that the value is already present.
+ else{
+ print("Value is already present in the tree.");
+ }
+ }
+ }
+ else{
+ // Insertion
+ root = Node(val);
+ }
+
+ return root;
+
+ }
+
+ // Utility method used to print the preorder traversal using recursion.
+ void preorder_utility(Node node) {
+
+ if (node != null) {
+ print(node.value);
+
+ // Recursion
+ preorder_utility(node.left);
+ preorder_utility(node.right);
+ }
+
+ }
+
+ // Method to print the preorder traversal of the binary tree.
+ void tree_preorder_traversal(){
+
+ print("The preorder traversal of the tree in the given input is follows:");
+ preorder_utility(this.root);
+
+ }
+
+}
+
+// Driver method of the program
+void main(){
+
+ // Reading user input
+ print("Enter root of the tree:");
+ var input = stdin.readLineSync();
+ int root_val = int.parse(input);
+
+ // Root node
+ Node root_node = Node(root_val);
+
+ // Binary Tree
+ Tree tree = Tree(root_node);
+
+ String choice = "y";
+
+ while (choice == "y") {
+
+ print("Enter number to insert:");
+ var input3 = stdin.readLineSync();
+ int insert_val = int.parse(input3);
+ tree.insert(root_node, insert_val);
+
+ print("Do you want to insert another number into the tree? (y/n)");
+ var input2 = stdin.readLineSync();
+ choice = input2;
+
+ }
+
+ /* Sample Input tree
+ 8
+ / \
+ 3 12
+ / \ / \
+ 2 6 9 15
+ / \
+ 5 7
+ */
+
+ // Calling method to print preorder traversal of the tree.
+ tree.tree_preorder_traversal();
+
+ /* Sample Output
+ The preorder traversal of the tree in the given input is follows:
+ 8
+ 3
+ 2
+ 6
+ 5
+ 7
+ 12
+ 9
+ 15
+ */
+
+}
+
From 007b6f94a16253d162f9b5b00989d1ebadbf25bf Mon Sep 17 00:00:00 2001
From: Yashasvi Sinha <59117774+heisastark@users.noreply.github.com>
Date: Tue, 14 Apr 2020 23:17:57 +0530
Subject: [PATCH 086/265] Added Karatsuba Algo in Dart (#2616)
* Sqashing 6 commits
* deleting accidentally added file
* deleting accidentally added file
* deleting accidentally added file
* deleting accidentally added file
* deleting accidentally added file
* deleting accidentally added file
* Karatsuba_Algorithm.dart added (accidently deleted while squashing commits)
---
Karatsuba_Algorithm/Karatsuba_Algorithm.dart | 57 ++++++++++++++++++++
1 file changed, 57 insertions(+)
create mode 100644 Karatsuba_Algorithm/Karatsuba_Algorithm.dart
diff --git a/Karatsuba_Algorithm/Karatsuba_Algorithm.dart b/Karatsuba_Algorithm/Karatsuba_Algorithm.dart
new file mode 100644
index 000000000..6fa0b0b3c
--- /dev/null
+++ b/Karatsuba_Algorithm/Karatsuba_Algorithm.dart
@@ -0,0 +1,57 @@
+import 'dart:io';
+import 'dart:math';
+
+// function to find minimun of two integers
+int minof(a, b){
+ if(a < b)
+ return a;
+ else return b;
+}
+
+int karatSuba(num1, num2){
+
+ // for single digit number multiply directly
+ if (num1 < 10 || num2 < 10) {
+ return num1 * num2;
+ }
+
+ String num1Str = num1.toString();
+ String num2Str = num2.toString();
+ int n = minof(num1Str.length, num2Str.length);
+ int half = (n / 2).round();
+
+ // divide num1 into two halves
+ int num1_H = int.parse(num1Str.substring(0, num1Str.length - half));
+ int num1_L = int.parse(num1Str.substring(num1Str.length - half, num1Str.length));
+
+ // divide num2 into two halves
+ int num2_H = int.parse(num2Str.substring(0, num2Str.length - half));
+ int num2_L = int.parse(num2Str.substring(num2Str.length - half, num2Str.length));
+
+ // using the KaratSuba Definition
+ int s1 = karatSuba(num1_L, num2_L);
+ int s2 = karatSuba(num1_L + num1_H, num2_L + num2_H);
+ int s3 = karatSuba(num1_H, num2_H);
+ int s4 = s2 - s3 - s1;
+
+ // karatsuba formula for finding product
+ int result = s3 * pow(10, 2 * half) + s4 * pow(10, half) + s1;
+
+ return result;
+}
+
+void main(){
+ String a, b;
+ a = stdin.readLineSync();
+ b = stdin.readLineSync();
+ print(karatSuba(int.parse(a), int.parse(b)));
+}
+
+/*
+Sample input:
+12345
+6789
+
+Sample Output:
+83810205
+*/
From 8f5692eae049825c98c8b92c826711b5463fb2b6 Mon Sep 17 00:00:00 2001
From: Lakshyajit Laxmikant <30868587+lakshyajit165@users.noreply.github.com>
Date: Tue, 14 Apr 2020 23:54:47 +0530
Subject: [PATCH 087/265] corrected indentation in shell sort using go (#2683)
---
Shell_Sort/Shell_Sort.go | 80 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 80 insertions(+)
create mode 100644 Shell_Sort/Shell_Sort.go
diff --git a/Shell_Sort/Shell_Sort.go b/Shell_Sort/Shell_Sort.go
new file mode 100644
index 000000000..aafea87fa
--- /dev/null
+++ b/Shell_Sort/Shell_Sort.go
@@ -0,0 +1,80 @@
+package main
+
+import (
+ "fmt"
+ "strconv"
+)
+
+func main() {
+ var n int
+ fmt.Scanf("%d", &n)
+
+ // input the size of the array
+ var arr = make([]int, n)
+
+ // input the elements of the array
+ for i := 0; i < n; i++ {
+ if _, err := fmt.Scan(&arr[i]); err != nil {
+ panic(err)
+ }
+ }
+
+ // calling the shellsort function to sort the array
+ shellsort(arr)
+
+ // printing the sorted array
+ for i := 0; i < n; i++ {
+ fmt.Print(strconv.Itoa(arr[i])+" ")
+ }
+}
+
+func shellsort(items []int) {
+ var (
+ n = len(items)
+ gaps = []int{1}
+ k = 1
+
+ )
+
+ // start with a bigger gap and then gradually reduce the gaps
+ for {
+ gap := element(2, k) + 1
+ if gap > n-1 {
+ break
+ }
+ gaps = append([]int{gap}, gaps...)
+ k++
+ }
+
+ // shell sort logic
+ for _, gap := range gaps {
+ for i := gap; i < n; i += gap {
+ j := i
+ for j > 0 {
+ if items[j-gap] > items[j] {
+ items[j-gap], items[j] = items[j], items[j-gap]
+ }
+ j = j - gap
+ }
+ }
+ }
+}
+
+// function to help calculate number of gaps
+func element(a, b int) int {
+ e := 1
+ for b > 0 {
+ if b&1 != 0 {
+ e *= a
+ }
+ b >>= 1
+ a *= a
+ }
+ return e
+}
+
+/*
+ SAMPLE INPUT: 5
+ 5 4 1 2 3
+ SAMPLE OUTPUT: 1 2 3 4 5
+*/
\ No newline at end of file
From 3188f22aa4672776066a52d2d111a90d1d1c63ed Mon Sep 17 00:00:00 2001
From: reeha <56428237+syedareehaquasar@users.noreply.github.com>
Date: Wed, 15 Apr 2020 23:33:52 +0530
Subject: [PATCH 088/265] README.md for Z-ALGORITHM (#2594)
---
Z_Algorithm/README.md | 95 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 95 insertions(+)
create mode 100644 Z_Algorithm/README.md
diff --git a/Z_Algorithm/README.md b/Z_Algorithm/README.md
new file mode 100644
index 000000000..d069a4a97
--- /dev/null
+++ b/Z_Algorithm/README.md
@@ -0,0 +1,95 @@
+# Z ALGORITHM
+This algorithm finds all occurrences of a pattern in a text in linear time. Let length of text be n and of pattern be m, then total time taken is O(m + n) with linear space complexity. Now we can see that both time and space complexity is same as KMP algorithm but this algorithm is Simpler to understand.
+Z algorithm is a linear time string matching algorithm which runs in complexity. It is used to find all occurrence of a pattern in a string , which is common string searching problem.
+In this algorithm, we construct a Z array.
+
+### What is Z Array?
+For a string str[0..n-1], Z array is of same length as string. An element Z[i] of Z array stores length of the longest substring starting from str[i] which is also a prefix of str[0..n-1]. The first entry of Z array is meaning less as complete string is always prefix of itself.
+
+```
+Example:
+
+Index 0 1 2 3 4 5 6 7 8 9 10 11
+Text a a b c a a b x a a a z
+Z values X 1 0 0 3 1 0 0 2 2 1 0
+
+str = "aaaaaa"
+Z[] = {x, 5, 4, 3, 2, 1}
+
+str = "aabaacd"
+Z[] = {x, 1, 0, 2, 1, 0, 0}
+
+str = "abababab"
+Z[] = {x, 0, 6, 0, 4, 0, 2, 0}
+```
+
+### How is Z array helpful in Searching Pattern in Linear time?
+The idea is to concatenate pattern and text, and create a string “P$T” where P is pattern, $ is a special character should not be present in pattern and text, and T is text. Build the Z array for concatenated string. In Z array, if Z value at any point is equal to pattern length, then pattern is present at that point.
+```
+Example:
+Pattern P = "aab", Text T = "baabaa"
+The concatenated string is = "aab$baabaa"
+Z array for above concatenated string is {x, 1, 0, 0, 0,
+ 3, 1, 0, 2, 1}.
+Since length of pattern is 3, the value 3 in Z array
+indicates presence of pattern.
+```
+
+### How to construct Z array?
+A Simple Solution is two run two nested loops, the outer loop goes to every index and the inner loop finds length of the longest prefix that matches substring starting at current index.
+
+## ALGORITHM
+
+
+## Pseudocode
+Simple and short. Note that the optimization L = R = i is used when S[0] ≠ S[i] (it doesn't affect the algorithm since at the next iteration i > R regardless).
+
+```
+int L = 0, R = 0;
+for (int i = 1; i < n; i++) {
+ if (i > R) {
+ L = R = i;
+ while (R < n && s[R-L] == s[R]){
+ R++;
+ z[i] = R-L;
+ R--;
+ }
+ }
+ else {
+ int k = i-L;
+ if (z[k] < R-i+1) {
+ z[i] = z[k];
+ }
+ else {
+ L = i;
+ while (R < n && s[R-L] == s[R]){
+ R++;
+ z[i] = R-L; R--;
+ }
+ }
+}
+```
+## Example:
+S = “abc”, T = “abcdabaabc”
+L = “abc$abcdabaabc”
+Compute Z values.
+Z[1] = 0, Z[2] = 0, Z[3] = 0, Z[4] = 3, Z[5] = 0, Z[6] = 0, Z[7] = 0, Z[8] = 2, Z[9] = 0, Z[10] = 1, Z[11] = 3, Z[12] = 0, Z[13] = 0
+Look at values of Z[4] and Z[11]
+hence string S matches at index 4 (abc$abcdabaabc) and index 11 (abc$abcdabaabc)
+
+## Time Complexity
+O(n)
+The algorithm runs in O(n) time. Characters are never compared at positions less than , and every time a match is found, is increased by one, so there are at most n comparisons
+
+## Implementation
+ - [c code](https://github.com/jainaman224/Algo_Ds_Notes/blob/master/Z_Algorithm/Z_Algorithm.c)
+ - [coffee code](https://github.com/jainaman224/Algo_Ds_Notes/blob/master/Z_Algorithm/Z_Algorithm.coffee)
+ - [cpp code](https://github.com/jainaman224/Algo_Ds_Notes/blob/master/Z_Algorithm/Z_Algorithm.cpp)
+ - [c# code]
+ - [go code]
+ - [java code](https://github.com/jainaman224/Algo_Ds_Notes/blob/master/Z_Algorithm/Z_Algorithm.java)
+ - [javaScript code](https://github.com/jainaman224/Algo_Ds_Notes/blob/master/Z_Algorithm/Z_Algorithm.js)
+ - [kotlin code]
+ - [python code](https://github.com/jainaman224/Algo_Ds_Notes/blob/master/Z_Algorithm/Z_Algorithm.py)
+ - [ruby code](https://github.com/jainaman224/Algo_Ds_Notes/blob/master/Z_Algorithm/Z_Algorithm.rb)
+ - [dart code]
From 4386283b09c0a23f090a8cfcf3d7d50f73000433 Mon Sep 17 00:00:00 2001
From: Ashish Nagpal <36301481+ashishnagpal2498@users.noreply.github.com>
Date: Thu, 16 Apr 2020 00:06:04 +0530
Subject: [PATCH 089/265] :star: add median of two sorted arrays (#2463)
:up: unequal arrays check
---
Median_Sorted_Arrays/Median_Sorted_Arrays.cpp | 74 +++++++++++++++++++
1 file changed, 74 insertions(+)
create mode 100644 Median_Sorted_Arrays/Median_Sorted_Arrays.cpp
diff --git a/Median_Sorted_Arrays/Median_Sorted_Arrays.cpp b/Median_Sorted_Arrays/Median_Sorted_Arrays.cpp
new file mode 100644
index 000000000..d4b121bfb
--- /dev/null
+++ b/Median_Sorted_Arrays/Median_Sorted_Arrays.cpp
@@ -0,0 +1,74 @@
+//median of two sorted arrays -
+#include
+#include
+using namespace std;
+
+float median(int *arr1, int * arr2, int n, int m)
+{
+ int low1 = 0,
+ hi1 = n - 1,
+ low2 = 0,
+ hi2 = m - 1;
+ while (true)
+ {
+ int m1 = (hi1 - low1) / 2,
+ m2 = (hi2 - low2) / 2,
+ median1 = arr1[m1],
+ median2 = arr2[m2];
+ if (hi1 - low1 <= 1 || hi2 - low1 <= 1)
+ {
+ //calculate the median
+ float leftVal = max(arr1[low1], arr2[low2]);
+ float rightVal = min(arr1[hi1], arr2[low2]);
+ float ans = (abs(n-m) >= 1) ? ceil((leftVal + rightVal)/2) : (leftVal + rightVal)/2;
+ return (float) ans;
+ }
+ if (median1 == median2)
+ {
+ return median1;
+ }
+ else if (median2 > median1)
+ { //Shift the lower pointer of array 1 to median 1
+ low1 = m1;
+ //Shift the Higher pointer of array 2 to median 2
+ hi2 = m2;
+ }
+ else {
+ //Shift the Higher pointer of array 1 to median 1
+ hi1 = m1;
+ //Shift the Lower pointer of array 2 to median 2
+ low2 = m2;
+ }
+
+ }
+}
+
+int main()
+{
+ int n, m, arr1[100005], arr2[100005];
+ cout << "Enter size of Array 1 \n";
+ cin >> n;
+ cout << "Enter size of Array 2 \n";
+ cin >> m;
+ cout << "Enter Elements of Array 1 \n";
+ for (int i = 0; i < n; i++) cin >> arr1[i];
+ cout << "Enter Elements of Array 2 \n";
+ for (int i = 0; i < m; i++) cin >> arr2[i];
+ cout << "Median of Combined Sorted Array is " << median(arr1, arr2, n, m);
+ cout << endl;
+ return 0;
+}
+
+/* Sample Input
+ Enter size of Array 1
+ 3
+ Enter size of Array 2
+ 3
+Enter Elements of Array 1
+ 1 2 3
+Enter Elements of Array 1
+ 4 5 6
+
+Sample Output
+Median of Combined Sorted Array is - 3.5
+ */
\ No newline at end of file
From ae9770f592eaf3c3f62d9653e4ddaac3a590fb7e Mon Sep 17 00:00:00 2001
From: Md Akdas Ahmad <43089126+MdAkdas@users.noreply.github.com>
Date: Fri, 17 Apr 2020 01:04:43 +0530
Subject: [PATCH 090/265] Segment tree RMQ in C added. (#2676)
---
Segment_Tree_RMQ/Segement_Tree_RMQ.c | 91 ++++++++++++++++++++++++++++
1 file changed, 91 insertions(+)
create mode 100644 Segment_Tree_RMQ/Segement_Tree_RMQ.c
diff --git a/Segment_Tree_RMQ/Segement_Tree_RMQ.c b/Segment_Tree_RMQ/Segement_Tree_RMQ.c
new file mode 100644
index 000000000..dc5609cba
--- /dev/null
+++ b/Segment_Tree_RMQ/Segement_Tree_RMQ.c
@@ -0,0 +1,91 @@
+#include
+#include
+#include
+
+int min(int x, int y)
+{
+ return (x < y) ? x : y;
+}
+
+void build(int *a, int *tree, int start, int end, int treenode)
+{
+ if (start == end)
+ {
+ tree[treenode] = a[start];
+ return;
+ }
+
+ int mid;
+ mid = (start + end) / 2;
+
+ //compute the values in the left and right subtrees
+ build(a, tree, start, mid, 2 * treenode);
+ build(a, tree, mid + 1, end, 2 * treenode + 1);
+
+ /*store the minimum value in the first and
+ second half of the interval*/
+ tree[treenode] = min(tree[2 * treenode], tree[2 * treenode + 1]);
+ return;
+}
+
+int query(int *tree, int start, int end, int l, int r, int treenode)
+{
+ /* if the current interval doesn’t intersect
+ the query interval return INT_MAX*/
+ if (start > r || end < l)
+ {
+ return INT_MAX;
+ }
+
+ /*if the current interval is included in
+ the query interval return tree[treenode]*/
+ if (start >= l && end <= r)
+ {
+ return tree[treenode];
+ }
+
+ int mid;
+ mid = (start + end) / 2;
+
+ //return the minimum value
+ int e = query(tree, start, mid, l, r, 2 * treenode);
+ int f = query(tree, mid + 1, end, l, r, 2 * treenode + 1);
+
+ return min(e, f);
+}
+
+int main()
+{
+ int size;
+ printf("Enter the size of the array: ");
+ scanf("%d", &size);
+ int array[size];
+ int *segTree = (int *)malloc(sizeof(4 * size));
+
+ printf("Enter the elements.\n");
+ for(int i = 0; i < size; i++)
+ {
+ scanf("%d", &array[i]);
+ }
+
+ build(array, segTree, 0, size - 1, 1);
+
+ int start, end;
+ printf("Enter the range of the query: ");
+ scanf("%d %d", &start, &end);
+ int result = query(segTree, 0, size - 1, start - 1, end - 1, 1);
+
+ printf("Minimum value in index range %d to %d is: %d\n", start, end, result);
+
+ return 0;
+}
+
+/*
+Input:
+Enter the size of the array.: 5
+-7 3 -1 8 1
+Enter the range of the query.: 2 5
+
+Output:
+Minimum value in index range 2 to 5 is: -1
+*/
From 9ebc24f5d305e3aa18bc880e88a8cb7306ba942b Mon Sep 17 00:00:00 2001
From: shreya kapoor <31164665+shreyakapoor08@users.noreply.github.com>
Date: Fri, 17 Apr 2020 12:23:08 +0530
Subject: [PATCH 091/265] Depth First Search in C# (#2674)
* Depth First Search in C#
---
Depth_First_Search/Depth_First_Search.cs | 69 ++++++++++++++++++++++++
1 file changed, 69 insertions(+)
create mode 100644 Depth_First_Search/Depth_First_Search.cs
diff --git a/Depth_First_Search/Depth_First_Search.cs b/Depth_First_Search/Depth_First_Search.cs
new file mode 100644
index 000000000..f1e65a25d
--- /dev/null
+++ b/Depth_First_Search/Depth_First_Search.cs
@@ -0,0 +1,69 @@
+/// C# program for Depth First Search Traversal
+
+using System;
+using System.Collections.Generic; //used for including List
+
+class DirectedGraph
+{
+ List[] adjacencylist;
+ int vertix;
+
+ DirectedGraph(int newv) //Constructor with same name as that of class
+ {
+ vertix = newv;
+ adjacencylist = new List[newv];
+ for (int i = 0; i < newv; ++i)
+ adjacencylist[i] = new List();
+ }
+
+ void DFSFunction(int newv, bool[] traversed)
+ {
+ traversed[newv] = true;
+ Console.Write(newv + " ");
+ List vList = adjacencylist[newv];
+ foreach (var n in vList)
+ {
+ if (!traversed[n])
+ DFSFunction(n, traversed);
+ }
+ }
+
+ void Addition_of_Edge(int newv, int var)
+ {
+ adjacencylist[newv].Add(var);
+ }
+
+ void Depth_First_Search(int newv)
+ {
+ bool[] traversed = new bool[vertix];
+
+ DFSFunction(newv, traversed);
+ }
+
+ public static void Main(String[] args)
+ {
+ DirectedGraph newgraph = new DirectedGraph(4); // Number of vertices is 4
+ Console.WriteLine("Number of edges between the vertices to enter");
+ int n = Convert.ToInt32(Console.ReadLine());
+ for (int i=0;i
Date: Fri, 17 Apr 2020 12:50:40 +0530
Subject: [PATCH 092/265] Added code of Longest Increasing Subsequence in Java
(#2598)
* Added code of Longest Increasing Subsequence in Java
---
Longest_Increasing_Subsequence/LIS.java | 54 +++++++++++++++++++++++++
1 file changed, 54 insertions(+)
create mode 100644 Longest_Increasing_Subsequence/LIS.java
diff --git a/Longest_Increasing_Subsequence/LIS.java b/Longest_Increasing_Subsequence/LIS.java
new file mode 100644
index 000000000..fb525d0a2
--- /dev/null
+++ b/Longest_Increasing_Subsequence/LIS.java
@@ -0,0 +1,54 @@
+/*
+Problem Statement :
+To find the length of the Longest Increasing
+Subsequence of a given sequence, that is all the
+elements of the subsequence are in increasing sorted order.
+*/
+
+import java.util.*;
+
+class LIS
+{
+ static int lis(int arr[], int n)
+ {
+ int lis[] = new int[n];
+ int result = Integer.MIN_VALUE;
+
+ for (int i = 0; i < n; ++i)
+ lis[i] = 1;
+
+ for (int i = 1; i < n; ++i)
+ {
+ for (int j = 0; j < i; ++j)
+ {
+ if (arr[i] > arr[j] && lis[i] < lis[j] + 1)
+ lis[i] = lis[j] + 1;
+ }
+ result = Math.max(result, lis[i]);
+ }
+
+ return result;
+ }
+
+ public static void main(String args[])
+ {
+ Scanner sc = new Scanner(System.in);
+
+ System.out.print("Enter the size of array : ");
+ int n = sc.nextInt();
+
+ int[] arr = new int[n];
+ System.out.print("Enter the array elements : ");
+ for (int i = 0; i < n; ++i)
+ arr[i] = sc.nextInt();
+
+ System.out.println("\nLength of the Longest Increasing Subsequence : " + lis(arr, n));
+ }
+}
+
+/*
+Enter the size of the array : 8
+Enter the array elements : 15 26 13 38 26 52 43 62
+
+Length of the Longest Increasing Subsequence : 5
+*/
From aa64927aca354810547f4c33a0090dd944c4bf1a Mon Sep 17 00:00:00 2001
From: Manish Choudhary <53442020+Manish-cloud@users.noreply.github.com>
Date: Fri, 17 Apr 2020 13:41:36 +0530
Subject: [PATCH 093/265] AVL Tree implementation in C++ (#2679)
---
AVL_Tree/AVL_Tree.cpp | 202 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 202 insertions(+)
create mode 100644 AVL_Tree/AVL_Tree.cpp
diff --git a/AVL_Tree/AVL_Tree.cpp b/AVL_Tree/AVL_Tree.cpp
new file mode 100644
index 000000000..3c68347ee
--- /dev/null
+++ b/AVL_Tree/AVL_Tree.cpp
@@ -0,0 +1,202 @@
+#include
+using namespace std;
+
+struct tnode
+{
+ int data;
+ tnode * L, * R;
+ tnode()
+ {
+ L = R = NULL;
+ }
+};
+
+class AVL
+{
+ private:
+ tnode * root;
+ public:
+ AVL() { root = NULL; }
+ tnode * LL(tnode *);
+ tnode * RR(tnode *);
+ tnode * LR(tnode *);
+ tnode * RL(tnode *);
+
+ int height(tnode *);
+ int MAX(int, int);
+
+ void create();
+ tnode * insert(tnode *, int);
+ void display();
+ void inorder(tnode *);
+ void preorder(tnode *);
+};
+
+tnode * AVL :: LL(tnode * parent)
+{
+ tnode * temp;
+ temp = parent -> L;
+ parent -> L = temp -> R;
+ temp -> R = parent;
+ return temp;
+}
+
+tnode * AVL :: RR(tnode * parent)
+{
+ tnode * temp;
+ temp = parent -> R;
+ parent -> R = temp -> L;
+ temp -> L = parent;
+ return temp;
+}
+
+tnode * AVL :: LR(tnode * parent)
+{
+ parent -> L = RR(parent -> L);
+ parent = LL(parent);
+ return parent;
+}
+
+tnode * AVL :: RL(tnode * parent)
+{
+ parent -> R = LL(parent -> R);
+ parent = RR(parent);
+ return parent;
+}
+
+int AVL :: MAX(int a, int b)
+{
+ if(a > b)
+ return a;
+ else
+ return b;
+}
+
+int AVL :: height(tnode * temp )
+{
+ if(temp == NULL) //height of empty node(subtree)
+ return -1;
+
+ if(temp -> L == NULL and temp -> R == NULL) //height of leaf node
+ return 0;
+
+ return (1 + MAX( height(temp -> L), height(temp -> R)));
+}
+
+void AVL :: create()
+{
+ int val;
+ char ch;
+ do
+ {
+ cout << "Enter Number : ";
+ cin >> val;
+ root = insert(root, val);
+ cout << "Continue : ";
+ cin >> ch;
+ }while(ch == 'y');
+}
+
+tnode * AVL :: insert(tnode * temp, int val)
+{
+ if(temp == NULL)
+ {
+ temp = new tnode;
+ temp -> data = val;
+ }
+ else
+ {
+ if(val < temp -> data)
+ {
+ temp -> L = insert(temp -> L, val);
+ if( ( height(temp -> L) - height(temp -> R) == 2 ) )
+ {
+ if(val < temp -> L -> data)
+ temp = LL(temp);
+ else
+ temp = LR(temp);
+ }
+ }
+ else
+ {
+ temp -> R = insert(temp -> R, val);
+ if( ( height(temp -> L) - height(temp -> R)== -2 ) )
+ {
+ if(val > temp -> R -> data)
+ temp = RR(temp);
+ else
+ temp = RL(temp);
+ }
+ }
+ }
+ return temp;
+}
+
+void AVL :: inorder(tnode * temp)
+{
+ if(temp != NULL)
+ {
+ inorder(temp -> L);
+ cout << "\n" << temp -> data;
+ inorder(temp -> R);
+ }
+}
+
+void AVL :: preorder(tnode * temp)
+{
+ if(temp != NULL)
+ {
+ cout << "\n"< data;
+ preorder(temp -> L);
+ preorder(temp -> R);
+ }
+}
+
+void AVL :: display()
+{
+ cout << "\n Data in Sorted way : ";
+ inorder(root);
+ cout << "\n Preorder : ";
+ preorder(root);
+}
+
+int main()
+{
+ AVL t;
+ t.create();
+ t.display();
+ cout << endl;
+ return 0;
+}
+
+/*
+ Initially putting data in increasing order to form right skewed tree
+
+Enter Number : 5
+Continue : y
+Enter Number : 6
+Continue : y
+Enter Number : 7
+Continue : y
+Enter Number : 8
+Continue : y
+Enter Number : 9
+Continue : y
+Enter Number : 10
+Continue : n
+
+ Data in Sorted way :
+5
+6
+7
+8
+9
+10
+ Preorder :
+8
+6
+5
+7
+9
+10
+ */
From 83c8169bdc60aa4dcc1c4f59cf0b7f1bcea857fe Mon Sep 17 00:00:00 2001
From: Sukriti Shah
Date: Sat, 18 Apr 2020 00:32:24 +0530
Subject: [PATCH 094/265] PHP implementation for LIS (#2669)
Update LIS.php
---
Longest_Increasing_Subsequence/LIS.php | 43 ++++++++++++++++++++++++++
1 file changed, 43 insertions(+)
create mode 100644 Longest_Increasing_Subsequence/LIS.php
diff --git a/Longest_Increasing_Subsequence/LIS.php b/Longest_Increasing_Subsequence/LIS.php
new file mode 100644
index 000000000..2554faaf1
--- /dev/null
+++ b/Longest_Increasing_Subsequence/LIS.php
@@ -0,0 +1,43 @@
+ $arr[$j] && $dp[$i] < $dp[$j] + 1)
+ $dp[$i] = $dp[$j] + 1;
+ }
+
+ // find the max out of computed lengths of LIS
+ // ending at different indices
+ $max = PHP_INT_MIN;
+ for($i = 0; $i < $n; $i++){
+ if($max < $dp[$i])
+ $max = $dp[$i];
+ }
+
+ return $max;
+}
+
+// Sample test case
+$arr = array(3, 10, 2, 1, 20, 40, 60, 7);
+$n = sizeof($arr);
+
+echo "Length of LIS is " , lisLen($arr, $n);
+
+/*
+Sample Input as specified in the code:
+3, 10, 2, 1, 20, 40, 60, 7
+
+Sample Output:
+Length of LIS is 5
+*/
+
+?>
From f68d36e4704fbad621983d50338f616ff677e774 Mon Sep 17 00:00:00 2001
From: Ritish Singh <54978105+ritish099@users.noreply.github.com>
Date: Sat, 18 Apr 2020 01:01:50 +0530
Subject: [PATCH 095/265] Prims Algorithm in C (#2684)
---
Prims_Algorithm/Prims_Algorithm.cs | 77 ++++++++++++++++++++++++++++++
1 file changed, 77 insertions(+)
create mode 100644 Prims_Algorithm/Prims_Algorithm.cs
diff --git a/Prims_Algorithm/Prims_Algorithm.cs b/Prims_Algorithm/Prims_Algorithm.cs
new file mode 100644
index 000000000..76e955f74
--- /dev/null
+++ b/Prims_Algorithm/Prims_Algorithm.cs
@@ -0,0 +1,77 @@
+using System;
+
+namespace Declaring_Method
+{
+ public class Prim_Algorithm
+ {
+ public static void Main(string[] args)
+ {
+ int a = 0, b = 0, u = 0, v = 0, n, i, j, edge_no = 1;
+ int min, mincost = 0;
+ int[] visited = new int[100];
+ int[, ] cost = new int[10, 10];
+
+ Console.WriteLine("Enter the number of Nodes");
+ n = Convert.ToInt32(Console.ReadLine());
+ Console.WriteLine("Enter the adjency matrix");
+
+ //Intilize all visited elements to 0
+ for (i = 0; i < 100; i++)
+ {
+ visited[i] = 0;
+ }
+
+ //Taking Matrix Input from the User
+ for (i = 1; i <= n; i++)
+ {
+ for (j = 1; j <= n; j++)
+ {
+ cost[i, j] = Convert.ToInt32(Console.ReadLine());
+ //Initialize Cost Matrix to Infintiy if user input is 0
+ if (cost[i, j] == 0)
+ cost[i, j] = 999;
+ }
+ }
+ visited[1] = 1;
+ Console.WriteLine(" ");
+
+ while (edge_no < n)
+ {
+ for (i = 1, min = 999; i <= n; i++)
+ for (j = 1; j <= n; j++)
+ if (cost[i, j] < min)
+ if (visited[i] != 0)
+ {
+ min = cost[i, j];
+ //Storing Position
+ a = u = i;
+ b = v = j;
+ }
+ // Print the Edge Number with its Cost
+ if (visited[u] == 0 || visited[v] == 0)
+ {
+ Console.WriteLine("Edge {0} : ({1} {2}) cost:{3} ", edge_no++, a, b, min);
+ mincost += min; // Calculating minimum Cost
+ visited[b] = 1;
+ }
+ cost[a, b] = cost[b, a] = 999;
+ }
+ Console.WriteLine("Minimum Cost : {0}", mincost);
+ }
+ }
+}
+
+/*Enter the number of Nodes
+5
+Enter the adjency matrix
+0 2 0 6 0
+2 0 3 8 5
+0 3 0 0 7
+6 8 0 0 9
+0 5 7 9 0
+
+Edge 1 : (1 2) cost:2
+Edge 2 : (2 3) cost:3
+Edge 3 : (2 5) cost:5
+Edge 4 : (1 4) cost:6
+Minimum Cost : 16 */
From 0e73cbf2e51c2009fa948c9606aaa9224e41f00e Mon Sep 17 00:00:00 2001
From: Ritish Singh <54978105+ritish099@users.noreply.github.com>
Date: Sat, 18 Apr 2020 01:02:55 +0530
Subject: [PATCH 096/265] Jhonson Algorithm in PHP (#2696)
---
Jhonson_Algoritm/Jhonson_Algorithm.php | 62 ++++++++++++++++++++++++++
1 file changed, 62 insertions(+)
create mode 100644 Jhonson_Algoritm/Jhonson_Algorithm.php
diff --git a/Jhonson_Algoritm/Jhonson_Algorithm.php b/Jhonson_Algoritm/Jhonson_Algorithm.php
new file mode 100644
index 000000000..59a2d1885
--- /dev/null
+++ b/Jhonson_Algoritm/Jhonson_Algorithm.php
@@ -0,0 +1,62 @@
+
From 329ca741f4355d53dfc7f0330e66ce47f3510563 Mon Sep 17 00:00:00 2001
From: Muskan Goyal
Date: Sat, 18 Apr 2020 14:46:01 +0530
Subject: [PATCH 097/265] Fenwick_Tree.php Added (#2689)
Update Fenwick_Tree.php
Updated
Done
---
Fenwick_Tree/Fenwick_Tree.php | 105 ++++++++++++++++++++++++++++++++++
1 file changed, 105 insertions(+)
create mode 100644 Fenwick_Tree/Fenwick_Tree.php
diff --git a/Fenwick_Tree/Fenwick_Tree.php b/Fenwick_Tree/Fenwick_Tree.php
new file mode 100644
index 000000000..71801c8ca
--- /dev/null
+++ b/Fenwick_Tree/Fenwick_Tree.php
@@ -0,0 +1,105 @@
+ 0){
+ // Adding tree node to sum
+ $s = $s + $ft[$index];
+ // Update tree node
+ $index -= $index & (-$index);
+ }
+ // Return total sum
+ return $s;
+}
+
+// Update function
+function update ($ft, $size, $index, $val) {
+ /*
+ Arguments
+ ft : Fenwick Tree
+ index : Index of ft to be updated
+ size : Length of the original array
+ val : Add val to the index "index"
+ Traverse all ancestors and add 'val'.
+ Add 'val' to current node of Fenwick Tree.
+ Update index to that of parent in update.
+ */
+ $index += 1;
+ while( $index <= $size){
+ // Update tree node value
+ $ft[$index] = $ft[$index] + $val;
+ // Update node index
+ $index += $index and (-$index);
+ }
+ }
+
+
+// Build function
+function construct($array, $size) {
+ /*
+ Argument
+ array : The original array
+ size : The length of the given array
+ This function will construct the Fenwick Tree
+ from the given array of length "size"
+
+ Return : Fenwick Tree array ft[]
+ */
+ // Init ft array of length 1000 with zero value initially
+ $ft = array();
+ // Constructing Fenwick Tree by Update operation
+ for( $i = 0; $i < $size; $i++) {
+ // Update operation
+ update($ft, $size, $i, $array[$i]);
+ }
+ // Return Fenwick Tree array
+ return $ft;
+}
+
+//Driver code to test above methods
+function main() {
+ $array = array(2, 1, 1, 3, 2, 3, 4, 5, 6, 7, 8, 9);
+ $n = construct($freq, sizeof($array));
+ echo implode(sum($n, 5));
+ $array[3] = $array[3] + 6;
+ update($n, sizeof($array), 3, 6) ;
+ echo implode(sum($n, 5));
+}
+
+/*
+INPUT
+-------
+array : [2, 1, 1, 3, 2, 3, 4, 5, 6, 7, 8, 9]
+Sum of elements in array[0..5] is 12
+Sum of elements in array[0..5] after update is 18
+
+OUTPUT
+------
+12
+18
+*/
+
+?>
From 85f7d36624717ed76af33f0c732d528ebe7618bf Mon Sep 17 00:00:00 2001
From: Ashish Nagpal <36301481+ashishnagpal2498@users.noreply.github.com>
Date: Sun, 19 Apr 2020 16:38:18 +0530
Subject: [PATCH 098/265] Tree Level order Traversal Tree (#2642)
:star: Tree Level order traversal
:up: Input Output addition
:bug: single node print
:up: indentation correction
:star: description added
---
.../Tree_Levelorder_Traversal.js | 59 +++++++++++++++++++
1 file changed, 59 insertions(+)
create mode 100644 Tree_Levelorder_Traversal/Tree_Levelorder_Traversal.js
diff --git a/Tree_Levelorder_Traversal/Tree_Levelorder_Traversal.js b/Tree_Levelorder_Traversal/Tree_Levelorder_Traversal.js
new file mode 100644
index 000000000..0d546041a
--- /dev/null
+++ b/Tree_Levelorder_Traversal/Tree_Levelorder_Traversal.js
@@ -0,0 +1,59 @@
+/*Description - Level order traveral of a tree is a traversal in which all the nodes which are at same
+level are explored and then we move to another level. It is implemented using a queue. The root node
+is pushed into queue intially and loops run till queue is not empty. The node at front is poped out
+and if child of that node exist then those are pushed into queue.
+Implementing Level Order Traversal in graph is also called Breath First Search.
+*/
+
+// Creates a Tree Node with input value
+class Node {
+ constructor(value) {
+ this.value = value;
+ this.left = null;
+ this.right = null;
+ }
+}
+
+//Level Order Traversal
+var traversal = function (root) {
+ if (root === null) return root;
+ if (root.left === null && root.right === null) {
+ console.log(root.value);
+ return root;
+ }
+ const queue = [];
+ queue.push(root);
+ while (queue.length > 0) {
+ const node = queue.splice(0, 1)[0];
+ console.log(node.value);
+ if (node.left) queue.push(node.left);
+ if (node.right) queue.push(node.right);
+ }
+ return root;
+};
+
+// Sample Input
+var root = new Node(1);
+root.left = new Node(2);
+root.right = new Node(3);
+root.left.left = new Node(4);
+root.left.right = new Node(5);
+root.right.left = new Node(6);
+root.right.right = new Node(7);
+
+// Sample Output
+console.log("Level Order traversal of tree is:-");
+traversal(root);
+
+/*
+* Output
+*
+* Level Order traversal of tree is
+1
+2
+3
+4
+5
+6
+7
+*/
From b5e7b15e29086a1657b144fd9d5d89c75d3eba8b Mon Sep 17 00:00:00 2001
From: prashansag62 <43422124+prashansag62@users.noreply.github.com>
Date: Sun, 19 Apr 2020 16:41:10 +0530
Subject: [PATCH 099/265] bfs in Csharp added (#2514)
---
Breadth_First_Search/BFS_in_Csharp.cs | 133 ++++++++++++++++++++++++++
1 file changed, 133 insertions(+)
create mode 100644 Breadth_First_Search/BFS_in_Csharp.cs
diff --git a/Breadth_First_Search/BFS_in_Csharp.cs b/Breadth_First_Search/BFS_in_Csharp.cs
new file mode 100644
index 000000000..aa25d7319
--- /dev/null
+++ b/Breadth_First_Search/BFS_in_Csharp.cs
@@ -0,0 +1,133 @@
+//Breadth First Search ALgorithm implemented using queue in C#
+
+using System;
+// for generic data structures
+using System.Collections.Generic;
+
+namespace GraphBfs
+{
+ class graph
+ { //no of vertices in a graph
+ private int vertices;
+ //declaraing list
+ private List[] adj;
+ public graph(int v)
+ {
+ //initialising Adjacency List with number of vertices
+ vertices = v;
+ adj = new List[v];
+ for(int i = 0; i < v; i++)
+ {
+ adj[i] = new List();
+ }
+ }
+
+ public void addedge(int c,int v)
+ {
+ adj[c].Add(v);
+ adj[v].Add(c);
+ }
+
+ // function for Breadth First Search ,starting node as parameter
+ public void BFS(int v)
+ {
+ bool[] visited = new bool[vertices];
+ Queue queue = new Queue();
+ visited[v] = true;
+ // enqueuing first node in queue
+ queue.Enqueue(v);
+ while(queue.Count != 0)
+ {
+ // dequeue node from beginning of queue
+ v = queue.Dequeue();
+ Console.Write(v + " ");
+ foreach(int i in adj[v])
+ {
+ //only unvisited node pushed into queue
+ if( !visited[i])
+ {
+ visited[i] = true;
+ queue.Enqueue(i);
+ }
+ }
+ }
+ }
+ }
+
+ class program
+ {
+ static void Main(string[] args)
+ { //Taking input number of vertices
+ Console.WriteLine("Enter number of vertices in a graph");
+ int v = Convert.ToInt32(Console.ReadLine());
+
+ graph g = new graph(v);
+
+ //Taking input number of edges
+ Console.WriteLine("Enter number of edge in a graph");
+ int e = Convert.ToInt32(Console.ReadLine());
+
+ for(int i = 0; i < e; i++)
+ {
+ Console.WriteLine("Enter nodes of " + (i+1) +" edge");
+ string s = Console.ReadLine();
+
+ int e1 = Convert.ToInt32(s.Split(" ")[0]);
+ int e2 = Convert.ToInt32(s.Split(" ")[1]);
+
+ g.addedge(e1, e2);
+ }
+ Console.WriteLine("Breadth First Search of Graph :-");
+ //calling BFS function with starting node provided
+ g.BFS(0);
+ }
+ }
+}
+
+/*Sample Input and Output
+
+Enter number of vertices in a graph
+10
+Enter number of edge in a graph
+12
+Enter nodes of 1 edge
+0 1
+Enter nodes of 2 edge
+0 2
+Enter nodes of 3 edge
+1 3
+Enter nodes of 4 edge
+2 4
+Enter nodes of 5 edge
+2 5
+Enter nodes of 6 edge
+3 6
+Enter nodes of 7 edge
+6 4
+Enter nodes of 8 edge
+4 5
+Enter nodes of 9 edge
+4 7
+Enter nodes of 10 edge
+7 8
+Enter nodes of 11 edge
+7 9
+Enter nodes of 12 edge
+8 9
+Breadth First Search of Graph :-
+0 1 2 3 4 5 6 7 8 9
+
+Adjacency List of Sample Input
+
+0 -> 1,2
+1 -> 0,3
+2 -> 0,4,5
+3 -> 1,6
+4 -> 2,6,5,7,
+5 -> 2,4
+6 -> 3,4
+7 -> 4,8,9
+8 -> 7,9
+9 -> 7,8
+
+*/
From ffa64bfbc031137c24172b55d676b5921266c12a Mon Sep 17 00:00:00 2001
From: Rukmini Meda <44504940+Rukmini-Meda@users.noreply.github.com>
Date: Mon, 20 Apr 2020 17:16:52 +0530
Subject: [PATCH 100/265] Chinese Remainder Theorem in Dart (#2763)
---
.../Chinese_Remainder_Theorem.dart | 119 ++++++++++++++++++
1 file changed, 119 insertions(+)
create mode 100644 Chinese_Remainder_Theorem/Chinese_Remainder_Theorem.dart
diff --git a/Chinese_Remainder_Theorem/Chinese_Remainder_Theorem.dart b/Chinese_Remainder_Theorem/Chinese_Remainder_Theorem.dart
new file mode 100644
index 000000000..ec990892c
--- /dev/null
+++ b/Chinese_Remainder_Theorem/Chinese_Remainder_Theorem.dart
@@ -0,0 +1,119 @@
+/*
+ Dart program to implement Chinese Remainder Theorem (CRT)
+ ---------------------------------------------------------------------
+
+ Chinese Remainder Theorem
+ ---------------------------------------------------------------------
+
+ The Chinese Remainder Theorem ( based on Extended Euclid's algorithm ) states that a set of 'k' congruency equations with a single variable
+ as follows
+
+ x % num[0] = rem[0]
+ x % num[1] = rem[1]
+ .
+ .
+ .
+ x % num[k] = rem[k]
+
+ can be solved by using the formula, x = ( sum(rem[i]*pd[i]*inv[i]) for all i ) % product where
+
+ product is the product of all numbers in num array
+ rem[i] is the i'th remainder in the given input,
+ pd[i] is the value of product divided by num[i],
+ inv[i] is the modulo inverse of pd[i] and num[i],
+ sum() is a function that sums up the values.
+
+ Here, the obtained solution is minimum possible x.
+
+*/
+
+// Importing required libraries.
+import 'dart:io';
+
+// Function to calculate modulo inverse.
+int modular_inverse(int a, int m){
+
+ // Temporary variable to store m to use later.
+ int temp = m;
+
+ if (m == 1){
+ return 0;
+ }
+
+ int y = 0, x = 1, temp2, quotient, remainder;
+
+ // Calculating x and y based on Euclid's algorithm
+ while (a > 1){
+ quotient = (a / m).floor();
+ remainder = a % m;
+ a = m;
+ m = remainder;
+ temp2 = y;
+ y = x - quotient * y;
+ x = temp2;
+ }
+
+ // Making x positive if found negative
+ if (x < 0){
+ x += temp;
+ }
+
+ return x;
+}
+
+// Driver function of the program
+void main(){
+
+ // Taking input of the number array (num[i]).
+ print("Enter array of pairwise co-prime numbers:");
+
+ var input = stdin.readLineSync();
+ var lis = input.split(' ');
+ List numbers = lis.map(int.parse).toList();
+
+ // Taking input of remainder array (rem[i]).
+ print("Enter remainders:");
+
+ input = stdin.readLineSync();
+ lis = input.split(' ');
+ List remainders = lis.map(int.parse).toList();
+
+ int product = 1;
+
+ // Length of the 'numbers' list.
+ int length = numbers.length;
+
+ // Finding product of all the numbers.
+ for (int i = 0; i < length; i ++){
+ product *= numbers[i];
+ }
+
+ int temp, result = 0;
+
+ // Summing the required values for all i according to the formula.
+ for (int i = 0; i < length; i ++){
+ temp = (product / numbers[i]).floor();
+ result += temp * (remainders[i]) * modular_inverse(temp,numbers[i]);
+ }
+
+ result = result % product;
+
+ // Printing result
+ print("The value of 'x' by Chinese Remainder Theorem is $result.");
+
+}
+
+/*
+ Sample Input
+
+ Enter array of pairwise co-prime numbers:
+ 9 8 5 7 1
+ Enter remainders:
+ 1 2 3 4 5
+
+ Sample Output
+
+ The value of 'x' by Chinese Remainder Theorem is 298.
+
+*/
+
From 7cd7f84b17cc70dd28513f28bf22ed26f8533d56 Mon Sep 17 00:00:00 2001
From: ka1shi <44312733+ka1shi@users.noreply.github.com>
Date: Wed, 22 Apr 2020 02:48:33 +0530
Subject: [PATCH 101/265] Johnson Algorithm implementation in C (#2334)
---
Johnson_Algorithm/Johnson_Algorithm.c | 359 ++++++++++++++++++++++++++
1 file changed, 359 insertions(+)
create mode 100644 Johnson_Algorithm/Johnson_Algorithm.c
diff --git a/Johnson_Algorithm/Johnson_Algorithm.c b/Johnson_Algorithm/Johnson_Algorithm.c
new file mode 100644
index 000000000..e68aeac41
--- /dev/null
+++ b/Johnson_Algorithm/Johnson_Algorithm.c
@@ -0,0 +1,359 @@
+// Implementation of Johnson's algorithm in C
+
+#include
+#include
+#include
+#include
+
+// Structure to represent Edge of graph
+struct Edge {
+ // Edge with a source and destination and weight as distance between source and destination
+ int source, destination, weight;
+};
+
+// Structure to represent a connected, weighted and directed graph
+struct Graph {
+ // V is number of vertices
+ // E is Number of Edges
+ int V, E;
+
+ // Array of Edge structure
+ struct Edge* edge;
+};
+
+struct Graph* createGraph(int V, int E)
+{
+ // Allocate memory to V vertices of graph
+ struct Graph* graph = malloc(V * sizeof(int));
+ graph -> V = V;
+ graph -> E = E;
+
+ // Allocate memory to E Edges of graph
+ graph -> edge = malloc(E * sizeof(int));
+
+ // Information Message
+ // printf("The graph is created with %d vertices and %d edges.\n", V, E);
+ return graph;
+}
+
+struct Graph* addEdge(struct Graph* graph, int src, int des, int wt, int i)
+{
+ graph -> edge[i].source = src;
+ graph -> edge[i].destination = des;
+ graph -> edge[i].weight = wt;
+
+ return graph;
+}
+
+void printGraph(struct Graph* graph)
+{
+ int E = graph -> E;
+
+ for(int i = 0; i < E; i++)
+ {
+ printf("The distance from %d to %d is: %d\n", graph -> edge[i].source, graph -> edge[i].destination, graph -> edge[i].weight);
+ }
+ printf("\n");
+}
+
+int* BellmanFord(struct Graph* graph, int extra, int* dist)
+{
+ int V = graph -> V;
+ int E = graph -> E;
+
+ // Initialize distance from extra vertex to all vertices as Infinite(INT_MAX)
+ for(int i = 0; i < V + 1; i++)
+ {
+ dist[i] = INT_MAX;
+ }
+
+ // Distance from extra vertex to itself is zero
+ dist[extra] = 0;
+
+ // Shortest path from any vertex can have atmost V-1 edges
+ for(int i = 1; i <= V; i++)
+ {
+ for(int j = 0; j < E + V; j++)
+ {
+ int u = graph -> edge[j].source;
+ int v = graph -> edge[j].destination;
+ int w = graph -> edge[j].weight;
+
+ // Check if old distance is greater than new distance
+ if(dist[u] != INT_MAX && dist[v] > dist[u] + w)
+ {
+ // Update old distance with new distance
+ dist[v] = dist[u] + w;
+ }
+ }
+ }
+
+ return dist;
+}
+
+struct Graph* updateEdge(struct Graph* graph, int dist[], int E)
+{
+ // Update Edge after getting distance from extra vertex to each original vertex
+ // To make distance between all vertices poitive
+ for(int i = 0; i < E; i++)
+ {
+ int u = graph -> edge[i].source;
+ int v = graph -> edge[i].destination;
+
+ // Update distance between from vertex u to v as => distance of u from extra vertex - distance of v from extra vertex + original distance from u to v
+ graph -> edge[i].weight = dist[u] - dist[v] + graph -> edge[i].weight;
+ }
+
+ return graph;
+}
+
+int minDistance(int dist[], bool visited[], int V)
+{
+ // Find closest vertex from source vertex that has not been visited
+
+ // Initialize as min as INFINITY(INT_MAX)
+ int min = INT_MAX, min_index;
+
+ for(int v = 0; v < V; v++)
+ {
+ // If vertex is not visited and is smaller than current min
+ if(!visited[v] && dist[v] <= min)
+ {
+ min = dist[v];
+ min_index = v;
+ }
+ }
+ return min_index;
+}
+
+int askGraph(struct Graph* graph, int u, int v, int E)
+{
+ // Return distance from vertex u to vertex v
+
+ for(int i = 0; i < E; i++)
+ {
+ if(graph -> edge[i].source == u && graph -> edge[i].destination == v)
+ {
+ return graph -> edge[i].weight;
+ }
+ }
+ // return INT_MIN if edge from u to v does not exist
+ return INT_MIN;
+}
+
+int* Dijsktra(struct Graph* graph, int V, int E, int src, int* dist)
+{
+ // Calculate shortest path from source vertex to all other vertices
+
+ // checks if vertex i is visited and is finalized
+ bool visited[V];
+
+ // Initialize all distances as INT_MAX and visited[] as false
+ for(int i = 0; i < V; i++)
+ {
+ dist[i] = INT_MAX;
+ visited[i] = false;
+ }
+
+ // Distance of source vertex from itself is zero
+ dist[src] = 0;
+
+ // Shortest path from any vertex can have atmost V-1 edges
+ for(int i = 0; i < V - 1; i++)
+ {
+ // Pick the minimum distance vertex from all vertices
+ int u = minDistance(dist, visited, V);
+
+ // Picked vertex is visited
+ visited[u] = true;
+
+ // Update distance of adjacent vertices from picked vertex
+ for(int v = 0; v < V; v++)
+ {
+ // Update dist[v] only if it is not in visited,
+ // Distance from src to v is smaller through src to u to v
+
+ // Distance from u to v
+ int temp = askGraph(graph, u, v, E);
+
+ if(!visited[v] && dist[u] != INT_MAX && temp != INT_MIN && dist[v] > dist[u] + temp)
+ {
+ // Update old distance
+ dist[v] = dist[u] + temp;
+ }
+ }
+
+ }
+
+ return dist;
+}
+
+int main(){
+
+ // V is number of vertices and E is number of Edges in graph
+ int V, E;
+
+ scanf("%d %d", &V, &E);
+
+ // Information Message
+ // printf("%d\n",V);
+ // printf("%d\n",E);
+
+ // Declaring source, destination and weight for edges
+ int src, des, wt;
+
+ // One Extra vertex (V+1) is considered for calculating distance with each vertex present in original graph
+ // Additional V edges (E+V) from extra vertex to all original vertices is considered
+
+ struct Graph* graph = createGraph(V + 1, E + V);
+
+ // Add each edge to graph with source, destination and weight
+ for(int i = 0; i < E + V; i++)
+ {
+ if(i < E) // Original E Edges
+ {
+ scanf("%d %d %d", &src, &des, &wt);
+ // printf("%d %d %d %d\n",src,des,wt, i);
+ graph = addEdge(graph, src, des, wt, i);
+ }
+ else // Extra V edges from one extra vertex to original vertices with 0 weight
+ {
+ // printf("%d %d %d %d\n",V,i-E,0, i);
+ graph = addEdge(graph, V, i - E, 0, i);
+ }
+ }
+
+ // printf("\n");
+
+ // Print graph
+ // printf("Original Graph:\n\n");
+ // printGraph(graph);
+
+ // Store distance of each original vertex from extra vertex(including itself)
+ int _dist[V + 1];
+
+ // BellmanFord Algorithm to calculate distance of all original vertices with negative edges from extra vertex
+ int* dist = BellmanFord(graph, V, _dist);
+
+ // Update new edge weights between vertices
+ graph = updateEdge(graph, dist, E);
+
+ // Now will consider original E Edges only, rest V will be ignored from extra vertex total of E+V
+ // Also extra vertex will be ignored
+ // As was required only to convert negative weight distance between vertices to positive weight distance
+
+ // New graph with all positive weight distance
+ // printf("Updated Graph:\n\n");
+ // printGraph(graph);
+
+ // Matrix to store distance of every vertex with every other vertex
+ int distance[V][V];
+ // Running Dijsktra for every vertex as source
+ for(int i = 0; i < V; i++)
+ {
+ int __dist[V];
+
+ // Calculating shortest distance from source i to every other vertices using Dijsktra
+ int* dist_final = Dijsktra(graph, V, E, i, __dist);
+
+ // Update the final matrix distance
+ for(int j = 0; j < V; j++)
+ {
+ distance[i][j] = dist_final[j];
+ }
+ }
+
+ printf("Final Result\n");
+ printf("(Value 2147483648 indicates vertex v is not reachable from vertex u)\n\n");
+ for(int i = 0; i < V; i++)
+ {
+ for(int j = 0; j < V; j++)
+ {
+ if(distance[i][j] == INT_MAX)
+ {
+ distance[i][j] = INT_MAX;
+ // To indicate that j vertex is not reachable from i vertex
+ // No Edge from i to j
+ }
+ printf("Distance from %d to %d is :%d\n", i, j, distance[i][j]);
+ }
+ printf("\n");
+ }
+}
+
+/*
+ INPUT:
+
+ 7 9
+ 0 1 -1
+ 0 2 0
+ 3 0 12
+ 3 2 5
+ 2 5 -6
+ 5 4 3
+ 4 1 4
+ 6 5 8
+ 1 6 -7
+
+ OUTPUT:
+
+ Final Result
+(Value -2147483648 indicates vertex v is not reachable from vertex u)
+
+Distance from 0 to 0 is :0
+Distance from 0 to 1 is :0
+Distance from 0 to 2 is :0
+Distance from 0 to 3 is :-2147483648
+Distance from 0 to 4 is :0
+Distance from 0 to 5 is :0
+Distance from 0 to 6 is :0
+
+Distance from 1 to 0 is :-2147483648
+Distance from 1 to 1 is :0
+Distance from 1 to 2 is :-2147483648
+Distance from 1 to 3 is :-2147483648
+Distance from 1 to 4 is :6
+Distance from 1 to 5 is :6
+Distance from 1 to 6 is :0
+
+Distance from 2 to 0 is :-2147483648
+Distance from 2 to 1 is :2
+Distance from 2 to 2 is :0
+Distance from 2 to 3 is :-2147483648
+Distance from 2 to 4 is :0
+Distance from 2 to 5 is :0
+Distance from 2 to 6 is :2
+
+Distance from 3 to 0 is :12
+Distance from 3 to 1 is :7
+Distance from 3 to 2 is :5
+Distance from 3 to 3 is :0
+Distance from 3 to 4 is :5
+Distance from 3 to 5 is :5
+Distance from 3 to 6 is :7
+
+Distance from 4 to 0 is :-2147483648
+Distance from 4 to 1 is :2
+Distance from 4 to 2 is :-2147483648
+Distance from 4 to 3 is :-2147483648
+Distance from 4 to 4 is :0
+Distance from 4 to 5 is :8
+Distance from 4 to 6 is :2
+
+Distance from 5 to 0 is :-2147483648
+Distance from 5 to 1 is :2
+Distance from 5 to 2 is :-2147483648
+Distance from 5 to 3 is :-2147483648
+Distance from 5 to 4 is :0
+Distance from 5 to 5 is :0
+Distance from 5 to 6 is :2
+
+Distance from 6 to 0 is :-2147483648
+Distance from 6 to 1 is :8
+Distance from 6 to 2 is :-2147483648
+Distance from 6 to 3 is :-2147483648
+Distance from 6 to 4 is :6
+Distance from 6 to 5 is :6
+Distance from 6 to 6 is :0
+
+ */
From d07d86eeb261ca2fe76c5b2a24ca83e5c85ac95c Mon Sep 17 00:00:00 2001
From: sandhyabhan <52604131+sandhyabhan@users.noreply.github.com>
Date: Thu, 23 Apr 2020 15:23:33 +0530
Subject: [PATCH 102/265] Add Level Order Traversal in Kotlin (#2757)
---
.../Tree_Levelorder_Traversal.kt | 104 ++++++++++++++++++
1 file changed, 104 insertions(+)
create mode 100644 Tree_Levelorder_Traversal/Tree_Levelorder_Traversal.kt
diff --git a/Tree_Levelorder_Traversal/Tree_Levelorder_Traversal.kt b/Tree_Levelorder_Traversal/Tree_Levelorder_Traversal.kt
new file mode 100644
index 000000000..43ec8d992
--- /dev/null
+++ b/Tree_Levelorder_Traversal/Tree_Levelorder_Traversal.kt
@@ -0,0 +1,104 @@
+// Code for printing Level Order of Tree in Kotlin
+
+class Node
+{
+ //Structure of Binary tree node
+ int num;
+ Node left, right;
+ public Node(int num)
+ {
+ key = item;
+ left = right = null;
+ }
+}
+
+class BinaryTree
+{
+ Node root;
+ BinaryTree()
+ {
+ root = null;
+ }
+
+ //function to print level order traversal
+ fun printLevelOrder():void
+ {
+ int h = height(root);
+ int i;
+ // To Print nodes at each level
+ for (i = 1; i <= h; i++)
+ {
+ printGivenLevel(root, i);
+ }
+
+ }
+
+ //Function to calculate height of Tree
+ fun height(Node: root):void
+ {
+ if (root == null)
+ {
+ return 0;
+ }
+ else
+ {
+ // compute height of each subtree
+ int lheight = height(root.left);
+ int rheight = height(root.right);
+ // use the larger one
+ if (lheight > rheight)
+ {
+ return(lheight + 1);
+ }
+ else
+ {
+ return(rheight + 1);
+ }
+ }
+ }
+
+ fun printGivenLevel(Node:root ,int: level):void
+ {
+ if (root == null)
+ {
+ return;
+ }
+ //Print data
+ if (level == 1)
+ {
+ println(root.data);
+ }
+ else if (level > 1)
+ {
+ printGivenLevel(root.left, level-1);
+ printGivenLevel(root.right, level-1);
+ }
+ }
+
+ fun main()
+ {
+ BinaryTree tree = new BinaryTree();
+ var read = Scanner(System.`in`)
+ println("Enter the size of Array:")
+ val arrSize = read.nextLine().toInt()
+ var arr = IntArray(arrSize)
+ println("Enter data of binary tree")
+
+ for(i in 0 until arrSize)
+ {
+ arr[i] = read.nextLine().toInt()
+ tree.root = new Node(arr[i]);
+ }
+
+ println("Level order traversal of binary tree is ");
+ tree.printLevelOrder();
+ }
+}
+
+/*
+Input:
+1 2 3 4 5 6 7 8 9
+Output:
+Level order traversal of binary tree is
+1 2 3 4 5 6 7 8 9
+*/
From a4052fbf160d1de39f8e413b43366c16260d2e94 Mon Sep 17 00:00:00 2001
From: sandhyabhan <52604131+sandhyabhan@users.noreply.github.com>
Date: Fri, 24 Apr 2020 00:32:26 +0530
Subject: [PATCH 103/265] Add spiral array in C (#2322)
---
Spiral_Array/SpiralArray.c | 96 ++++++++++++++++++++++++++++++++++++++
1 file changed, 96 insertions(+)
create mode 100644 Spiral_Array/SpiralArray.c
diff --git a/Spiral_Array/SpiralArray.c b/Spiral_Array/SpiralArray.c
new file mode 100644
index 000000000..ef1da21b5
--- /dev/null
+++ b/Spiral_Array/SpiralArray.c
@@ -0,0 +1,96 @@
+#include
+int main()
+{
+ int a[20][20], int d, int i, int j, int ra, int ca, int r, int c, int k;
+ //accepting number of rows
+ do
+ {
+ printf("enter number of rows:");
+ scanf("%d", &ra);
+ }while(ra < 1);
+ //accepting number of columns
+ do
+ {
+ printf("enter number of columns:");
+ scanf("%d", &ca);
+ }while(ca < 1);
+ printf("\n\t enter elements:");
+ printf("\n");
+ //accepting matrix
+ for(i = 0; i < ra; i++)
+ {
+ for(j = 0; j < ca; j++)
+ {
+ scanf("%d", &a[i][j]);
+ }
+ }
+ printf(" INTIAL MATRIX = ");
+ for(i = 0; i < ra; i++)
+ {
+ printf("\n");
+
+ for(j = 0; j < ca; j++)
+ {
+ printf("%d" , a[i][j]);
+ }
+ }
+ printf("\n");
+ printf("spiral form = ");
+ printf("\n");
+ r = ra - 1;
+ c = ca - 1;
+ i = 0;
+ j = 0;
+ //printing each side so as to get spiral form
+ while(i <= c && j <= r)
+ {
+ if(d == 0)
+ {
+ for(k = i; k <= c; k++)
+ {
+ printf("%d", a[j][k]);
+ }
+ j++;
+ d = 1;
+ }
+ else if(d == 1)
+ {
+ for(k = j; k <= r; k++)
+ {
+ printf("%d", a[k][c]);
+ }
+ c--;
+ d = 2;
+ }
+ else if(d == 2)
+ {
+ for(k = c; k >= i; k--)
+ {
+ printf("%d", a[r][k]);
+ }
+ r--;
+ d = 3;
+ }
+ else if(d == 3)
+ {
+ for(k = r; k >= j; k--)
+ {
+ printf("%d", a[k][i]);
+ }
+ i++;
+ d = 0;
+ }
+ }
+return 0;
+}
+/* Test Cases
+
+Input:
+ 1 2 3 4
+ 5 6 7 8
+ 9 10 11 12
+ 13 14 15 16
+Output:
+1 2 3 4 8 12 16 15 14 13 9 5 6 7 11 10
+
+*/
From 3d4de052f8a5266b9848bcddc6aa472d1fba23df Mon Sep 17 00:00:00 2001
From: Tahanima Chowdhury
Date: Sat, 25 Apr 2020 13:25:28 +0600
Subject: [PATCH 104/265] Added LCS implementation in Ruby (#2252) (#2766)
---
.../Longest_Common_Subsequence.rb | 58 +++++++++++++++++++
1 file changed, 58 insertions(+)
create mode 100644 Longest_Common_Subsequence/Longest_Common_Subsequence.rb
diff --git a/Longest_Common_Subsequence/Longest_Common_Subsequence.rb b/Longest_Common_Subsequence/Longest_Common_Subsequence.rb
new file mode 100644
index 000000000..27e5aa5ec
--- /dev/null
+++ b/Longest_Common_Subsequence/Longest_Common_Subsequence.rb
@@ -0,0 +1,58 @@
+=begin
+Problem Statement- Given two sequences, find
+the length of longest subsequence present in both of them.
+A subsequence is a sequence that can be derived
+from another sequence by deleting some or
+no elements without changing the order of the remaining elements.
+=end
+
+def longest_common_subsequence(arr1, arr2, size1, size2)
+ lcs = Array.new(size1 + 1){Array.new(size2 + 1)}
+
+ for i in 0..size1
+ for j in 0..size2
+ if (i == 0 || j == 0)
+ lcs[i][j] = 0
+ # when the last character of both subsequences match,
+ # increase length of lcs by 1
+ elsif (arr1[i - 1] == arr2[j - 1])
+ lcs[i][j] = lcs[i - 1][j - 1] + 1
+ # when the last character is not same,
+ # take maximum obtained by adding
+ # one character to one of the subsequences
+ else
+ lcs[i][j] = [lcs[i - 1][j], lcs[i][j - 1]].max
+ end
+ end
+ end
+
+ lcs[size1][size2]
+end
+
+# Driver Code
+puts "Enter the size of first array:"
+size1 = gets.to_i
+
+puts "Enter the first array elements:"
+arr1 = gets.split(" ").map(&:to_i)
+
+puts "Enter the size of second array:"
+size2 = gets.to_i
+
+puts "Enter the second array elements:"
+arr2 = gets.split(" ").map(&:to_i)
+
+len = longest_common_subsequence(arr1, arr2, size1, size2)
+puts "Length of Longest Common Subsequence is: #{len}"
+
+=begin
+Enter the size of first array:
+7
+Enter the first array elements:
+10 15 20 25 30 35 40
+Enter the size of second array:
+8
+Enter the second array elements:
+10 12 23 25 28 30 32 40
+Length of Longest Common Subsequence is: 4
+=end
From 6a9acfeda16594973221056e4611bbcf4b25eeeb Mon Sep 17 00:00:00 2001
From: monikajha <53649201+m-code12@users.noreply.github.com>
Date: Sun, 26 Apr 2020 01:18:13 +0530
Subject: [PATCH 105/265] Merge Sort in Rust (#2760)
* Merge Sort in Rust
* Update Merge_Sort.rs
---
Merge_Sort/Merge_Sort.rs | 97 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 97 insertions(+)
create mode 100644 Merge_Sort/Merge_Sort.rs
diff --git a/Merge_Sort/Merge_Sort.rs b/Merge_Sort/Merge_Sort.rs
new file mode 100644
index 000000000..4ee67d93f
--- /dev/null
+++ b/Merge_Sort/Merge_Sort.rs
@@ -0,0 +1,97 @@
+/*
+ Rust Program to implement Merge Sort
+ --------------------------------------------------------
+ Merge Sort
+ --------------------------------------------------------
+Merge sort is a divide-conquer-combine algorithm based on the idea of breaking down a list into several sub-lists .
+The list is broken into sublists until each sublist consists of a single element and merging those sublists in a
+manner that results into a sorted list.
+
+The idea is :
+ -> Divide the unsorted list into N sublists, each containing 1 element.
+ -> Take adjacent pairs of two singleton lists and merge them to form a list of 2 elements.N will now convert
+ into N/2 lists of size 2.
+ -> Repeat the process till a single sorted list of size N is obtained.
+
+Complexity Analysis :
+
+The list of size N is divided into a max of logN parts, and the merging of all sublists into a single list takes O(N) time.
+The worst case run time of this algorithm is O(NlogN) .
+The average and best case run time of this algorithm is N(logN) .
+The space complexity of this algorithm is N .
+*/
+
+
+use std::io;
+use std::str::FromStr;
+
+fn main() {
+ println!("Enter the numbers to be sorted (separated by space) : ");
+ let mut i = read_values::().unwrap();
+ merge_sort(&mut i);
+ println!("Sorted array: {:?}", i)
+ }
+
+fn merge_sort(a: &mut Vec) {
+ let size = a.len();
+ let mut buffer = vec![0; size];
+ merge_split(a, 0, size, &mut buffer);
+}
+
+fn merge_split(a: &mut Vec, start: usize, end: usize, buffer: &mut Vec) {
+ if end - start > 1 {
+ // Determine the split index
+ let split = (start + end) / 2;
+
+ // Split and merge sort
+ merge_split(a, start, split, buffer);
+ merge_split(a, split, end, buffer);
+ merge(a, buffer, start, split, end);
+ merge_copy(buffer, a, start, end);
+ }
+}
+
+fn merge(src: &Vec, dest: &mut Vec, start: usize, split: usize, end: usize) {
+ // Define cursor indices for the left and right part that will be merged
+ let mut left = start;
+ let mut right = split;
+
+ // Merge the parts into the destination in the correct order
+ for i in start..end {
+ if left < split && (right >= end || src[left] <= src[right]) {
+ dest[i] = src[left];
+ left += 1;
+ } else {
+ dest[i] = src[right];
+ right += 1;
+ }
+ }
+}
+
+fn merge_copy(src: &Vec, dest: &mut Vec, start: usize, end: usize) {
+ (start..end).for_each(|i| dest[i] = src[i]);
+}
+
+fn read_values() -> Result, T::Err> {
+ let mut s = String::new();
+ io::stdin()
+ .read_line(&mut s)
+ .expect("could not read from stdin");
+ s.trim()
+ .split_whitespace()
+ .map(|word| word.parse())
+ .collect()
+}
+
+/*
+
+ Sample Input :
+
+ Enter the numbers to be sorted (separated by space) :
+ 76 56 45 3 1 4
+
+ Sample Output :
+
+ Sorted array: [1, 3, 4, 45, 56, 76]
+*/
+
From 30a9f398e67f828d6ae50cfe721b31bfd662f741 Mon Sep 17 00:00:00 2001
From: Ankita Saloni
Date: Sun, 26 Apr 2020 01:50:52 +0530
Subject: [PATCH 106/265] Created Ternary_Search.kt (#2745)
Co-authored-by: Ankita Saloni <56873389+saloniankita23@users.noreply.github.com>
---
Ternary_Search/Ternary_Search.kt | 77 ++++++++++++++++++++++++++++++++
1 file changed, 77 insertions(+)
create mode 100644 Ternary_Search/Ternary_Search.kt
diff --git a/Ternary_Search/Ternary_Search.kt b/Ternary_Search/Ternary_Search.kt
new file mode 100644
index 000000000..65b82347a
--- /dev/null
+++ b/Ternary_Search/Ternary_Search.kt
@@ -0,0 +1,77 @@
+ import java.util.*
+ import kotlin.collections.ArrayList
+
+ //Ternary Search begins
+ public fun ternarySearch(l:Int, r:Int, key:Int, ar:ArrayList): Int {
+ if(r>=1){
+ var mid1 = l + (r - l) / 3
+ var mid2 = r - (r - l) / 3
+
+ //Searching for the key element
+ if (ar[mid1] == key) {
+ return mid1
+ }
+
+ if (ar[mid2] == key) {
+ return mid2
+ }
+
+ if (key < ar[mid1]) {
+ return ternarySearch(l, mid1 - 1, key, ar)
+ }
+
+ else if (key > ar[mid2]) {
+ return ternarySearch(mid2 + 1, r, key, ar)
+ }
+
+ else {
+ return ternarySearch(mid1 + 1, mid2 - 1, key, ar)
+ }
+ }
+ return -1;
+}
+
+ //Main function
+ fun main() {
+ var l:Int = 0
+ var r:Int
+ var p:Int
+ var key:Int
+ var scan1: Scanner = Scanner(System.`in`)
+
+ //var ar = arrayOf(1,2,3,4,5,6,7,8,9,10)
+ var ar = ArrayList()
+
+ //Taking input from user
+ println("Enter the number of elements: ")
+ var n:Int = scan1.nextInt()
+ var temp:Int
+ for (i in 1..n) {
+ temp = scan1.nextInt()
+ ar.add(temp)
+ }
+
+ //Sorting the array
+ println("Sorting the array in ascending order...")
+ ar.sort()
+ r = ar.count()
+ println("Enter the key element to search for:")
+ key = scan1.nextInt()
+ p = ternarySearch(l, r, key, ar)
+ //Printing the key element with its position
+ print("Index of $key is $p \n")
+
+
+ /*Sample Input and Output
+ Enter the number of elements :
+ 6
+ 5
+ 4
+ 3
+ 2
+ 1
+ Sorting the array in ascending order...
+ Enter the key element to search for:
+ 5
+ Index of 5 is 4
+ */
From e43cc39e99e9855ff214659d1df9681709a5d7eb Mon Sep 17 00:00:00 2001
From: Anmol Kaur
Date: Sun, 26 Apr 2020 14:11:51 +0530
Subject: [PATCH 107/265] added PHP/Heap sort (#2147) (#2737)
---
Heap_Sort/heap_sort.php | 74 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 74 insertions(+)
create mode 100644 Heap_Sort/heap_sort.php
diff --git a/Heap_Sort/heap_sort.php b/Heap_Sort/heap_sort.php
new file mode 100644
index 000000000..f16b141cc
--- /dev/null
+++ b/Heap_Sort/heap_sort.php
@@ -0,0 +1,74 @@
+ $data[$index]) // If left child is larger than root
+ $largest = $left;
+ else
+ $largest = $index;
+
+ if ($right < $heapSize && $data[$right] > $data[$largest]) // If right child is larger than largest so far
+ $largest = $right;
+
+ if ($largest != $index) // If largest is not root
+ {
+ $temp = $data[$index];
+ $data[$index] = $data[$largest];
+ $data[$largest] = $temp;
+
+ //Recursively heapify the affected sub-tree
+ MaxHeapify($data, $heapSize, $largest);
+ }
+}
+
+function HeapSort(&$data, $count) {
+ $heapSize = $count;
+
+ // Build heap (rearrange array)
+ for ($p = ($heapSize - 1) / 2; $p >= 0; $p--)
+ MaxHeapify($data, $heapSize, $p);
+
+ // One by one extract an element from heap
+ for ($i = $count - 1; $i > 0; $i--)
+ {
+ $temp = $data[$i];
+ $data[$i] = $data[0];
+ $data[0] = $temp;
+
+ $heapSize--;
+ MaxHeapify($data, $heapSize, 0);
+ }
+}
+
+// example of driver function
+$array = array(20 , 43 , 65 , 88 , 11 , 33 , 56 , 74);
+HeapSort($array , 8);
+print_r($array);
+
+ // output
+ /*Array
+ (
+ [0] => 11
+ [1] => 20
+ [2] => 33
+ [3] => 65
+ [4] => 43
+ [5] => 56
+ [6] => 74
+ [7] => 88
+ )
+
+*/
+
+?>
From 85d70e506a8d4bd6d9d67c09d0aaca0f9517f93a Mon Sep 17 00:00:00 2001
From: monikajha <53649201+m-code12@users.noreply.github.com>
Date: Tue, 28 Apr 2020 08:26:16 +0530
Subject: [PATCH 108/265] Bucket Sort in Ruby (#2759)
---
Bucket_Sort/Bucket_Sort.rb | 36 ++++++++++++++++++++++++++++++++++++
1 file changed, 36 insertions(+)
create mode 100644 Bucket_Sort/Bucket_Sort.rb
diff --git a/Bucket_Sort/Bucket_Sort.rb b/Bucket_Sort/Bucket_Sort.rb
new file mode 100644
index 000000000..92c906c86
--- /dev/null
+++ b/Bucket_Sort/Bucket_Sort.rb
@@ -0,0 +1,36 @@
+DEFAULT_BUCKET_SIZE = 5
+
+def bucket_sort(input, bucket_size = DEFAULT_BUCKET_SIZE)
+ print 'Array is empty' if input.empty?
+
+ array = input.split(' ').map(&:to_i)
+
+ bucket_count = ((array.max - array.min) / bucket_size).floor + 1
+
+ # create buckets
+ buckets = []
+ bucket_count.times { buckets.push [] }
+
+ # fill buckets
+ array.each do |item|
+ buckets[((item - array.min) / bucket_size).floor].push(item)
+ end
+
+ # sort buckets
+ buckets.each(&:sort!)
+
+ buckets.flatten.join(' ')
+end
+
+puts 'Enter a list of numbers (separated by space) : '
+list = gets
+puts 'The sorted list is : '
+print bucket_sort(list)
+
+
+# Output :
+# Enter a list of numbers (separated by space) :
+# 7 9 5 4 1
+# The sorted list is :
+# 1 4 5 7 9
+
From 8ca15ba84cf9391c82f163fd0e98ab5a1c74f6a2 Mon Sep 17 00:00:00 2001
From: Rukmini Meda <44504940+Rukmini-Meda@users.noreply.github.com>
Date: Tue, 28 Apr 2020 11:37:00 +0530
Subject: [PATCH 109/265] Topological Sort implemented in Dart (#2812)
---
Topological_Sort/Topological_Sort.dart | 181 +++++++++++++++++++++++++
1 file changed, 181 insertions(+)
create mode 100644 Topological_Sort/Topological_Sort.dart
diff --git a/Topological_Sort/Topological_Sort.dart b/Topological_Sort/Topological_Sort.dart
new file mode 100644
index 000000000..88d35a0b7
--- /dev/null
+++ b/Topological_Sort/Topological_Sort.dart
@@ -0,0 +1,181 @@
+/**
+ * Topological Sort implementation in Dart
+ * -------------------------------------------------------
+ *
+ * In a directed acyclic graph, if there is an edge from u to v. Then, u comes before v.
+ * This observation has many real life application like scheduling tasks, ordering things etc.,.
+ *
+ * Topological sorting for Directed Acyclic Graph (DAG) is a linear ordering of vertices such that
+ * for every directed edge uv, vertex u comes before v in the ordering.
+ *
+ * Topological sorting is an application of Depth First Search.
+ *
+ */
+
+
+// Importing required libraries
+import 'dart:io';
+import 'dart:core';
+
+// Class for a graph
+class Graph{
+
+ // Number of vertices in a graph.
+ int vertices;
+
+ // Adjacency list to store the graph.
+ List< List< int > > adjlist;
+
+ // Constructor
+ Graph(int v){
+
+ // Assigning number of vertices
+ this.vertices = v;
+
+ // Initializing the graph
+ this.adjlist = new List< List< int > >(vertices);
+
+ for (int i = 0 ; i < vertices ; i ++){
+
+ this.adjlist[i] = new List< int >();
+
+ }
+
+ }
+
+ // Method to add an edge
+ void add_edge(int source , int destination){
+
+ this.adjlist[source].add(destination);
+
+ }
+
+
+ // Utility method for Topological Sort
+ void topologicalSortUtil(int source , List< int > stack , List< bool > visited){
+
+ // Marking source vertex visited
+ visited[source] = true;
+
+ int len = this.adjlist[source].length;
+
+ // Recursively visiting it's neighbours
+ for (int i = 0 ; i < len ; i ++){
+
+ if (visited[adjlist[source][i]] == false){
+
+ // Recursive call
+ topologicalSortUtil(adjlist[source][i] , stack , visited);
+
+ }
+ }
+
+ // Adding to stack
+ stack.add(source);
+
+ }
+
+ // Method to find the topological sort
+ void topologicalSort(){
+
+ // Stack required to print the topological sort
+ List< int > stack = new List< int >();
+
+ // Initializing the visited list.
+ List< bool > visited = new List< bool >.generate(this.vertices , ( i ) => false);
+
+ // Running the utility on all vertices to cover the entire graph.
+ for (int i = 0 ; i < this.vertices ; i ++){
+
+ if (visited[i] == false){
+
+ topologicalSortUtil(i , stack , visited);
+
+ }
+
+ }
+
+ // Converting the elements in the stack into a string and printing them.
+ String s;
+
+ List temp = new List< int >();
+
+ while ( ! stack.isEmpty ){
+
+ temp.add(stack.removeLast());
+
+ }
+
+ s = temp.join(" ");
+
+ // Printing the result
+ print(s);
+
+ }
+
+}
+
+// Driver function of the program
+void main(){
+
+ // Taking input of number of vertices
+ print("Enter number of vertices:");
+
+ var input = stdin.readLineSync();
+
+ int n = int.parse(input);
+
+ Graph g = new Graph(n);
+
+ // Taking input of number of edges
+ print("Enter number of edges:");
+
+ input = stdin.readLineSync();
+
+ int m = int.parse(input);
+
+ // Taking input of edges
+ print("Enter edges for vertices in 0 - n range:");
+
+ for(int i = 0 ; i < m ; i ++){
+
+ input = stdin.readLineSync();
+
+ var lis = input.split(" ");
+
+ List list1 = lis.map(int.parse).toList();
+
+ g.add_edge(list1[0] , list1[1]);
+
+ }
+
+ // Printing the result
+ print("Following is the topological sort of the input graph: ");
+
+ g.topologicalSort();
+
+}
+
+/*
+
+ Sample Input
+ ----------------------
+ Enter number of vertices:
+ 8
+ Enter number of edges:
+ 7
+ Enter edges for vertices in 0 - n range:
+ 0 1
+ 0 4
+ 1 7
+ 1 2
+ 2 3
+ 4 5
+ 5 6
+
+ Sample Output
+ -----------------------
+ Following is the topological sort of the input graph:
+ 0 4 5 6 1 2 3 7
+
+*/
From 19c851e5b62d7c998fff5c5e3c50c8a7424aa482 Mon Sep 17 00:00:00 2001
From: Bieky Mahato <60212331+biekymahato@users.noreply.github.com>
Date: Wed, 29 Apr 2020 13:13:03 +0530
Subject: [PATCH 110/265] Implementation Of Tower of Hanoi in C# (#2599)
Implementation Tower_Of_Hanoi in C#
Tower Of Hanoi (c#)
Modified the Tower of hanoi in C#
Changes the folder
Implementation of Tower of Hanoi in C# after required changes
---
Tower_Of_Hanoi/Tower_of_Hanoi.cs | 93 ++++++++++++++++++++++++++++++++
1 file changed, 93 insertions(+)
create mode 100644 Tower_Of_Hanoi/Tower_of_Hanoi.cs
diff --git a/Tower_Of_Hanoi/Tower_of_Hanoi.cs b/Tower_Of_Hanoi/Tower_of_Hanoi.cs
new file mode 100644
index 000000000..8e190dfc0
--- /dev/null
+++ b/Tower_Of_Hanoi/Tower_of_Hanoi.cs
@@ -0,0 +1,93 @@
+/*
+C# recursive program to solve
+tower of hanoi puzzle */
+using System;
+
+class geek
+{
+
+ // C# recursive function to solve Tower of Hanoi puzzle
+ static void towerOfHanoi(int n, char from_rod, char to_rod, char aux_rod)
+ {
+ if (n == 1)
+ {
+ Console.WriteLine("Move disk 1 from rod " + from_rod + " to rod " + to_rod);
+ return;
+ }
+ towerOfHanoi(n-1, from_rod, aux_rod, to_rod);
+ Console.WriteLine("Move disk " + n + " from rod "+ from_rod + " to rod " + to_rod);
+ towerOfHanoi(n-1, aux_rod, to_rod, from_rod);
+ }
+
+ // Driver method
+ public static void Main()
+ {
+ // Number of disks
+ int n;
+ String val;
+
+ //Input taken
+ val = Console.ReadLine();
+ n = Convert.ToInt32(val);
+
+ // A, B and C are names of rods
+ towerOfHanoi(n, 'A', 'C', 'B');
+ }
+}
+
+/*
+Input for Test Case 1:
+4 //n = 4
+Output for Test Case 1:
+Move disk 1 from rod A to rod B
+Move disk 2 from rod A to rod C
+Move disk 1 from rod B to rod C
+Move disk 3 from rod A to rod B
+Move disk 1 from rod C to rod A
+Move disk 2 from rod C to rod B
+Move disk 1 from rod A to rod B
+Move disk 4 from rod A to rod C
+Move disk 1 from rod B to rod C
+Move disk 2 from rod B to rod A
+Move disk 1 from rod C to rod A
+Move disk 3 from rod B to rod C
+Move disk 1 from rod A to rod B
+Move disk 2 from rod A to rod C
+Move disk 1 from rod B to rod C
+*/
+/*
+Input for Test Case 2:
+5 //n = 5
+Output for Test case 2:
+Move disk 1 from rod A to rod C
+Move disk 2 from rod A to rod B
+Move disk 1 from rod C to rod B
+Move disk 3 from rod A to rod C
+Move disk 1 from rod B to rod A
+Move disk 2 from rod B to rod C
+Move disk 1 from rod A to rod C
+Move disk 4 from rod A to rod B
+Move disk 1 from rod C to rod B
+Move disk 2 from rod C to rod A
+Move disk 1 from rod B to rod A
+Move disk 3 from rod C to rod B
+Move disk 1 from rod A to rod C
+Move disk 2 from rod A to rod B
+Move disk 1 from rod C to rod B
+Move disk 5 from rod A to rod C
+Move disk 1 from rod B to rod A
+Move disk 2 from rod B to rod C
+Move disk 1 from rod A to rod C
+Move disk 3 from rod B to rod A
+Move disk 1 from rod C to rod B
+Move disk 2 from rod C to rod A
+Move disk 1 from rod B to rod A
+Move disk 4 from rod B to rod C
+Move disk 1 from rod A to rod C
+Move disk 2 from rod A to rod B
+Move disk 1 from rod C to rod B
+Move disk 3 from rod A to rod C
+Move disk 1 from rod B to rod A
+Move disk 2 from rod B to rod C
+Move disk 1 from rod A to rod C
+*/
From e6e79ba6f319e98fab4607f0e1d606e0d035d94b Mon Sep 17 00:00:00 2001
From: Debdut Goswami
Date: Wed, 29 Apr 2020 14:42:26 +0530
Subject: [PATCH 111/265] Insertion Sort #2148 (#2806)
---
Insertion_Sort/README.md | 130 +++++++++++++++++++++++++++++++++++++++
1 file changed, 130 insertions(+)
create mode 100644 Insertion_Sort/README.md
diff --git a/Insertion_Sort/README.md b/Insertion_Sort/README.md
new file mode 100644
index 000000000..d1add4837
--- /dev/null
+++ b/Insertion_Sort/README.md
@@ -0,0 +1,130 @@
+# INSERTION SORT
+
+[Insertion Sort](https://en.wikipedia.org/wiki/Insertion_Sort) is a simple sorting algorithm that builds the final sorted array (or list) one item at a time. It is much less efficient on large lists than more advanced algorithms such as quicksort, heapsort, or merge sort.
+
+## EXAMPLE
+
+Given below is an unsorted array. `Insertion sort` takes O(n) time in Best Case and Ο(n2) time for Average and Worst Case.
+
+
+
+`Insertion sort` compares the first two elements
+
+
+
+It finds that both 14 and 33 are already in ascending order. For now, 14 is in sorted sub-list.
+
+
+
+Insertion sort moves ahead and compares 33 with 27.
+
+
+
+And finds that 33 is not in the correct position.
+
+
+
+It swaps 33 with 27. It also checks with all the elements of sorted sub-list. Here we see that the sorted sub-list has only one element 14, and 27 is greater than 14. Hence, the sorted sub-list remains sorted after swapping.
+
+
+
+By now we have 14 and 27 in the sorted sub-list. Next, it compares 33 with 10.
+
+
+
+These values are not in a sorted order.
+
+
+
+So we swap them.
+
+
+
+However, swapping makes 27 and 10 unsorted.
+
+
+
+Hence, we swap them too.
+
+
+
+Again we find 14 and 10 in an unsorted order.
+
+
+
+We swap them again. By the end of third iteration, we have a sorted sub-list of 4 items.
+
+
+
+This process goes on until all the unsorted values are covered in a sorted sub-list. Now we shall see some programming aspects of insertion sort.
+
+## ALGORITHM
+
+```
+Step 1 − If it is the first element, it is already sorted. return 1;
+Step 2 − Pick next element
+Step 3 − Compare with all elements in the sorted sub-list
+Step 4 − Shift all the elements in the sorted sub-list that is greater than the value to be sorted
+Step 5 − Insert the value
+Step 6 − Repeat until list is sorted
+```
+
+## PSEUDOCODE
+
+Pseudocode of InsertionSort algorithm can be expressed as −
+
+```
+procedure insertionSort( A : array of items )
+ int holePosition
+ int valueToInsert
+
+ for i = 1 to length(A) inclusive do:
+
+ /* select value to be inserted */
+ valueToInsert = A[i]
+ holePosition = i
+
+ /*locate hole position for the element to be inserted */
+
+ while holePosition > 0 and A[holePosition-1] > valueToInsert do:
+ A[holePosition] = A[holePosition-1]
+ holePosition = holePosition -1
+ end while
+
+ /* insert the number at hole position */
+ A[holePosition] = valueToInsert
+
+ end for
+
+end procedure
+```
+
+## COMPLEXITY
+
+**Time complexity**
+
+_Best Case_: O(n)
+
+_Average and Worst Case_: О(n2)
+
+where _n_ is the number of items being sorted.
+
+**Space complexity** - O(1), due to auxillary space only.
+
+## Implementation
+
+- [C Code](https://github.com/jainaman224/Algo_Ds_Notes/blob/master/Insertion_Sort/Insertion_Sort.c)
+
+- [CoffeeScript Code](https://github.com/jainaman224/Algo_Ds_Notes/blob/master/Insertion_Sort/Insertion_Sort.coffee)
+
+- [C++ Code](https://github.com/jainaman224/Algo_Ds_Notes/blob/master/Insertion_Sort/Insertion_Sort.cpp)
+
+- [C# Code](https://github.com/jainaman224/Algo_Ds_Notes/blob/master/Insertion_Sort/Insertion_Sort.cs)
+
+- [Java Code](https://github.com/jainaman224/Algo_Ds_Notes/blob/master/Insertion_Sort/Insertion_Sort.java)
+
+- [JavaScript Code](https://github.com/jainaman224/Algo_Ds_Notes/blob/master/Insertion_Sort/Insertion_Sort.js)
+
+- [PHP Code](https://github.com/jainaman224/Algo_Ds_Notes/blob/master/Insertion_Sort/Insertion_Sort.php)
+
+- [Python Code](https://github.com/jainaman224/Algo_Ds_Notes/blob/master/Insertion_Sort/Insertion_Sort.py)
From f6ca8c26197ceda9653eb8fa06745177066b514d Mon Sep 17 00:00:00 2001
From: Rukmini Meda <44504940+Rukmini-Meda@users.noreply.github.com>
Date: Wed, 29 Apr 2020 16:48:47 +0530
Subject: [PATCH 112/265] Segment Tree RMQ implemented in Dart (#2799)
---
Segment_Tree_RMQ/Segment_Tree_RMQ.dart | 230 +++++++++++++++++++++++++
1 file changed, 230 insertions(+)
create mode 100644 Segment_Tree_RMQ/Segment_Tree_RMQ.dart
diff --git a/Segment_Tree_RMQ/Segment_Tree_RMQ.dart b/Segment_Tree_RMQ/Segment_Tree_RMQ.dart
new file mode 100644
index 000000000..8aa67af20
--- /dev/null
+++ b/Segment_Tree_RMQ/Segment_Tree_RMQ.dart
@@ -0,0 +1,230 @@
+/**
+ * Dart implementation of Segment Tree for Range Minimum Query
+ * -------------------------------------------------------------------------
+ * Segment Tree is a binary tree whose nodes are ranges of an interval.
+ * Each node has a value corresponding to it's interval.
+ * Construction of a Segment Tree takes O(n) time.
+ * Querying on the same takes O(logn) time.
+ * Hence, many queries can be answered efficiently in time using Segment Tree.
+ *
+ *
+*/
+
+// Importing required libraries
+import 'dart:io';
+import 'dart:math';
+
+// Maximum range of int of 64 bits.
+const int int64MaxValue = 9223372036854775807;
+
+// Function to find logarithm to base 2.
+double logtobase2(int n){
+
+ return log(n) / log(2);
+
+}
+
+// Function to update value at a particular position in the tree
+void updateNode(List tree , int treestart , int treeend , int nodeindex , int position , int newval){
+
+ if (treestart == treeend){
+
+ tree[nodeindex] = newval;
+
+ }
+ else{
+
+ int mid = (treestart + ((treeend - treestart) / 2)).floor();
+
+ if (position < mid){
+
+ updateNode(tree , treestart , mid , 2 * nodeindex , position , newval);
+
+ }
+ else{
+
+ updateNode(tree , mid + 1 , treeend, 2 * nodeindex + 1 , position, newval);
+
+ }
+
+ tree[nodeindex] = min(tree[2 * nodeindex] , tree[2 * nodeindex + 1]);
+
+ }
+
+}
+
+// Function to query on a Segment Tree
+int queryonSegmentTree(List tree , int start , int end , int treestart , int treeend , int nodeindex){
+
+ if (start > end){
+
+ return int64MaxValue;
+
+ }
+
+ // Base Case
+ if (start == treestart && end == treeend){
+
+ return tree[nodeindex];
+
+ }
+
+ // Finding the index of midpoint
+ int mid = (treestart + (treeend - treestart) / 2).floor();
+
+ int value1 , value2;
+
+
+ // Recursion to find the minimum.
+ value1 = queryonSegmentTree(tree , start , min(end,mid) , treestart , mid , 2 * nodeindex );
+
+ value2 = queryonSegmentTree(tree , max(start , mid + 1) , end , mid + 1 , treeend , 2 * nodeindex + 1 );
+
+ // Returning minimum.
+ return min(value1 , value2);
+
+}
+
+// Function to construct the Segment Tree.
+void constructSegmentTree(List tree , List numbers , int start , int end , int nodeindex){
+
+ // Base Case
+ if (start == end){
+
+ tree[nodeindex] = numbers[start];
+ return;
+
+ }
+
+ // Finding index of the midpoint.
+ int mid = (start + ((end - start) / 2)).floor();
+
+ // Recursion to find minimum.
+ constructSegmentTree(tree , numbers , start , mid , 2 * nodeindex);
+
+ constructSegmentTree(tree , numbers , mid + 1 , end , 2 * nodeindex + 1);
+
+ // Finding minimum of the parent from its children.
+ tree[nodeindex] = min(tree[2 * nodeindex],tree[2 * nodeindex + 1]);
+
+}
+
+// Driver function of the program.
+void main(){
+
+ // Taking input of number of array elements.
+ print("Enter number of elements: ");
+
+ var input = stdin.readLineSync();
+
+ int n = int.parse(input);
+
+ // Taking input of the number array (num[i]).
+ print("Enter array of numbers:");
+
+ input = stdin.readLineSync();
+
+ var lis = input.split(' ');
+
+ List numbers = lis.map(int.parse).toList();
+
+ // Calculating the depth of the possible binary tree.
+ int depth = logtobase2(n).ceil();
+ // Finding the maximum number of nodes in the binary tree.
+ int num_nodes = 2 * pow(2 , depth) - 1;
+
+ // Initializing the Segment tree.
+ List tree = List.generate(num_nodes + 1 , (i) => 0);
+
+ // Constructing the Segment Tree.
+ constructSegmentTree(tree , numbers , 0 , n - 1 , 1);
+
+ // Taking input of number of queries.
+ print("Enter number of queries: ");
+
+ input = stdin.readLineSync();
+
+ int q = int.parse(input);
+
+ List queries = List(2);
+
+ int flag;
+
+
+ // Taking input of queries.
+ print("Enter queries: ");
+
+ for (int i = 0 ; i < q ; i ++){
+
+ print("Enter 1 to retrieve minimum in a range or 2 to update a value: ");
+
+ input = stdin.readLineSync();
+
+ flag = int.parse(input);
+
+ print("Enter corresponding query: ");
+
+ input = stdin.readLineSync();
+
+ lis = input.split(' ');
+
+ queries = lis.map(int.parse).toList();
+
+ if (flag == 2){
+
+ numbers[queries[0]] = queries[1];
+ updateNode(tree , 0 , n - 1 , 1 , queries[0] , queries[1]);
+
+ }
+ else{
+
+ // Printing output of each query.
+ print(queryonSegmentTree(tree , queries[0] , queries[1] , 0 , n - 1 , 1));
+
+ }
+
+ }
+
+}
+
+/**
+ *
+ * Sample Input & Output
+ * ---------------------------
+ * Enter number of elements:
+ * 10
+ * Enter array of numbers:
+ * 12 43 9 -2 1 8 6 5 10 23
+ * Enter number of queries:
+ * 6
+ * Enter queries:
+ * Enter 1 to retrieve minimum in a range or 2 to update a value:
+ * 1
+ * Enter corresponding query:
+ * 1 2
+ * 9 (Output)
+ * Enter 1 to retrieve minimum in a range or 2 to update a value:
+ * 2
+ * Enter corresponding query:
+ * 0 -12
+ * Enter 1 to retrieve minimum in a range or 2 to update a value:
+ * 1
+ * Enter corresponding query:
+ * 1 2
+ * -12 (Output)
+ * Enter 1 to retrieve minimum in a range or 2 to update a value:
+ * 2
+ * Enter corresponding query:
+ * 7 -100
+ * Enter 1 to retrieve minimum in a range or 2 to update a value:
+ * 1
+ * Enter corresponding query:
+ * 4 9
+ * -100 (Output)
+ * Enter 1 to retrieve minimum in a range or 2 to update a value:
+ * 1
+ * Enter corresponding query:
+ * 2 6
+ * -2 (Output)
+ *
+ */
From 35880677b465d602e63d58bb8104c2cecd2def29 Mon Sep 17 00:00:00 2001
From: Anushka-Rajvanshi <60550664+Anushka-Rajvanshi@users.noreply.github.com>
Date: Thu, 30 Apr 2020 14:59:18 +0530
Subject: [PATCH 113/265] Added Chinese remainder theorem in C. (#2832)
---
.../Chinese_remainder_theorem.c | 64 +++++++++++++++++++
1 file changed, 64 insertions(+)
create mode 100644 Chinese_Remainder_Theorem/Chinese_remainder_theorem.c
diff --git a/Chinese_Remainder_Theorem/Chinese_remainder_theorem.c b/Chinese_Remainder_Theorem/Chinese_remainder_theorem.c
new file mode 100644
index 000000000..0ace268c5
--- /dev/null
+++ b/Chinese_Remainder_Theorem/Chinese_remainder_theorem.c
@@ -0,0 +1,64 @@
+#include
+
+//function to find minimum number such that num%divisor[i] gives corresponding remainder[i]
+int minresult( int divisor[], int rem[], int size)
+{
+ int m = 1, M[size], inv[size], i, k, count, x = 0;
+ for (i = 0; i < size; i++)
+ {
+ m = m * divisor[i];
+ }
+ for (i = 0; i < size; i++)
+ {
+ M[i] = m / divisor[i];
+ }
+ for (i = 0; i < size; i++)
+ {
+ count = 0;
+ k = 1;
+ do
+ {
+ if(((M[i] % divisor[i]) * k) % divisor[i] == 1)
+ {
+ inv[i] = k;
+ count++;
+ }
+ k++;
+ }while(count == 0);
+ }
+ for (i = 0; i < size; i++)
+ {
+ x = x + (rem[i] * M[i] * inv[i]); //according to CRT
+ }
+ x = x % m;
+ return x;
+}
+
+int main()
+{
+ int size, i, divisor[100], rem[100];
+ //input size of array in variable size
+ printf("Enter size of array:");
+ scanf("%d", &size);
+ //input divisor values and then remainder values
+ printf("Enter value of coprime divisors:");
+ for (i = 0; i < size; i++ )
+ {
+ scanf("%d", &divisor[i]);
+ }
+ printf("Enter value of remainders:");
+ for (i = 0; i < size; i++ )
+ {
+ scanf("%d", &rem[i]);
+ }
+ //function call to find result.
+ printf("Answer is: %d ", minresult( divisor, rem, size));
+ return 0;
+}
+
+/* Sample input-output:
+Enter size of array:3
+Enter value of coprime divisors:2 3 5
+Enter value of remainders:1 2 4
+Answer is: 29
+*/
From 1457fe4cc45fe81e42d4cb7b988eb7b141c4bc53 Mon Sep 17 00:00:00 2001
From: Subhradeep Saha
Date: Fri, 1 May 2020 15:02:42 +0530
Subject: [PATCH 114/265] Gray Code generation of any input bit length (#2005)
---
Gray_Code/Gray_Code.cpp | 53 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 53 insertions(+)
create mode 100644 Gray_Code/Gray_Code.cpp
diff --git a/Gray_Code/Gray_Code.cpp b/Gray_Code/Gray_Code.cpp
new file mode 100644
index 000000000..2c349500b
--- /dev/null
+++ b/Gray_Code/Gray_Code.cpp
@@ -0,0 +1,53 @@
+//C++ program to generate the Gray Code for any input bit length
+
+#include
+#define pb push_back
+using namespace std;
+
+// Function to generate the Gray Code sequence
+void Gray(int n){
+ //If input size is less than or equal to 0
+ if(n <= 0){
+ cout << "Invalid input";
+ return;
+ }
+
+ vector v;
+ v.pb("0");
+ v.pb("1");
+
+ for(int i = 2; i < (1 << n); i <<= 1){
+ for(int j = i - 1; j >= 0; j--)
+ v.pb(v[j]);
+
+ for(int j = 0; j < i; j++)
+ v[j] = "0" + v[j];
+
+ for(int j = i; j < 2 * i; j++)
+ v[j] = "1" + v[j];
+ }
+
+ cout << "Gray Code for bit length = " << n << " : " << endl;
+
+ for(int i = 0; i < v.size(); i++)
+ cout << v[i] << endl;
+}
+
+int main(){
+ int n;
+ cout << "Enter the bit length for Gray Code generation : ";
+ cin >> n;
+ Gray(n);
+}
+
+/* Sample input-output
+Enter the bit length for Gray Code generation : 3
+Gray Code for bit length = 3 :
+000
+001
+011
+010
+110
+111
+101
+100 */
From bcccc63f22d43c47690c170d0a0fc560477bde97 Mon Sep 17 00:00:00 2001
From: Hardev Khandhar <54733460+HardevKhandhar@users.noreply.github.com>
Date: Fri, 1 May 2020 15:28:56 +0530
Subject: [PATCH 115/265] Karatsuba Algorithm In GO (#2817)
Updated Changes
---
Karatsuba_Algorithm/Karatsuba_Algorithm.go | 136 +++++++++++++++++++++
1 file changed, 136 insertions(+)
create mode 100644 Karatsuba_Algorithm/Karatsuba_Algorithm.go
diff --git a/Karatsuba_Algorithm/Karatsuba_Algorithm.go b/Karatsuba_Algorithm/Karatsuba_Algorithm.go
new file mode 100644
index 000000000..19f3ceba6
--- /dev/null
+++ b/Karatsuba_Algorithm/Karatsuba_Algorithm.go
@@ -0,0 +1,136 @@
+// Karatsuba Algorithm In GO
+
+/**
+
+The Karatsuba Algorithm is a fast multiplication algorithm.
+It was discovered by Anatoly Karatsuba in 1960. It reduces
+the multiplication of two n-digit numbers to at most single
+digit multiplications in general. It is therefore faster
+than classical multiplication operation.
+
+*/
+
+package main
+
+// Importing Necessary Packages
+import
+(
+ "fmt"
+ "math"
+)
+
+// Input Function To Get The Digits
+func getDigits(number int64) uint {
+
+ var ans uint
+
+ if number == 0 {
+ return 1
+ }
+
+ if number < 0 {
+ number = -number
+ }
+
+ for number > 0 {
+ ans++
+ number = number / 10
+ }
+
+ return ans
+}
+
+func getHighAndLowDigits(num int64, digits uint) (int64, int64) {
+
+ divisor := int64(math.Pow(10, float64(digits)))
+
+ if num >= divisor {
+ return num / divisor, num % divisor
+ }
+ else {
+ return 0, num
+ }
+}
+
+// Karatsuba Algorithm Function
+func karatsuba(x int64, y int64) int64 {
+
+ var max_digits uint
+ positive := true
+
+ if x == 0 || y == 0 {
+ return 0
+ }
+
+ if (x > 0 && y < 0) || (x < 0 && y > 0) {
+ positive = false
+ }
+
+ if x < 0 {
+ x = -x
+ }
+
+ if y < 0 {
+ y = -y
+ }
+
+ if x < 10 || y < 10 {
+ return x * y
+ }
+
+ x_digits := getDigits(x)
+ y_digits := getDigits(y)
+
+ if x_digits >= y_digits {
+ max_digits = x_digits / 2
+ }
+ else {
+ max_digits = y_digits / 2
+ }
+
+ x_high, x_low := getHighAndLowDigits(x, max_digits)
+ y_high, y_low := getHighAndLowDigits(y, max_digits)
+
+ z0 := karatsuba(x_low, y_low)
+ z1 := karatsuba((x_low + x_high), (y_low + y_high))
+ z2 := karatsuba(x_high, y_high)
+
+ if positive {
+ return (z2 * int64(math.Pow(10, float64(2 * max_digits)))) +
+ (z1 - z2 - z0) * int64(math.Pow(10, float64(max_digits))) + z0
+ }
+ else {
+ return -((z2 * int64(math.Pow(10, float64(2 * max_digits)))) +
+ (z1 - z2 - z0) * int64(math.Pow(10, float64(max_digits))) + z0)
+ }
+}
+
+// Main Function & Taking User Inputs
+func main() {
+
+ fmt.Println("Enter the first number: ")
+ var first int64
+ fmt.Scanln(&first)
+
+ fmt.Println("Enter the second number: ")
+ var second int64
+ fmt.Scanln(&second)
+ fmt.Println()
+
+ fmt.Print("Result: ")
+ fmt.Println(karatsuba(first, second))
+}
+
+/**
+
+Enter the first number: 121547
+Enter the second number: 1855324
+
+Result: 225509066228
+
+Enter the first number: -8859460
+Enter the second number: 1154486
+
+Result: -10228122537560
+
+*/
From 565a6e8c43fd7e33204fa1d0ad5ffdfb4c8a7a55 Mon Sep 17 00:00:00 2001
From: shweta gurnani <43384092+shwetagurnani@users.noreply.github.com>
Date: Sat, 2 May 2020 17:09:27 +0530
Subject: [PATCH 116/265] Postman sort readme added (#2829)
---
Postman_Sort/readme.md | 104 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 104 insertions(+)
create mode 100644 Postman_Sort/readme.md
diff --git a/Postman_Sort/readme.md b/Postman_Sort/readme.md
new file mode 100644
index 000000000..fc4ef136d
--- /dev/null
+++ b/Postman_Sort/readme.md
@@ -0,0 +1,104 @@
+# Postman Sort
+
+Postman sort works by sorting the integers of an array from their most significant digits to their least
+significant digits. In the Postman sort the integer having most significant digits and the number of
+elements in that integer is determined, the length of the longest integer is stored. All the elements in the
+array are divided by a particular base. The elements of the array are sorted on the basis of the most significant
+digit to the least significant digit i.e. from leftmost to rightmost digit.
+
+## Example
+
+Let's arrange the numbers in ascending order using postman sort.
+
+- Unsorted List
+
+The input array contains 7 elements which are {25, 432, 788, 130, 23, 121, 564}
+
+- Iteration 1
+
+The elements of the array being sorted on the basis of the most significant digit, *it becomes {25, 23, 130, 121, 432, 564, 788}*
+
+- Iteration 2
+
+The elements of the array being sorted on the basis of the second most significant digit, *it becomes {25, 23, 121, 130, 432, 564, 788}*
+
+- Iteration 3
+
+At last those elements of the array are compared which have same value of significant digit and if they are not in correct
+order, the elements gets swapped and are arranged in desired order. The array after getting sorted *becomes
+{23, 25, 121, 130, 432, 564, 788}*
+
+*In this way the elements of the array are sorted on the basis of their significant digits.*
+
+## Algorithm
+
+1.Compare the leftmost digit of the elements of the array then the next to it and so on.
+
+2.If the elements are not in correct order swap them according to their significant digit.
+
+3.The function recurses which compares the elements having same value of significant digit and arranges the elements in correct order.
+
+## Pseudocode
+```
+declare temp, max, count, maxdigits = 0, c = 0
+declare t1, t ,i, j
+Initialise n = 1
+Input the number of elements in the array and store their values in arr[], arr1[]
+for(i = 0; i < count; i++)
+ t = arr[i]
+ while(t > 0)
+ c++
+ t = t/10
+ if(maxdigits < c)
+ maxdigits = c
+ c = 0
+
+for(i = 0; i < maxdigits; i++)
+ n = n * 10
+for(i = 0; i < count; i++)
+ max = arr[i] / n
+ t = i
+ for(j = i + 1; j < count; j++)
+ if(max > (arr[j] / n))
+ max = arr[j] / n
+ t = j
+ temp = arr1[t]
+ arr1[t] = arr1[i]
+ arr1[i] = temp
+ temp = arr[t]
+ arr[t] = arr[i]
+ arr[i] = temp
+while(n >= 1)
+ for(i = 0; i < count;)
+ t1 = arr[i] / n
+ for(j = i + 1; t1 == (arr[j]/n); j++);
+ arrange(i, j)
+ i = j
+ n = n / 10
+
+void arrange(int k, int n)
+ for(i = k; i < n - 1; i++)
+ for(j = i + 1; j < n; j++)
+ if(arr1[i] > arr[j])
+ temp = arr1[i]
+ arr1[i] = arr1[j]
+ arr1[j] = temp
+ temp = arr[i] % 10
+ arr[i] = arr[j] % 10
+ arr[j] = temp
+
+```
+
+## Complexity
+
+ Time Complexity = d * (n + k)
+ Space Complexity = n + 2^d
+
+where
+>d = number of digits
+>n = number of keys
+>k = size of bucket
+
+## Implementation
+* [C# Code](https://github.com/jainaman224/Algo_Ds_Notes/blob/master/Postman_Sort/Postman_Sort.cs)
+
From 8f33b4e6b565827a15d54e2bf8cc52e784e7456f Mon Sep 17 00:00:00 2001
From: Arkadip Bhattacharya
Date: Sat, 2 May 2020 20:23:38 +0530
Subject: [PATCH 117/265] Added Boyer_Moore_Algorithm in Kotlin (#2813)
---
Boyer_Moore_Algorithm/Boyer_Moore.kt | 78 ++++++++++++++++++++++++++++
1 file changed, 78 insertions(+)
create mode 100644 Boyer_Moore_Algorithm/Boyer_Moore.kt
diff --git a/Boyer_Moore_Algorithm/Boyer_Moore.kt b/Boyer_Moore_Algorithm/Boyer_Moore.kt
new file mode 100644
index 000000000..5bc69cb02
--- /dev/null
+++ b/Boyer_Moore_Algorithm/Boyer_Moore.kt
@@ -0,0 +1,78 @@
+/*
+Boyer Moore String Matching Algorithm in Kotlin
+Author: Arkadip Bhattacharya (@darkmatter18)
+ */
+import java.util.*
+
+internal object Main {
+ private var NO_OF_CHARACTERS = 256
+ private fun maxOfAAndB(a: Int, b: Int): Int {
+ return a.coerceAtLeast(b)
+ }
+
+ private fun badCharacterHeuristic(str: CharArray, size: Int, badcharacter: IntArray) {
+
+ // Initialize all elements of bad character as -1
+ var i = 0
+ while (i < NO_OF_CHARACTERS) {
+ badcharacter[i] = -1
+ i++
+ }
+ // Fill the actual value of last occurrence of a character
+ i = 0
+ while (i < size) {
+ badcharacter[str[i].toInt()] = i
+ i++
+ }
+ }
+
+ // A pattern searching function
+ private fun search(text: CharArray, pattern: CharArray) {
+ val m = pattern.size
+ val n = text.size
+ val badCharacterHeuristic = IntArray(NO_OF_CHARACTERS)
+
+ // Fill the bad character array by calling the preprocessing function
+ badCharacterHeuristic(pattern, m, badCharacterHeuristic)
+
+ // s is shift of the pattern with respect to text
+ var s = 0
+ while (s <= n - m) {
+ var j = m - 1
+
+ // Keep reducing index j of pattern while characters of pattern and text are matching at this shift s
+ while (j >= 0 && pattern[j] == text[s + j]) j--
+
+ // If the pattern is present at current shift, then index j will become -1 after the above loop
+ s += if (j < 0) {
+ println("Patterns occur at shift = $s")
+
+ // Shift the pattern so that the next character in text aligns with the last occurrence of it in pattern.
+ // The condition s+m < n is necessary for the case when pattern occurs at the end of text
+ if (s + m < n) m - badCharacterHeuristic[text[s + m].toInt()] else 1
+ } else maxOfAAndB(1, j - badCharacterHeuristic[text[s + j].toInt()])
+ }
+ }
+
+ /* Driver program*/
+ @JvmStatic
+ fun main(args: Array) {
+ val sc = Scanner(System.`in`)
+ var s = sc.nextLine()
+ val text = s.toCharArray()
+ s = sc.nextLine()
+ val pattern = s.toCharArray()
+ search(text, pattern)
+ }
+}
+
+/*
+Sample Input:
+AABAACAADAABAABA
+AABA
+
+Sample Output:
+Patterns occur at shift = 0
+Patterns occur at shift = 9
+Patterns occur at shift = 12
+ */
From 1e9cf085d8ba896c6d7f07955842e9f40b41f04e Mon Sep 17 00:00:00 2001
From: Muskan Jaiswal <60754388+codermuskanj@users.noreply.github.com>
Date: Sat, 2 May 2020 21:10:50 +0530
Subject: [PATCH 118/265] 'c++_implementation_of_RSA_CRT' (#2724)
'modified'
'modified0'
'update11'
Co-authored-by: abc
---
RSA_CRT/RSA_CRT.cpp | 90 +++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 90 insertions(+)
create mode 100644 RSA_CRT/RSA_CRT.cpp
diff --git a/RSA_CRT/RSA_CRT.cpp b/RSA_CRT/RSA_CRT.cpp
new file mode 100644
index 000000000..7518643d4
--- /dev/null
+++ b/RSA_CRT/RSA_CRT.cpp
@@ -0,0 +1,90 @@
+#include
+using namespace std;
+
+// gcd function
+long long int egcd (long long int a, long long int b) {
+ int rem;
+
+ while (b != 0) {
+ rem = a % b;
+ a = b;
+ b = rem;
+ }
+ return a;
+}
+
+// modular inversion function
+long long int findInv (long long int x, long long int y, long long int n) {
+ long long int d = 2, temp;
+
+ while (d < n) {
+ temp = ((d * x) - 1) % y;
+ if (temp == 0)
+ break;
+ d ++;
+ }
+ return d;
+}
+
+// m is message to be encrypted, 1 < m < n
+int main() {
+ long long int m, p, q, n, e, c, m1 = 1, m2 = 1, c11;
+ long long int phi, dP, dQ, qInv, h, message;
+
+ cout << "Enter the message \n";
+ cin >> m;
+
+ // p and q are two random prime numbers
+ cout << "Enter two prime numbers";
+ cin >> p;
+ cin >> q;
+ n = p * q;
+
+ // eulers toitent function
+ phi = (p - 1) * (q - 1);
+
+ // (n, e) forms our public key , 1 < e < phi
+ e = 2;
+ while ( e < phi) {
+ if (egcd (e, phi) == 1)
+ break;
+ e ++;
+ }
+
+ //calculating CRT exponents dP, dQ and qInv to make calculations shorter and faster
+ dP = findInv (e , p - 1, n);
+ dQ = findInv (e , q - 1 , n);
+ qInv = findInv (q, p, n);
+
+ //printing ciper text
+ c11 = pow (m, e);
+ c = c11 % n;
+ cout << "Cipher = " << c << "\n";
+
+ //printing original message
+ for (int i = 1; i <= dP; i++) {
+ m1 = ( m1 * c) % p;
+ }
+
+ for(int i = 1; i <= dQ; i++) {
+ m2 = (m2 * c) % q;
+ }
+ h = (qInv * (m1 + p - m2)) % p;
+ message = m2 + (h * q);
+ cout << "Orignal message = " << message << "\n";
+
+ return 0;
+}
+
+/*
+Input :
+Enter the message
+1331
+Enter two prime numbers
+131
+137
+Output :
+Cipher = 16990
+Orignal Message = 1331
+*/
+
From e5f9fda3ca3ea90857f3e2e2676a8c9d94535d55 Mon Sep 17 00:00:00 2001
From: Muskan Jaiswal <60754388+codermuskanj@users.noreply.github.com>
Date: Sat, 2 May 2020 21:14:37 +0530
Subject: [PATCH 119/265] 'Python_Implementation_of_Rabin_Karp' (#2728)
'updated0'
'updated1'
'modified11'
Co-authored-by: abc
---
Rabin_Karp/Rabin_Karp.py | 57 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 57 insertions(+)
create mode 100644 Rabin_Karp/Rabin_Karp.py
diff --git a/Rabin_Karp/Rabin_Karp.py b/Rabin_Karp/Rabin_Karp.py
new file mode 100644
index 000000000..5eaa02854
--- /dev/null
+++ b/Rabin_Karp/Rabin_Karp.py
@@ -0,0 +1,57 @@
+# Rabin Karp Algorithm
+
+# AN : range or No of alphabets
+# val : AN ^ patlen-1
+# patlen : pattern length
+# PN: any prime no given input from main
+# Time-Complexity:-
+# The average case running time of the Rabin-Karp algorithm = O(n + m).
+# The best case running time of the Rabin-Karp algorithm = O(n + m).
+# The worst-case running time of the Rabin-Karp algorithm = O(n * m).
+
+AN = 256
+
+def search (pattern, text, PN ) :
+
+ patlen = len(pattern) # pattern length
+ txtlen = len(text) # text length
+ val = 1
+ hpat = 0 # pattern hash value
+ htxt = 0 # text hash value
+ i = 0
+ j = 0
+
+ for i in range (patlen - 1) :
+ val = (val * AN) % PN # PN is a prime number
+
+ for i in range (patlen) :
+ hpat = (AN * hpat + ord(pattern[i])) % PN
+ htxt = (AN * htxt + ord(text[i])) % PN
+
+ for i in range (txtlen - patlen + 1) :
+ if hpat == htxt :
+ for j in range (patlen) :
+ if text[i + j] != pattern[j]:
+ break
+ j += 1
+ if j == patlen :
+ print( "Found at index starting from " + str(i))
+
+ # calculate the new position including i + m
+ if i < txtlen - patlen :
+ htxt = (AN * (htxt - ord(text[i]) * val) + ord(text[i + patlen])) % PN
+
+ if htxt < 0 :
+ htxt = htxt + PN
+
+# Driver program
+text = input()
+pattern = input()
+PN = 101 # Prime number
+search (pattern, text, PN)
+
+# Input:-XWINGO XOR WINGO
+# WINGO
+# 101
+# OUTPUT:-Found at index starting from 1
+# Found at index starting from 11
From 1f212dd5d6541f6cad4bd8421957cbb526c15e4f Mon Sep 17 00:00:00 2001
From: Bhuwan Chandra
Date: Sat, 2 May 2020 21:21:52 +0530
Subject: [PATCH 120/265] implementation dijkstra algo in ts (#2732)
---
Dijkstra_Algorithm/Dijkstra_Algorithm.ts | 173 +++++++++++++++++++++++
1 file changed, 173 insertions(+)
create mode 100644 Dijkstra_Algorithm/Dijkstra_Algorithm.ts
diff --git a/Dijkstra_Algorithm/Dijkstra_Algorithm.ts b/Dijkstra_Algorithm/Dijkstra_Algorithm.ts
new file mode 100644
index 000000000..61b630b60
--- /dev/null
+++ b/Dijkstra_Algorithm/Dijkstra_Algorithm.ts
@@ -0,0 +1,173 @@
+// Description: Function to perform the Dijkstra algorithm on a weighted graph
+// Expected Output: returns the shorted path
+
+// class for new node
+class NewNode {
+ val: string;
+ priority: number;
+ constructor(val: string, priority: number) {
+ this.val = val;
+ this.priority = priority;
+ }
+}
+
+// class for graph
+class WeightedGraph {
+ adjacencyList: {};
+ constructor() {
+ this.adjacencyList = {};
+ }
+ // function to add vertex on graph
+ addVertex = (vertex: string) => {
+ if (!this.adjacencyList[vertex]) this.adjacencyList[vertex] = [];
+ };
+
+ // function to add weight of the edge between two vertices
+ addEdge = (vertex1: string, vertex2: string, weight: number) => {
+ this.adjacencyList[vertex1].push({ node: vertex2, weight });
+ this.adjacencyList[vertex2].push({ node: vertex1, weight });
+ };
+
+ // main function to implement Dijkstra Algorithm from start to end node
+ DijkstraFunction = (start: string, finish: string) => {
+ const nodes: PriorityQueue = new PriorityQueue();
+ const distances = {};
+ const previous = {};
+ // to return at end
+ let path = [];
+ let smallest;
+
+ // build up initial state
+ for (let vertex in this.adjacencyList) {
+ if (vertex === start) {
+ distances[vertex] = 0;
+ nodes.enqueue(vertex, 0);
+ } else {
+ distances[vertex] = Infinity;
+ nodes.enqueue(vertex, Infinity);
+ }
+ previous[vertex] = null;
+ }
+
+ // as long as there is something to visit, visit the node
+ while (nodes.values.length) {
+ smallest = nodes.dequeue().val;
+ if (smallest === finish) {
+ // reached the end , need to form the path now and return
+ while (previous[smallest]) {
+ path.push(smallest);
+ smallest = previous[smallest];
+ }
+ break;
+ }
+
+ if (smallest || distances[smallest] !== Infinity) {
+ for (let neighbor in this.adjacencyList[smallest]) {
+ // find neighboring node
+ let nextNode = this.adjacencyList[smallest][neighbor];
+ // calculate new distance to neighboring node
+ let candidate = distances[smallest] + nextNode.weight;
+ let nextNeighbor = nextNode.node;
+ if (candidate < distances[nextNeighbor]) {
+ // updating new smallest distance to neighbor
+ distances[nextNeighbor] = candidate;
+ // updating previous - How we got to neighbor
+ previous[nextNeighbor] = smallest;
+ // enqueue in priority queue with new priority
+ nodes.enqueue(nextNeighbor, candidate);
+ }
+ }
+ }
+ }
+ return path.concat(smallest).reverse();
+ };
+}
+
+// class defnition for Priority Queue
+class PriorityQueue {
+ values: NewNode[];
+ constructor() {
+ this.values = [];
+ }
+ enqueue = (val: string, priority: number) => {
+ let newNode = new NewNode(val, priority);
+ this.values.push(newNode);
+ this.bubbleUp();
+ };
+ bubbleUp = () => {
+ let idx: number = this.values.length - 1;
+ const element: NewNode = this.values[idx];
+ while (idx > 0) {
+ let parentIdx: number = Math.floor((idx - 1) / 2);
+ let parent: NewNode = this.values[parentIdx];
+ if (element.priority >= parent.priority) break;
+ this.values[parentIdx] = element;
+ this.values[idx] = parent;
+ idx = parentIdx;
+ }
+ };
+ dequeue = () => {
+ const min: NewNode = this.values[0];
+ const end: NewNode = this.values.pop();
+ if (this.values.length > 0) {
+ this.values[0] = end;
+ this.sinkDown();
+ }
+ return min;
+ };
+ sinkDown = () => {
+ let idx: number = 0;
+ const length: number = this.values.length;
+ const element: NewNode = this.values[0];
+ while (true) {
+ let leftChildIdx: number = 2 * idx + 1;
+ let rightChildIdx: number = 2 * idx + 2;
+ let leftChild: NewNode, rightChild: NewNode;
+ let swap: number = null;
+ if (leftChildIdx < length) {
+ leftChild = this.values[leftChildIdx];
+ if (leftChild.priority < element.priority) swap = leftChildIdx;
+ }
+ if (rightChildIdx < length) {
+ rightChild = this.values[rightChildIdx];
+ if (
+ (swap === null && rightChild.priority < element.priority) ||
+ (swap !== null && rightChild.priority < leftChild.priority)
+ )
+ swap = rightChildIdx;
+ }
+ if (swap === null) break;
+ this.values[idx] = this.values[swap];
+ this.values[swap] = element;
+ idx = swap;
+ }
+ };
+}
+
+function main() {
+ const wtdGraph = new WeightedGraph();
+ // INPUT WEIGHTED GRAPH
+ // adding vertices of the graph
+ wtdGraph.addVertex("A");
+ wtdGraph.addVertex("B");
+ wtdGraph.addVertex("C");
+ wtdGraph.addVertex("D");
+ wtdGraph.addVertex("E");
+ wtdGraph.addVertex("F");
+ // addition weight of the edges
+ wtdGraph.addEdge("A", "B", 1);
+ wtdGraph.addEdge("A", "C", 3);
+ wtdGraph.addEdge("B", "E", 2);
+ wtdGraph.addEdge("C", "D", 4);
+ wtdGraph.addEdge("C", "F", 5);
+ wtdGraph.addEdge("D", "E", 3);
+ wtdGraph.addEdge("D", "F", 1);
+ wtdGraph.addEdge("E", "F", 2);
+
+ // running the algorithm for the ghraph
+ const output = wtdGraph.DijkstraFunction("A", "F");
+ // OUTPUT OF wtdGraph
+ console.log(output); //[ 'A', 'B', 'E', 'F']
+}
+
+main();
From df1e034cb211758f0af5474f55d1d2ee6b3720ab Mon Sep 17 00:00:00 2001
From: Hardev Khandhar <54733460+HardevKhandhar@users.noreply.github.com>
Date: Sat, 2 May 2020 21:27:14 +0530
Subject: [PATCH 121/265] Floyd Warshall Algorithm In Ruby (#2758)
Updated Changes
Updated Minor Changes
Updated Changes
Final Changes
---
.../Floyd_Warshall_Algorithm.rb | 96 +++++++++++++++++++
1 file changed, 96 insertions(+)
create mode 100644 Floyd_Warshall_Algorithm/Floyd_Warshall_Algorithm.rb
diff --git a/Floyd_Warshall_Algorithm/Floyd_Warshall_Algorithm.rb b/Floyd_Warshall_Algorithm/Floyd_Warshall_Algorithm.rb
new file mode 100644
index 000000000..c416f3b36
--- /dev/null
+++ b/Floyd_Warshall_Algorithm/Floyd_Warshall_Algorithm.rb
@@ -0,0 +1,96 @@
+## Floyd Warshall Algorithm In Ruby
+
+def floyd_warshall(node, edge)
+ dist = Array.new(node){|i| Array.new(node){|j| i == j ? 0 : Float::INFINITY}}
+ next_node = Array.new(node){Array.new(node)}
+ edge.each do |u, v, w|
+ dist[u - 1][v - 1] = w
+ next_node[u - 1][v - 1] = v - 1
+ end
+
+ node.times do |k|
+ node.times do |i|
+ node.times do |j|
+ if dist[i][j] > dist[i][k] + dist[k][j]
+ dist[i][j] = dist[i][k] + dist[k][j]
+ next_node[i][j] = next_node[i][k]
+ end
+ end
+ end
+ end
+
+ ## Displaying The Output
+ puts "Pair Distance Path"
+ node.times do |i|
+ node.times do |j|
+ next if i == j
+ u = i
+ path = [u]
+ path << (u = next_node[u][j]) while u != j
+ path = path.map{|u| u + 1}.join(" -> ")
+ puts "%d -> %d %6d %s" % [i + 1, j + 1, dist[i][j], path]
+ end
+ end
+end
+
+## User Input For Number Of Nodes
+puts "Enter the number of Nodes: "
+nodes = gets.to_i
+
+## User Input For Number Of Edge Pairs
+puts "Enter number of Edge Pairs: "
+pair = gets.to_i
+
+puts "\nFor Edge Matrix, Enter Starting Node, Ending Node & Distance Between Them..."
+
+edge_matrix = Array.new(pair) { Array.new(3) }
+
+i = 0
+counter = 0
+
+while(counter != pair)
+ i = 0
+ puts "\nEnter the values of row #{counter + 1}: "
+ while(i != 3)
+ edge_matrix[counter][i] = gets.to_i
+ i += 1
+ end
+ counter += 1
+end
+
+puts
+
+floyd_warshall(nodes, edge_matrix)
+
+= begin
+
+Enter the number of Nodes: 4
+Enter number of Edge Pairs: 5
+
+For Edge Matrix, Enter Starting Node, Ending Node & Distance Between Them...
+
+Enter the values of row 1: 1 3 -2
+
+Enter the values of row 2: 2 1 4
+
+Enter the values of row 3: 2 3 3
+
+Enter the values of row 4: 3 4 2
+
+Enter the values of row 5: 4 2 -1
+
+Pair Distance Path
+1 -> 2 -1 1 -> 3 -> 4 -> 2
+1 -> 3 -2 1 -> 3
+1 -> 4 0 1 -> 3 -> 4
+2 -> 1 4 2 -> 1
+2 -> 3 2 2 -> 1 -> 3
+2 -> 4 4 2 -> 1 -> 3 -> 4
+3 -> 1 5 3 -> 4 -> 2 -> 1
+3 -> 2 1 3 -> 4 -> 2
+3 -> 4 2 3 -> 4
+4 -> 1 3 4 -> 2 -> 1
+4 -> 2 -1 4 -> 2
+4 -> 3 1 4 -> 2 -> 1 -> 3
+
+= end
From 99c78512ec2f4e37ad0c752b4544ba2b9027f164 Mon Sep 17 00:00:00 2001
From: "Kesha K. Kaneria" <46588494+keshakaneria@users.noreply.github.com>
Date: Sat, 2 May 2020 21:48:36 +0530
Subject: [PATCH 122/265] Linear Search in dart language (#2838)
linear search algorithm in dart
Binary search in dart language
Binary search algorithm in dart language
deleting file to create same in new branch
deleting binary search from master branch
Binary Search in Dart language
Binary search algorithm in dart
Deleting this irrelevant file of linear search
Change in deleting file as requested
binary search code with dynamic user values
dynamic values taken with sample input and output
deleting irrelevant file
deleting unused file
Binary search tree in dart language
binary search tree to search element and insert and display in pre/in/post order
Renamed Binary_Search_Tree to BinarySearchTree
renamed
corrected indentation and removed spaces
changes requested are corrected to remove spaces after brackets and changed indentation
Indentation changed from tabs to spaces
Indentation changed from tabs to spaces, as requested
added space after comma
---
Binary_Search_Trees/BinarySearchTree.dart | 291 ++++++++++++++++++++++
1 file changed, 291 insertions(+)
create mode 100644 Binary_Search_Trees/BinarySearchTree.dart
diff --git a/Binary_Search_Trees/BinarySearchTree.dart b/Binary_Search_Trees/BinarySearchTree.dart
new file mode 100644
index 000000000..ed9f7f25e
--- /dev/null
+++ b/Binary_Search_Trees/BinarySearchTree.dart
@@ -0,0 +1,291 @@
+import 'dart:io';
+
+class Node{
+ int value;
+ Node leftNode;
+ Node rightNode;
+
+ Node(int val){
+ this.value = val;
+ this.leftNode = null;
+ this.rightNode = null;
+ }
+
+ Node get left{
+ return this.leftNode;
+ }
+
+ Node get right{
+ return this.rightNode;
+ }
+
+ int get val{
+ return this. value;
+ }
+
+ void set val(int x){
+ this.value = x;
+ }
+
+ void set left(Node x){
+ this.leftNode = x;
+ }
+
+ void set right(Node x){
+ this.rightNode = x;
+ }
+}
+
+Node root;
+
+preOrderTraversal(Node x){
+ if(x == null) return;
+ print(x.val);
+ preOrderTraversal(x.left);
+ preOrderTraversal(x.right);
+}
+
+inOrderTraversal(Node x){
+ if(x == null) return;
+ inOrderTraversal(x.left);
+ print(x.val);
+ inOrderTraversal(x.right);
+}
+
+postOrderTraversal(Node x){
+ if(x == null) return;
+ postOrderTraversal(x.left);
+ print(x.val);
+ postOrderTraversal(x.right);
+}
+
+insertElement(Node x, int val){
+ if(root == null){
+ root == new Node(val);
+ print(root.val);
+ return;
+ }
+ if(x.val == val) return;
+ if(x.val > val){
+ if(x.left == null){
+ Node newNode = new Node(val);
+ x.left = newNode;
+ return;
+ }
+ insertElement(x.left, val);
+ return;
+ }
+ if(x.right == null){
+ Node newNode = new Node(val);
+ x.right = newNode;
+ return;
+ }
+ insertElement(x.right, val);
+ return;
+}
+
+searchTree(Node x, int val){
+ if(x == null){
+ print('Did not find $val in Tree!');
+ return;
+ }
+ if(x.val == val){
+ print('Found $val in Tree!');
+ return;
+ }
+ if(x.val > val){
+ searchTree(x.left, val);
+ return;
+ }
+ if(x.val < val){
+ searchTree(x.right, val);
+ return;
+ }
+}
+
+main() {
+ int task = 0;
+ print('Binary Search Tree Program');
+ while(task != 3){
+ print('0 - Display Tree\n1 - Insert Element in Tree \n2 - Search element in Tree\n3 - Quit\nSelect task:-');
+ try{
+ task = int.parse(stdin.readLineSync());
+ } on Exception{
+ print('Please enter valid Integer value!');
+ continue;
+ }
+ switch(task){
+ case 0:
+ if(root == null){
+ print('Empty Tree!');
+ }
+ else{
+ print('Traversal Order:-\n1 - Preorder \n2 - Inorder \n3 - Postorder');
+ int val;
+ try{
+ val = int.parse(stdin.readLineSync());
+ } on Exception{
+ print('Please enter valid Integer value!');
+ continue;
+ }
+ switch(val){
+ case 1:
+ print('PreOrder Traversal');
+ preOrderTraversal(root);
+ break;
+ case 2:
+ print('InOrder Traversal');
+ inOrderTraversal(root);
+ break;
+ case 3:
+ print('PostOrder Traversal');
+ postOrderTraversal(root);
+ break;
+ default:
+ print('Please enter valid Integer value!');
+ }
+ }
+ break;
+
+ case 1:
+ int val = null;
+ print('Enter value that needs to be inserted in Tree:-');
+ try{
+ val = int.parse(stdin.readLineSync());
+ } on Exception{
+ print('Please enter valid Integer value!');
+ continue;
+ }
+ if(val == null){
+ print('Failed to insert element in Tree!');
+ continue;
+ }
+ insertElement(root, val);
+ print('Successfully inserted $val in Tree!');
+ break;
+
+ case 2:
+ int val = null;
+ print('Enter value that needs to be searched in Tree:-');
+ try{
+ val = int.parse(stdin.readLineSync());
+ } on Exception{
+ print('Failed to search element in Tree!');
+ continue;
+ }
+ if(val == null){
+ print('Failed to search element in Tree!');
+ continue;
+ }
+ searchTree(root, val);
+ break;
+
+ case 3:
+ print('Binary Search Tree Program Complete');
+ break;
+
+ default:
+ continue;
+ }
+ }
+}
+
+/*
+Sample Input/Output:
+Binary Search Tree Program
+0 - Display Tree
+1 - Insert element in Tree
+2 - Search element in Tree
+3 - Quit
+Select task:-
+1
+Enter value that needs to be inserted in Tree:-
+1
+1
+Successfully inserted 1 in Tree!
+0 - Display Tree
+1 - Insert element in Tree
+2 - Search element in Tree
+3 - Quit
+Select task:-
+1
+Enter value that needs to be inserted in Tree:-
+2
+Successfully inserted 2 in Tree!
+0 - Display Tree
+1 - Insert element in Tree
+2 - Search element in Tree
+3 - Quit
+Select task:-
+1
+Enter value that needs to be inserted in Tree:-
+3
+Successfully inserted 3 in Tree!
+0 - Display Tree
+1 - Insert element in Tree
+2 - Search element in Tree
+3 - Quit
+Select task:-
+0
+Traversal Order:-
+1 - Preorder
+2 - Inorder
+3 - Postorder
+1
+PreOrder Traversal
+1
+2
+3
+0 - Display Tree
+1 - Insert element in Tree
+2 - Search element in Tree
+3 - Quit
+Select task:-
+0
+0 - Display Tree
+1 - Insert element in Tree
+2 - Search element in Tree
+3 - Quit
+Select task:-
+0
+Traversal Order:-
+1 - Preorder
+2 - Inorder
+3 - Postorder
+2
+InOrder Traversal
+1
+2
+3
+0 - Display Tree
+1 - Insert element in Tree
+2 - Search element in Tree
+3 - Quit
+Select task:-
+0
+Traversal Order:-
+1 - Preorder
+2 - Inorder
+3 - Postorder
+3
+PostOrder Traversal
+3
+2
+1
+0 - Display Tree
+1 - Insert element in Tree
+2 - Search element in Tree
+3 - Quit
+Select task:-
+2
+Enter value that needs to be searched in Tree:-
+2
+Found 2 in Tree!
+0 - Display Tree
+1 - Insert element in Tree
+2 - Search element in Tree
+3 - Quit
+Select task:-
+3
+Binary Search Tree Program Complete
+*/
From 3e91af41e049387130bd8c0209b2097a4f8f20a9 Mon Sep 17 00:00:00 2001
From: "Kesha K. Kaneria" <46588494+keshakaneria@users.noreply.github.com>
Date: Sun, 3 May 2020 13:32:33 +0530
Subject: [PATCH 123/265] Linear Search in dart language (#2410)
linear search algorithm in dart
Binary search in dart language
Binary search algorithm in dart language
deleting file to create same in new branch
deleting binary search from master branch
Linear search algo updated
Dynamic values taken from user with conditions to delete, insert and search input given by user as correction suggested in PR #2410
sample input and output added
user input along with output added
indentation changed
changed the indentation from 2 tabs to 4 tabs
Delete functionality removed
Removed additional functionality which is not required
---
Linear_Search/Linear_Search.dart | 129 +++++++++++++++++++++++++++++++
1 file changed, 129 insertions(+)
create mode 100644 Linear_Search/Linear_Search.dart
diff --git a/Linear_Search/Linear_Search.dart b/Linear_Search/Linear_Search.dart
new file mode 100644
index 000000000..1afcfd8ff
--- /dev/null
+++ b/Linear_Search/Linear_Search.dart
@@ -0,0 +1,129 @@
+//Linear search or sequential search is a method for finding an element within a list.
+//It sequentially checks each element of the list until a match is found or the whole list has been searched.
+import 'dart:io';
+
+void linearSearch(List list, int x) {
+ int pass = 0;
+ list.forEach((val) {
+ if (val == x) {
+ print('Found $x in the List!');
+ pass = 1;
+ }
+ });
+ if (pass == 0) print('Did not find $x in the List!');
+}
+
+main() {
+ List list = new List();
+ int task = 0;
+ print('Linear Search Program');
+ while (task != 4) {
+ print(
+ '0 - Display List\n1 - Insert element in List \n2 - Search element in List\n3 - Quit\nSelect task:-');
+ try {
+ task = int.parse(stdin.readLineSync());
+ } on Exception {
+ print('Please enter valid Integer value!');
+ continue;
+ }
+ switch (task) {
+ case 0:
+ if (list.length == 0) {
+ print('Empty List!');
+ } else {
+ print('List:-');
+ list.forEach((val) {
+ print(val);
+ });
+ }
+ break;
+ case 1:
+ int val = null;
+ print('Enter value that needs to be inserted in List:- ');
+ try {
+ val = int.parse(stdin.readLineSync());
+ } on Exception {
+ print('Please enter valid Integer value!');
+ continue;
+ }
+ if (val == null) {
+ print('Failed to insert element in List!');
+ continue;
+ }
+ list.add(val);
+ print('Successfully inserted $val in List!');
+ break;
+
+ case 2:
+ int val = null;
+ print('Enter value that needs to be searched in List:- ');
+ try {
+ val = int.parse(stdin.readLineSync());
+ } on Exception {
+ print('Please enter valid Integer value!');
+ continue;
+ }
+ if (val == null) {
+ print('Failed to search element in List!');
+ continue;
+ }
+ linearSearch(list, val);
+ break;
+
+ case 3:
+ print('Linear Search Program Complete');
+ break;
+
+ default:
+ continue;
+ }
+ }
+}
+
+/*
+Sample Input/Output:
+Linear Search Program
+0 - Display List
+1 - Insert element in List
+2 - Search element in List
+3 - Quit
+Select task:- //to insert element in list
+1
+Enter value that needs to be inserted in List:-
+1
+Successfully inserted 1 in List!
+0 - Display List
+1 - Insert element in List
+2 - Search element in List
+3 - Quit
+Select task:-
+1
+Enter value that needs to be inserted in List:-
+2
+Successfully inserted 2 in List!
+0 - Display List
+1 - Insert element in List
+2 - Search element in List
+3 - Quit
+Select task:-
+1
+Enter value that needs to be inserted in List:-
+3
+Successfully inserted 3 in List!
+0 - Display List
+1 - Insert element in List
+2 - Search element in List
+3 - Quit
+Select task:- //to search the given element
+2
+Enter value that needs to be searched in List:-
+2
+Found 2 in the List!
+0 - Display List
+1 - Insert element in List
+2 - Search element in List
+3 - Quit
+Select task:- //to end the linear program algorithm
+3
+Linear Search Program Complete
+*/
From 2c2d0bb75ea6fbbb1b22261cf3e5d13ac4732112 Mon Sep 17 00:00:00 2001
From: monikajha <53649201+m-code12@users.noreply.github.com>
Date: Sun, 3 May 2020 13:37:49 +0530
Subject: [PATCH 124/265] Depth First Search in Go (#2818)
---
Depth_First_Search/Depth_First_Search.go | 114 +++++++++++++++++++++++
1 file changed, 114 insertions(+)
create mode 100644 Depth_First_Search/Depth_First_Search.go
diff --git a/Depth_First_Search/Depth_First_Search.go b/Depth_First_Search/Depth_First_Search.go
new file mode 100644
index 000000000..9b3f9e47b
--- /dev/null
+++ b/Depth_First_Search/Depth_First_Search.go
@@ -0,0 +1,114 @@
+package main
+import "fmt"
+type set map[int]bool
+
+// Define Graph structure
+type Graph struct {
+ adjList map[int]set
+}
+
+// Create a graph and initialize its adjacency list, and return a pointer to it.
+func createGraph() *Graph {
+ var g = Graph{}
+ g.adjList = make(map[int]set)
+ return &g
+}
+
+// Add an edge between the two given nodes.If a node does not exist in the graph yet, add it.
+func (g *Graph) addEdge(node1 int, node2 int) {
+ // Check if node1 is already in the graph
+ if g.adjList[node1] == nil {
+ g.adjList[node1] = make(set)
+ }
+
+ g.adjList[node1][node2] = true
+ // Check if node2 is already in the graph
+ if g.adjList[node2] == nil {
+ g.adjList[node2] = make(set)
+ }
+
+ g.adjList[node2][node1] = true
+}
+
+// Perform a depth first search from the given node and apply the given function to each node.
+func dfs(g *Graph, current int, visited set, visitFunction func(int)) {
+ if _, seen := visited[current]; seen {
+ return
+ }
+
+ visited[current] = true
+ visitFunction(current)
+ for neighbour := range g.adjList[current] {
+ dfs(g, neighbour, visited, visitFunction)
+ }
+}
+
+func main() {
+ graph := createGraph()
+ var n int
+ fmt.Println("Enter the number of vertices : ")
+ fmt.Scan(&n)
+ for i := 0; i < n; i++ {
+ var a int
+ var b int
+ fmt.Println("Enter the source vertex : ")
+ fmt.Scan(&a)
+ fmt.Println("Enter the destination vertex : ")
+ fmt.Scan(&b)
+ graph.addEdge(a, b)
+ }
+ fmt.Println("\nThe DFS Traversal of the graph is : ")
+ visited := make(set)
+ dfs(graph, 1, visited, func(node int) {
+ fmt.Print(node, " ")
+ })
+}
+
+
+/*
+
+ The sample input is given in the form of the following graph :
+ 1
+ / \
+ / \
+ 2 5
+ / \ / \
+ 3 - 4 6 7
+
+ Sample Input :
+ Enter the number of vertices :
+ 7
+ Enter the source vertex :
+ 1
+ Enter the destination vertex :
+ 2
+ Enter the source vertex :
+ 2
+ Enter the destination vertex :
+ 3
+ Enter the source vertex :
+ 2
+ Enter the destination vertex :
+ 4
+ Enter the source vertex :
+ 3
+ Enter the destination vertex :
+ 4
+ Enter the source vertex :
+ 1
+ Enter the destination vertex :
+ 5
+ Enter the source vertex :
+ 5
+ Enter the destination vertex :
+ 6
+ Enter the source vertex :
+ 5
+ Enter the destination vertex :
+ 7
+
+ The DFS Traversal of the graph is :
+ 1 2 3 4 5 6 7
+
+*/
+
From 7f0ec41d8b5cef2d6179ca940e49791715460ea9 Mon Sep 17 00:00:00 2001
From: shivank singh <97shivank@gmail.com>
Date: Sun, 3 May 2020 13:41:53 +0530
Subject: [PATCH 125/265] Qsort in kotlin (#2831)
---
Quick_Sort/Quick_Sort.kt | 63 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 63 insertions(+)
create mode 100644 Quick_Sort/Quick_Sort.kt
diff --git a/Quick_Sort/Quick_Sort.kt b/Quick_Sort/Quick_Sort.kt
new file mode 100644
index 000000000..509722dd1
--- /dev/null
+++ b/Quick_Sort/Quick_Sort.kt
@@ -0,0 +1,63 @@
+/* QuickSort is a Divide and Conquer algorithm. It picks an element as pivot and partitions the given array
+around the picked pivot.It's Best case complexity is n*log(n) & Worst case complexity is n^2. */
+
+//partition array
+fun quick_sort(A: Array, p: Int, r: Int) {
+ if (p < r) {
+ var q: Int = partition(A, p, r)
+ quick_sort(A, p, q - 1)
+ quick_sort(A, q + 1, r)
+
+ }
+}
+
+//assign last value as pivot
+fun partition(A: Array, p: Int, r: Int): Int {
+ var x = A[r]
+ var i = p - 1
+ for (j in p until r) {
+ if (A[j] <= x) {
+ i++
+ exchange(A, i, j)
+ }
+ }
+ exchange(A, i + 1, r)
+ return i + 1
+}
+
+//swap
+fun exchange(A: Array, i: Int, j: Int) {
+ var temp = A[i]
+ A[i] = A[j]
+ A[j] = temp
+}
+
+fun main(arg: Array) {
+ print("Enter no. of elements :")
+ var n = readLine()!!.toInt()
+
+ println("Enter elements : ")
+ var A = Array(n, { 0 })
+ for (i in 0 until n)
+ A[i] = readLine()!!.toInt()
+
+ quick_sort(A, 0, A.size - 1)
+
+ println("Sorted array is : ")
+ for (i in 0 until n)
+ print("${A[i]} ")
+}
+
+/*-------OUTPUT--------------
+Enter no. of elements :6
+Enter elements :
+4
+8
+5
+9
+2
+6
+Sorted array is :
+2 4 5 6 8 9
+*/
+
From 9dc9e66956fcaa2f0d696e4f1187fa0da620940d Mon Sep 17 00:00:00 2001
From: coderprasukj <60914425+coderprasukj@users.noreply.github.com>
Date: Sun, 3 May 2020 20:49:13 +0530
Subject: [PATCH 126/265] Added Postman Sort in JavaScript (#2729)
Modified
Modified
---
Postman_Sort/Postman_Sort.js | 88 ++++++++++++++++++++++++++++++++++++
1 file changed, 88 insertions(+)
create mode 100644 Postman_Sort/Postman_Sort.js
diff --git a/Postman_Sort/Postman_Sort.js b/Postman_Sort/Postman_Sort.js
new file mode 100644
index 000000000..01c6ecc65
--- /dev/null
+++ b/Postman_Sort/Postman_Sort.js
@@ -0,0 +1,88 @@
+/*
+* JavaScript Implementation for Postman Sort Algorithm
+*/
+
+let temp, max, count, maxdigits = 0, c = 0;
+let t1, t2, k, t, n = 1, p, s;
+
+/* Function to arrange the of sequence having same base */
+function arrange(p, s) {
+ for(var i = p; i < s - 1; i++) {
+ for(var j = i + 1; j < s; j++) {
+ if(arr1[i] > arr1[j]) {
+ // swap array1[i] and array1[j]
+ swap (arr1[i], arr1[j]);
+
+ temp = arr[i] % 10;
+ arr[i] = arr[j] % 10;
+ arr[j] = temp;
+ }
+ }
+ }
+}
+
+count = 10;
+console.log("The size of the Array : " + count);
+let arr = [70, 80, 20, 50, 10, 60, 40, 100, 90, 30];
+console.log("The Unsorted Array is : ");
+console.log(arr);
+
+let arr1 = new Array();
+for(let i = 0; i < count; i++) {
+ // first element in t
+ t = arr[i];
+ // Calculating the Number of digits using logarithmic
+ c = Math.trunc(Math.log(arr[i] / Math.log(10)));
+ // number of digits in a each number
+ if(maxdigits < c)
+ maxdigits = c;
+}
+
+while(--maxdigits)
+ n = n * 10;
+
+for(var i = 0; i < count; i++) {
+ // MSB - Dividing by particular base
+ max = arr[i] / n;
+ t = i;
+ for(var j = i + 1; j < count; j++) {
+ if(max > arr[j] / n) {
+ max = arr[j] / n;
+ t = j;
+ }
+ }
+ temp = arr1[t];
+ arr1[t] = arr1[i];
+ arr1[i] = temp;
+ temp = arr[t];
+ arr[t] = arr[i];
+ arr[i] = temp;
+}
+
+function swap(x, y) {
+ var t = x;
+ x = y;
+ y = t;
+}
+
+while (n >= 1) {
+ for(var i = 0; i < count;) {
+ t1 = arr[i] / n;
+ for(j = i + 1; t1 == (arr[j] / n); j++);
+ arrange(i, j);
+ i = j;
+ }
+ n = n / 10;
+}
+
+console.log("Sorted Array is : ");
+console.log(arr);
+
+/*
+INPUT :
+The size of the Array : 10
+The Unsorted Array is : [70, 80, 20, 50, 10, 60, 40, 100, 90, 30]
+
+OUTPUT :
+Sorted Array is : [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]
+*/
From 553c775ea86abdf12e7fb458e43440fdf90a60b9 Mon Sep 17 00:00:00 2001
From: Raksha <57195964+raksha009@users.noreply.github.com>
Date: Sun, 3 May 2020 20:51:38 +0530
Subject: [PATCH 127/265] Matrix_identical in java (#2750)
Changes done
---
Matrix_Operations/Java/Matrix_identical.java | 104 +++++++++++++++++++
1 file changed, 104 insertions(+)
create mode 100644 Matrix_Operations/Java/Matrix_identical.java
diff --git a/Matrix_Operations/Java/Matrix_identical.java b/Matrix_Operations/Java/Matrix_identical.java
new file mode 100644
index 000000000..03028e617
--- /dev/null
+++ b/Matrix_Operations/Java/Matrix_identical.java
@@ -0,0 +1,104 @@
+// Java Program to check and find if two matrices are identical or not
+import java.util.Scanner;
+
+public class Matrix_identical {
+
+ // This function return true if the matrices are identical otherwise false
+ public static boolean check_identical(int[][] matrix1, int[][] matrix2){
+ int index1, index2 = 0;
+ for ( index1 = 0; index1 < matrix1.length; index1++ ){
+ for ( index2 = 0; index2 < matrix1[0].length; index2++ ){
+ if (matrix1[index1][index2] != matrix2[index1][index2]) {
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+
+ public static void main(String args[]){
+ Scanner s = new Scanner(System.in);
+
+ System.out.println("Of First Matrix");
+ System.out.println(" Enter number of rows ");
+ int rows_first = s.nextInt();
+
+ System.out.println(" Enter number of columns ");
+ int columns_first = s.nextInt();
+ int[][] matrix1 = new int[rows_first][columns_first];
+
+ System.out.println("Of Second Matrix");
+ System.out.println(" Enter number of rows ");
+ int rows_second = s.nextInt();
+
+ System.out.println(" Enter number of columns ");
+ int columns_second = s.nextInt();
+ int[][] matrix2 = new int[rows_second][columns_second];
+
+ if (columns_first != columns_second || rows_first != rows_second) {
+ System.out.println(" Matrices's order is not identical ");
+ }
+ else {
+
+ System.out.println(" Enter elements of 1st matrix ");
+ for (int i = 0; i < rows_first; i++) {
+ for (int j = 0; j < columns_first; j++) {
+ matrix1[i][j] = s.nextInt();
+ }
+ }
+
+ System.out.println(" Enter elements of 2nd matrix ");
+ for (int i = 0; i < rows_first; i++) {
+ for (int j = 0; j < columns_first; j++) {
+ matrix2[i][j] = s.nextInt();
+ }
+ }
+ boolean b = check_identical(matrix1, matrix2);
+ if (b) System.out.println("Matrices are identical");
+ else System.out.println(" Matrices are not identical");
+ }
+ }
+}
+/*
+TEST CASES
+INPUT
+Of First Matrix
+ Enter number of rows
+2
+ Enter number of columns
+2
+Of Second Matrix
+ Enter number of rows
+2
+ Enter number of columns
+2
+ Enter elements of 1st matrix
+1 2
+0 4
+ Enter elements of 2nd matrix
+1 2
+7 6
+OUTPUT
+ Matrices are not identical
+
+INPUT
+Of First Matrix
+ Enter number of rows
+2
+ Enter number of columns
+2
+Of Second Matrix
+ Enter number of rows
+2
+ Enter number of columns
+2
+ Enter elements of 1st matrix
+1 2
+0 4
+ Enter elements of 2nd matrix
+1 2
+0 4
+OUTPUT
+ Matrices are identical
+*/
+
From 9819cdb6d1a158b52ea41e6c20a019e64fed66c1 Mon Sep 17 00:00:00 2001
From: "Kesha K. Kaneria" <46588494+keshakaneria@users.noreply.github.com>
Date: Sun, 3 May 2020 21:01:58 +0530
Subject: [PATCH 128/265] Binary search in dart language (#2411)
Binary search algorithm in dart language
deleting file to create same in new branch
deleting binary search from master branch
Binary Search in Dart language
Binary search algorithm in dart
Deleting this irrelevant file of linear search
Change in deleting file as requested
binary search code with dynamic user values
dynamic values taken with sample input and output
changed the indentation
indentation added from 2 tab to 4 tab
Delete functionality removed
Delete functionality was not required in binary search program so is removed.
---
Binary_Search/Binary_Search.dart | 149 +++++++++++++++++++++++++++++++
1 file changed, 149 insertions(+)
create mode 100644 Binary_Search/Binary_Search.dart
diff --git a/Binary_Search/Binary_Search.dart b/Binary_Search/Binary_Search.dart
new file mode 100644
index 000000000..a6b7e1fe8
--- /dev/null
+++ b/Binary_Search/Binary_Search.dart
@@ -0,0 +1,149 @@
+//Binary Search is an efficient algorithm for finding an item from a sorted list of items.
+//This is the implementation of Binary Search in dart language to insert and search the elements.
+import 'dart:io';
+
+void binarySearch(List list, int x){
+ int size = list.length;
+ int low = 0;
+ int high = size - 1;
+ while(low <= high){
+ int mid = ((low + high) / 2).floor();
+ if(list[mid] == x){
+ print('Found $x in the List at Index $mid!');
+ return;
+ }
+ if(list[mid] > x){
+ high = mid - 1;
+ continue;
+ }
+ low = mid + 1;
+ }
+ print('Did not $x in the List!');
+ return;
+}
+
+main(){
+ List list = new List();
+ int task = 0;
+ print('Binary Search Program');
+ while(task != 4){
+ print('0 - Display List\n1 - Insert element in List \n2 - Search element in List\n3 - Quit\nSelect task:-');
+ try{
+ task = int.parse(stdin.readLineSync());
+ } on Exception{
+ print('Please enter valid Integer value!');
+ continue;
+ }
+ switch(task){
+ case 0:
+ if(list.length == 0){
+ print('Empty List!');
+ }
+ else{
+ print('List:-');
+ list.forEach((val){
+ print(val);
+ });
+ }
+ break;
+ case 1:
+ int val = null;
+ print('Enter value that needs to be inserted in List:- ');
+ try{
+ val = int.parse(stdin.readLineSync());
+ } on Exception{
+ print('Please enter valid Integer value!');
+ continue;
+ }
+ if(val == null){
+ print('Failed to insert element in List!');
+ continue;
+ }
+ list.add(val);
+ list.sort();
+ print('Successfully inserted $val in List!');
+ break;
+
+ case 2:
+ int val = null;
+ print('Enter value that needs to be searched in List:- ');
+ try{
+ val = int.parse(stdin.readLineSync());
+ } on Exception{
+ print('Please enter valid Integer value!');
+ continue;
+ }
+ if(val == null){
+ print('Failed to search element in List!');
+ continue;
+ }
+ binarySearch(list, val);
+ break;
+
+ case 3:
+ print('Binary Search Program Complete');
+ break;
+ default:
+ continue;
+ }
+ }
+}
+
+
+/*
+Sample Input/Output:
+Binary Search Program
+0 - Display List
+1 - Insert element in List
+2 - Search element in List
+3 - Quit
+Select task:- //to add element
+1
+Enter value that needs to be inserted in List:-
+1
+Successfully inserted 1 in List!
+0 - Display List
+1 - Insert element in List
+2 - Search element in List
+3 - Quit
+Select task:-
+1
+Enter value that needs to be inserted in List:-
+2
+Successfully inserted 2 in List!
+0 - Display List
+1 - Insert element in List
+2 - Search element in List
+3 - Quit
+Select task:-
+1
+Enter value that needs to be inserted in List:-
+3
+Successfully inserted 3 in List!
+0 - Display List
+1 - Insert element in List
+2 - Search element in List
+3 - Quit
+Select task:- //to display the list
+0
+List:-
+1
+2
+3
+0 - Display List
+1 - Insert element in List
+2 - Search element in List
+3 - Quit
+Select task:- //to search the element
+2
+Enter value that needs to be searched in List:-
+2
+Found 2 in the List at Index 1!
+0 - Display List
+1 - Insert element in List
+2 - Search element in List
+3 - Quit
+Select task:- //quiting the program
+3
+Binary Search Program Complete
+*/
From 80216a45bc39db8d8733e4b5289e4449394727c7 Mon Sep 17 00:00:00 2001
From: Roma Vardiyani <59890472+bohemian98@users.noreply.github.com>
Date: Mon, 4 May 2020 15:03:30 +0530
Subject: [PATCH 129/265] KMP Algorithm in JavaScript is added (#2801)
KMP in JavaScript Input/Output added
suggested changes made in KMP.js file
Changes in KMP.js done as suggested
KMP Algo in JS was added
---
Knuth_Morris_Pratt_Algorithm/KMP.js | 95 +++++++++++++++++++++++++++++
1 file changed, 95 insertions(+)
create mode 100644 Knuth_Morris_Pratt_Algorithm/KMP.js
diff --git a/Knuth_Morris_Pratt_Algorithm/KMP.js b/Knuth_Morris_Pratt_Algorithm/KMP.js
new file mode 100644
index 000000000..884336313
--- /dev/null
+++ b/Knuth_Morris_Pratt_Algorithm/KMP.js
@@ -0,0 +1,95 @@
+/* Function to create Longest Proper Prefix for given pattern that we want to search in the text*/
+function lpsValues( lps, pattern, len_pattern)
+{
+ //length of longest prefix that is also suffix, will be zero for 1st charater as no prefix ans no suffix
+ lps[0] = 0;
+ //length of previous longest prefix that is also suffix
+ var len_prev = 0;
+ //iterator to calculate values lps[1].....lps[len_pattern]
+ var i = 1;
+ while (i < len_pattern )
+ {
+ if (pattern.charAt(i) === pattern.charAt( len_prev))
+ {
+ len_prev = len_prev+1;;
+ lps[i] = len_prev;
+ i++;
+ }
+ else // (pat[i] != pat[len])
+ {
+
+ if (len_prev != 0)
+ {
+ len_prev = lps[len_prev - 1];
+ }
+
+ else // if (len == 0) as no prefix found
+ {
+ lps[i] = 0;
+ i++;
+ }
+ }
+ }
+}
+
+
+function KmpPatternSearch(pattern, text)
+{
+ len_pattern = pattern.length;
+ len_text = text.length;
+
+ //We find Longest Proper Prefix to decide which chater will be matched next
+ var lps = new Array(len_pattern);
+
+ lpsValues(lps, pattern, len_pattern);
+
+ //iterator
+ var i = j = 0;
+ while (i < len_text)
+ {
+ if (pattern.charAt(j) === text.charAt(i))
+ {
+ //Pattern ans text matched
+ i = i+1;
+ j = j+1;
+ }
+ if (j === len_pattern)
+ {
+ return i-j;
+ j = lps[j-1];
+ }
+ else if (j != len_pattern && pattern.charAt(j) != text.charAt(i))
+ {
+
+ if (j != 0)
+ {
+ j = lps[j-1];
+ }
+ else
+ {
+ i = i+1;
+ }
+ }
+ }
+}
+//Used synchronous readline package to take console input
+var readlineSync = require('readline-sync');
+//User input for text to be searched
+var a = readlineSync.question('Enter text to be searched: ');
+//User input for pattern to be searched in text
+var b = readlineSync.question('Enter the pattern to be searched: ');
+var index=KmpPatternSearch(b,a);
+if (index == undefined)
+{
+ console.log("Pattern not found.");
+}
+else
+{
+ console.log("Pattern observed at index:", index);
+}
+//Input 1: text :"abcabaabcabac" pattern:"abaa"
+//Output will be 3
+//Input 2: text:"aabbcdefgh" pattern:"fgh"
+//Output will be 7
+//Input 3: text:"aaaaaa" pattern:"bb"
+//Output: Pattern not found
From fbf8ee5229dd7316ff72e9d1780bad3de9f2b17b Mon Sep 17 00:00:00 2001
From: Manas2520 <60315152+Manas2520@users.noreply.github.com>
Date: Mon, 4 May 2020 22:34:04 +0530
Subject: [PATCH 130/265] Updated Decimal_to_Binary.cpp (#2862)
* Updated Decimal_to_Binary.cpp
* Update Decimal_to_Binary.cpp
Co-authored-by: Shreya Singh
---
Number_Conversion/C++/Decimal_to_Binary.cpp | 41 +++++++++++++++++++++
1 file changed, 41 insertions(+)
create mode 100644 Number_Conversion/C++/Decimal_to_Binary.cpp
diff --git a/Number_Conversion/C++/Decimal_to_Binary.cpp b/Number_Conversion/C++/Decimal_to_Binary.cpp
new file mode 100644
index 000000000..219352146
--- /dev/null
+++ b/Number_Conversion/C++/Decimal_to_Binary.cpp
@@ -0,0 +1,41 @@
+
+// C++ program to convert numbers from decimal to binary form
+
+#include
+#include
+using namespace std;
+
+// Function to convert the number from decimal to binary form
+void printBinary(int n){
+
+ // command to find out number of bits in the given number
+ // which decides the size of the array
+ int size = log2(n) + 1;
+
+ // Array to store the binary number
+ int b[size], j = 0;
+ while(n != 0){
+ b[j] = n % 2;
+ n = n / 2;
+ j++;
+ }
+
+ cout << "The binary form is : ";
+ for(j = size - 1; j >= 0; j--)
+ cout << b[j];
+}
+
+
+int main()
+{
+ cout << "Enter the number you wish to convert:" << endl;
+ int n;
+ cin >> n;
+ printBinary(n); // Calling function printBinary to convert the number to binary form
+ cout << "\n";
+ return 0;
+}
+/*
+Input : 25
+Output : 11001
+*/
From 90c61a0ce48634c08800cdc71edab35136c5b406 Mon Sep 17 00:00:00 2001
From: thakran14 <47153756+thakran14@users.noreply.github.com>
Date: Mon, 4 May 2020 22:39:56 +0530
Subject: [PATCH 131/265] Update Longest_Common_Subsequence.php (#2815)
---
.../Longest_Common_Subsequence.php | 78 +++++++++++++++++++
1 file changed, 78 insertions(+)
create mode 100644 Longest_Common_Subsequence/Longest_Common_Subsequence.php
diff --git a/Longest_Common_Subsequence/Longest_Common_Subsequence.php b/Longest_Common_Subsequence/Longest_Common_Subsequence.php
new file mode 100644
index 000000000..72a618ec1
--- /dev/null
+++ b/Longest_Common_Subsequence/Longest_Common_Subsequence.php
@@ -0,0 +1,78 @@
+ 0 && $j > 0)
+ {
+ // If current character in X[] and Y are same,
+ // then current character is part of LCS
+ if ($X[$i - 1] == $Y[$j - 1])
+ {
+ // Put current character in result
+ $lcs[$index - 1] = $X[$i - 1];
+ $i--;
+ $j--;
+ $index--; // reduce values of i, j and index
+ }
+
+ // If not same, then find the larger of two
+ // and go in the direction of larger value
+ else if ($L[$i - 1][$j] > $L[$i][$j - 1])
+ $i--;
+ else
+ $j--;
+ }
+
+ // Print the lcs
+ echo "LCS of " . $X . " and " . $Y . " is ";
+ for($k = 0; $k < $temp; $k++)
+ echo $lcs[$k];
+}
+
+// Driver Code
+$X = "ABCDE";
+$Y = "BCDEF";
+$m = strlen($X);
+$n = strlen($Y);
+lcs($X, $Y, $m, $n);
+
+/*
+OUTPUT:
+LCS of ABCDE and BCDEF is BCDE
+*/
+
+?>
From ad27788db9d61ff097d944da95c1e68c17f66dea Mon Sep 17 00:00:00 2001
From: Raksha <57195964+raksha009@users.noreply.github.com>
Date: Tue, 5 May 2020 17:53:30 +0530
Subject: [PATCH 132/265] Multiplication in java (#2856)
---
Matrix_Operations/Java/Matrix_multiply.java | 109 ++++++++++++++++++++
1 file changed, 109 insertions(+)
create mode 100644 Matrix_Operations/Java/Matrix_multiply.java
diff --git a/Matrix_Operations/Java/Matrix_multiply.java b/Matrix_Operations/Java/Matrix_multiply.java
new file mode 100644
index 000000000..94260cbd6
--- /dev/null
+++ b/Matrix_Operations/Java/Matrix_multiply.java
@@ -0,0 +1,109 @@
+// Java Program to calculation multiplication of 2 matrices (2D Array)
+import java.util.*;
+
+public class Matrix_Multiplication {
+ // Find multiplication of 2 Matrices and store it in matrix3
+ public static void multiply_matrices(int[][] matrix1, int[][] matrix2) {
+
+ int index1, index2, index3;
+ int[][] matrix3 = new int[matrix1.length][matrix1[0].length];
+
+ for ( index1 = 0; index1 < matrix1.length; index1++) {
+ for ( index2 = 0; index2 < matrix2[0].length; index2++) {
+ matrix3[index1][index2] = 0;
+ for ( index3 = 0; index3 < matrix1.length; index3++){
+ matrix3[index1][index2] += matrix1[index1][index3] * matrix2[index3][index2];
+ }
+ }
+ }
+ // Print the calculated matrix
+ for ( index1 = 0; index1 < matrix3.length; index1++) {
+ for ( index2 = 0; index2 < matrix3[0].length; index2++) {
+ System.out.print( matrix3[index1][index2] + " ");
+ }
+ System.out.println();
+ }
+ }
+
+ public static void main(String args[]) {
+ Scanner s = new Scanner(System.in);
+
+ System.out.println("Of First Matrix");
+ System.out.println(" Enter number of rows ");
+ int rows_first = s.nextInt();
+
+ System.out.println(" Enter number of columns ");
+ int columns_first = s.nextInt();
+ int[][] matrix1 = new int[rows_first][columns_first];
+
+ System.out.println("Of Second Matrix");
+ System.out.println(" Enter number of rows ");
+ int rows_second = s.nextInt();
+
+ System.out.println(" Enter number of columns ");
+ int columns_second = s.nextInt();
+ int[][] matrix2 = new int[rows_second][columns_second];
+
+ if (columns_first != rows_second) {
+ System.out.println(" Multiplication of matrix is not possible ");
+ }
+ else {
+
+ System.out.println(" Enter elements of 1st matrix ");
+ for (int i = 0; i < rows_first; i++) {
+ for (int j = 0; j < columns_first; j++) {
+ matrix1[i][j] = s.nextInt();
+ }
+ }
+
+ System.out.println(" Enter elements of 2nd matrix ");
+ for (int i = 0; i < rows_first; i++) {
+ for (int j = 0; j < columns_first; j++) {
+ matrix2[i][j] = s.nextInt();
+ }
+ }
+ multiply_matrices(matrix1, matrix2);
+ }
+ }
+}
+/*
+TEST CASE
+
+INPUT
+Of First Matrix
+ Enter number of rows
+1
+ Enter number of columns
+2
+Of Second Matrix
+ Enter number of rows
+1
+ Enter number of columns
+3
+
+OUTPUT
+ Multiplication of matrix is not possible
+
+INPUT
+Of First Matrix
+ Enter number of rows
+2
+ Enter number of columns
+2
+Of Second Matrix
+ Enter number of rows
+2
+ Enter number of columns
+2
+ Enter elements of 1st matrix
+1 2
+3 4
+ Enter elements of 2nd matrix
+1 1
+1 1
+
+OUTPUT
+3 3
+7 7
+*/
+
From a67cc022135676d479c6fc2430729fe77692e438 Mon Sep 17 00:00:00 2001
From: Ankita Saloni
Date: Wed, 6 May 2020 15:31:20 +0530
Subject: [PATCH 133/265] Created Shell_Sort.php (#2772)
Created Insertion_Sort.php
Delete Insertion_Sort.php
Updated Shell_Sort.php
---
Shell_Sort/Shell_Sort.php | 41 +++++++++++++++++++++++++++++++++++++++
1 file changed, 41 insertions(+)
create mode 100644 Shell_Sort/Shell_Sort.php
diff --git a/Shell_Sort/Shell_Sort.php b/Shell_Sort/Shell_Sort.php
new file mode 100644
index 000000000..b37063bc7
--- /dev/null
+++ b/Shell_Sort/Shell_Sort.php
@@ -0,0 +1,41 @@
+ 0)
+ {
+ for($b = $a; $b < count($new_arr); $b++) //Comparing and Sorting the elements of array
+ {
+ $d = $new_arr[$b];
+ $c = $b;
+ while($c >= $a && $new_arr[$c - $a] > $d)
+ {
+ $new_arr[$c] = $new_arr[$c - $a];
+ $c -= $a;
+ }
+ $new_arr[$c] = $d;
+ }
+ $a = round($a / 2.2);
+ }
+ return $new_arr; //Array is returned after sorting
+}
+
+//Driver Code :
+$sample_arr = array(4, 9, 11, -5, 8, 1, 0, 6, -3);
+echo "Array before sorting : ";
+echo implode(', ', $sample_arr);
+echo " ";
+echo " Array after sorting : ";
+echo implode(', ', shell_Sort($sample_arr)). PHP_EOL;
+
+/*
+Implementing Shell Sort Algorithm :
+
+Array before sorting :
+4, 9, 11, -5, 8, 1, 0, 6, -3
+
+Array after sorting :
+-5, -3, 0, 1, 4, 6, 8, 9, 11
+*/
+
+?>
From 7631ddb95a13021e5dfff13abaaf29c09bfe92c4 Mon Sep 17 00:00:00 2001
From: Sukriti Shah
Date: Wed, 6 May 2020 15:39:56 +0530
Subject: [PATCH 134/265] Updated Prim's Algorithm in JS (#2835)
Updated Prims_Algorithm.js
Adding Prim's algorithm in JS
Updated Prims_Algorithm.js
Updated Prim's Algorithm in JS
---
Prims_Algorithm/Prims_Algorithm.js | 81 ++++++++++++++++++++++++++++++
1 file changed, 81 insertions(+)
create mode 100644 Prims_Algorithm/Prims_Algorithm.js
diff --git a/Prims_Algorithm/Prims_Algorithm.js b/Prims_Algorithm/Prims_Algorithm.js
new file mode 100644
index 000000000..cf2d2d18b
--- /dev/null
+++ b/Prims_Algorithm/Prims_Algorithm.js
@@ -0,0 +1,81 @@
+/* Prim's algorithm is used to find minimum cost spanning tree (MST). It uses the greedy approach. */
+
+// Represents a weighted edge from first to second
+var Edge = function(first, second, weight) {
+ this.first = first;
+ this.second = second;
+ this.weight = weight;
+};
+
+// To create graph
+var Graph = function() {
+ this.vertices = [];
+ this.edges = {};
+
+ // Add a node to the graph
+ this.addVertex = function(vertex) {
+ this.vertices.push(vertex);
+ this.edges[vertex] = [];
+ };
+
+ // Add a weighted edge from first to second
+ this.addEdge = function(first, second, weight) {
+ this.edges[first].push(new Edge(first, second, weight));
+ this.edges[second].push(new Edge(second, first, weight));
+ };
+};
+
+// To get nearest vertex to visited vertices
+function getMinVertex(g, result, visitedVertices) {
+ var min = [Infinity , null];
+ for(var i = 0; i < result.length; i++)
+ for(var j = 0; j < g.edges[result[i]].length; j++)
+ if(g.edges[result[i]][j].weight < min[0] && visitedVertices[g.edges[result[i]][j].second] === undefined)
+ min = [g.edges[result[i]][j].weight, g.edges[result[i]][j].second];
+ return min[1];
+}
+
+// To perform Prim's algorithm
+function Prims(g) {
+ var result = [];
+ var visitedVertices = {};
+
+ // Start from node 0
+ var start = g.vertices[0];
+ result.push(start);
+ visitedVertices[start] = true;
+
+ var min = getMinVertex(g, result, visitedVertices);
+ while(min != null) {
+ result.push(min);
+ visitedVertices[min] = true;
+ min = getMinVertex(g, result, visitedVertices);
+ }
+
+ return result;
+};
+
+var g = new Graph();
+
+// Vertices for the graph - Sample Input
+g.addVertex(0);
+g.addVertex(1);
+g.addVertex(2);
+g.addVertex(3);
+
+// Weighted edges for the graph - Sample Input
+g.addEdge(0, 1, 3);
+g.addEdge(1, 3, 1);
+g.addEdge(1, 2, 5);
+g.addEdge(2, 3, 8);
+
+var result = Prims(g);
+console.log("Order in which vertices are visited during the implementation of Prim's Algorithm: ")
+console.log(result);
+
+/*
+ Sample Input is as taken in the code.
+ Sample Output:
+ Order in which vertices are visited during the implementation of Prim's Algorithm:
+ 0,1,3,2
+*/
From 41604ec8f7f934248e36ac35e6e65519a68e4353 Mon Sep 17 00:00:00 2001
From: Santushti Sharma <60578091+santushtisharma10@users.noreply.github.com>
Date: Fri, 8 May 2020 23:31:51 +0530
Subject: [PATCH 135/265] adding c file of fenwick tree
---
Fenwick_Tree/Fenwick_Tree.c | 122 ++++++++++++++++++++++++++++++++++++
1 file changed, 122 insertions(+)
create mode 100644 Fenwick_Tree/Fenwick_Tree.c
diff --git a/Fenwick_Tree/Fenwick_Tree.c b/Fenwick_Tree/Fenwick_Tree.c
new file mode 100644
index 000000000..3553fb4f4
--- /dev/null
+++ b/Fenwick_Tree/Fenwick_Tree.c
@@ -0,0 +1,122 @@
+/*
+ Fenwick Tree[also known as binary indexed tree] is used when there is a problem of range sum query wiht update i.e.RMQ.
+ Suppose you have an array and you have been asked to find sum in range.It can be done in linear time with static array
+ method.It will be difficult for on to do it in linear time when you have point updates.In this, update operation
+ incrementing an index by some value.Brute force approach will take O(n^2) time but Fenwick tree will take O(nlogn) time.
+*/
+
+#include
+#include
+
+/* n --> No. of elements present in input array.
+ BITree[0..n] --> Array that represents Fenwick Tree(Binary Indexed Tree).
+ arr[0..n-1] --> Input array for which prefix sum is evaluated.
+*/
+/*
+ Returns sum of arr[0..index]. This function assumes that the array is preprocessed and partial sums of
+ array elements are stored in BITree[].
+*/
+
+int getSum(int BITree[], int index)
+{
+ int sum = 0; // Iniialize result
+
+ // index in BITree[] is 1 more than the index in arr[]
+ index = index + 1;
+
+ // Traverse ancestors of BITree[index]
+ while (index > 0)
+ {
+ // Add current element of BITree to sum
+ sum += BITree[index];
+
+ // Move index to parent node in getSum View
+ index -= index & (-index);
+ }
+ return sum;
+}
+
+/*
+ Updates a node in Fenwick Tree at given index in BITree. The given value 'val' is added to BITree[i] and
+ all of its ancestors in tree.
+*/
+
+void updateBIT(int BITree[], int n, int index, int val)
+{
+ // index in BITree[] is 1 more than the index in arr[]
+ index = index + 1;
+
+ // Traverse all ancestors and add 'val'
+ while (index <= n)
+ {
+ // Add 'val' to current node of BI Tree
+ BITree[index] += val;
+
+ // Update index to that of parent in update View
+ index += index & (-index);
+ }
+}
+
+/*
+ Constructs and returns a Fenwick Tree for given array of size n.
+*/
+
+int *constructBITree(int arr[], int n)
+{
+ // Create and initialize BITree[] as 0
+ int *BITree = (int*) calloc(n+1, sizeof(int));
+
+ for (int i = 1; i <= n; ++i)
+ BITree[i] = 0;
+
+ // Store the actual values in BITree[] using update()
+ for (int i = 0; i < n; ++i)
+ updateBIT(BITree, n, i, arr[i]);
+
+ return BITree;
+}
+
+int rangeSum(int l, int r, int BITree[])
+{
+ return getSum(BITree, r) - getSum(BITree, l);
+}
+
+int main()
+{
+ int n;
+ scanf("%d", &n);
+
+ int freq[n];
+ for (int i = 0; i < n; ++i)
+ {
+ scanf("%d", &freq[i]);
+ }
+ int *BITree = constructBITree(freq, n);
+ // Print sum of freq[0...5]
+ printf("%d\n", getSum(BITree, 5));
+
+ //Update operation
+ freq[4] += 16;
+ updateBIT(BITree, n, 4, 16);
+
+ //Print sum of freq[2....7] after update
+ printf("%d\n", rangeSum(2, 7, BITree));
+
+ return 0;
+
+}
+
+/*
+INPUT
+-----
+n=12
+freq :[2,1,1,3,2,3,4,5,6,7,8,9];
+Print sum of freq[0...5]
+Update position 4 by adding 16
+Print sum of freq[2....7] after update
+
+OUTPUT
+------
+12
+33
+*/
From ba243da8eb54e15bde67b22042e714d21bf9c675 Mon Sep 17 00:00:00 2001
From: Raksha <57195964+raksha009@users.noreply.github.com>
Date: Sat, 9 May 2020 02:57:16 +0530
Subject: [PATCH 136/265] Subtraction of matrix in java (#2528)
changes made
Changes done
---
.../Java/Matrix_Subtraction.java | 90 +++++++++++++++++++
1 file changed, 90 insertions(+)
create mode 100644 Matrix_Operations/Java/Matrix_Subtraction.java
diff --git a/Matrix_Operations/Java/Matrix_Subtraction.java b/Matrix_Operations/Java/Matrix_Subtraction.java
new file mode 100644
index 000000000..ab1419281
--- /dev/null
+++ b/Matrix_Operations/Java/Matrix_Subtraction.java
@@ -0,0 +1,90 @@
+// Java Program to calculation subtraction of 2 matrices (2D Array)
+import java.util.*;
+
+public class Matrix_Subtraction {
+
+ // Find subtraction of 2 Matrices and store it in matrix3
+ public static void subtract_matrices(int[][] matrix1, int[][] matrix2){
+ int index1, index2 = 0;
+ int[][] matrix3 = new int[matrix1.length][matrix1[0].length];
+ for ( index1 = 0; index1 < matrix1.length; index1++ ){
+ for ( index2 = 0; index2 < matrix1[0].length; index2++ ){
+ matrix3[index1][index2] = matrix1[index1][index2] - matrix2[index1][index2];
+ }
+ }
+
+ // Print the calculated matrix
+ for ( index1 = 0; index1 < matrix3.length; index1++ ){
+ for ( index2 = 0; index2 < matrix3[0].length; index2++ ){
+ System.out.print( matrix3[index1][index2] + " ");
+ }
+ System.out.println();
+ }
+ }
+
+ public static void main(String args[]){
+ Scanner s = new Scanner(System.in);
+
+ System.out.println("Of First Matrix");
+ System.out.println(" Enter number of rows ");
+ int rows_first = s.nextInt();
+
+ System.out.println(" Enter number of columns ");
+ int columns_first = s.nextInt();
+ int[][] matrix1 = new int[rows_first][columns_first];
+
+ System.out.println("Of Second Matrix");
+ System.out.println(" Enter number of rows ");
+ int rows_second = s.nextInt();
+
+ System.out.println(" Enter number of columns ");
+ int columns_second = s.nextInt();
+ int[][] matrix2 = new int[rows_second][columns_second];
+
+ if (columns_first != columns_second || rows_first != rows_second) {
+ System.out.println(" Subtraction of matrix is not possible ");
+ }
+ else {
+
+ System.out.println(" Enter elements of 1st matrix ");
+ for (int i = 0 ; i < rows_first; i++) {
+ for (int j = 0 ; j < columns_first; j++) {
+ matrix1[i][j] = s.nextInt();
+ }
+ }
+
+ System.out.println(" Enter elements of 2nd matrix ");
+ for (int i = 0 ; i < rows_first; i++) {
+ for (int j = 0 ; j < columns_first; j++) {
+ matrix2[i][j] = s.nextInt();
+ }
+ }
+ subtract_matrices(matrix1, matrix2);
+ }
+ }
+}
+
+/*
+TEST CASES
+
+INPUT
+Of First Matrix
+ Enter number of rows
+1
+ Enter number of columns
+2
+Of Second Matrix
+ Enter number of rows
+1
+ Enter number of columns
+2
+ Enter elements of 1st matrix
+3
+4
+ Enter elements of 2nd matrix
+1
+3
+
+OUTPUT
+2 1
+*/
From 2f8a66f28ab6c5e8ceb629d553bc561f71ab89fa Mon Sep 17 00:00:00 2001
From: Disha Sinha <42354197+disha2sinha@users.noreply.github.com>
Date: Sat, 9 May 2020 03:04:44 +0530
Subject: [PATCH 137/265] KMP algorithm in dart added (#2852)
KMP in Dart
KMP in Dart
KMP in Dart
---
Knuth_Morris_Pratt_Algorithm/KMP.dart | 73 +++++++++++++++++++++++++++
1 file changed, 73 insertions(+)
create mode 100644 Knuth_Morris_Pratt_Algorithm/KMP.dart
diff --git a/Knuth_Morris_Pratt_Algorithm/KMP.dart b/Knuth_Morris_Pratt_Algorithm/KMP.dart
new file mode 100644
index 000000000..318f7b788
--- /dev/null
+++ b/Knuth_Morris_Pratt_Algorithm/KMP.dart
@@ -0,0 +1,73 @@
+/*The KMP matching algorithm uses degenerating property (pattern having same sub-patterns appearing more than once in the pattern)
+of the pattern and improves the worst case complexity to O(n). The basic idea behind KMP’s algorithm is: whenever we detect a mismatch
+(after some matches), we already know some of the characters in the text of the next window. This information is used to avoid
+matching the characters that will anyway match.*/
+import 'dart:io';
+
+List prefix_function (String pattern)
+{
+ var m = pattern.length;
+ var pi = [];
+ pi.add(-1);
+ var k = -1;
+ for (var j = 1; j < m; j++)
+ {
+ while (k > -1 && pattern[k + 1] != pattern[j])
+ {
+ k = pi[k];
+ }
+ if (pattern[k + 1] == pattern[j])
+ {
+ k = k + 1;
+ }
+ pi.insert(j,k);
+ }
+ return pi;
+}
+
+void KMP_matcher (String text, String pattern)
+{
+ var n = text.length;
+ var m = pattern.length;
+ var pi = [];
+ pi = prefix_function(pattern);
+
+ var j = -1; //number of chars matched
+ for (var i = 0; i < n; i++)
+ {
+ while (j >= 0 && pattern[j+1] != text[i])
+ {
+ j = pi[j]; //next char doesnot match
+ }
+ if (pattern[j+1] == text[i])
+ {
+ j = j + 1;
+ }
+ if (j == m - 1)
+ {
+ var result = i - m + 2;
+ print ("Pattern found at position: $result");
+ j = pi[j];
+ }
+ }
+}
+
+main()
+{
+ print ("Enter Text:");
+ String text = stdin.readLineSync();
+ print ("Enter Pattern:");
+ String pattern = stdin.readLineSync();
+ KMP_matcher (text, pattern);
+ return 0;
+}
+
+/*
+Enter Text:
+gfmghdmgmgcc
+Enter Pattern:
+mg
+Pattern found at position: 3
+Pattern found at position: 7
+Pattern found at position: 9 */
+
From 03e3e33ffc0b2919d0f9d9e6077d78a2e5246fa9 Mon Sep 17 00:00:00 2001
From: Shweta Bhardwaj <59722795+BhardwajShweta25@users.noreply.github.com>
Date: Sat, 9 May 2020 15:09:26 +0530
Subject: [PATCH 138/265] Added Selection_Sort.php (#2272)
---
Selection_Sort/Selection_Sort.php | 43 +++++++++++++++++++++++++++++++
1 file changed, 43 insertions(+)
create mode 100644 Selection_Sort/Selection_Sort.php
diff --git a/Selection_Sort/Selection_Sort.php b/Selection_Sort/Selection_Sort.php
new file mode 100644
index 000000000..e4f57201d
--- /dev/null
+++ b/Selection_Sort/Selection_Sort.php
@@ -0,0 +1,43 @@
+/*
+ * Selection sort is used for sorting arrays.
+ * It is based on identifying minimum element from the array
+ * and placing it in beginning.
+ * This is repeated until we reach the end of array.
+ */
+
+/*
+ * Sample Output
+ * 1 3 4 5 10
+ */
From 9d417bb3c0cf83ad6a482366f1445e5b20be018d Mon Sep 17 00:00:00 2001
From: Raksha <57195964+raksha009@users.noreply.github.com>
Date: Sun, 10 May 2020 16:08:32 +0530
Subject: [PATCH 139/265] Matrix_intersection in java (#2877)
changes done
---
.../Java/Matrix_intersection.java | 90 +++++++++++++++++++
1 file changed, 90 insertions(+)
create mode 100644 Matrix_Operations/Java/Matrix_intersection.java
diff --git a/Matrix_Operations/Java/Matrix_intersection.java b/Matrix_Operations/Java/Matrix_intersection.java
new file mode 100644
index 000000000..d4d077c79
--- /dev/null
+++ b/Matrix_Operations/Java/Matrix_intersection.java
@@ -0,0 +1,90 @@
+// Java Program to check where the elements of matrix are different and replacing them with a character
+import java.util.Scanner;
+
+public class Matrix_intersection {
+
+ //Finding the elements which are different in both the matrices and replacing it with a char
+ public static void check_intersection(int[][] matrix1, int[][] matrix2, String character){
+ int index1, index2 = 0;
+ for ( index1 = 0; index1 < matrix1.length; index1++) {
+ for ( index2 = 0; index2 < matrix1[0].length; index2++) {
+ if (matrix1[index1][index2] != matrix2[index1][index2]) {
+ System.out.print(character + " ");
+ }
+ else{
+ System.out.print(matrix1[index1][index2] + " ");
+ }
+ }
+ System.out.println();
+ }
+ }
+
+ public static void main(String args[]){
+ Scanner s = new Scanner(System.in);
+
+ System.out.println("Of First Matrix");
+ System.out.println(" Enter number of rows ");
+ int rows_first = s.nextInt();
+
+ System.out.println(" Enter number of columns ");
+ int columns_first = s.nextInt();
+ int[][] matrix1 = new int[rows_first][columns_first];
+
+ System.out.println("Of Second Matrix");
+ System.out.println(" Enter number of rows ");
+ int rows_second = s.nextInt();
+
+ System.out.println(" Enter number of columns ");
+ int columns_second = s.nextInt();
+ int[][] matrix2 = new int[rows_second][columns_second];
+
+ if (columns_first != columns_second || rows_first != rows_second) {
+ System.out.println(" Matrices's order is not same ");
+ }
+ else {
+
+ System.out.println(" Enter elements of 1st matrix ");
+ for (int i = 0; i < rows_first; i++) {
+ for (int j = 0; j < columns_first; j++) {
+ matrix1[i][j] = s.nextInt();
+ }
+ }
+
+ System.out.println(" Enter elements of 2nd matrix ");
+ for (int i = 0; i < rows_first; i++) {
+ for (int j = 0; j < columns_first; j++) {
+ matrix2[i][j] = s.nextInt();
+ }
+ }
+ System.out.println("Enter character to replace");
+ String character = s.next();
+ check_intersection(matrix1, matrix2, character);
+ }
+ }
+}
+/*
+TEST CASES
+INPUT
+OOf First Matrix
+ Enter number of rows
+2
+ Enter number of columns
+2
+Of Second Matrix
+ Enter number of rows
+2
+ Enter number of columns
+2
+ Enter elements of 1st matrix
+4 0
+1 2
+ Enter elements of 2nd matrix
+4 9
+3 2
+Enter character to replace
+%
+OUTPUT
+4 %
+% 2
+*/
+
From da4a40a70fe9313f8b61ab10f7a665ccf1237628 Mon Sep 17 00:00:00 2001
From: Chandrika Deb
Date: Sun, 10 May 2020 16:12:20 +0530
Subject: [PATCH 140/265] Create Readme.md (#2843)
Updated Chinese Remainder Theorem Readme.md
---
Chinese_Remainder_Theorem/Readme.md | 116 ++++++++++++++++++++++++++++
1 file changed, 116 insertions(+)
create mode 100644 Chinese_Remainder_Theorem/Readme.md
diff --git a/Chinese_Remainder_Theorem/Readme.md b/Chinese_Remainder_Theorem/Readme.md
new file mode 100644
index 000000000..136c5d072
--- /dev/null
+++ b/Chinese_Remainder_Theorem/Readme.md
@@ -0,0 +1,116 @@
+# Chinese Remainder Theorem
+
+If m1, m2, .., mk are pairwise relatively prime positive integers, and if a1, a2, .., ak are any integers, then the simultaneous congruences x ≡ a1 (mod m1), x ≡ a2 (mod m2), ..., x ≡ ak (mod mk) have a solution, and the solution is unique modulo m, where m = m1m2⋅⋅⋅mk .
+
+**Problem Statement :**
+
+We are given two arrays num[0..n-1] and rem[0..n-1]. In num[0..n-1], every pair is coprime (gcd for every pair is 1). We need to find minimum positive number x such that:
+
+ x % num[0] = rem[0],
+ x % num[1] = rem[1],
+ x % num[2] = rem[2],
+ .......................
+ x % num[n-1] = rem[n-1]
+
+## Algorithm
+
+The solution is based on the below given formula :
+
+ x = sum of { (rem[i]* pp[i]* inv[i]) % prod } where 0 <= i <= n-1
+
+ where,
+
+ rem[i] is given array of remainders
+
+ prod is product of all given numbers
+ prod = num[0] * num[1] * ... * num[k-1]
+
+ pp[i] is product of all divided by num[i]
+ pp[i] = prod / num[i]
+
+ inv[i] = Modular Multiplicative Inverse of pp[i] with respect to num[i]
+
+
+## Example
+
+
+
+Consider the above given example for understanding **Chinese Remainder Theorem**.
+
+ Input : num[] = {3, 5, 7}, rem[] = {1, 2, 3}
+ output : x = 52
+
+ Explanation: 52 is the smallest number such that:
+ (1) When we divide it by 3, we get remainder 1.
+ (2) When we divide it by 5, we get remainder 2
+ (3) When we divide it by 7, we get remainder 3.
+
+
+Let us consider an example for a better understanding of **above given formula**.
+
+ Input: num[] = {3, 5, 7}, rem[] = {1, 2, 3}
+ Output: x = 52
+
+ Explanation: num[] = {3, 5, 7}, rem[] = {1, 2, 3}
+ prod = 3*5*7 = 105
+ pp[] = {35, 21, 15}
+ inv[] = {2, 1, 1} // (35*2)%3 = 1, (21*1)%5 = 1, // (15*1)%7 = 1
+
+ x = (rem[0]* pp[0]* inv[0] + rem[1]* pp[1]* inv[1] + rem[2]* pp[2]* inv[2]) % prod
+ = (1*35*2 + 2*21*1 + 3*15*1) % 105
+ = (70 + 42 + 45) % 105
+ = 52
+
+## Pseudo Code
+
+The code is a simple 4-step process followed to find the solution :
+
+ STEP 1 : Find the Product of all the numbers given in num[].
+ STEP 2 : Find the number which is equal to Product divided by num[i] and store it in pp[i].
+ STEP 3 : Find the Modular Multiplicative Inverse of pp[i] with respect to num[i] and store it
+ in inv[i].
+ STEP 4 : Multiply rem[i] with the product of pp[i] and inv[i] for all 0 <= i <= n-1 and
+ add them. This is our required Output.
+
+
+## Complexity
+
+ Time complexity : __O(n*log(max(a,b))__ , where
+
+* __n__ is the total number of elements in the array.
+* __a__ is the maximum value in __num[ ]__
+* __b__ is the minimum value in __rem[ ]__
+
+
+## Implementation
+
+- [C Code](https://github.com/jainaman224/Algo_Ds_Notes/blob/master/Chinese_Remainder_Theorem/Chinese_remainder_theorem.c)
+
+- [CoffeeScript code](https://github.com/jainaman224/Algo_Ds_Notes/blob/master/Chinese_Remainder_Theorem/Chinese_Remainder_Theorem.coffee)
+
+- [C++ Code](https://github.com/jainaman224/Algo_Ds_Notes/blob/master/Chinese_Remainder_Theorem/Chinese_Remainder_Theorem.cpp)
+
+- [C# Code](https://github.com/jainaman224/Algo_Ds_Notes/blob/master/Chinese_Remainder_Theorem/Chinese_Remainder_Theorem.cs)
+
+- [Dart Code](https://github.com/jainaman224/Algo_Ds_Notes/blob/master/Chinese_Remainder_Theorem/Chinese_Remainder_Theorem.dart)
+
+- [Go Code](https://github.com/jainaman224/Algo_Ds_Notes/blob/master/Chinese_Remainder_Theorem/Chinese_Remainder_Theorem.go)
+
+- [Java Code](https://github.com/jainaman224/Algo_Ds_Notes/blob/master/Chinese_Remainder_Theorem/Chinese_Remainder_Theorem.java)
+
+- [JavaScript Code](https://github.com/jainaman224/Algo_Ds_Notes/blob/master/Chinese_Remainder_Theorem/Chinese_Remainder_Theorem.js)
+
+- [PHP Code](https://github.com/jainaman224/Algo_Ds_Notes/blob/master/Chinese_Remainder_Theorem/Chinese_Remainder_Theorem.php)
+
+- [Python Code](https://github.com/jainaman224/Algo_Ds_Notes/blob/master/Chinese_Remainder_Theorem/Chinese_Remainder_Theorem.py)
+
+### Refer this [link](https://www.youtube.com/watch?v=ru7mWZJlRQg) to know more!
+
+## References
+
+Image source: [https://www.storyofmathematics.com/chinese.html](https://www.storyofmathematics.com/chinese.html)
+
+#### Websites:
+1. [http://homepages.math.uic.edu/~leon/mcs425-s08/handouts/chinese_remainder.pdf](http://homepages.math.uic.edu/~leon/mcs425-s08/handouts/chinese_remainder.pdf)
+2. [https://www.geeksforgeeks.org/chinese-remainder-theorem-set-2-implementation/](https://www.geeksforgeeks.org/chinese-remainder-theorem-set-2-implementation/)
+3. [https://medium.com/free-code-camp/how-to-implement-the-chinese-remainder-theorem-in-java-db88a3f1ffe0](https://medium.com/free-code-camp/how-to-implement-the-chinese-remainder-theorem-in-java-db88a3f1ffe0)
From 35097a319f0abff7b8eff3985420ca0ba10c3bfd Mon Sep 17 00:00:00 2001
From: Chandrika Deb
Date: Sun, 10 May 2020 16:13:21 +0530
Subject: [PATCH 141/265] Readme for Segment_Tree_RMQ (#2841)
Updated Readme.md for Segment Tree RMQ
---
Segment_Tree_RMQ/README.md | 134 +++++++++++++++++++++++++++++++++++++
1 file changed, 134 insertions(+)
create mode 100644 Segment_Tree_RMQ/README.md
diff --git a/Segment_Tree_RMQ/README.md b/Segment_Tree_RMQ/README.md
new file mode 100644
index 000000000..a0bc4dd71
--- /dev/null
+++ b/Segment_Tree_RMQ/README.md
@@ -0,0 +1,134 @@
+# Segment Tree
+
+Segment Tree is a basically a binary tree used for storing the intervals or segments. Each node in the Segment Tree represents an interval.
+
+Segment Tree is used in cases where there are multiple range queries on array and modifications of elements of the same array. For example, finding the sum of all the elements in an array from indices L to R, or finding the minimum (famously known as __Range Minumum Query__ problem) of all the elements in an array from indices L to R.
+
+## Explanation
+
+Consider an array __A__ of size __N__ and a corresponding Segment Tree __T__:
+
+1. The root of __T__ will represent the whole array __A[0 : N-1]__.
+2. Each leaf in the Segment Tree __T__ will represent a single element __A[i]__ such that __0 <= i < N__.
+3. The internal nodes in the Segment Tree __T__ represents the union of elementary intervals __A[i : j]__ where __0<=i2N__.
+* There are __N__ leaves representing the elements of the array. The number of internal nodes is __N - 1__. So, a total number of nodes are __2 * N - 1__.
+
+The Segment Tree of array __A__ of size __7__ will look like this:
+
+
+
+
+
+## Algorithm
+
+#### Query for minimum value of given range
+
+Once the tree is constructed, how to do range minimum query using the constructed segment tree. Following is the algorithm to get the minimum.
+
+```
+// qs --> query start index, qe --> query end index
+int RMQ(node, qs, qe)
+{
+ if range of node is within qs and qe
+ return value in node
+ else if range of node is completely outside qs and qe
+ return ZERO
+ else
+ return min( RMQ(node's left child, qs, qe), RMQ(node's right child, qs, qe) )
+}
+```
+
+## Pseudocode
+
+After we've built a tree, we want to be able to search the tree for its values. (Which, in this case, is the minimum value between indices L and R.)
+
+Similar to the technique we used before, we recursively search the tree, starting from the root, and if a node is within the range [L, R], then we check it's value as a valid minimum of the range.
+
+```
+function RecursivelySearchForMin(L, R, nodeIndex, nodeStartIndex, nodeEndIndex)
+{
+ /*
+ If this node's range is anywhere outside of [L, R]
+ then don't use it's value. Just return some
+ really big number (which wouldn't be taken as the minimum).
+ */
+ if(nodeEndIndex < L || R < nodeStartIndex)
+ {
+ return reallyBigNumber;
+ }
+
+ /*
+ If this node is completely within [L, R],
+ then return it as the min value.
+ */
+ if(L <= nodeStartIndex && nodeEndIndex <= R)
+ {
+ return stArray[nodeIndex];
+ }
+
+ /*
+ Otherwise this node is partially within [L, R].
+ (Recursively) check this node's children and return the min of those two.
+ */
+ middleIndex = nodeStartIndex + ((nodeEndIndex - nodeStartIndex) / 2);
+
+ leftChildNodeIndex = 2 * nodeIndex;
+ rightChildNodeIndex = 2 * nodeIndex + 1;
+
+ leftChildMin = RecursivelySearchForMin(L, R, leftChildNodeIndex, nodeStartIndex, middleIndex);
+ rightChildMin = RecursivelySearchForMin(L, R, rightChildNodeIndex, middleIndex + 1, nodeEndIndex);
+
+ minOfThisNode = min(leftChildMin, rightChildMin);
+
+ return minOfThisNode;
+}
+
+// Find the minimum value between indices L and R.
+function FindMin(L, R)
+{
+ // Recursively search the tree, starting from the root (node 0).
+ min = RecursivelySearchForMin(L, R, 0, 0, origArrayLength - 1);
+ return min;
+}
+```
+## Example
+
+Given an array A[1 … n] of n objects taken from a well-ordered set(such as numbers), returns the position of the minimal element in the specified sub-array A[l … r], (r<=n).
+
+When A = [2,4,3,1,6,7,8,9,1,7], then the answer to the range minimum query for the sub-array A[2 … 7] = [3,1,6,7,8,9] is 3, as A[3] = 1.
+
+
+
+## Time Complexity
+
+Time Complexity for tree construction is __O(n)__. There are total __2N - 1__ nodes, and value of every node is calculated only once in tree construction.
+
+Time complexity to query is __O(Log N)__. To query a range minimum, at worst, we'll have to go down the height of the tree twice, once for the left subtree, and one for the right subtree. We process at most two nodes at every level and number of levels is **O(Log N)**.
+
+## Implementation
+
+-[C Code](https://github.com/jainaman224/Algo_Ds_Notes/blob/master/Segment_Tree_RMQ/Segement_Tree_RMQ.c)
+
+-[C++ Code](https://github.com/jainaman224/Algo_Ds_Notes/blob/master/Segment_Tree_RMQ/Segement_Tree_RMQ.cpp)
+
+-[Python Code](https://github.com/jainaman224/Algo_Ds_Notes/blob/master/Segment_Tree_RMQ/Segement_Tree_RMQ.py)
+
+-[Dart Code](https://github.com/jainaman224/Algo_Ds_Notes/blob/master/Segment_Tree_RMQ/Segment_Tree_RMQ.dart)
+
+-[Java Code](https://github.com/jainaman224/Algo_Ds_Notes/blob/master/Segment_Tree_RMQ/Segment_Tree_RMQ.java)
+
+## References
+
+#### Images source:
+1. [https://www.hackerearth.com/practice/notes/segment-tree-and-lazy-propagation/](https://www.hackerearth.com/practice/notes/segment-tree-and-lazy-propagation/)
+2. [https://www.topcoder.com/community/competitive-programming/tutorials/range-minimum-query-and-lowest-common-ancestor/](https://www.topcoder.com/community/competitive-programming/tutorials/range-minimum-query-and-lowest-common-ancestor/)
+
+#### Websites:
+1. [https://www.hackerearth.com/practice/data-structures/advanced-data-structures/segment-trees/tutorial/](https://www.hackerearth.com/practice/data-structures/advanced-data-structures/segment-trees/tutorial/)
+2. [https://www.geeksforgeeks.org/segment-tree-set-1-range-minimum-query/](https://www.geeksforgeeks.org/segment-tree-set-1-range-minimum-query/)
+3. [https://www.geeksforgeeks.org/segment-tree-set-1-sum-of-given-range/](https://www.geeksforgeeks.org/segment-tree-set-1-sum-of-given-range/)
+4. [https://www.srcmake.com/home/segment-tree](https://www.srcmake.com/home/segment-tree)
From c49739c043d7a69dee5539fdb702fcd0c12834be Mon Sep 17 00:00:00 2001
From: Mrunal <44579222+mruna7@users.noreply.github.com>
Date: Sun, 10 May 2020 16:18:15 +0530
Subject: [PATCH 142/265] squashingthecommits (#2827)
Create Decimal_to_Binary
Update Decimal_to_Binary
Update Decimal_to_Binary
Update Decimal_to_Binary
Update Decimal_to_Binary
Update Decimal_to_Binary
Add files via upload
Update Binary_To_Octal.java
Update Decimal_to_Binary
Update Decimal_to_Binary
Update Binary_To_Octal.java
Update Binary_To_Octal.java
Delete Decimal_to_Binary
---
Number_Conversion/Java/Binary_To_Octal.java | 46 +++++++++++++++++++++
1 file changed, 46 insertions(+)
create mode 100644 Number_Conversion/Java/Binary_To_Octal.java
diff --git a/Number_Conversion/Java/Binary_To_Octal.java b/Number_Conversion/Java/Binary_To_Octal.java
new file mode 100644
index 000000000..edea549b6
--- /dev/null
+++ b/Number_Conversion/Java/Binary_To_Octal.java
@@ -0,0 +1,46 @@
+import java.io.*;
+import java.util.Scanner;
+
+public class Binary_To_Octal
+{
+ public static void binToOctal(long num)
+ {
+ int n = 0, decimal = 0;
+ //converting binary to decimal
+ while(num > 0)
+ {
+ long temp = num % 10;
+ decimal += temp * Math.pow(2, n);
+ num = num / 10;
+ n++;
+ }
+ int octal[] = new int[20];
+ int i = 0;
+ while(decimal > 0)
+ {
+ int t = decimal % 8;
+ octal[i++] = t;
+ decimal = decimal / 8;
+ }
+ System.out.print("Octal representation");
+ for(int j = i-1 ; j >= 0 ; j--)
+ System.out.print(octal[j]);
+ }
+ public static void main(String[] args)
+ {
+ long num;
+ Scanner sc = new Scanner(System.in);
+ System.out.println("Enter a Binary number");
+ num = sc.nextLong();
+ binToOctal(num);
+ sc.close();
+ }
+}
+/*
+Input:
+Enter a Binary number
+1011001010
+Output:
+Octal representation
+2625
+*/
From 1c7f472f99700013b6167ee49f2aa3a4c5cfa983 Mon Sep 17 00:00:00 2001
From: Ritish Singh
Date: Sun, 10 May 2020 20:04:15 +0530
Subject: [PATCH 143/265] Kosraju Algorithm in C# (#2834)
Update Kosaraju_Algorithm.cs
---
Kosaraju_Algorithm/Kosaraju_Algorithm.cs | 84 ++++++++++++++++++++++++
1 file changed, 84 insertions(+)
create mode 100644 Kosaraju_Algorithm/Kosaraju_Algorithm.cs
diff --git a/Kosaraju_Algorithm/Kosaraju_Algorithm.cs b/Kosaraju_Algorithm/Kosaraju_Algorithm.cs
new file mode 100644
index 000000000..1c2046d8f
--- /dev/null
+++ b/Kosaraju_Algorithm/Kosaraju_Algorithm.cs
@@ -0,0 +1,84 @@
+using System;
+using System.Collections.Generic;
+
+namespace Declaring_Method
+{
+ public static class Kosaraju_Algorithm
+ {
+ public static void Main(string[] args)
+ {
+ List[] g = new List[3];
+ for (int i = 0; i < g.Length; i++)
+ g[i] = new ArrayList<>();
+
+ //Initializing the List.
+ g[2].Add(0);
+ g[2].Add(1);
+ g[0].Add(1);
+ g[1].Add(0);
+
+ List> components = scc(g);
+
+ //Final Output
+ foreach (int i in components)
+ {
+ Console.WriteLine(i);
+ }
+ }
+
+ public static List> scc(List[] graph)
+ {
+ int n = graph.Length; // Storing length of the graph
+ bool[] used = new bool[n];
+ List order = new ArrayList<>();
+ for (int i = 0; i < n; i++)
+ if (!used[i])
+ dfs(graph, used, order, i);
+
+ List[] reverseGraph = new List[n];
+ for (int i = 0; i < n; i++)
+ reverseGraph[i] = new ArrayList<>();
+ for (int i = 0; i < n; i++)
+ foreach (int j in graph[i])
+ reverseGraph[j].Add(i);
+
+ List> components = new ArrayList<>();
+ fill(used, false);
+ order.Reverse(); // Reversing the contents
+
+ foreach (int u in order)
+ if (!used[u])
+ {
+ List component = new ArrayList<>();
+ dfs(reverseGraph, used, component, u);
+ components.Add(component);
+ }
+
+ return components;
+ }
+
+ //Depth First Search
+ static void dfs(List[] graph, bool[] used, List res, int u)
+ {
+ used[u] = true;
+ foreach (int v in graph[u])
+ if (!used[v])
+ dfs(graph, used, res, v);
+ res.Add(u);
+ }
+
+ //To fill the bool array
+ public static void fill(this T[] originalArray, T with)
+ {
+ for (int i = 0; i < originalArray.Length; i++)
+ {
+ originalArray[i] = with;
+ }
+ }
+
+ }
+}
+/*OUTPUT:
+2
+1
+0*/
From b58f319845cbbc466e8e4227f6f18816b22eac6e Mon Sep 17 00:00:00 2001
From: jedicakelord <46528937+jedicakelord@users.noreply.github.com>
Date: Sun, 10 May 2020 23:00:26 +0530
Subject: [PATCH 144/265] Z Algorithm in Rust (#2677)
---
Z_Algorithm/Z_Algorithm.rs | 103 +++++++++++++++++++++++++++++++++++++
1 file changed, 103 insertions(+)
create mode 100644 Z_Algorithm/Z_Algorithm.rs
diff --git a/Z_Algorithm/Z_Algorithm.rs b/Z_Algorithm/Z_Algorithm.rs
new file mode 100644
index 000000000..e20bf9792
--- /dev/null
+++ b/Z_Algorithm/Z_Algorithm.rs
@@ -0,0 +1,103 @@
+/* Problem Statement : Find all occurrences of
+ * a pattern in a string in linear time O(m+n)
+ * where m is the length of the pattern and n
+ * is the length of the string.*/
+
+use std::io::{stdin, stdout, Write};
+use std::convert::TryInto;
+
+fn z_array(zstring: &Vec) -> Vec {
+ let z_length = zstring.len();
+ let mut z_arr = vec![0u32; z_length];
+ z_arr[0] = 1;
+ let mut index = 1;
+ let mut var_ind = 0;
+ let mut left = 0; let mut right = 0;
+ /* To form the z array, run two loops from the beg of the
+ * array, match the char at that index for the outer loop
+ * with the char at index in the inner loop. If they match,
+ * move both of the indices forward, calculate the max length
+ * til which they match. */
+ while index < z_length {
+
+ if index > right {
+ left = index; right = index;
+
+ while right < z_length &&
+ zstring[right - left] == zstring[right] {
+ right += 1;
+ }
+ z_arr[index] = (right - left).try_into().unwrap();
+ right -= 1;
+ }
+ else {
+ var_ind = index - left;
+
+ if z_arr[var_ind] < ((right - index + 1).try_into().unwrap()) {
+ z_arr[index] = z_arr[var_ind];
+ }
+ else {
+ left = index;
+ while (right < z_length &&
+ zstring[right - left] == zstring[right]) {
+ right += 1;
+ }
+
+ z_arr[index] = (right - left).try_into().unwrap();
+ right -= 1;
+ }
+ }
+ index += 1;
+ }
+
+ z_arr
+}
+
+fn search_the_pattern(strng :&str, pattern :&str) {
+ let strng: Vec = strng.chars().collect();
+ let pattern: Vec = pattern.chars().collect();
+ let mut z_string = Vec::with_capacity(strng.len() + pattern.len());
+ let pattern_length = pattern.len();
+ z_string.extend(pattern);
+ z_string.push('$');
+ z_string.extend(strng);
+ let z_array = z_array(&z_string);
+
+ // Go through the z array, if at any index value is equal to the
+ // length of the pattern, the pattern appears in the string.
+ for index in pattern_length + 1.. z_array.len() - 1 {
+ if z_array[index] as usize == pattern_length {
+ println!("Pattern found at index : {}", index - pattern_length - 1);
+ }
+ }
+
+}
+
+fn main() {
+ println!("Enter the string :");
+ let mut strng = String::new();
+ //let _ = stdout().flush();
+ stdin().read_line(&mut strng).expect("Error in string input.");
+ let strng: String = strng.trim().parse().unwrap();
+ let strng: &str = &*strng;
+
+ let mut pattern = String::new(); // make a mutable string variable
+ println!("Enter the pattern :");
+ stdin().read_line(&mut pattern).expect("Error in pattern input.");
+ let pattern: String = pattern.trim().parse().unwrap();
+ let pattern: &str = &*pattern;
+ //let tokens:Vec<&str>= strng.split(",").collect();
+
+ // Call the driver function with the string and the pattern
+ search_the_pattern(strng, pattern);
+}
+
+/* Example :
+ * Enter the string :
+The thesis was defended there then.
+Enter the pattern :
+the
+Pattern found at index : 4
+Pattern found at index : 24
+Pattern found at index : 30
+*/
From 7f375480773d83849d99cd304591d218daaeee51 Mon Sep 17 00:00:00 2001
From: Simrann Arora
Date: Mon, 11 May 2020 22:17:24 +0530
Subject: [PATCH 145/265] Create Readme.md (#2480) (#2888)
---
Boyer_Moore_Algorithm/Readme.md | 137 ++++++++++++++++++++++++++++++++
1 file changed, 137 insertions(+)
create mode 100644 Boyer_Moore_Algorithm/Readme.md
diff --git a/Boyer_Moore_Algorithm/Readme.md b/Boyer_Moore_Algorithm/Readme.md
new file mode 100644
index 000000000..f86721f1e
--- /dev/null
+++ b/Boyer_Moore_Algorithm/Readme.md
@@ -0,0 +1,137 @@
+# Boyer Moore Algorithm
+The Boyer Moore Algorithm was established by Robert Boyer and J Strother Moore in 1977. The Boyer Moore (B-M) String search algorithm is a particularly efficient algorithm and has served as a standard benchmark for string search algorithm ever since.The algorithm takes a 'backward' approach: the pattern string (P) is aligned with the start of the text string (T), and then compares the characters of a pattern from right to left, beginning with rightmost character.If a character is compared that is not within the pattern, no match can be found by analyzing any further aspects at this position so the pattern can be changed entirely past the mismatching character.
+## **Explanation**
+The B-M algorithm ,for deciding the possible shifts, uses two preprocessing strategies simultaneously. Whenever a mismatch occurs, the algorithm calculates a variation using both approaches and selects the more significant shift thus, if make use of the most effective strategy for each case.
+The two strategies are called heuristics of B - M as they are used to reduce the search. They are:
+1) Bad Character Heuristics
+2) Good Suffix Heuristics
+
+ ***Bad Character Heuristic***
+The idea of bad character heuristic is simple. The character of the text which doesn’t match with the current character of the pattern is called the Bad Character. Upon mismatch, we shift the pattern until –
+1) The mismatch becomes a match
+2) Pattern P move past the mismatched character.
++ Case 1 – Mismatch become match
+We will lookup the position of last occurrence of mismatching character in pattern and if mismatching character exist in pattern then we’ll shift the pattern such that it get aligned to the mismatching character in text T.
+
++ Case 2 – Pattern move past the mismatch character
+We’ll lookup the position of last occurrence of mismatching character in pattern and if character does not exist we will shift pattern past the mismatching character.
+
+
+ ***Good Suffix Heuristic***
+ Let t be substring of text T which is matched with substring of pattern P. Now we shift pattern until :
+ 1) Another occurrence of t in P matched with t in T.
+ 2) A prefix of P, which matches with suffix of t
+ 3) P moves past t
++ Case 1: Another occurrence of t in P matched with t in T
+Pattern P might contain few more occurrences of t. In such case, we will try to shift the pattern to align that occurrence with t in text T. For example-
+
++ Case 2: A prefix of P, which matches with suffix of t in T
+It is not always likely that we will find the occurrence of t in P. Sometimes there is no occurrence at all, in such cases sometimes we can search for some suffix of t matching with some prefix of P and try to align them by shifting P. For example –
+
++ Case 3: P moves past t
+If the above two cases are not satisfied, we will shift the pattern past the t. For example –
+
+## Algorithm
+```
+fullSuffixMatch(shiftArray, borderArray, pattern)
+
+Input: Array to store shift locations, the border array and the pattern to search
+
+Output: Fill the shift array and the border array
+
+Begin
+ n := pattern length
+ j := n
+ j := n + 1
+ borderArray[i] := j
+
+ while i > 0, do
+ while j <= n AND pattern[i - 1] ≠ pattern[j - 1], do
+ if shiftArray[j] = 0, then
+ shiftArray[j] := j - i;
+ j := borderArray[j];
+ done
+
+ decrease i and j by 1
+ borderArray[i] := j
+ done
+End
+
+partialSuffixMatch(shiftArray, borderArray, pattern)
+
+Input: Array to store shift locations, the border array and the pattern to search
+
+Output: Fill the shift array and the border array
+
+Begin
+ n := pattern length
+ j := borderArray[0]
+
+ for index of all characters ‘i’ of pattern, do
+ if shiftArray[i] = 0, then
+ shiftArray[i] := j
+ if i = j then
+ j := borderArray[j]
+ done
+End
+
+searchPattern(text, pattern)
+
+Input: The main text and the pattern, that will be searched
+
+Output: The indexes where the pattern is found
+
+Begin
+ patLen := pattern length
+ strLen := text size
+
+ for all entries of shiftArray, do
+ set all entries to 0
+ done
+
+ call fullSuffixMatch(shiftArray, borderArray, pattern)
+ call partialSuffixMatch(shiftArray, borderArray, pattern)
+ shift := 0
+
+ while shift <= (strLen - patLen), do
+ j := patLen -1
+ while j >= 0 and pattern[j] = text[shift + j], do
+ decrease j by 1
+ done
+
+ if j < 0, then
+ print the shift as, there is a match
+ shift := shift + shiftArray[0]
+ else
+ shift := shift + shiftArray[j + 1]
+ done
+End
+```
+## Examples
+ Input: txt[] = "THIS IS A TEST TEXT"
+ pat[] = "TEST"
+ Output: Pattern found at index 10
+ Input: txt[] = "AABAACAADAABAABA"
+ pat[] = "AABA"
+ Output: Pattern found at index 0
+ Pattern found at index 9
+ Pattern found at index 12
+
+ 
+## Time Complexity
+ Preprocessing Time Complexity: O(|∑|)
+ Matching Time Complexity: (O ((n - m + 1) + |∑|))
+## Implementation
+- [C Code](https://github.com/jainaman224/Algo_Ds_Notes/blob/da4a40a70f/Boyer_Moore_Algorithm/Boyer_Moore.c)
+- [C++ Code](https://github.com/jainaman224/Algo_Ds_Notes/blob/da4a40a70f/Boyer_Moore_Algorithm/Boyer_Moore.cpp )
+- [C# Code](https://github.com/jainaman224/Algo_Ds_Notes/blob/da4a40a70f/Boyer_Moore_Algorithm/Boyer_Moore.cs)
+- [Go Code](https://github.com/jainaman224/Algo_Ds_Notes/blob/da4a40a70f/Boyer_Moore_Algorithm/Boyer_Moore.go)
+- [Java Code](https://github.com/jainaman224/Algo_Ds_Notes/blob/da4a40a70f/Boyer_Moore_Algorithm/Boyer_Moore.java)
+- [Kotlin Code](https://github.com/jainaman224/Algo_Ds_Notes/blob/da4a40a70f/Boyer_Moore_Algorithm/Boyer_Moore.kt)
+- [Python Code](https://github.com/jainaman224/Algo_Ds_Notes/blob/da4a40a70f/Boyer_Moore_Algorithm/Boyer_Moore.py)
+## References
++ Image source: [https://www.geeksforgeeks.org/boyer-moore-algorithm-for-pattern-searching/](https://www.geeksforgeeks.org/boyer-moore-algorithm-for-pattern-searching/)
+#### Websites:
+1. [https://www.javatpoint.com/daa-boyer-moore-algorithm](https://www.javatpoint.com/daa-boyer-moore-algorithm)
+2. [https://www.cs.auckland.ac.nz/courses/compsci369s1c/lectures/GG-notes/CS369-StringAlgs.pdf](https://www.cs.auckland.ac.nz/courses/compsci369s1c/lectures/GG-notes/CS369-StringAlgs.pdf)
+3. [geeksforgeeks.org/boyer-moore-algorithm-good-suffix-heuristic/?ref=rp](geeksforgeeks.org/boyer-moore-algorithm-good-suffix-heuristic/?ref=rp)
From 48c56280516608bc4ebf91b082de37135ce97128 Mon Sep 17 00:00:00 2001
From: Shr03mink <44133832+Shr03mink@users.noreply.github.com>
Date: Tue, 12 May 2020 13:07:49 +0000
Subject: [PATCH 146/265] Go implementation of Heap Sort (#2884)
changes made in heapsort.go
reduced blank lines
Co-authored-by: unknown
---
Heap_Sort/heapsort.go | 99 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 99 insertions(+)
create mode 100644 Heap_Sort/heapsort.go
diff --git a/Heap_Sort/heapsort.go b/Heap_Sort/heapsort.go
new file mode 100644
index 000000000..16b1548d3
--- /dev/null
+++ b/Heap_Sort/heapsort.go
@@ -0,0 +1,99 @@
+/* Heap Sort is a comparison-based sorting method performed on a Heap data structure.
+ Here we build a max heap first to later sort the elements in the heap in ascending order.
+*/
+
+package main
+import "fmt"
+
+func max_heapify(arr []int, n int, i int) {
+
+ largest := i // Initialize largest as root
+ l := 2 * i + 1 // left child
+ r := 2 * i + 2 // right child
+
+ // If left child is larger than root
+ if l < n && arr[l] > arr[largest] {
+ largest = l
+ }
+
+ // If right child is larger than largest so far
+ if r < n && arr[r] > arr[largest] {
+ largest = r
+ }
+
+ // If largest is not root
+ if largest != i {
+
+ //swapping
+ arr[i], arr[largest] = arr[largest], arr[i]
+
+ // Recursively heapify the affected sub-tree
+ max_heapify(arr, n, largest)
+ }
+}
+
+func heapSort(arr []int, n int) {
+
+ // Build heap (rearrange array)
+ for i := n / 2 - 1; i >= 0; i-- {
+ max_heapify(arr, n, i)
+ }
+
+ // One by one extract an element from heap
+ for i := n - 1; i >= 0; i-- {
+
+ // Move current root to end
+ arr[0], arr[i] = arr[i], arr[0];
+
+ // call heapify on the reduced heap
+ max_heapify(arr, i, 0);
+ }
+}
+
+func printArray(arr []int, no int) {
+
+ //printing the sorted array
+ for i := 0; i < no; i++ {
+ fmt.Print(arr[i], " ")
+ }
+
+}
+
+func main() {
+ var n int
+ fmt.Println("Enter the number of elements :")
+
+ //accepting the number of elements from the user
+ fmt.Scan(&n)
+ arr := make([]int, n)
+ for i := 0; i < n; i++ {
+
+ //accepting input elements
+ fmt.Scan(&arr[i])
+ }
+ fmt.Println(arr)
+
+ fmt.Println("\nSorted array is")
+ heapSort(arr, n)
+ printArray(arr, n)
+}
+
+/* OUTPUT:
+
+Enter the number of elements : 7
+Enter the elements :
+0
+12
+11
+13
+5
+6
+7
+
+Original Array: [0 12 11 13 5 6 7]
+
+Sorted array is
+0 5 6 7 11 12 13
+
+*/
+
From 24c52a807ba7be536319417498be1f51c4cc616f Mon Sep 17 00:00:00 2001
From: Arkadip Bhattacharya
Date: Tue, 12 May 2020 18:44:31 +0530
Subject: [PATCH 147/265] Added Knuth Morris Pratt Algorithm in Kotlin (#2814)
Update KMP.kt
feat: added comments
Signed-off-by: Arkadip Bhattacharya
---
Knuth_Morris_Pratt_Algorithm/KMP.kt | 83 +++++++++++++++++++++++++++++
1 file changed, 83 insertions(+)
create mode 100644 Knuth_Morris_Pratt_Algorithm/KMP.kt
diff --git a/Knuth_Morris_Pratt_Algorithm/KMP.kt b/Knuth_Morris_Pratt_Algorithm/KMP.kt
new file mode 100644
index 000000000..8882c1623
--- /dev/null
+++ b/Knuth_Morris_Pratt_Algorithm/KMP.kt
@@ -0,0 +1,83 @@
+/*
+Knuth Morris Pratt String Searching Algorithm
+Given a text txt[0..n-1] and a pattern pat[0..m-1], the algo will find all occurrences of pat[] in txt[]
+*/
+
+import java.util.*
+
+internal class KMP {
+ fun kmpSearch(pat: String, txt: String) {
+ val m = pat.length
+ val n = txt.length
+ // longest_prefix_suffix array
+ val lps = IntArray(m)
+
+ // index for pat[]
+ var j = 0
+
+ //calculate lps[] array
+ computeLPSArray(pat, m, lps)
+
+ //index for txt[]
+ var i = 0
+ while (i < n) {
+ if (pat[j] == txt[i]) {
+ j++
+ i++
+ }
+ if (j == m) {
+ println("Found pattern at index" + (i - j))
+ j = lps[j - 1]
+ } else if (i < n && pat[j] != txt[i]) {
+ if (j != 0) j = lps[j - 1] else i += 1
+ }
+ }
+ }
+
+ // length of the previous longest prefix suffix
+ private fun computeLPSArray(pat: String, M: Int, lps: IntArray) {
+ var len = 0
+ var i = 1
+
+ //lps[0] is always 0
+ lps[0] = 0
+
+ //calculate lps[i] for i=1 to M-1
+ while (i < M)
+ {
+ if (pat[i] == pat[len]) {
+ len++
+ lps[i] = len
+ i++
+ }
+ else {
+ if (len != 0) len = lps[len - 1] else {
+ lps[i] = len
+ i++
+ }
+ }
+ }
+ }
+
+ companion object {
+ //Driver program to test above function
+ @JvmStatic
+ fun main(args: Array) {
+ val sc = Scanner(System.`in`)
+ val txt = sc.nextLine()
+ val pat = sc.nextLine()
+ KMP().kmpSearch(pat, txt)
+ }
+ }
+}
+
+/*
+Sample Input
+namanchamanbomanamansanam
+aman
+
+Sample Output:
+Patterns occur at shift = 1
+Patterns occur at shift = 7
+Patterns occur at shift = 16
+ */
From ad5c987d44a99e59499a0ffcffe9f17e422d6247 Mon Sep 17 00:00:00 2001
From: Tahanima Chowdhury
Date: Tue, 12 May 2020 19:18:11 +0600
Subject: [PATCH 148/265] Added KMP implementation in Ruby (#2555) (#2848)
---
Knuth_Morris_Pratt_Algorithm/KMP.rb | 76 +++++++++++++++++++++++++++++
1 file changed, 76 insertions(+)
create mode 100644 Knuth_Morris_Pratt_Algorithm/KMP.rb
diff --git a/Knuth_Morris_Pratt_Algorithm/KMP.rb b/Knuth_Morris_Pratt_Algorithm/KMP.rb
new file mode 100644
index 000000000..677e37f10
--- /dev/null
+++ b/Knuth_Morris_Pratt_Algorithm/KMP.rb
@@ -0,0 +1,76 @@
+# Given a text and a pattern, we need to find all occurrences of pattern in text
+
+def kmp_search(pattern, text)
+ pattern_size = pattern.length
+ text_size = text.length
+
+ lps = Array.new(pattern_size) # longest_prefix_suffix array
+ lps = calculate_lps(pattern, lps) # compute lps[]
+ i = 0 # index for pattern[]
+ j = 0 # index for text[]
+
+ while i < text_size
+ if pattern[j] == text[i]
+ i += 1
+ j += 1
+ end
+
+ if j == pattern_size
+ puts "Pattern found at #{i - j + 1}"
+ j = lps[j - 1]
+ elsif i < text_size && pattern[j] != text[i]
+ if j != 0
+ j = lps[j - 1]
+ else
+ i += 1
+ end
+ end
+ end
+end
+
+# function to preprocess lps[] to hold the longest prefix suffix values for pattern
+def calculate_lps(pattern, lps)
+ len = 0
+ lps[0] = 0
+
+ i = 1
+ while i < pattern.length
+ if pattern[i] == pattern[len]
+ len += 1
+ lps[i] = len
+ i += 1
+ else
+ if len != 0
+ len = lps[len - 1]
+ else
+ lps[i] = 0
+ i += 1
+ end
+ end
+ end
+
+ return lps
+end
+
+# Driver Code
+puts "Enter the text:"
+text = gets.chomp
+
+puts "Enter the pattern:"
+pattern = gets.chomp
+
+kmp_search(pattern, text)
+
+=begin
+Enter the text:
+namanchamanbomanamansanam
+
+Enter the pattern:
+aman
+
+Output
+
+Pattern found at 2
+Pattern found at 8
+Pattern found at 17
+=end
From 6b87d35e1a98c4fb627e2452fb7c91fede4f0df9 Mon Sep 17 00:00:00 2001
From: thakran14 <47153756+thakran14@users.noreply.github.com>
Date: Tue, 12 May 2020 18:50:03 +0530
Subject: [PATCH 149/265] Update Depth_First_Search.php (#2876)
---
Depth_First_Search/Depth_First_Search.php | 81 +++++++++++++++++++++++
1 file changed, 81 insertions(+)
create mode 100644 Depth_First_Search/Depth_First_Search.php
diff --git a/Depth_First_Search/Depth_First_Search.php b/Depth_First_Search/Depth_First_Search.php
new file mode 100644
index 000000000..85c0197be
--- /dev/null
+++ b/Depth_First_Search/Depth_First_Search.php
@@ -0,0 +1,81 @@
+// Depth First Search implementation in PHP
+
+ name = $name;
+ }
+
+ public function link_to(Node $node, $also = true)
+ {
+ if (!$this -> linked($node))
+ $this -> linked[] = $node;
+ if ($also)
+ $node -> link_to($this, false);
+ return $this;
+ }
+
+ private function linked(Node $node)
+ {
+ foreach ($this->linked as $l)
+ {
+ if ($l -> name === $node -> name)
+ return true;
+ }
+ return false;
+ }
+
+ public function not_visited_nodes($visited_names)
+ {
+ $ret = array();
+ foreach ($this -> linked as $l)
+ {
+ if (!in_array($l -> name, $visited_names)) $ret[] = $l;
+ }
+ return $ret;
+ }
+}
+
+/* Building Graph */
+$root = new Node('root');
+foreach (range(1, 6) as $v)
+{
+ $name = "node{$v}";
+ $$name = new Node($name);
+}
+
+$root -> link_to($node1) -> link_to($node2);
+$node1 -> link_to($node3) -> link_to($node4);
+$node2 -> link_to($node5) -> link_to($node6);
+$node4 -> link_to($node5);
+
+
+/* Searching Path */
+function dfs(Node $node, $path = '', $visited = array())
+{
+ $visited[] = $node -> name;
+ $not_visited = $node -> not_visited_nodes($visited);
+ if (empty($not_visited))
+ {
+ echo 'path : ' . $path . ' -> ' . $node -> name . PHP_EOL;
+ return;
+ }
+ foreach ($not_visited as $n)
+ dfs($n, $path . ' -> ' . $node -> name, $visited);
+}
+
+dfs($root);
+
+/*
+OUTPUT:
+path : -> root -> node1 -> node3
+path : -> root -> node1 -> node4 -> node5 -> node2 -> node6
+path : -> root -> node2 -> node5 -> node4 -> node1 -> node3
+path : -> root -> node2 -> node6
+*/
From da0c596a934e02b68449c9af5e5567b6a5cc8c40 Mon Sep 17 00:00:00 2001
From: Jyoti Jauhari
Date: Wed, 13 May 2020 18:52:50 +0530
Subject: [PATCH 150/265] introsort.py added in new folder named Intro_Sort
(#2895)
Update introsort.py
Update introsort.py
---
Intro_Sort/introsort.py | 101 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 101 insertions(+)
create mode 100644 Intro_Sort/introsort.py
diff --git a/Intro_Sort/introsort.py b/Intro_Sort/introsort.py
new file mode 100644
index 000000000..b8b1ab814
--- /dev/null
+++ b/Intro_Sort/introsort.py
@@ -0,0 +1,101 @@
+'''
+Introsort sort is a sorting algorithm that initially uses quicksort,
+but switches to heap sort if the depth of the recursion is too deep,
+and uses insertion sort for small cases.
+'''
+
+#a function that takes a list as argument.
+def introsort(nlist):
+
+ #maxdepth is chosen equal to 2 times floor of log base 2 of the length of the list.
+ maxdepth = (len(nlist).bit_length() - 1 ) * 2
+ # Call introsort_helper with start = 0 and end = len(alist).
+ introsort_helper(nlist, 0, len(nlist), maxdepth)
+
+#The function sorts the list from indexes start to end.
+def introsort_helper(nlist, start, end, maxdepth):
+ if end - start <= 1:
+ return
+ elif maxdepth == 0:
+ heapsort(alist, start, end)
+ else:
+ p = partition(nlist, start, end)
+ introsort_helper(nlist, start, p + 1, maxdepth - 1)
+ introsort_helper(nlist, p + 1, end, maxdepth - 1)
+
+#partition function uses Hoare partition scheme to partition the list.
+def partition(nlist, start, end):
+ pivot = nlist[start]
+ i = start - 1
+ j = end
+
+ while True:
+ i = i + 1
+ while nlist[i] < pivot:
+ i = i + 1
+ j = j - 1
+ while nlist[j] > pivot:
+ j = j - 1
+
+ if i >= j:
+ return j
+
+ swap(nlist, i, j)
+
+#function for swapping
+def swap(nlist, i, j):
+ nlist[i], nlist[j] = nlist[j], nlist[i]
+
+#heapsort from indexes start to end - 1
+def heapsort(alist, start, end):
+ build_max_heap(nlist, start, end)
+ for i in range(end - 1, start, -1):
+ swap(alist, start, i)
+ max_heapify(nlist, index = 0, start = start, end = i)
+
+#rearrange the list into a list representation of a heap.
+def build_max_heap(nlist, start, end):
+ def parent(i):
+ return (i - 1) // 2
+ length = end - start
+ index = parent(length - 1)
+ while index >= 0:
+ max_heapify(nlist, index, start, end)
+ index = index - 1
+
+#modifies the heap structure at and below the node at given index to make it satisfy the heap property.
+def max_heapify(nlist, index, start, end):
+ def left(i):
+ return 2 * i + 1
+ def right(i):
+ return 2 * i + 2
+
+ size = end - start
+ l = left(index)
+ r = right(index)
+ if (l < size and nlist[start + l] > nlist[start + index]):
+ largest = l
+ else:
+ largest = index
+ if (r < size and nlist[start + r] > nlist[start + largest]):
+ largest = r
+ if largest != index:
+ swap(alist, start + largest, start + index)
+ max_heapify(alist, largest, start, end)
+
+#taking list as input from user (dynamic input)
+nlist = input('Enter the list of numbers: ').split()
+nlist = [int(n) for n in nlist]
+introsort(nlist)
+print('Sorted list: ', end = '')
+#printing sorted list
+print(nlist)
+
+
+'''
+Sample input
+Enter the list of numbers: 8 4 3 2 1
+
+Sample output
+Sorted list: [1, 2, 3, 4, 8]
+'''
From 9c3e46faf7c5bf7a759aa498a19ccb603314be82 Mon Sep 17 00:00:00 2001
From: j-shreya <53999364+j-shreya@users.noreply.github.com>
Date: Wed, 13 May 2020 23:14:05 +0530
Subject: [PATCH 151/265] Generic tree (#2365)
* Create GENERIC_TREE_LOTRAVERSAL.java
* Update GENERIC_TREE_LOTRAVERSAL.java
* Revert "Update GENERIC_TREE_LOTRAVERSAL.java"
This reverts commit dfdd3095201cbf35c1ee673a6332a0eaf4960a88.
* Revert "Create GENERIC_TREE_LOTRAVERSAL.java"
This reverts commit 2c87bbb08c1e7f312d3e9410b7ff5423d25f1458.
* Create GenericTree_Levelorder_Traversal.java
* Update GenericTree_Levelorder_Traversal.java
* Update GenericTree_Levelorder_Traversal.java
Corrected the indentation and allignment as requested
* Update GenericTree_Levelorder_Traversal.java
All extra lines removed.
* Update GenericTree_Levelorder_Traversal.java
Removed the lines requested
---
.../GenericTree_Levelorder_Traversal.java | 94 +++++++++++++++++++
1 file changed, 94 insertions(+)
create mode 100644 GenericTree_Levelorder_Traversal/GenericTree_Levelorder_Traversal.java
diff --git a/GenericTree_Levelorder_Traversal/GenericTree_Levelorder_Traversal.java b/GenericTree_Levelorder_Traversal/GenericTree_Levelorder_Traversal.java
new file mode 100644
index 000000000..cb1726cf7
--- /dev/null
+++ b/GenericTree_Levelorder_Traversal/GenericTree_Levelorder_Traversal.java
@@ -0,0 +1,94 @@
+import java.util.ArrayList;
+import java.util.LinkedList;
+import java.util.Scanner;
+
+public class GenericTree_Levelorder_Traversal {
+ Scanner scn = new Scanner(System.in);
+
+ private class Node {
+ int data;
+ ArrayList children = new ArrayList<>();
+ }
+
+ private Node root;
+
+ public GenericTree_Levelorder_Traversal() {
+ root = takeInput(null, -1);
+ }
+
+ private Node takeInput(Node parent, int ith) {
+ if (parent == null) {
+ System.out.println("Enter the data for Root Node ?");
+ } else {
+ System.out.println(
+ "Enter data for " + ith + " child of " + parent.data);
+ }
+
+ // take input
+ int item = scn.nextInt();
+ // make a new node
+ Node nn = new Node();
+ nn.data = item;
+
+ System.out.println("No. of children for " + nn.data + " ?");
+ int noc = scn.nextInt();
+
+ for (int i = 0; i < noc; i++) {
+
+ Node child = takeInput(nn, i);
+ // add children in array list
+ nn.children.add(child);
+ }
+ return nn;
+ }
+
+ public void display() {
+ display(root);
+ }
+
+ // function to display generic tree
+ private void display(Node node) {
+ String str = node.data + " -> ";
+
+ for (Node child : node.children) {
+ str += child.data + ", ";
+ }
+
+ str += ".";
+ System.out.println(str);
+
+ for (Node child : node.children) {
+ display(child);
+ }
+ }
+
+ // level order traversal
+ public void levelorder() {
+ // create a linked list which will be used as queue
+ LinkedList queue = new LinkedList();
+ // add root node to last of queue
+ queue.addLast(root);
+
+ while (!queue.isEmpty()) {
+
+ // remove node from front and print
+ Node rn = queue.removeFirst();
+
+ System.out.print(rn.data + " ");
+
+ // add children of current node to the end of queue
+ for (Node child : rn.children) {
+ queue.addLast(child);
+ }
+ }
+ System.out.println();
+ }
+
+ public static void main(String[] args) {
+ GenericTree_Levelorder_Traversal gt = new GenericTree_Levelorder_Traversal();
+ gt.levelorder();
+ }
+}
+
+//SAMPLE INPUT: 10 3 20 2 50 0 60 0 30 0 40 0
+//OUTPUT: 10 20 30 40 50 60
From 5021c39810e9aea4fef00abc61c1d1c810744d79 Mon Sep 17 00:00:00 2001
From: Disha Sinha <42354197+disha2sinha@users.noreply.github.com>
Date: Thu, 14 May 2020 02:53:21 +0530
Subject: [PATCH 152/265] Rabin Karp in C (#2844)
Changes in file made
Changes Done in Rabin_Karp
---
Rabin_Karp/Rabin_Karp.c | 77 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 77 insertions(+)
create mode 100644 Rabin_Karp/Rabin_Karp.c
diff --git a/Rabin_Karp/Rabin_Karp.c b/Rabin_Karp/Rabin_Karp.c
new file mode 100644
index 000000000..f2df21efd
--- /dev/null
+++ b/Rabin_Karp/Rabin_Karp.c
@@ -0,0 +1,77 @@
+/*Rabin Karp algorithm is a string matching algorithm which matches the hash value of the pattern with the hash
+value of current substring of text and if the hash values match then only it starts matching individual characters*/
+
+#include
+#include
+
+void Rabin_Karp (char *text, char *pattern)
+{
+ int text_len = strlen (text);
+ int pattern_len = strlen (pattern);
+ int hash = 1;
+ int asciichars = 256;
+ int prime = 149;
+
+ for (int i = 0; i < pattern_len - 1; i++)
+ {
+ hash = (hash * asciichars) % prime;
+ // there are 256 total characters in Ascii table & 149 is a prime number chosen randomly
+ }
+ int hash_txt = 0, hash_pat = 0;
+
+ for (int i = 0; i < pattern_len; i++)
+ {
+ hash_txt = (hash_txt * asciichars + text [i]) % prime; // hash value for text
+ hash_pat = (hash_pat * asciichars + pattern [i]) % prime; // hash value for pattern
+ }
+
+ for(int i = 0; i <= text_len - pattern_len; i++)
+ {
+ int j;
+
+ if (hash_txt == hash_pat)
+ {
+ // checking if all the chars are equal in text portion & pattern
+ for (j = 0; j < pattern_len; j++)
+ {
+ if (text [i+j] != pattern [j])
+ break;
+ }
+ if (j == pattern_len)
+ {
+ printf ("\n\nPattern searched is found at position %d\n\n", i+1);
+ }
+ }
+ // finding the pattern in remaining portion of the text
+ if (i < text_len-pattern_len)
+ {
+ hash_txt = ((hash_txt - text [i] * hash) * asciichars + text [i + pattern_len]) % prime;
+ if (hash_txt < 0)
+ {
+ hash_txt = hash_txt + prime;
+ }
+ }
+ }
+}
+
+int main()
+{
+ char text [30];
+ char pattern [15];
+ printf ("Enter Text:\n");
+ scanf ("%s", text);
+ printf ("Enter Pattern to be searched:\n");
+ scanf ("%s", pattern);
+ Rabin_Karp (text, pattern);
+ return 0;
+}
+
+/* Input/Output Demo:
+Enter Text:
+bbaavcaavaavifjkdfkfaav
+Enter Pattern to be searched:
+aav
+Pattern searched is found at position 3
+Pattern searched is found at position 7
+Pattern searched is found at position 10
+Pattern searched is found at position 21 */
From 8b7e6fed1a03046727d222d0504ea4b2f6d4ec46 Mon Sep 17 00:00:00 2001
From: shweta gurnani <43384092+shwetagurnani@users.noreply.github.com>
Date: Fri, 15 May 2020 19:56:12 +0530
Subject: [PATCH 153/265] Kosaraju readme added (#2920)
---
.../Kosaraju_algorithm.cpp | 0
Kosaraju_Algorithm/readme.md | 104 ++++++++++++++++++
2 files changed, 104 insertions(+)
rename kosaraju_algorithm/kosaraju_algorithm.cpp => Kosaraju_Algorithm/Kosaraju_algorithm.cpp (100%)
create mode 100644 Kosaraju_Algorithm/readme.md
diff --git a/kosaraju_algorithm/kosaraju_algorithm.cpp b/Kosaraju_Algorithm/Kosaraju_algorithm.cpp
similarity index 100%
rename from kosaraju_algorithm/kosaraju_algorithm.cpp
rename to Kosaraju_Algorithm/Kosaraju_algorithm.cpp
diff --git a/Kosaraju_Algorithm/readme.md b/Kosaraju_Algorithm/readme.md
new file mode 100644
index 000000000..c0068c647
--- /dev/null
+++ b/Kosaraju_Algorithm/readme.md
@@ -0,0 +1,104 @@
+# Kosaraju Algorithm
+
+Kosaraju Algorithm is used to find strongly connected components in a directed graph. A directed graph is strongly connected if there is a path between all pairs of vertices.
+
+## Example
+
+Let's find strongly connected components in the directed graph given below.
+
+
+- Create an empty stack 's'. Push the vertex in the stack only after all its neighbours are visited.
+
+- Create a boolean array 'visited' to keep track of all the vertices which are visited.
+
+- Let's start the DFS from vertex 0. Mark 0 as visited. Mark the neighbour of vertex 0 i.e. 2 as visited. Now mark the neighbour of 2 i.e. 1 as visited. There is only one neighbour of 1 i.e. 0 which is already visited. So, no neighbours of 1 are left to be traversed therefore push vertex 1 into the stack. Now, backtrack. There is no neighbour of vertex 2 left to be traversed. Push 2 into the stack.
+Stack: 1, 2
+
+- Now mark the another neighbour of 0 i.e. 3 as visited. Mark the neighbour of 3 i.e. 4 as visited. There is no neighbour of 4 left to be visited. Push 4 into the stack. Similarly, push 3 into the stack.
+Stack: 1, 2, 4, 3
+
+- All neighbours of vertex 0 are marked visited. Push 0 into the stack
+Stack: 1, 2, 4, 3, 0
+
+
+
+- Reverse directions of all arcs to obtain the transpose graph. Also, initialise the boolean array 'visited' as false.
+
+- Pop a vertex from stack 's' i.e. 0. Take vertex 0 as source and do DFS. Now, DFS will print the strongly connected component of vertex 0.
+Print: 0, 1, 2
+Stack: 1, 2, 4, 3
+
+- Pop again from the stack i.e. 3. Take vertex 3 as source and do DFS. Now, DFS will print the strongly connected component of vertex 3.
+Print: 0, 1, 2
+ 3
+Stack: 1, 2, 4
+
+- Repeat the above step with vertex 4.
+Print: 0, 1, 2
+ 3
+ 4
+Stack: 1, 2
+
+- Now pop 2 from the stack. It is already marked as visited so no DFS will be performed. Similar case with vertex 1.
+Print: 0, 1, 2
+ 3
+ 4
+
+## Algorithm
+
+1. Create an empty stack ‘S’ and do DFS traversal of a graph. In DFS traversal, after calling recursive DFS for adjacent vertices of a vertex, push the vertex to stack.
+
+2. Reverse directions of all arcs to obtain the transpose graph.
+
+3. One by one pop a vertex from S while S is not empty. Let the popped vertex be ‘v’. Take v as source and do DFS (call DFSUtil(v)). The DFS starting from v prints strongly connected component of v.
+
+## Pseudocode
+```
+Declare array of vectors adj and transpose, stack st and a boolean array visited.
+Initialise all the elements of array visited with false.
+dfs(s)
+ visited[s] = true
+ for(i = 0; i < adj[s].size; i++)
+ if(visited[adj[s][i]] == false)
+ dfs(adj[s][i])
+ st.push(s)
+
+dfsUtil(s)
+ visited[s] = true
+ print(s)
+ for(i = 0; i < transpose[s].size; i++)
+ if(visited[transpose[s][i]] == false)
+ dfsUtil(transpose[s][i])
+
+Kosaraju_Algorithm(nodes, edges, adj, src)
+ dfs(0)
+ Initialise all the elements of array visited with false.
+ for(i = 0; i < stack.size; i++)
+ top = stack.top
+ stack.pop
+ if(visited[top] is false):
+ dfsUtil(top)
+ print new line
+```
+
+## Complexity
+
+ Time Complexity = O(V + E)
+ Space Complexity = O(V)
+
+where
+>V = number of vertices
+>E = number of edges
+
+## Implementation
+
+* [C# Code](https://github.com/jainaman224/Algo_Ds_Notes/blob/master/Kosaraju_Algorithm/Kosaraju_Algorithm.cs)
+* [Python Code](https://github.com/jainaman224/Algo_Ds_Notes/blob/master/Kosaraju_Algorithm/Kosaraju_Algorithm.py)
+* [C++ Code](https://github.com/jainaman224/Algo_Ds_Notes/blob/master/Kosaraju_Algorithm/Kosaraju_Algorithm.cpp)
+
+## References
+
+* [Tutorial - GeeksforGeeks](https://www.geeksforgeeks.org/strongly-connected-components/)
+* [Tutorial - OpenGenus](https://iq.opengenus.org/kosarajus-algorithm-for-strongly-connected-components/)
+* [Wikipedia](http://en.wikipedia.org/wiki/Kosaraju%27s_algorithm)
+
From 44121a0cf3bfa2ddb24d96aaa353e87240aa3077 Mon Sep 17 00:00:00 2001
From: Amit sharma <54413110+Amitsharma45@users.noreply.github.com>
Date: Fri, 15 May 2020 19:58:23 +0530
Subject: [PATCH 154/265] Create README.md (#2822)
---
Sleep_Sort/README.md | 84 ++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 84 insertions(+)
create mode 100644 Sleep_Sort/README.md
diff --git a/Sleep_Sort/README.md b/Sleep_Sort/README.md
new file mode 100644
index 000000000..6e39d8942
--- /dev/null
+++ b/Sleep_Sort/README.md
@@ -0,0 +1,84 @@
+# Sleep Sort
+
+ Sleep sort works by starting a separate task for each item to be sorted, where each task sleeps for an interval corresponding to the item's sort key, then emits the item. Items are then collected sequentially in time.
+# Example
+ Let’s assume we have a laptop that’s takes 1 seconds to work through each element.
+
+ **INPUT: 10 8 6**
+
+ - 1s 10
+ - 2s: 8
+ - 3s: 6
+ - 9s: print(6) (6 wake up so print it)
+ - 10s: print(8) (8 wake up so print it)
+ - 11s: print(10) (10 wake up so print it)
+
+ **OUTPUT : 6 8 10**
+
+ # Time complexity
+
+ - Creating multiple threads is done internally by the OS using a priority queue (used for scheduling purposes). Hence inserting all the array elements in the priority queue takes O(Nlog N) time.
+
+- Also the output is obtained only when all the threads are processed, i.e., when all the elements ‘wakes’ up. Since it takes O(arr[i]) time to wake the ith array element’s thread. So it will take a maximum of O(max_element(array)) for the largest element of the array to wake up.
+
+ - Thus overall time complexitu is ,O(NlogN + max(input))
+ ("where, N = number of elements in the input array, and input = input array elements")
+
+ # Limitations
+ - This algorithm won’t work for negative numbers as a thread cannot sleep for a negative amount of time.
+
+ # Sleep Sort Algorithm implementation in Python
+ import threading
+ import time
+
+ _lk = threading.Lock()
+
+ class SleepSortThread(threading.Thread):
+ def __init__(self, val):
+ self.val = val
+ threading.Thread.__init__(self)
+
+ def run(self):
+ global _lk
+ # Thread is made to sleep in proportion to value
+ time.sleep(self.val * 0.1)
+ # Acquire lock
+ _lk.acquire()
+ print(self.val, end = " ")
+ # Release lock
+ _lk.release()
+
+ def SleepSort(list):
+ ts = []
+ # Intialize a thread corresponding to each element in list
+ for i in list:
+ t = SleepSortThread(i)
+ ts.append(t)
+ # Start all Threads
+ for i in ts:
+ i.start()
+ # Wait for all threads to terminate
+ for i in ts:
+ i.join()
+
+ x = [2, 4, 3, 1, 6, 8, 4]
+ x = SleepSort(x)
+
+ # Output
+ # 1 2 3 4 4 6 8
+
+# Pseudocode
+
+ procedure print(n)
+ sleep n second
+ print(n)
+ end
+ for arg in args
+ run print(arg) in background
+ end
+
+ wait for all processes o finish
+
+[Reference: Geeksforgeeks](https://www.geeksforgeeks.org/sleep-sort-king-laziness-sorting-sleeping/)
+
+[Reference: Wikipedia](https://it.wikipedia.org/wiki/Sleep_sort)
From 8a262204b00582096abab091d9bbd1e704d1e366 Mon Sep 17 00:00:00 2001
From: monikajha <53649201+m-code12@users.noreply.github.com>
Date: Fri, 15 May 2020 20:01:34 +0530
Subject: [PATCH 155/265] Bucket_Sort in go (#2898)
---
Bucket_Sort/Bucket_Sort.go | 104 +++++++++++++++++++++++++++++++++++++
1 file changed, 104 insertions(+)
create mode 100644 Bucket_Sort/Bucket_Sort.go
diff --git a/Bucket_Sort/Bucket_Sort.go b/Bucket_Sort/Bucket_Sort.go
new file mode 100644
index 000000000..7a7d11022
--- /dev/null
+++ b/Bucket_Sort/Bucket_Sort.go
@@ -0,0 +1,104 @@
+/*
+ Bucket Sort Implementation in GO
+ ---------------------------------------------------
+ Bucket Sort
+ ---------------------------------------------------
+Bucket Sort is a sorting technique that sorts the elements by first dividing the elements into several groups called buckets.
+The elements inside each bucket are sorted using any of the suitable sorting algorithms or recursively calling the same algorithm.
+Several buckets are created. Each bucket is filled with a specific range of elements.
+The elements inside the bucket are sorted using any other algorithm. Finally, the elements of the bucket are gathered to get the sorted array.
+The process of bucket sort can be understood as a scatter-gather approach. The elements are first scattered into buckets then
+the elements of buckets are sorted.
+
+Bucket sort is used when:
+-> input is uniformly distributed over a range.
+-> there are floating point values
+*/
+
+
+package main
+
+import (
+ "fmt"
+ "os"
+ "strconv"
+)
+
+func insertionSort(array []float64) {
+ for i := 0; i < len(array); i++ {
+ temp := array[i]
+ j := i - 1
+ for ; j >= 0 && array[j] > temp; j-- {
+ array[j + 1] = array[j]
+ }
+ array[j + 1] = temp
+ }
+}
+
+func bucketSort(array []float64, bucketSize int) []float64 {
+ var max, min float64
+ for _, n := range array {
+ if n < min {
+ min = n
+ }
+ if n > max {
+ max = n
+ }
+ }
+
+ nBuckets := int(max-min) / bucketSize + 1
+ buckets := make([][]float64, nBuckets)
+ for i := 0; i < nBuckets; i++ {
+ buckets[i] = make([]float64, 0)
+ }
+
+ for _, n := range array {
+ idx := int(n-min) / bucketSize
+ buckets[idx] = append(buckets[idx], n)
+ }
+
+ sorted := make([]float64, 0)
+ for _, bucket := range buckets {
+ if len(bucket) > 0 {
+ insertionSort(bucket)
+ sorted = append(sorted, bucket...)
+ }
+ }
+ return sorted
+}
+
+func main() {
+ var x int
+ fmt.Printf("Enter the size of the array : ")
+ fmt.Scan(&x)
+ fmt.Printf("Enter the elements of the array : ")
+ a := make([]float64, x)
+ for i := 0; i < x; i++ {
+ fmt.Scan(&a[i])
+ }
+
+ array := a // A copy of the array 'a' is assigned to 'array'
+ for _, arg := range os.Args[1:] {
+ if n, err := strconv.ParseFloat(arg, 64); err == nil {
+ array = append(array, n)
+ }
+ }
+
+ fmt.Printf("The array before sorting is %v\n", array)
+ array = bucketSort(array, 5)
+ fmt.Printf("The array after sorting is %v\n", array)
+}
+
+
+/*
+
+ Sample Input :
+ Enter the size of the array : 3
+ Enter the elements of the array : 2 8 5
+
+ Sample Output :
+ The array before sorting is [2 8 5]
+ The array after sorting is [2 5 8]
+
+*/
+
From a675575be4711bed74bb85791fb5ada365062cec Mon Sep 17 00:00:00 2001
From: Ritish Singh
Date: Fri, 15 May 2020 22:31:41 +0530
Subject: [PATCH 156/265] Red Black Tree implementation in C# (#2924)
---
Red_Black_Tree/Red_Black_Tree.cs | 554 +++++++++++++++++++++++++++++++
1 file changed, 554 insertions(+)
create mode 100644 Red_Black_Tree/Red_Black_Tree.cs
diff --git a/Red_Black_Tree/Red_Black_Tree.cs b/Red_Black_Tree/Red_Black_Tree.cs
new file mode 100644
index 000000000..da8abef36
--- /dev/null
+++ b/Red_Black_Tree/Red_Black_Tree.cs
@@ -0,0 +1,554 @@
+using System;
+
+namespace Declaring_Methods
+{
+ public static class Program
+ {
+ public static void Main(String[] args)
+ {
+ RedBlackTree bst = new RedBlackTree();
+ bst.insert(54);
+ bst.insert(38);
+ bst.insert(62);
+ bst.insert(58);
+ bst.insert(73);
+ bst.insert(55);
+ bst.printTree();
+ Console.WriteLine("\nAfter deleting:");
+ bst.deleteNode(40);
+ bst.printTree();
+ }
+ public class Node
+ {
+ public int data;
+ public Node parent;
+ public Node left;
+ public Node right;
+ public int color;
+ }
+
+ public class RedBlackTree
+ {
+ public Node root;
+ public Node TNULL;
+
+ //PreOder Traversal
+ public void PreOder(Node node)
+ {
+ if (node != TNULL)
+ {
+ Console.Write(node.data + " ");
+ PreOder(node.left);
+ PreOder(node.right);
+ }
+ }
+
+ //InOder Traversal
+ public void InOrder(Node node)
+ {
+ if (node != TNULL)
+ {
+ InOrder(node.left);
+ Console.Write(node.data + " ");
+ InOrder(node.right);
+ }
+ }
+
+ //PostOder Traversal
+ public void PostOrder(Node node)
+ {
+ if (node != TNULL)
+ {
+ PostOrder(node.left);
+ PostOrder(node.right);
+ Console.Write(node.data + " ");
+ }
+ }
+
+ //Searching in the Tree
+ public Node searchTreeHelper(Node node, int key)
+ {
+ if (node == TNULL || key == node.data)
+ {
+ return node;
+ }
+
+ if (key < node.data)
+ {
+ return searchTreeHelper(node.left, key);
+ }
+ return searchTreeHelper(node.right, key);
+ }
+
+ // Balance the tree after deletion of a node
+ public void fixDelete(Node x)
+ {
+ Node s;
+ while (x != root && x.color == 0)
+ {
+ if (x == x.parent.left)
+ {
+ s = x.parent.right;
+ if (s.color == 1)
+ {
+ s.color = 0;
+ x.parent.color = 1;
+ leftRotate(x.parent);
+ s = x.parent.right;
+ }
+
+ if (s.left.color == 0 && s.right.color == 0)
+ {
+ s.color = 1;
+ x = x.parent;
+ }
+ else
+ {
+ if (s.right.color == 0)
+ {
+ s.left.color = 0;
+ s.color = 1;
+ rightRotate(s);
+ s = x.parent.right;
+ }
+
+ s.color = x.parent.color;
+ x.parent.color = 0;
+ s.right.color = 0;
+ leftRotate(x.parent);
+ x = root;
+ }
+ }
+ else
+ {
+ s = x.parent.left;
+ if (s.color == 1)
+ {
+ s.color = 0;
+ x.parent.color = 1;
+ rightRotate(x.parent);
+ s = x.parent.left;
+ }
+
+ if (s.right.color == 0 && s.right.color == 0)
+ {
+ s.color = 1;
+ x = x.parent;
+ }
+ else
+ {
+ if (s.left.color == 0)
+ {
+ s.right.color = 0;
+ s.color = 1;
+ leftRotate(s);
+ s = x.parent.left;
+ }
+
+ s.color = x.parent.color;
+ x.parent.color = 0;
+ s.left.color = 0;
+ rightRotate(x.parent);
+ x = root;
+ }
+ }
+ }
+ x.color = 0;
+ }
+
+ public void rbTransplant(Node u, Node v)
+ {
+ if (u.parent == null)
+ {
+ root = v;
+ }
+ else if (u == u.parent.left)
+ {
+ u.parent.left = v;
+ }
+ else
+ {
+ u.parent.right = v;
+ }
+ v.parent = u.parent;
+ }
+
+ //Deleting the Node element
+ public void deleteNodeHelper(Node node, int key)
+ {
+ Node z = TNULL;
+ Node x, y;
+ while (node != TNULL)
+ {
+ if (node.data == key)
+ {
+ z = node;
+ }
+
+ if (node.data <= key)
+ {
+ node = node.right;
+ }
+ else
+ {
+ node = node.left;
+ }
+ }
+
+ if (z == TNULL)
+ {
+ Console.WriteLine("Couldn't find key in the tree");
+ return;
+ }
+
+ y = z;
+ int yOriginalColor = y.color;
+ if (z.left == TNULL)
+ {
+ x = z.right;
+ rbTransplant(z, z.right);
+ }
+ else if (z.right == TNULL)
+ {
+ x = z.left;
+ rbTransplant(z, z.left);
+ }
+ else
+ {
+ y = minimum(z.right);
+ yOriginalColor = y.color;
+ x = y.right;
+ if (y.parent == z)
+ {
+ x.parent = y;
+ }
+ else
+ {
+ rbTransplant(y, y.right);
+ y.right = z.right;
+ y.right.parent = y;
+ }
+
+ rbTransplant(z, y);
+ y.left = z.left;
+ y.left.parent = y;
+ y.color = z.color;
+ }
+ if (yOriginalColor == 0)
+ {
+ fixDelete(x);
+ }
+ }
+
+ // Balance the node after insertion
+ public void fixInsert(Node k)
+ {
+ Node u;
+ while (k.parent.color == 1)
+ {
+ if (k.parent == k.parent.parent.right)
+ {
+ u = k.parent.parent.left;
+ if (u.color == 1)
+ {
+ u.color = 0;
+ k.parent.color = 0;
+ k.parent.parent.color = 1;
+ k = k.parent.parent;
+ }
+ else
+ {
+ if (k == k.parent.left)
+ {
+ k = k.parent;
+ rightRotate(k);
+ }
+ k.parent.color = 0;
+ k.parent.parent.color = 1;
+ leftRotate(k.parent.parent);
+ }
+ }
+ else
+ {
+ u = k.parent.parent.right;
+
+ if (u.color == 1)
+ {
+ u.color = 0;
+ k.parent.color = 0;
+ k.parent.parent.color = 1;
+ k = k.parent.parent;
+ }
+ else
+ {
+ if (k == k.parent.right)
+ {
+ k = k.parent;
+ leftRotate(k);
+ }
+ k.parent.color = 0;
+ k.parent.parent.color = 1;
+ rightRotate(k.parent.parent);
+ }
+ }
+ if (k == root)
+ {
+ break;
+ }
+ }
+ root.color = 0;
+ }
+
+ //Printing the Tree
+ public void printHelper(Node root, String indent, bool last)
+ {
+ if (root != TNULL)
+ {
+ Console.Write(indent);
+ if (last)
+ {
+ Console.Write("R----");
+ indent += " ";
+ }
+ else
+ {
+ Console.Write("L----");
+ indent += "| ";
+ }
+
+ String sColor = root.color == 1 ? "RED" : "BLACK";
+ Console.WriteLine(root.data + "(" + sColor + ")");
+ printHelper(root.left, indent, false);
+ printHelper(root.right, indent, true);
+ }
+ }
+
+ public RedBlackTree()
+ {
+ TNULL = new Node();
+ TNULL.color = 0;
+ TNULL.left = null;
+ TNULL.right = null;
+ root = TNULL;
+ }
+
+ // PreOder Traversal
+ public void preorder()
+ {
+ PreOder(this.root);
+ }
+
+ //InOder Traversal
+ public void inorder()
+ {
+ InOrder(this.root);
+ }
+
+ //Post Oder Traversal
+ public void postorder()
+ {
+ PostOrder(this.root);
+ }
+
+ //Searching in the tree
+ public Node searchTree(int k)
+ {
+ return searchTreeHelper(this.root, k);
+ }
+
+ //Finding the minimum Node element
+ public Node minimum(Node node)
+ {
+ while (node.left != TNULL)
+ {
+ node = node.left;
+ }
+ return node;
+ }
+
+ //Finding the maximum Node element
+ public Node maximum(Node node)
+ {
+ while (node.right != TNULL)
+ {
+ node = node.right;
+ }
+ return node;
+ }
+
+ //Find the Successor of the element
+ public Node successor(Node x)
+ {
+ if (x.right != TNULL)
+ {
+ return minimum(x.right);
+ }
+
+ Node y = x.parent;
+ while (y != TNULL && x == y.right)
+ {
+ x = y;
+ y = y.parent;
+ }
+ return y;
+ }
+
+ //Finding the Predecessor of the element
+ public Node predecessor(Node x)
+ {
+ if (x.left != TNULL)
+ {
+ return maximum(x.left);
+ }
+
+ Node y = x.parent;
+ while (y != TNULL && x == y.left)
+ {
+ x = y;
+ y = y.parent;
+ }
+
+ return y;
+ }
+
+ //Left Rotation
+ public void leftRotate(Node x)
+ {
+ Node y = x.right;
+ x.right = y.left;
+ if (y.left != TNULL)
+ {
+ y.left.parent = x;
+ }
+ y.parent = x.parent;
+ if (x.parent == null)
+ {
+ this.root = y;
+ }
+ else if (x == x.parent.left)
+ {
+ x.parent.left = y;
+ }
+ else
+ {
+ x.parent.right = y;
+ }
+ y.left = x;
+ x.parent = y;
+ }
+
+ //Right Rotation
+ public void rightRotate(Node x)
+ {
+ Node y = x.left;
+ x.left = y.right;
+ if (y.right != TNULL)
+ {
+ y.right.parent = x;
+ }
+ y.parent = x.parent;
+ if (x.parent == null)
+ {
+ this.root = y;
+ }
+ else if (x == x.parent.right)
+ {
+ x.parent.right = y;
+ }
+ else
+ {
+ x.parent.left = y;
+ }
+ y.right = x;
+ x.parent = y;
+ }
+
+ //Inserting Key to Tree
+ public void insert(int key)
+ {
+ Node node = new Node();
+ node.parent = null;
+ node.data = key;
+ node.left = TNULL;
+ node.right = TNULL;
+ node.color = 1;
+
+ Node y = null;
+ Node x = this.root;
+
+ while (x != TNULL)
+ {
+ y = x;
+ if (node.data < x.data)
+ {
+ x = x.left;
+ }
+ else
+ {
+ x = x.right;
+ }
+ }
+
+ node.parent = y;
+ if (y == null)
+ {
+ root = node;
+ }
+ else if (node.data < y.data)
+ {
+ y.left = node;
+ }
+ else
+ {
+ y.right = node;
+ }
+
+ if (node.parent == null)
+ {
+ node.color = 0;
+ return;
+ }
+
+ if (node.parent.parent == null)
+ {
+ return;
+ }
+
+ fixInsert(node);
+ }
+
+ //Getting the Root element of the tree
+ public Node getRoot()
+ {
+ return this.root;
+ }
+
+ //Delete Node
+ public void deleteNode(int data)
+ {
+ deleteNodeHelper(this.root, data);
+ }
+
+ //Print the Tree
+ public void printTree()
+ {
+ printHelper(this.root, " ", true);
+ }
+ }
+ }
+}
+/*R----54(BLACK)
+ L----38(BLACK)
+ R----62(RED)
+ L----58(BLACK)
+ | L----55(RED)
+ R----73(BLACK)
+
+After deleting:
+Couldn't find key in the tree
+ R----54(BLACK)
+ L----38(BLACK)
+ R----62(RED)
+ L----58(BLACK)
+ | L----55(RED)
+ R----73(BLACK)*/
From ffb5a2cca7ec4800bbe29fd2e1f0f07e47c9a3a1 Mon Sep 17 00:00:00 2001
From: Rukmini Meda <44504940+Rukmini-Meda@users.noreply.github.com>
Date: Sun, 17 May 2020 13:30:41 +0530
Subject: [PATCH 157/265] AVL Tree implemented in Dart (#2914)
---
AVL_Tree/AVL_Tree.dart | 321 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 321 insertions(+)
create mode 100644 AVL_Tree/AVL_Tree.dart
diff --git a/AVL_Tree/AVL_Tree.dart b/AVL_Tree/AVL_Tree.dart
new file mode 100644
index 000000000..a0e496ebd
--- /dev/null
+++ b/AVL_Tree/AVL_Tree.dart
@@ -0,0 +1,321 @@
+/**
+ * ------------------------------------------------
+ * AVL Tree implementation in Dart
+ * ------------------------------------------------
+ *
+ * AVL Tree is a binary search tree that provides insertion, deletion
+ * and search in O(logn) time in all cases. It is an improvement over BST as a BST can
+ * take O(n) time when the tree takes a linear shape whereas AVL tree takes O(logn) time
+ * in all cases as it balances the tree using various rotations.
+ *
+ * AVL tree is preferred when insertions and deletions are less frequent and search is a
+ * more frequent operation.
+ *
+ * References - Geeksforgeeks
+ *
+ */
+
+// Importing required libraries
+import 'dart:io';
+import 'dart:math';
+
+// Class definition for a tree node.
+class Node{
+ int value;
+ Node left , right;
+ int height;
+
+ Node(value){
+ this.value = value;
+ this.left = null;
+ this.right = null;
+ this.height = 1;
+ }
+}
+
+// Class defintion for an AVL tree.
+class AVL_Tree{
+ Node root;
+
+ // Utility function to print the tree in preorder traversal.
+ void print_AVL(Node root){
+ if(root != null){
+ print(root.value);
+ print_AVL(root.left);
+ print_AVL(root.right);
+ }
+ }
+
+ // Utility function to find the height of the tree.
+ int height(Node node){
+ if(node == null){
+ return 0;
+ }
+ return node.height;
+ }
+
+ // Utility function ro find the balance of the tree.
+ int balance(Node node){
+ if(node == null){
+ return 0;
+ }
+ return height(node.left) - height(node.right);
+ }
+
+ //Utility function for right rotation
+ Node rightRotate(Node root){
+ Node z = root , y = root.left , x = y.left;
+ Node c2 = root.left.right;
+ y.right = z;
+ y.left = x;
+ z.left = c2;
+ y.height = 1 + max(height(y.left) , height(y.right));
+ x.height = 1 + max(height(x.left) , height(x.right));
+ z.height = 1 + max(height(z.left) , height(z.right));
+ return y;
+ }
+
+ // Utility function for left rotation
+ Node leftRotate(Node root){
+ Node z = root , y = root.right , x = y.right;
+ Node c2 = y.left;
+ y.left = z;
+ y.right = x;
+ z.right = c2;
+ y.height = 1 + max(height(y.left) , height(y.right));
+ x.height = 1 + max(height(x.left) , height(x.right));
+ z.height = 1 + max(height(z.left) , height(z.right));
+ return y;
+ }
+
+ // Utility function for leftRight rotation
+ Node leftRightRotate(Node root){
+ Node z = root , y = root.left , x = y.right;
+ Node c1 = z.right , c2 = y.left , c3 = x.left , c4 = x.right;
+ x.right = z;
+ x.left = y;
+ y.left = c2;
+ y.right = c3;
+ z.left = c4;
+ z.right = c1;
+ y.height = 1 + max(height(y.left) , height(y.right));
+ x.height = 1 + max(height(x.left) , height(x.right));
+ z.height = 1 + max