forked from nishitpanchal395/projecthactoberfest
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfibonacci.java
More file actions
68 lines (67 loc) · 1.24 KB
/
fibonacci.java
File metadata and controls
68 lines (67 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package recursion;
public class fibonacci {
// O(2^n)
public int fib(int n)
{
if(n==0)
{
// System.out.print(0+" ");
return 0;
}
if(n==1)
{
// System.out.print(1+" ");
return 1;
}
return fib(n-1)+fib(n-2);
}
public int pow(int n,int base)
{
if(base==0)
return 1;
return n*pow(n,base-1);
}
public int gcd(int a,int b)
{
if(a==0 ||b==0)
{
if(a==0)
return b;
else
return a;
}
if( a>b)
return gcd(a-b,b);
else
return gcd(a,b-a);
}
public int minnoofways(int n,int m)
{
if(n==1 || m==1)
return 1;
return minnoofways(n-1,m)+ minnoofways(n,m-1);
}
public int joseph(int n,int k)
{
if(n==1)
return 0;
return (joseph(n-1,k)+k)%n;
}
public boolean isPallindrome(String s,int l,int r)
{
if(l>=r)
return true;
if(s.charAt(l)!=s.charAt(r))
return false;
return isPallindrome(s,l+1,r-1);
}
public void powersetOfString(String s,int i,String curr)
{
if(i==s.length()){
System.out.print(curr+",");
return;
}
powersetOfString(s,i+1,curr+s.charAt(i));
powersetOfString(s,i+1,curr);
}
}