Reference no: EM132387950
Question 1
What is the output from the following sequence of linked list operations?
LinkedList<String> myList = new LinkedList<String>();
ListIterator<String> iter;
myList.addFirst("John");
myList.addFirst("David");
iter = list.listIterator(); iter.next();
iter.add("Peter"); iter.next();
iter.add("Joshua");
Question 2
Write an application to implement the three Set operations: intersection, union, and difference. You should build three methods corresponding to the operations. In your main method, test these methods on two HashSets of Strings.
Question 3
Create a PriorityQueue of type Integers and add the following values which represent months: 2, 5, 8, 3, 11, 7, and 6.
• Display the values using the peek method.
• Remove 2 from the queue and add 12.
• Remove 3 and add 4 to the queue.
• Display the queue.
Question 4
What is Big-O notation? By using the definition of Big-O, show that the running time for term T(n)=100+2n+ n2 is O(n2).
Question 5
Write a java program to generate twenty five random integers between 0 and 100 (inclusive), display the values, display the sorted values, sum, and average of the values. Use Lambdas.
Question 6
Create a database named Books and write and execute the query to create an Authors Table having three columns - AuthorID, FirstName, and LastName.
Create the database and table programmatically.
• Write preparedStatement to insert values into the Authors table.
• Use PreparedStatement to search and display author details of an author whose firstName is entered from the keyboard.
Question 7
Write a method to calculate the sum of integers 1 to n recursively.
Question 8
The following Java code segment uses the data structure - queue. It contains some operations such as enqueue( ) and dequeue( ). Please write down the output when the code segment is executed. Queue class has implemented standard Queue interface.
Queue<Integer> q = new Queue<Integer>(); int a = 10;
q.enqueue(5);
q.enqueue(a); q.enqueue(20);
System.out.println(q.peek()); q.dequeue();
q.enqueue(30); while (!q.isEmpty())
System.out.print(q.dequeue() + " ");
Question 9
Manually provide the inorder, preorder and postorder traversals of the binary search tree as shown below.
