




Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
Main points of this exam paper are: Recursive Function, Object Oriented, Processor Speed, Data Size, Recursive Function, Internal Node, Two Pointers
Typology: Exams
1 / 8
This page cannot be seen from the preview
Don't miss anything!
Instructions: You are allowed to bring one page of notes. You will have access to APIs’. No other material allowed. Please write your answers clearly and legibly to receive full credit.
Name: ____________________________________________ (please print)
f. Given a collection of algorithms that runs on O(1), O(n log n), O(n), O(n^2 ), O(log n), O(n!), order the algorithms from fastest to slowest i. O(1), O(n log n), O(n), O(n^2 ), O(log n), O(n!) ii. O(1), O(log n), O(n), O(n log n), O(n^2 ), O(n!) iii. O(1), O(log n), O(n log n), O(n), O(n^2 ), O(n!) iv. None of the above g. Suppose that the complexity of an algorithm is O(n^2 ). Suppose that the program that uses the algorithm run in 10 seconds for a data set of size n. If the data size is doubled, how long will it take (approximately) to run the program? i. 10 seconds ii. 100 seconds iii. 6-7 minutes iv. None of the above h. What is the best data structure to solve the following problem? A list needs to be built dynamically. Data must be easy to find, preferably in O(1). The user does not care about any order statistics such as finding max or min or median. i. Use an Array ii. Use a Singly LL iii. Use a Stack iv. Use a Queue v. None of the above i. Finding the max element in an unordered stack would require i. O(1) operations ii. O(log n) operations iii. O(n) operations. iv. None of the above j. Suppose that recursive function foo(n) calls itself twice within its body(assume foo(n-1) called twice). Also assume the recursion would end when n=0. How many function calls does foo initiates? i. O(n) ii. O(n^2 ) iii. O(2n) iv. O(n!) v. None of the above
a. Delete the head node
b. Insert a node P immediately after M
c. Swap head and the node M (you may not swap data)
public boolean contains(Comparable c) {
Public Stack mergeSortedStacks(Stack A, Stack B) {
public Node findLast(LinkedList myLL){
a. Suppose that a grocery store decided that customers who come first will be served first
b. A list must be maintained so that any element can be accessed randomly
c. A program needs to remember operations it performed in opposite order
d. The size of a file is unknown. The entries need to be entered as they come in. Entries must be deleted when they are no longer needed. It is important that structure has flexible memory management
e. A list must be maintained so that elements can be added to the beginning or end in O(1)
Extra Credit: (10 pts) write a method createArrayOfLL that takes a file of words, one in each line and creates an array of linked list nodes as follows.
(a) Create an array of 26 linked lists (b) Open the file and Insert each word into the array based on its first letter, eg: any word that begins with ‘a’ goes to A[0] list etc.. (c) Return the reference to the array of linked lists
You must consider ALL cases. You must write reasonable comments to describe your algorithm. You may assume public fields for each node, data and next. There WILL NOT be any partial credit for this problem. The question will be graded ALL or NOTHING. [Use extra paper, if necessary to write the answer]. Node class is defined as follows.
Public Node[] createArrayOfLL(String inputfile) {