Math
1. What is a tautology?
2. Is the statement ~(X & (X | Y)) <=> ~X a tautology?
3. Simplify the statement ~(A <=> B).
4. Describe the language given by the regular expression [abc] [0-9] {2} d? 5+.
a) Modify the regular expression so that it accepts the string "a23".
5. Given the following code:
int x = 872;
byte y = x;
What is the value of y?
6. Perform matrix multiplication on (1, 2; 3, 4; 5, 6) * (-1, 1, 3; 2, 2, 2).
a) What is the transpose of the result?
b) What is the product of the result with its inverse?
7. For the binary tree with depth 3, nodes {a,b,c,d,e,f,g} given left-to-right and top-to-bottom, give all the different DFS traversals of the tree (pre-order, in-order, post-order).
Programming Concepts
1. What is the difference between local and global scope? Why is global scope bad?
2. What is a static variable?
3. What does it mean for a function f to be O(n)?
a) If f=O(n) and g=O(n!), what is f+g?
b) if f=O(n) and g=O(n^2), what is f*g?
4. What is OOP in your own words? What are inheritance/polymorphism/encapsulation?
5. What is the difference between a DAG and a tree?
C++
1. Suppose you have the base class A, a derived class B, and a function alpha which takes parameter of type A. If you declare an object b of type B, what happens when you call alpha(b)?
2. Will this code compile?
class Bank { public int savings; }
main() {
Bank a;
cout << a.savings;
}
3. What value is x assigned?
#define multiply(a,b) a*b
int x = multiply(1+2, 3);
4. How would you prevent the multiple definition of a class?
5. What is the difference between "using namespace std;" and "using std::cout;"? Why are "using" statements bad?
6. There is a base class Person and derived class Student, each has a greet() method. What is the result of the following code?
Person * myPtr = new Student();
myPtr->greet();
6. How would you declare an array of ints, for which the size is determined at runtime by the user?
a) How would you declare the array if the size is unknown, and the user inputs values in a while loop until a newline character is reached?
7. How would you write a C++ program called replace that takes in two chars from the command line, asks the user to input a string, replaces all occurrences in the string of a with b, and prints the result to the screen?
Java
1. How would you represent a fixed set of constants like the days of the week or suits in a deck of cards?
2. What is the difference between int and Integer? Why would you use Integer over int?
3. What is the difference between JDK, JRE and JVM?
a) Explain how JVM achieves platform independence.
4. Describe how a Java program is converted from high level code to low level code.
5. Your friend writes this function. What are your concerns?
public static int divide(int[] A, int x) {
try {
return A[1] / x;
} catch(Exception e) {
return -1;
}
}