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 recursive fibonacci series using Java #39

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
19 changes: 19 additions & 0 deletions Divide_and_Conquer/SearchMissingNumber1.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class SearchMissingNumber{
static int missingNumber1(int ar[],int size) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be missingNumber?
As i see missingNumber1 has no usages in the code

Copy link
Owner

@vanshikaarora vanshikaarora Oct 23, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@avkapratwar could you please address before adding other algos
Thanks

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it should be missing umber.. :)

int a = 0, b = size - 1;
int mid = 0;
while ((b - a) > 1) {
mid = (a + b) / 2;
if ((ar[a] - a) != (ar[mid] - mid))
b = mid;
else if ((ar[b] - b) != (ar[mid] - mid))
a = mid;
}
return (ar[mid] + 1);
}
public static void main (String[] args) {
int ar[] = { 10,11,12,13,15,16,17,18,19 };
int size = ar.length;
System.out.println("Missing number: " +missingNumber(ar, size));
}
}
22 changes: 22 additions & 0 deletions Recursion/FibonacciRecursion.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import java.util.*;
public class FibonacciRecursion {
static int n1=0,n2=1,n3=0;
static void fibonacciSeries(int count){
if(count>0){
n3 = n1 + n2;
n1 = n2;
n2 = n3;
System.out.print(" "+n3);
fibonacciSeries(count-1);
}
}

public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int count=0;
System.out.print("Enter number: ");
count = scanner.nextInt();
System.out.print(n1+" "+n2);
fibonacciSeries(count-2);
}
}