Skip to content

Commit 8317165

Browse files
authored
Merge branch 'master' into feat/add-bell-numbers
2 parents 921057f + 48f6322 commit 8317165

File tree

2 files changed

+30
-15
lines changed

2 files changed

+30
-15
lines changed

src/main/java/com/thealgorithms/recursion/FibonacciSeries.java

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,26 @@
11
package com.thealgorithms.recursion;
22

3-
/*
4-
The Fibonacci series is a sequence of numbers where each number is the sum of the two preceding ones,
5-
starting with 0 and 1.
6-
NUMBER 0 1 2 3 4 5 6 7 8 9 10 ...
7-
FIBONACCI 0 1 1 2 3 5 8 13 21 34 55 ...
8-
*/
3+
/**
4+
* The Fibonacci series is a sequence of numbers where each number is the sum of the two preceding ones,
5+
* starting with 0 and 1.
6+
* <p>
7+
* Example:
8+
* 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55 ...
9+
* </p>
10+
*/
911

1012
public final class FibonacciSeries {
1113
private FibonacciSeries() {
1214
throw new UnsupportedOperationException("Utility class");
1315
}
16+
17+
/**
18+
* Calculates the nth term in the Fibonacci sequence using recursion.
19+
*
20+
* @param n the position in the Fibonacci sequence (must be non-negative)
21+
* @return the nth Fibonacci number
22+
* @throws IllegalArgumentException if n is negative
23+
*/
1424
public static int fibonacci(int n) {
1525
if (n < 0) {
1626
throw new IllegalArgumentException("n must be a non-negative integer");

src/main/java/com/thealgorithms/searches/LinearSearch.java

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,26 @@
11
package com.thealgorithms.searches;
22

33
import com.thealgorithms.devutils.searches.SearchAlgorithm;
4-
54
/**
6-
* Linear search is the easiest search algorithm It works with sorted and
7-
* unsorted arrays (an binary search works only with sorted array) This
8-
* algorithm just compares all elements of an array to find a value
5+
* Linear Search is a simple searching algorithm that checks
6+
* each element of the array sequentially until the target
7+
* value is found or the array ends.
8+
*
9+
* It works for both sorted and unsorted arrays.
910
*
10-
* <p>
11-
* Worst-case performance O(n) Best-case performance O(1) Average performance
12-
* O(n) Worst-case space complexity
11+
* Time Complexity:
12+
* - Best case: O(1)
13+
* - Average case: O(n)
14+
* - Worst case: O(n)
1315
*
14-
* @author Varun Upadhyay (https://github.com/varunu28)
15-
* @author Podshivalov Nikita (https://github.com/nikitap492)
16+
* Space Complexity: O(1)
17+
*
18+
* @author Varun Upadhyay
19+
* @author Podshivalov Nikita
1620
* @see BinarySearch
1721
* @see SearchAlgorithm
1822
*/
23+
1924
public class LinearSearch implements SearchAlgorithm {
2025

2126
/**

0 commit comments

Comments
 (0)