Q1:What does each of the following print? Explain each outcome. 1.System.out.println(2 + "bc"); 2.System.out.println(2 + "bc" + 3); 3.System.out.println( 2 + 3 + "bc"); 4.System.out.println("bc"...

1 answer below »

Q1:What does each of the following print? Explain each outcome.


1.System.out.println(2 + "bc");


2.System.out.println(2 + "bc" + 3);


3.System.out.println( 2 + 3 + "bc");


4.System.out.println("bc" + (2 + 3) );


5.System.out.println("bc" + 2 + 3 );










Q2:





Write out a program trace
to find out what operation the following Java method performs, using the following example inputs:N=17,N=25.



public static Boolean mystery (int N) {
if (Nfor (int i=2; i*i
if (N%i==0) {
return false;
}
}
return true;
}
















Q3: Show, using a memory trace, how an insertion sortsorts the sequence of characters below:



E A G E R N E S S




Q4:


A program that processes a file of input numbers is run a number of times, each time doubling the size of the input. The running time for each input was recorded, and the data are presented below.
























N



250



500



1000



2000



4000



8000



t (s)



14



160



1813



20596



233983



2658252




Use the doubling hypothesis to find a power law relationship that approximately describes the program's performance. Show all your workings.





Q5:


Perform one single partitioning operation on the following sequence of random characters, as part of a quicksort operation. Show all your workings.


I R T H U D O A N E Q S










Q6:


Explain the steps taken to add a sequence of (key, value) pairs to an initially empty binary search tree (BST). The keys are as follows:




D I S T R I B U T E



In your answer, include an explanation of each step, and a diagram showing the final BST.












Q7:




Horner’s methodis a popular way of implementing hash codes for strings. Describe Horner’s method, and give an example of its operation on the string “flew”, given the following data.



























Char




Unicode



‘f’



102



‘l’



108



‘e’



101



‘w’



119




Answered Same DayMay 10, 2021

Answer To: Q1:What does each of the following print? Explain each outcome. 1.System.out.println(2 + "bc");...

Kshitij answered on May 10 2021
132 Votes
Q1:What does each of the following print? Explain each outcome.
1. System.out.println(2 + "bc");
2. System.out.println(2 + "bc" + 3);

3. System.out.println( 2 + 3 + "bc");
4. System.out.println("bc" + (2 + 3) );
5. System.out.println("bc" + 2 + 3 );
Ans 1: 2bc
Ans2: 2bc3
Ans3:5bc
Ans4:bc5
Ans5:bc23
Q2:
Write out a program trace to find out what operation the following Java method performs, using the following example inputs: N = 17, N = 25.
public static Boolean mystery (int N) {
    if (N<2) return false;
    for (int i=2; i*i<=N; i++) {
        if (N%i==0) {
            return false;
         }
    }
    return true;
}
Solution :--
1 for N= 17 when we call the method mystery firstly it chech n is les than 2 or not and answer is not than it go next start loop from 2 to N and i*I is less than N means loop for sqrt of N if n is divisible by I then it return false ;
Now for 17 no value which divides 17 then it return 17
2->> For 25 loop run for sqrt of 25 means 2 to 5 it is divisible by 5 so it return true;
Q3: Show, using a memory trace, how an insertion sort sorts the sequence of characters below:
E A G E R N E S S
Solution:-------
pass 0 [E, A, G, E, R, N, E, S, S]
pass 1 [A, E, G, E, R, N, E, S, S]
pass 2 [A, E, G, E, R, N, E, S, S]
pass 3 [A, E, E, G, R, N, E, S, S]
pass 4 [A, E, E, G, R, N, E, S, S]
pass 5 [A, E, E, G, N, R, E, S,...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here