Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c08f93c

Browse files
fixing
1 parent 6ac6688 commit c08f93c

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

‎src/main/java/ir/sk/algorithm/mathematic/Algorithms.java‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import ir.sk.helper.complexity.SpaceComplexity;
44
import ir.sk.helper.complexity.TimeComplexity;
5+
import ir.sk.helper.paradigm.DivideAndConquer;
56
import ir.sk.helper.paradigm.DynamicProgramming;
67
import ir.sk.helper.paradigm.DynamicProgrammingType;
78

@@ -22,6 +23,10 @@ public class Algorithms {
2223
* (1) Only one disk can be moved at a time.
2324
* (2) A disk is slid off the top of one tower onto another tower.
2425
* (3) A disk cannot be placed on top of a smaller disk.
26+
*
27+
* T(n):
28+
* 1 n = 1
29+
* 2*T(n-1) + 1 n > 1
2530
*
2631
* @param n the number of disks
2732
* @param src the name of the source rod
@@ -30,6 +35,7 @@ public class Algorithms {
3035
*/
3136
@TimeComplexity("O(2^n)")
3237
@SpaceComplexity("O(n)")
38+
@DivideAndConquer
3339
public static void towerOfHanoi(int n, char src, char buffer, char dest) {
3440
if (n == 1)
3541
System.out.println("Disk 1 from " + src + " to " + dest);

‎src/main/java/ir/sk/algorithm/mathematic/Factorial.java‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@
44
import ir.sk.helper.complexity.SpaceComplexity;
55
import ir.sk.helper.complexity.TimeComplexity;
66
import ir.sk.helper.paradigm.BruteForce;
7+
import ir.sk.helper.paradigm.DivideAndConquer;
78

89
import java.math.BigInteger;
910

1011
/**
11-
* f(n) =
12-
* 1 n = 1
13-
* n * f(n-1) n > 1
12+
* Divide-and-conquer algorithm
13+
*
14+
* T(n) =
15+
* 1 n = 1
16+
* n * T(n-1) n > 1
1417
*
1518
* @author <a href="kayvanfar.sj@gmail.com">Saeed Kayvanfar</a> on 1/31/2020.
1619
*/
@@ -27,6 +30,7 @@ public class Factorial {
2730
@RecurrenceRelation("T(n) = T(n-1) + O(1)")
2831
@TimeComplexity("O(n)")
2932
@SpaceComplexity("O(n)")
33+
@DivideAndConquer
3034
public static int factorialByRecursive(int n) {
3135
if (n == 0)
3236
return 1;

‎src/main/java/ir/sk/algorithm/mathematic/Fibonacci.java‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,15 @@
33
import ir.sk.helper.complexity.SpaceComplexity;
44
import ir.sk.helper.complexity.TimeComplexity;
55
import ir.sk.helper.paradigm.BruteForce;
6+
import ir.sk.helper.paradigm.DivideAndConquer;
67
import ir.sk.helper.paradigm.DynamicProgramming;
78
import ir.sk.helper.paradigm.DynamicProgrammingType;
89

910
/**
11+
* Divide-and-conquer algorithm
12+
* T(n)=
13+
* 1 n = 1, n = 2
14+
* T(n-1) + T(n-2)
1015
* Created by sad.keyvanfar on 6/25/2020.
1116
*/
1217
public class Fibonacci {
@@ -20,6 +25,7 @@ public class Fibonacci {
2025
@BruteForce
2126
@TimeComplexity("T(n-1) + T(n-2) which is exponential. t(n) = 2 ^ (n/2). O(2^n) exponential. O(branches ^ depth)")
2227
@SpaceComplexity(" O(n) if we consider the function call stack size, otherwise O(1)")
28+
@DivideAndConquer
2329
public static long naiveFibonacciByRecursive(long n) {
2430
if (n == 0 || n == 1)
2531
return n;

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /