Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Multiple Algorithms, Updated Readme, Restructure Few Directories #90

Closed
wants to merge 31 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
7f043ef
Create Merge_Sort.py
Toulik-Das Oct 7, 2020
29b83bf
Rename euclidean algorithm.c to euclidean_algorithm.c
Toulik-Das Oct 7, 2020
2798285
Rename maximum_pairwise_sum.py to MaxPairProduct.py
Toulik-Das Oct 7, 2020
c3feb77
Rename maximum_parwise.ipynb to MaxPairProduct.ipynb
Toulik-Das Oct 7, 2020
d4ffb32
Rename minimum_elements_with_difference_one_or_zero.ipynb to Minimum_…
Toulik-Das Oct 7, 2020
7a569f0
Rename DamianArado.c to Seive of Eratosthenes.c
Toulik-Das Oct 7, 2020
8ce1fed
Rename Seive_of_erat...cpp to Seive of Eratosthenes.cpp
Toulik-Das Oct 7, 2020
99e2a46
Rename Seive of Eratosthenes.c to Seive of Eratosthenes2.c
Toulik-Das Oct 7, 2020
1417701
Rename SieveOfEratosthenes.java to Seive of Eratosthenes.java
Toulik-Das Oct 7, 2020
96f015e
Delete .gitignore
Toulik-Das Oct 7, 2020
3a85e92
Rename knapsack_problem_in_oops.py to knapsack_problem(Using Object O…
Toulik-Das Oct 7, 2020
3fa2202
Rename BinarySearchMain.java to Binary Search.java
Toulik-Das Oct 7, 2020
c974845
Rename PerfectSquare-BSearch.c to PerfectSquare-Binary Search.c
Toulik-Das Oct 7, 2020
eacd3a7
Rename perfect_square.ipynb to Perfect_square using Binary Search.ipynb
Toulik-Das Oct 7, 2020
0cce028
Create bubbleSort.py
Toulik-Das Oct 7, 2020
9c1b143
Create Radix Sort.cpp
Toulik-Das Oct 7, 2020
88567a7
Update Radix Sort.cpp
Toulik-Das Oct 7, 2020
ded98e1
Create Radix Sort.java
Toulik-Das Oct 7, 2020
ab68209
Rename QuickSortMain.java to QuickSort.java
Toulik-Das Oct 7, 2020
595f7f1
Rename quick_sort_recursion.ipynb to quick_sort_using_recursion.ipynb
Toulik-Das Oct 7, 2020
3cd4400
Update README.md
Toulik-Das Oct 7, 2020
a760300
Update README.md
Toulik-Das Oct 7, 2020
b520253
Update README.md
Toulik-Das Oct 7, 2020
51aba9b
Update README.md
Toulik-Das Oct 7, 2020
814e722
Update README.md
Toulik-Das Oct 7, 2020
4c4eedb
Update README.md
Toulik-Das Oct 7, 2020
b2f46c8
Update README.md
Toulik-Das Oct 7, 2020
d46de1d
Update README.md
Toulik-Das Oct 7, 2020
4008bb9
Update README.md
Toulik-Das Oct 7, 2020
07ace81
Update README.md
Toulik-Das Oct 7, 2020
858531e
Update README.md
Toulik-Das Oct 7, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,4 @@
]
}
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@ int main(void)



}
}
4 changes: 0 additions & 4 deletions Algorithms/Greedy_Algorithms/.gitignore

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ def get_max(weights,values):
weights=[10,40,20,30]
values=[60,40,100,120]
max_value=final_value.get_max(weights,values)
print(max_value)
print(max_value)
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,4 @@
]
}
]
}
}
25 changes: 25 additions & 0 deletions Algorithms/Sorting_Algorithms/Bubble_Sort/bubbleSort.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
def bubbleSort(arr):
n = len(arr)

# Traverse through all array elements
for i in range(n-1):
# range(n) also work but outer loop will repeat one time more than needed.

# Last i elements are already in place
for j in range(0, n-i-1):

# traverse the array from 0 to n-i-1
# Swap if the element found is greater
# than the next element
if arr[j] > arr[j+1] :
arr[j], arr[j+1] = arr[j+1], arr[j]

# Driver code to test above
arr = []
arr = [int(item) for item in input().split()]

bubbleSort(arr)

print ("Sorted array is:")
for i in range(len(arr)):
print ("%d" %arr[i])
70 changes: 70 additions & 0 deletions Algorithms/Sorting_Algorithms/Merge Sort/Merge_Sort.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
def merge(arr, l, m, r):
n1 = m - l + 1
n2 = r- m

# create temp arrays
L = [0] * (n1)
R = [0] * (n2)

# Copy data to temp arrays L[] and R[]
for i in range(0 , n1):
L[i] = arr[l + i]

for j in range(0 , n2):
R[j] = arr[m + 1 + j]

# Merge the temp arrays back into arr[l..r]
i = 0 # Initial index of first subarray
j = 0 # Initial index of second subarray
k = l # Initial index of merged subarray

while i < n1 and j < n2 :
if L[i] <= R[j]:
arr[k] = L[i]
i += 1
else:
arr[k] = R[j]
j += 1
k += 1

