Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

5 Solved Questions on Introduction to Computer Science II - Paper | CSAS 1112, Papers of Computer Science

Material Type: Paper; Class: Intro to Comp Science II; Subject: Computer Science; University: Seton Hall University; Term: Unknown 2008;

Typology: Papers

Pre 2010

Uploaded on 08/08/2009

koofers-user-sh9
koofers-user-sh9 🇺🇸

10 documents

1 / 3

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
More about Big-O
1) Find the following limits at infinity:
a)
124
32
lim
23
4
xxx
xx
x
b)
1
lim
23
5

xxx
xx
x
c)
4
23
32
124
lim xx
xxx
x

d)
3
23
3
1
lim xx
xxx
x

e)
)2)(72(
)1)(43(
lim

xx
xx
x
f)
x
x
x
1
lim
2
2) Find the order of complexity of:
a)
1
23
xxx
b)
1)ln(
3
xex
x
c)
xx )ln(
d)
e)
)2)(72(
)1)(43(
xx
xx
3.) Find the order of complexity for the following Java functions. If there are best-case, worst-case
scenarios, assume the worst.
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;
}
pf3

Partial preview of the text

Download 5 Solved Questions on Introduction to Computer Science II - Paper | CSAS 1112 and more Papers Computer Science in PDF only on Docsity!

More about Big-O

1) Find the following limits at infinity:

a)

lim 32

4

  x x x

x x

x

b)

lim 32

5

  x x x

x x

x

c) 4

3 2

lim

x x

x x x

x 

 

d) 3

3 2

lim

x x

x x x

x 

 

e)

lim

  x x

x x

x f)^ x

x

x

lim

 

2) Find the order of complexity of:

a) x^3  x^2  x  1 b) x^^3 ^ ex ln( x )^1

c) ln(^ x^ ) x d) 2

3

x ln( x ) 4 x

e)

x x

x x

3.) Find the order of complexity for the following Java functions. If there are best-case, worst-case

scenarios, assume the worst.

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); } }

4. Suppose A is an array of N integers. Find the order of complexity for each procedure. Which procedure

is preferred? One of the methods, actually, is missing a line. Please add it. One of the methods only

works under one assumption (pre-condition). You may need 'worst case', 'best case', and 'average case'

analysis.

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; }