Skip to content

Instantly share code, notes, and snippets.

View gaurav1780's full-sized avatar

Gaurav Gupta gaurav1780

  • Macquarie University
  • Sydney
View GitHub Profile
package compareToProject;
class Rectangle {
public int width, height;
public Rectangle(int w, int h) {
width = Math.max(0, w);
height = Math.max(0, h);
}
public class Permutations {
public static void main(String[] args) {
int n = 5;
for(int i=0; i < factorial(n); i++)
System.out.println("P_"+i+": "+getPermutation(n, i, getSymbolString(n)));
}
public static String getPermutation(int n, int k, String s) {
if(n==1 || k==0) {
public class RecursionTraceString {
public static void main(String[] args) {
String str = "stressed";
String rev = reverse(str);
System.out.println(rev);
}
public static String reverse(String s) {
if(s==null || s.length() < 2) {
return s;
public class RecursionTraceNumerical {
public static void main(String[] args) {
int n = 18672;
int totalEven = sumEvenDigits(n);
System.out.println(totalEven);
}
public static int sumEvenDigits(int val) {
if(val == 0) {
return 0;
public class RecursionTraceMix {
public static void main(String[] args) {
int n = 19;
int to = 3;
String s = convert(n, to);
System.out.println(s);
}
public static String convert(int decVal, int baseTo) {
if(decVal == 0) {
class Rectangle {
public int width, height;
public Rectangle(int w, int h) {
width = w;
height = h;
}
}
public class MemoryDiagrams {
import java.util.*;
public class RecursionBacktracking {
public static ArrayList<Integer> itemsAddingUpto(ArrayList<Integer> list, int start, int target) {
if(target == 0) {
return new ArrayList<Integer>();
}
if(start >= list.size()) {
return null;
}
public class StringRecursion {
public static String reverse(String str) {
if(str == null || str.length() < 2) {
return str;
}
//string has at least 2 characters
char first = str.charAt(0);
char last = str.charAt(str.length()-1);
public class NumericalRecursion {
public static boolean isSquare(int n) {
return Math.pow((int)Math.sqrt(n), 2) == n;
}
public static int countSquares(int low, int high) {
if(low > high) {
return 0;
}
boolean lowSq = isSquare(low);
import java.util.Arrays;
class MyArrayList {
public double[] data;
public int nItems;
public MyArrayList() {
data = new double[5];
nItems = 0; //no item added yet
}