

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
Material Type: Paper; Class: Intro to Comp Science II; Subject: Computer Science; University: Seton Hall University; Term: Unknown 2008;
Typology: Papers
1 / 3
This page cannot be seen from the preview
Don't miss anything!
4
x
5
x
3 2
3 2
x
3
public static void printArray(int[] X) { for ( int i = 0; i < X.length; i++) { System. out .println("X[" + i + "] = " + X[i]); } } public static boolean isIncreasing(int[] A) { for ( int i = 0; i < A.length-1; i++) { if (A[i] > A[i+1]) return false ; } return true ; } private static void swap(int[] X, int pos1, int pos2) { int tmp = X[pos1]; X[pos1] = X[pos2]; X[pos2] = tmp; }
public static int fib(int n) { if (n <= 2) return 1; else return fib (n-1) + fib (n-2); } public static int fib_iter(int n) { if (n <= 2) return 1; else { int one = 1; int two = 1; int tmp = 0; for ( int i = 3; i <= n; i++) { tmp = one + two; one = two; two = tmp; } return two; } } public static String convert(int n) { if (n == 0) return "0"; else if (n == 1) return "1"; else if ((n % 2) == 0) return "0" + convert (n/2); else return "1" + convert (n/2); } public static void hanoi(char from, char to, char aux, int N) { if (N >= 1) { // move n-1 disks from 'from' to 'aux' hanoi (from, aux, to, N-1); // move n-th disk from 'from' to 'to' System. out .println("Move disk " + N + " from " + from + " to " + to); // move n-1 disks from 'aux' to 'to' hanoi (aux, to, from, N-1); } }
boolean S1(int A[], int key) { boolean found = false; for (int i = 0; i < A.length; i+ +) if (A[i] == key) found = true; return found; } boolean S2(int A[], int key) { boolean found = false; int i = 0; while ((i < A.length) && (!found)) { if (A[i] == key) found = true; } return found; }