Skip to content

Instantly share code, notes, and snippets.

View tmosest's full-sized avatar

Tyler Moses tmosest

View GitHub Profile
@tmosest
tmosest / DynamicFibonacci.java
Created January 24, 2017 23:38
Dynamic Fibonacci
public class DynamicFibonacci {
int[] fibs;
public static void printFibsUpToN(int n)
{
fibs[n] = new int[n + 1]
}
public int fib(int n)
@tmosest
tmosest / StringPermutations.java
Created January 24, 2017 23:15
Permutations of a String
public static void permutation(String str)
{
permutation(str, "");
}
public static permutation(String str, String prefix)
{
if(str.length() == 0)
System.out.println(prefix);
else {
@tmosest
tmosest / factorial.java
Created January 24, 2017 23:10
factorial.java
public static int factorial(int n)
{
if(n <= 1)
return 1;
else
return n * factorial(n - 1);
}
@tmosest
tmosest / sieve.java
Created January 24, 2017 23:04
Sieve.java
public static boolean isPrime(int n)
{
for(int i = 0; i * i <= n; i++)
if(n % i == 0)
return false;
return true;
}
@tmosest
tmosest / PrintUnorderedPairs.java
Created January 24, 2017 22:59
Print Unordered Pairs
public static void printUnorderedPairs(int[] array) {
for(int i = 0; i < array.length - 1; i++)
for(int j = i + i; j < array.length; j++)
System.out.println("(" + array[i] + ", " + array[j] + ")");
}
/*
Note that 1 + 2 + 3 + 4 + 5 + ..+ n = (n * (n + 1)) / 2
*/
@tmosest
tmosest / MultiplyComplexities.java
Created January 24, 2017 22:17
Multiply Complexities
// Computers m binary searches
public static boolean containsElements(int[] seaches, int[] array)
{
boolean hasElements = true;
int m = searches.length;
int n = array.length;
// O(m) loop
for(int i = 0; i < m; i++) {
// Each Binary Search has O(lg n) complexity
if(binarySearch(array, searches[i] == false)
@tmosest
tmosest / AddComplexities.java
Last active January 24, 2017 21:36
AddComplexities
//Sums from 1 to n and then from 1 to m^2
public static long example1(int n, int m)
{
long sum = 0;
//O(n)
for(int i = 1; i <= n; i++;) {
sum += i;
}
@tmosest
tmosest / ConstantsDontMatter2.java
Created January 24, 2017 21:15
Constants Don’t Matter Part 2
public static void loopThroughAlphabet(int n)
{
for(int i = 0; i < n; i++) {
}
}
package WeekOfCode.Week28;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.text.DecimalFormat;
import java.util.Scanner;
import java.util.TreeMap;
/**
@tmosest
tmosest / FraudulentActivityNotifications.java
Created November 22, 2016 16:21
Almost working solution to Fraudulent Activity Notifications
import java.util.Arrays;
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Scanner;
/**
* Algorithms -> Sorting -> Fraudulent Activity Notifications
* Medium
*/
public class FraudulentActivityNotifications {