Skip to content
Closed
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Golomb Sequence algorithm added
  • Loading branch information
Deeeeksha committed Jan 2, 2022
commit 7ef489b1beddf009fdeceebce52545b5961557ac
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import java.util.*;

class GolombSequence
{
public static void printGolomb(int n)
{
int dp[] = new int[n + 1];

dp[1] = 1;
System.out.print(dp[1] + " ");

for (int i = 2; i <= n; i++)
{
dp[i] = 1 + dp[i - dp[dp[i - 1]]];

System.out.print(dp[i] + " ");
}
}
public static void main (String[] args)
{
int n = 9;
printGolomb(n);
}
}