Teste
Teste
cal Test
DEV - D
Date: City/State:
Instructions:
This test consists of 8 multiple choice questions, 1 algorithm
implementation and 1 non- technical question. The algorithm is worth
60% of the total score. The non-technical question must be answered in
Portuguese.
You may use any blank space on
this test as a draft. Use the table
below to record your answers.
Good luck!
Answer Sheet
1 2 3 4 5 6 7 8
A
B
C
D
Question 1
1
Given:
1. public class A {
2. public void print(){ System.out.println("x"); } 3.
}
4. public class B extends A {
5. public void print(){ System.out.println("y"); } 6.
}
7. public class Main{
⦁ public static void main(String[] args) {
⦁ B test = new A();
⦁ test.print();
11. }
12. }
What’s the output?
⦁ x
⦁ y
⦁ Runtime or Compilation error on line 9
⦁ Runtime or Compilation error on line 10
Question 2
Given:
2
Consider the following statements:
⦁ Line 18 is not valid because y is protected on A
⦁ Line 19 is not valid because x is private
⦁ Line 20 is valid because m1() is public
18. z = y;
19. z = a.x;
20. z = a.m1();
21. }
22. }
Question 3
Question 4
Suppose the keys {1,2,3,4,6,9} are inserted into a hash table with
collisions resolved by chaining. Let the table have 3 slots, and the hash
function be h(k) = k % 3, that is, h(k) returns the remainder of the
Euclidean division of k by 3. How will the keys be organized into this hash
table?
3
Question 5
⦁ A Binary Tree is a tree data structure in which each node has at most two
child nodes, usually distinguished as "left" and "right", and a tree with n
nodes has exactly n−1 branches.
⦁ A Hash Map is a data structure in which, if there’s no collision
among the keys, you can always find an element in O(1) time, even
in the worst case.
⦁ In a doubly linked list data structure, each item is linked to both the
previous and the next items in the list, allowing easy access of list
items backwards as well as forwards.
Question 6
In the following code, assume that Queue is not thread-safe, there is more than
one Producer thread and more than one Consumer thread running and this
program is crashing on runtime. In order to fix the code below how should you
fill in lines (1), (2), (3) and (4)?
Global variables
Queue q;
(1)
Producer thread Consumer thread
runProducer() runConsumer(){ while(true)
{ while(true){ {
item = new item(); (2)
(2) if (q is not empty)
if (q is not full) { item =
{ q.enqueue(item); q.dequeue(); (3)
(3) }
} (4)
(4) }
} }
}
4
⦁ (
1
)
(
2
)
⦁ if(Consumer) sleep(1); else sleep(2);
(
4
)
⦁ (1) mutex m;
(
2
)
⦁ m.lock();
⦁ m.unlock();
Question 7
Considering the following tables and data information, what would be the
correct result of the SQL command below?
Orders
Number Order_Date cust_id salesperson_id Amount
10 8/2/2010 4 2 540
20 5/6/2012 9 7 150
30 3/12/2012 8 5 1,500
40 1/30/2013 4 8 1,800
50 7/14/2009 9 1 460
60 1/29/2012 7 2 2,400
70 2/3/2012 6 7 600
80 4/1/2013 8 2 2,300
90 3/2/2012 6 7 720
5
A. Abe B. Abe C. Abe D. Bob
Chris Bob Chris Ken
Dan Chris Dan
Dan Joe
Question 8
Infinite
Coins
Given an infinite number of quarters (25 cents), dimes (10 cents), nickels (5
cents) and pennies (1 cent), write a method makeChange() to calculate and
return a Set containing the ways of representing n cents using those coins.
Each element of the returned Set should represent the number of coins to
compose the entry value, an array like this: [quarters, dimes,
nickels, pennies].
The method makeChange() can use a Set data structure to store each
representation of n cents, and then, return it. A Set is a collection that contains
no duplicate elements and the order of elements is irrelevant. Consider the
following interface defined for Set:
boolean addAll(Set s) Adds all elements from s that are not already present in this set.
boolean contains(Element e) Returns true if this set contains the specified element.
boolean equals(Set s) Compares the specified set s with this set for equality.
boolean remove(Element e) Removes the specified element from this set if it is present
(optional operation).
int size() Returns the number of elements in this set (its cardinality).
Element[] toArray() Returns an array containing all of the elements in this set.
6
* this is the content of the Set which should be returned by the function.
/**
⦁ The function below will ...
⦁ - Obtain the input
⦁ - Iterate over the elements
⦁ …
⦁ - Print the output and return ...
*/
Algoritm
Solution
Qual a disciplina que você mais gostou de cursar na faculdade e por quê?
(Responder em português)