CSE 2011Z 2012W Midterm Practice Questions

CSE 2011Z 2012W Midterm Practice Questions - CSE 2011Z...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CSE 2011Z 2012W Prof. J. Elder Midterm Practice Questions Here is a set of questions you can use to help study for the midterm. All of these questions are from the textbook (Goodrich), and include the original problem numbers. These are not all necessarily questions I would put on a midterm, but they all address aspects of data structures that we have covered and that are important. On the midterm, you should expect to see some definitional questions as well as problem ­solving questions. I will post solutions to the problems below later this week. Your solutions will not be collected, and will not be marked. Good luck studying! Introduction R ­2.13 Give an example of a Java code fragment that performs an array reference that is possibly out of bounds, and if it is out of bounds, the program catches that exception and prints the following error message: “Don’t try buffer overflow attacks in Java!” Analysis R ­4.32 Show that n2 is ! ( n log n ) . Arrays, Array Lists & Stacks C ­5.2 Suppose you have a stack S containing n elements and a queue Q that is initially empty. Describe (in pseudocode or English) how you can use Q to scan S to see if it contains a certain element x, with the additional constraint that your algorithm must return the elements back to S in their original order. You may not use an array or linked list – only S and Q and a constant number of reference variables. C ­6.9 Give a pseudo ­code description for an array ­based implementation of the array list ADT that achieves O(1) time for insertions and removals at index 0, as well as insertions and removals at the end of the array list. Queues & Linked Lists C ­3.12 Describe (in pseudocode or English) an algorithm for reversing a singly linked list L using only a constant amount of additional space and not using any recursion. C ­6.15 Describe how to implement an iterator for a circularly linked list. Since hasNext() will always return true in this case, describe how to perform hasNewNext(), which returns true if and only if the next node in the list has not previously had its element returned by this iterator. Recursion CSE 2011Z 2012W Prof. J. Elder C ­3.8 Describe (in pseudocode or English) an O(n) recursive algorithm for reversing a singly linked list L, so that the ordering of the nodes becomes opposite of what it was before. C ­3.16 Describe (in pseudocode or English) an algorithm that will output all of the subsets of a set of n elements (without repeating any subsets). What is the asymptotic running time of your algorithm? Trees C ­7.11 The balance factor of an internal node v of a proper binary tree is the difference between the heights of the right and left subtrees of v. Describe (in pseudocode or English) an efficient algorithm that specializes the Euler tour traversal of Section 7.3.7 to print the balance factors of all the internal nodes of a proper binary tree. C ­7.23 Let T be a tree with n nodes. Define the lowest common ancestor (LCA) between two nodes v and w as the lowest node in T that has both v and w as descendents (where, by definition, a node is a descendent of itself). Given two nodes v and w, describe (in pseudocode or English) an efficient algorithm for finding the LCA of v and w. What is the running time of your algorithm? Heaps & Priority Queues C ­8.14 We can represent a path from the root to a given node of a binary tree by means of a binary string, where 0 means “go to the left child” and 1 means “go to the right child.” Use this to design an O(log n) time algorithm for finding the last node of a complete binary tree with n nodes, assuming a linked structure implementation that does not keep a reference to the last node. C ­8.15 Given a heap T and a key k, give an algorithm to compute all of the entries in T with key less than or equal to k. The algorithm should run in time proportional to the number of entries returned. ...
View Full Document

This note was uploaded on 02/14/2012 for the course CSE 2011Z taught by Professor Elder during the Fall '11 term at York University.

Ask a homework question - tutors are online