From 81a74633f751fa52b42c24a3605d8994eab24c84 Mon Sep 17 00:00:00 2001 From: "@2001!" <59911272+ErzaTitania-2001@users.noreply.github.com> Date: Tue, 15 Dec 2020 20:48:11 +0530 Subject: [PATCH 01/14] Strong Number Using Indirect Recursion Math Programs (WoC) #1527 --- Java/math/StrongRecursion.java | 47 ++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 Java/math/StrongRecursion.java diff --git a/Java/math/StrongRecursion.java b/Java/math/StrongRecursion.java new file mode 100644 index 0000000000..6395c3b247 --- /dev/null +++ b/Java/math/StrongRecursion.java @@ -0,0 +1,47 @@ +//checking for a strong number using indirect recursion +import java.util.*; +class StrongRecursion +{ + public static int sofd(int n) //recursive function for sum of factorial of digits + + { + if(n==0) + return n; + else + return (factorial(n%10)+sofd(n/10)); + + } + + public static int factorial(int n) //factorial of n + { + if (n == 0) + return 1; + else + return(n * factorial(n-1)); + } + + public static void main() + { + Scanner sc=new Scanner(System.in); + System.out.print(" N = "); + int num=sc.nextInt(); + if(num==sofd(num)) + System.out.println(" It is a Strong Number"); + else + System.out.println(" It is not a Strong Number"); + } +} + +/* Sample Input And Output ; + * N = 145 + * It is a Strong Number + * N = 534 + * It is not a Strong Number + * + * + * Time Complexity : O(n) + * Space Complexity : 1 + * + * + */ + \ No newline at end of file From 5789e014d34e098e14e35805e908264d759a10de Mon Sep 17 00:00:00 2001 From: "@2001!" <59911272+ErzaTitania-2001@users.noreply.github.com> Date: Tue, 15 Dec 2020 20:50:14 +0530 Subject: [PATCH 02/14] Updated Indirect Recursion for Strong Number Math Programs (WoC) #1527 --- Java/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/Java/README.md b/Java/README.md index 7a3f5f6a48..8a07689d22 100644 --- a/Java/README.md +++ b/Java/README.md @@ -100,6 +100,7 @@ _add list here_ - [Sieve of Eratosthenes](math/SieveOfEratosthenes.java) - [Catalan Number](math/CatalanNumber.java) - [Palindrome Number Using Recursion](math/PalindromeRecursion.java) +- [Strong Number Using Recursion] (math/StrongRecursion.java) ## Dynamic Programming From 42babaf271b74a4ca88ab6949d3bf0b2d92c30a1 Mon Sep 17 00:00:00 2001 From: "@2001!" <59911272+ErzaTitania-2001@users.noreply.github.com> Date: Tue, 15 Dec 2020 20:52:17 +0530 Subject: [PATCH 03/14] Update README.md --- Java/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Java/README.md b/Java/README.md index 8a07689d22..78fe64b8d0 100644 --- a/Java/README.md +++ b/Java/README.md @@ -100,7 +100,7 @@ _add list here_ - [Sieve of Eratosthenes](math/SieveOfEratosthenes.java) - [Catalan Number](math/CatalanNumber.java) - [Palindrome Number Using Recursion](math/PalindromeRecursion.java) -- [Strong Number Using Recursion] (math/StrongRecursion.java) +- [Strong Number Using Recursion](math/StrongRecursion.java) ## Dynamic Programming From ddd9036f38f9de4b2dad361a742b2002fd46a6d5 Mon Sep 17 00:00:00 2001 From: "@2001!" <59911272+ErzaTitania-2001@users.noreply.github.com> Date: Wed, 16 Dec 2020 10:49:56 +0530 Subject: [PATCH 04/14] Updated file Added description of algorithm/code Changed function name Modified comment lines Made user input more friendly Added new line at the EOF --- Java/math/StrongRecursion.java | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/Java/math/StrongRecursion.java b/Java/math/StrongRecursion.java index 6395c3b247..bd1f1a9d40 100644 --- a/Java/math/StrongRecursion.java +++ b/Java/math/StrongRecursion.java @@ -1,8 +1,16 @@ -//checking for a strong number using indirect recursion + +/* checking for a strong number using indirect recursion +Strong Number = 145 +1! + 4! + 5! =145 +sumOfFactorialOfDigit(int n) - extracts digit of n and calls factorial(n). Returns sum of factorial of digits +factorial(n)- returns factorial of extracted digits passed in the argument*/ + + import java.util.*; class StrongRecursion -{ - public static int sofd(int n) //recursive function for sum of factorial of digits +{ + /*recursive function for sum of factorial of digits*/ + public static int sumOfFactorialOfDigit(int n) { if(n==0) @@ -11,8 +19,8 @@ public static int sofd(int n) //recursive function for sum of factorial of digit return (factorial(n%10)+sofd(n/10)); } - - public static int factorial(int n) //factorial of n + /*recursive function to find the factorial of n */ + public static int factorial(int n) { if (n == 0) return 1; @@ -23,9 +31,9 @@ public static int factorial(int n) //factorial of n public static void main() { Scanner sc=new Scanner(System.in); - System.out.print(" N = "); + System.out.print(" Enter Number. N = "); int num=sc.nextInt(); - if(num==sofd(num)) + if(num==sumOfFactorialOfDigit(num)) System.out.println(" It is a Strong Number"); else System.out.println(" It is not a Strong Number"); @@ -44,4 +52,5 @@ public static void main() * * */ - \ No newline at end of file + + From 911e328f7055f896e941d95459d5f4a25c70b3ea Mon Sep 17 00:00:00 2001 From: "@2001!" <59911272+ErzaTitania-2001@users.noreply.github.com> Date: Wed, 16 Dec 2020 15:23:48 +0530 Subject: [PATCH 05/14] Update StrongRecursion.java Removed extra lines of code Formatted space around operators --- Java/math/StrongRecursion.java | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/Java/math/StrongRecursion.java b/Java/math/StrongRecursion.java index bd1f1a9d40..25deab59be 100644 --- a/Java/math/StrongRecursion.java +++ b/Java/math/StrongRecursion.java @@ -13,19 +13,19 @@ class StrongRecursion public static int sumOfFactorialOfDigit(int n) { - if(n==0) + if(n == 0) return n; else - return (factorial(n%10)+sofd(n/10)); + return(factorial(n % 10)+sofd(n / 10)); } /*recursive function to find the factorial of n */ public static int factorial(int n) { - if (n == 0) + if(n == 0) return 1; else - return(n * factorial(n-1)); + return(n * factorial(n - 1)); } public static void main() @@ -45,12 +45,8 @@ public static void main() * It is a Strong Number * N = 534 * It is not a Strong Number - * - * - * Time Complexity : O(n) + Time Complexity : O(n) * Space Complexity : 1 - * - * - */ + */ From b4461b0844c1014c35cf9ac8402bc36cfa02f254 Mon Sep 17 00:00:00 2001 From: "@2001!" <59911272+ErzaTitania-2001@users.noreply.github.com> Date: Wed, 16 Dec 2020 15:26:00 +0530 Subject: [PATCH 06/14] Update StrongRecursion.java changed ; to : --- Java/math/StrongRecursion.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Java/math/StrongRecursion.java b/Java/math/StrongRecursion.java index 25deab59be..4e5c044a71 100644 --- a/Java/math/StrongRecursion.java +++ b/Java/math/StrongRecursion.java @@ -40,7 +40,7 @@ public static void main() } } -/* Sample Input And Output ; +/* Sample Input And Output : * N = 145 * It is a Strong Number * N = 534 From 10f75e6b3178443d9c395d2fd51863bc4b0ec333 Mon Sep 17 00:00:00 2001 From: "@2001!" <59911272+ErzaTitania-2001@users.noreply.github.com> Date: Wed, 16 Dec 2020 23:49:15 +0530 Subject: [PATCH 07/14] Update StrongRecursion.java Changed class name Formatted code using https://www.tutorialspoint.com/online_java_formatter.htm --- Java/math/StrongRecursion.java | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/Java/math/StrongRecursion.java b/Java/math/StrongRecursion.java index 4e5c044a71..fd2e2bdf6f 100644 --- a/Java/math/StrongRecursion.java +++ b/Java/math/StrongRecursion.java @@ -7,33 +7,30 @@ import java.util.*; -class StrongRecursion -{ +class check_strong_number { /*recursive function for sum of factorial of digits*/ - public static int sumOfFactorialOfDigit(int n) + public static int sumOfFactorialOfDigit(int n) { - if(n == 0) + if (n == 0) return n; else - return(factorial(n % 10)+sofd(n / 10)); + return (factorial(n % 10) + sumOfFactorialOfDigit(n / 10)); } /*recursive function to find the factorial of n */ - public static int factorial(int n) - { - if(n == 0) - return 1; - else - return(n * factorial(n - 1)); - } - - public static void main() - { - Scanner sc=new Scanner(System.in); + public static int factorial(int n) { + if (n == 0) + return 1; + else + return (n * factorial(n - 1)); + } + + public static void main() { + Scanner sc = new Scanner(System.in); System.out.print(" Enter Number. N = "); - int num=sc.nextInt(); - if(num==sumOfFactorialOfDigit(num)) + int num = sc.nextInt(); + if (num == sumOfFactorialOfDigit(num)) System.out.println(" It is a Strong Number"); else System.out.println(" It is not a Strong Number"); From 27289fbf4c8b3cca0138b8d7153b3d7cd899970e Mon Sep 17 00:00:00 2001 From: "@2001!" <59911272+ErzaTitania-2001@users.noreply.github.com> Date: Thu, 17 Dec 2020 17:04:03 +0530 Subject: [PATCH 08/14] Rename StrongRecursion.java to check_strong_number.java Changed class name --- Java/math/{StrongRecursion.java => check_strong_number.java} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Java/math/{StrongRecursion.java => check_strong_number.java} (100%) diff --git a/Java/math/StrongRecursion.java b/Java/math/check_strong_number.java similarity index 100% rename from Java/math/StrongRecursion.java rename to Java/math/check_strong_number.java From 42ebe939681645179ba9ee103fe0df8699517875 Mon Sep 17 00:00:00 2001 From: "@2001!" <59911272+ErzaTitania-2001@users.noreply.github.com> Date: Thu, 17 Dec 2020 17:05:43 +0530 Subject: [PATCH 09/14] Update README.md --- Java/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Java/README.md b/Java/README.md index 78fe64b8d0..9997359506 100644 --- a/Java/README.md +++ b/Java/README.md @@ -100,7 +100,7 @@ _add list here_ - [Sieve of Eratosthenes](math/SieveOfEratosthenes.java) - [Catalan Number](math/CatalanNumber.java) - [Palindrome Number Using Recursion](math/PalindromeRecursion.java) -- [Strong Number Using Recursion](math/StrongRecursion.java) +- [Strong Number Using Recursion](math/check_strong_number.java) ## Dynamic Programming From 11b37ec9ac086b91817f36fc033b9795ec281c5e Mon Sep 17 00:00:00 2001 From: Rajiv Singh Date: Thu, 17 Dec 2020 22:22:57 +0530 Subject: [PATCH 10/14] Update check_strong_number.java --- Java/math/check_strong_number.java | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/Java/math/check_strong_number.java b/Java/math/check_strong_number.java index fd2e2bdf6f..de7f92f6f3 100644 --- a/Java/math/check_strong_number.java +++ b/Java/math/check_strong_number.java @@ -1,10 +1,11 @@ -/* checking for a strong number using indirect recursion +/* +Checking for a strong number using indirect recursion Strong Number = 145 -1! + 4! + 5! =145 +1! + 4! + 5! =145 sumOfFactorialOfDigit(int n) - extracts digit of n and calls factorial(n). Returns sum of factorial of digits -factorial(n)- returns factorial of extracted digits passed in the argument*/ - +factorial(n)- returns factorial of extracted digits passed in the argument +*/ import java.util.*; class check_strong_number { @@ -37,13 +38,13 @@ public static void main() { } } -/* Sample Input And Output : - * N = 145 - * It is a Strong Number - * N = 534 - * It is not a Strong Number - Time Complexity : O(n) - * Space Complexity : 1 - */ - +/* +Sample Input And Output : +N = 145 +It is a Strong Number +N = 534 +It is not a Strong Number +Time Complexity : O(n) +Space Complexity : 1 +*/ From 60f4cb89131eb014ff3b8de495f11eee5dcc315c Mon Sep 17 00:00:00 2001 From: "@2001!" <59911272+ErzaTitania-2001@users.noreply.github.com> Date: Sat, 19 Dec 2020 11:32:31 +0530 Subject: [PATCH 11/14] Bucket Sort Bucket Sort #1590 --- Java/sort/Bucket_Sort.java | 55 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 Java/sort/Bucket_Sort.java diff --git a/Java/sort/Bucket_Sort.java b/Java/sort/Bucket_Sort.java new file mode 100644 index 0000000000..5640ebc808 --- /dev/null +++ b/Java/sort/Bucket_Sort.java @@ -0,0 +1,55 @@ +/* Sorting floating point numbers in ascending order betweent the range of 0.0 to 0.1 by bucket sort + hash(float value) : Returns the value of key multiplied with 10 + bucket_sorting(float[] list) : Creates 10 bucktes and sorts them */ +import java.util.*; +class Bucket_Sort { + /* Multiplying each value of the array with 10*/ + public static float hash(float value) { + return value * 10; + } + public static List < Float > bucket_sorting(float[] list) { + /* The bucket sorted array*/ + List < Float > sorted = new ArrayList < > (); + //Creates 10 bucktes + List < List < Float >> buckets = new ArrayList < > (10); + for (int i = 0; i < 10; i++) + buckets.add(new ArrayList < > ()); + // inputting values in buckets depending on values from list + for (float values: list) { + float key = hash(values); + buckets.get((int) key).add(values); + + } + //sorting individual buckets and adding them + for (int i = 0; i < buckets.size(); i++) { + if (buckets.get(i) != null) { + Collections.sort(buckets.get(i)); + sorted.addAll(buckets.get(i)); + } + } + return sorted; + } + public static void main(String args[]) { + Scanner sc = new Scanner(System.in); + System.out.print(" Enter size of array. N = "); + int n = sc.nextInt(); + float arr[] = new float[n]; + System.out.println(" Enter the elements of the array"); + for (int i = 0; i < n; i++) + arr[i] = sc.nextFloat(); + System.out.println("Sorted array : " + "\n" + bucket_sorting(arr)); + } +} + +/* Sample Input and Output : + * Enter size of array. N = 5 + Enter the elements of the array +0.5 0.4 0.3 0.2 0.6 +Sorted array : +[0.2, 0.3, 0.4, 0.5, 0.6] + +Worst Time Complexity : O(n^2) +Average Time Complexity : O(n) + +Space Complexity : O(1) + */ \ No newline at end of file From 99c6060a2e55bb2856e05ed878a1b27b570fe93f Mon Sep 17 00:00:00 2001 From: "@2001!" <59911272+ErzaTitania-2001@users.noreply.github.com> Date: Sat, 19 Dec 2020 11:35:21 +0530 Subject: [PATCH 12/14] Bucket Sort Using Hash Bucket Sort #1590 --- Java/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/Java/README.md b/Java/README.md index 9997359506..01eaa7f068 100644 --- a/Java/README.md +++ b/Java/README.md @@ -141,6 +141,7 @@ _add list here_ - [Quick Sort](sort/QuickSort.java) - [Selection Sort](sort/SelectionSort.java) - [Merge Sort Using Recursion](sort/MergeSortRecursion.java) +- [Bucket Sort Using Hash](sort/Bucket_Sort.java) ## Machine Learning From bf8488f665628ce9aebdc06bc3ac131834bb6c4a Mon Sep 17 00:00:00 2001 From: "@2001!" <59911272+ErzaTitania-2001@users.noreply.github.com> Date: Sun, 20 Dec 2020 20:18:03 +0530 Subject: [PATCH 13/14] Delete Bucket_Sort.java --- Java/sort/Bucket_Sort.java | 55 -------------------------------------- 1 file changed, 55 deletions(-) delete mode 100644 Java/sort/Bucket_Sort.java diff --git a/Java/sort/Bucket_Sort.java b/Java/sort/Bucket_Sort.java deleted file mode 100644 index 5640ebc808..0000000000 --- a/Java/sort/Bucket_Sort.java +++ /dev/null @@ -1,55 +0,0 @@ -/* Sorting floating point numbers in ascending order betweent the range of 0.0 to 0.1 by bucket sort - hash(float value) : Returns the value of key multiplied with 10 - bucket_sorting(float[] list) : Creates 10 bucktes and sorts them */ -import java.util.*; -class Bucket_Sort { - /* Multiplying each value of the array with 10*/ - public static float hash(float value) { - return value * 10; - } - public static List < Float > bucket_sorting(float[] list) { - /* The bucket sorted array*/ - List < Float > sorted = new ArrayList < > (); - //Creates 10 bucktes - List < List < Float >> buckets = new ArrayList < > (10); - for (int i = 0; i < 10; i++) - buckets.add(new ArrayList < > ()); - // inputting values in buckets depending on values from list - for (float values: list) { - float key = hash(values); - buckets.get((int) key).add(values); - - } - //sorting individual buckets and adding them - for (int i = 0; i < buckets.size(); i++) { - if (buckets.get(i) != null) { - Collections.sort(buckets.get(i)); - sorted.addAll(buckets.get(i)); - } - } - return sorted; - } - public static void main(String args[]) { - Scanner sc = new Scanner(System.in); - System.out.print(" Enter size of array. N = "); - int n = sc.nextInt(); - float arr[] = new float[n]; - System.out.println(" Enter the elements of the array"); - for (int i = 0; i < n; i++) - arr[i] = sc.nextFloat(); - System.out.println("Sorted array : " + "\n" + bucket_sorting(arr)); - } -} - -/* Sample Input and Output : - * Enter size of array. N = 5 - Enter the elements of the array -0.5 0.4 0.3 0.2 0.6 -Sorted array : -[0.2, 0.3, 0.4, 0.5, 0.6] - -Worst Time Complexity : O(n^2) -Average Time Complexity : O(n) - -Space Complexity : O(1) - */ \ No newline at end of file From 446597dc1096bb39dfa7735b1188481e7969a2b0 Mon Sep 17 00:00:00 2001 From: Rajiv Singh Date: Mon, 21 Dec 2020 02:41:33 +0530 Subject: [PATCH 14/14] Update README.md --- Java/README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/Java/README.md b/Java/README.md index 01eaa7f068..9997359506 100644 --- a/Java/README.md +++ b/Java/README.md @@ -141,7 +141,6 @@ _add list here_ - [Quick Sort](sort/QuickSort.java) - [Selection Sort](sort/SelectionSort.java) - [Merge Sort Using Recursion](sort/MergeSortRecursion.java) -- [Bucket Sort Using Hash](sort/Bucket_Sort.java) ## Machine Learning