# Copy the remaining elements of L[], if there
# are any
while i < n1:
arr[k] = L[i]
i += 1
k += 1

# Copy the remaining elements of R[], if there
# are any
while j < n2:
arr[k] = R[j]
j += 1
k += 1

# l is for left index and r is right index of the
# sub-array of arr to be sorted
def mergeSort(arr,l,r):
if l < r:

# Same as (l+r)//2, but avoids overflow for
# large l and h
m = (l+(r-1))//2

# Sort first and second halves
mergeSort(arr, l, m)
mergeSort(arr, m+1, r)
merge(arr, l, m, r)


# Driver code to test above
arr = []
arr = [int(item) for item in input().split()]
n = len(arr)
print ("Given array is")
for i in range(n):
print ("%d" %arr[i]),

mergeSort(arr,0,n-1)
print ("\n\nSorted array is")
for i in range(n):
print ("%d" %arr[i]),
76 changes: 76 additions & 0 deletions Algorithms/Sorting_Algorithms/Radix Sort/Radix Sort.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// C++ implementation of Radix Sort
#include <iostream>
using namespace std;

// A utility function to get maximum value in arr[]
int getMax(int arr[], int n)
{
int mx = arr[0];
for (int i = 1; i < n; i++)
if (arr[i] > mx)
mx = arr[i];
return mx;
}

// A function to do counting sort of arr[] according to
// the digit represented by exp.
void countSort(int arr[], int n, int exp)
{
int output[n]; // output array
int i, count[10] = { 0 };

// Store count of occurrences in count[]
for (i = 0; i < n; i++)
count[(arr[i] / exp) % 10]++;

// Change count[i] so that count[i] now contains actual
// position of this digit in output[]
for (i = 1; i < 10; i++)
count[i] += count[i - 1];

// Build the output array
for (i = n - 1; i >= 0; i--) {
output[count[(arr[i] / exp) % 10] - 1] = arr[i];
count[(arr[i] / exp) % 10]--;
}

// Copy the output array to arr[], so that arr[] now
// contains sorted numbers according to current digit
for (i = 0; i < n; i++)
arr[i] = output[i];
}

// The main function to that sorts arr[] of size n using
// Radix Sort
void radixsort(int arr[], int n)
{
// Find the maximum number to know number of digits
int m = getMax(arr, n);

// Do counting sort for every digit. Note that instead
// of passing digit number, exp is passed. exp is 10^i
// where i is current digit number
for (int exp = 1; m / exp > 0; exp *= 10)
countSort(arr, n, exp);
}

// A utility function to print an array
void print(int arr[], int n)
{
for (int i = 0; i < n; i++)
cout << arr[i] << " ";
}

int main()
{
int arr[1000];
for(int i=0;i<1000;i++){
cin>>arr[i];
}
int n = sizeof(arr) / sizeof(arr[0]);

// Function Call
radixsort(arr, n);
print(arr, n);
return 0;
}
92 changes: 92 additions & 0 deletions Algorithms/Sorting_Algorithms/Radix Sort/Radix Sort.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
// Radix sort Java implementation
import java.io.*;
import java.util.*;

class Radix {

// A utility function to get maximum value in arr[]
static int getMax(int arr[], int n)
{
int mx = arr[0];
for (int i = 1; i < n; i++)
if (arr[i] > mx)
mx = arr[i];
return mx;
}

// A function to do counting sort of arr[] according to
// the digit represented by exp.
static void countSort(int arr[], int n, int exp)
{
int output[] = new int[n]; // output array
int i;
int count[] = new int[10];
Arrays.fill(count, 0);

// Store count of occurrences in count[]
for (i = 0; i < n; i++)
count[(arr[i] / exp) % 10]++;

// Change count[i] so that count[i] now contains
// actual position of this digit in output[]
for (i = 1; i < 10; i++)
count[i] += count[i - 1];

// Build the output array
for (i = n - 1; i >= 0; i--) {
output[count[(arr[i] / exp) % 10] - 1] = arr[i];
count[(arr[i] / exp) % 10]--;
}

// Copy the output array to arr[], so that arr[] now
// contains sorted numbers according to curent digit
for (i = 0; i < n; i++)
arr[i] = output[i];
}

// The main function to that sorts arr[] of size n using
// Radix Sort
static void radixsort(int arr[], int n)
{
// Find the maximum number to know number of digits
int m = getMax(arr, n);

// Do counting sort for every digit. Note that
// instead of passing digit number, exp is passed.
// exp is 10^i where i is current digit number
for (int exp = 1; m / exp > 0; exp *= 10)
countSort(arr, n, exp);
}

// A utility function to print an array
static void print(int arr[], int n)
{
for (int i = 0; i < n; i++)
System.out.print(arr[i] + " ");
}

/*Driver Code*/
public static void main(String[] args)
{
Scanner s=new Scanner(System.in);

System.out.println("enter number of elements: ");
int n=s.nextInt();

int arr[]=new int[n];

System.out.println("Enter array elements: ");

for(int i=0;i<n;i++){
//for reading array
arr[i]=s.nextInt();

}

int n = arr.length;

// Function Call
radixsort(arr, n);
print(arr, n);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,4 @@
]
}
]
}
}
Loading