What is an algorithm
a finite sequence of rigorous instructions, typically used to solve a class of specific problems or to perform a computation.
what does i++ do?
increments variable i by 1
what does this print?
print(75<<1)
150
What is the time complexity of this code?
for i in range(N):
a = a + 1
O(n)
What can be stored in a variable?
Addresses to objects in memory and primitive data types.
What is binary code
a mathematical language that uses 0's or 1's
what is wrong with this code?
for (int i ; arr);
element based for-loops use a colon, not a semicolon
what does __repr__() do in a class?
it changes how the objects of the class are represented as strings, when printed.
Provide an example of O(n logn) algorithm
mergesort, heapsort, quicksort (in best case)
Where are objects stored in Java?
The heap.
What is type casting
Converting a variable's data type from one type to another.
What will this code output?
int a = 5;
char b = '5';
System.out.println(a + b);
5 + ASCII value of char '5' = 58
will print 58
what does this produce?
majors = ['cs', 'math', 'english', 'psych'] majors[::-2]
['psych', 'math']
What is the worst case runtime for selection sort
O(n2)
What is a linked list, and what advantages does using a linked list have over an array?
A linked list stores a sequence of items in separate nodes. Each node in the list contains the address to the next node in the linked list. Each address is also stored in a separate address. A linked list allows for easier and more efficient insertion and deletion at any point.
What is polymorphism?
a variable that holds a reference to an object from a different data type as the variable itself.
Classes G and H both have methods called method1(). Which version of method1() will be called?
G g = new H();
g.method1();
The method1() defined in class H.
What does this code produce?
list = []
list += 2*x for x in range(6) if x % 2 == 0
[0, 4, 8]
What is more efficient:
O(2n) or O(n logn)
O(n logn)
Difference between Stack and Queue
STACK IS FILO; QUEUE IS FIFO
What is Agile software development
Agile software development refers to a group of software development methodologies based on iterative development, where requirements and solutions evolve through collaboration between self-organizing cross-functional teams.
How many total stack frames will be made for fib(4)?
public static int fib(int i) { int lim = 2; if( i < lim ) return 1; else return fib(i-1) + fib(i-2); }
8 calls
What does this code print?
table = [[15, 3, 6, 8, 2], [6, 12, 3, 7, 8], [12, 65, 3, 7, 7]]
table[-1][-2] = 0
print(table[-1])
[12, 65, 3, 0, 7]
What is the time complexity of statement 2:
public static int mystery(int n) {
int x = 0
for (int i = 0; i < n; i++) {
x += i;
for (int j = 0; j < i; j++) {
x += j; // statement 2
}
}
return x;
}
O(n2)
What is a 2-3 Tree's worst case for searching
O(logn)