Reference no: EM132245775
Assignment Questions -
Question 1- If you implement a stack as an array, should the top element be the one with the lowest index, or the one with the highest index? Why?
Question 2 - What is tail recursion? Describe how to rewrite code to remove tail recursion. Why would the rewritten version be more efficient?
Question 3 - Consider the Java code below. If a single integer (int) requires 4 bytes of memory for storage then how many bytes of memory does the integer array "anArray" require for storage just before the program exits?
class ClassA {
public static void main(String[] args) {
Int[] anArray = new int[40];
anArray[0] = 0;
anArray[1] = 1;
anArray[2] = 100;
anArray[3] = 100000;
//how many bytes of memory is anArray using at this point?
System.exit(0);
}
}
Question 4 - For the given list of numbers, perform a radix sort (with base-10 arithmetic). At each step, write a sentence describing how you are reordering the data and then rewrite the list of numbers.
475 215 441 224 421 175 115 124 021 275
Question 5 - Convert the infix expression
P-(Q+R)/S*T
to a postfix expression.
Question 6 - What is a pivot value and how is it used when partitioning an array?
Question 7 - What does FIFO stand for? Give an example of a FIFO data structure.
Question 8 - What are the two basic operations of the selection sort algorithm?
Question 9 - Describe the difference between the term double-ended list and the term doubly-linked list when discussing linked lists.
Question 10 - Why is it important to have a base case in a recursive method?
Question 11 - List the contents of Stack "s" after the following code is executed (assume the top of the stack is on the left):
Stack s = new Stack();
s.push("B");
s.push('A");
s.pop();
s.push("C");
s.push(s.pop());
s.push("D");
Question 12 - When you create a Node variable what is stored in that variable? E.g. what is stored in n in the following line?
Node n = new Node();
Question 13 - List the contents of "q" after the following code is executed (assume the front of the queue is on the left):
Queue q = new Queue();
q.enqueue("A");
q.enqueue("B");
q.enqueue("C");
q.enqueue(q.dequeue());
q.enqueue("D");
q.dequeue();