Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

A database server processes queries based on their priority and time of arrival. The priority associated with each query is an integer in the range

  1. A database server processes queries based on their priority and time of arrival. The priority associated with each query is an integer in the range from 1 to 100. Two designs have been proposed:

    Design 1: Keep all the queries in one list, sorted by their time of arrival.

    Design 2: Keep the queries in 100 lists; each list holds all the queries of a given priority, sorted by their time of arrival.

    Which of the following three operations will be more efficient with Design 1 than with Design 2?

    Process the earliest query of the highest priority

    Report how many queries have arrived within the last hour

    Create a single list of all queries sorted by priority and, within the same priority, by time of arrival.

    1. I only

    2. II only

    3. III only

    4. I and II only

    5. II and III only

  2. Consider the following method.

    private int swap(int a, int b) { if (a < b) { b = a; a = b; } return b - a; }

    What are the values of the variables a, b and c after the following statements are executed?

    int a = 2, b = 5; int c = swap(a, b);

    1. 2, 5, 0

    2. 2, 5, 3

    3. 2, 5, -3

    4. 2, 2, 0

    5. 5, 2, 3

  3. Consider the following class

    public class BankAccount { private int balance; public BankAccount() { balance = 0; } public BankAccount(int amt) { balance = amt; } public int getBalance() { return balance; } public void makeDeposit(int amt) { balance += amt; } }

    What is the output when the following code segment (in a client class) is executed?

    List bank = new ArrayList(); bank.add(new BankAccount()); bank.add(new BankAccount(5)); bank.add(new BankAccount(10)); bank.add(new BankAccount(15)); for (BankAccount customer : bank) customer.makeDeposit(10); int total = 0; for (BankAccount customer : bank) total += customer.getBalance(); System.out.println(total);

    1. 0

    2. 30

    3. 40

    4. 60

    5. 70

  4. The statement

    System.out.println(Integer.MAX_VALUE);

    prints 2147483647 which is equal to 231 - 1. What does the following statement print?

    System.out.println(Integer.MAX_VALUE + 2);

    1. 0

    2. 2147483649

    3. 2147483647.0

    4. -2147483647

    5. Nothing: it causes a ArithmeticException

  5. Brad has derived his class from a library class JPanel. JPanel's paintComponent method displays a blank picture in a panel. Brad has redefined JPanel's paintComponent to display his own picture. Brad's class compiles with no errors, but when he runs the program, only a blank background is displayed. Which of the following hypotheses cannot be true in this situation?

    1. Brad misspelled "paintComponent" in his method's name.

    2. Brad specified an incorrect return type for his paintComponent method.

    3. Brad chose the wrong type for a parameter in his paintComponent method.

    4. Brad specified two parameters for his paintComponent method, while JPanel's paintComponent takes only one parameter.

    5. Brad has a logic error in his paintComponent code which prevents it from generating the picture.

  6. Suppose each pixel (picture element) in a digital image is represented by a 24-bit color value. How much memory does it take to store an uncompressed image of 2048 pixels by 1024 pixels?

    1. 2 KB

    2. 2 MB

    3. 6 MB

    4. 6 GB

    5. 32 TB

  7. Consider the following method.

    public void printSomething(String s) { int n = s.length(); if (n < 1) return; String s1 = s.substring(1, n); printSomething(s1); System.out.println(s); printSomething(s1); }

    How many letters 'A' and how many letters total will be printed as a result of calling printSomething("ABCD")?

    A's Total
    1 10
    4 10
    1 26
    4 26
    15 26
  8. Consider the following method.

    public int countSomething(int[] arr) { int m = arr[0]; int count = 1; for (int k = 1; k < arr.length; k++) { int a = arr[k]; if (a > m) { m = a; count = 1; } else if (m == a) count++; } return count; }

    For which of the following arrays will countSomething return 3?

    1. int[] arr = {0, 1, 1, 1, 1};

    2. int[] arr = {1, 6, 5, 4, 0};

    3. int[] arr = {1, 0, 5, 6, 1};

    4. int[] arr = {3, 2, 1, 0, 5};

    5. None of the above

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2022 Grenoble France September 19 23 2022 Proceedings Part 4 Lnai 13716

Authors: Massih-Reza Amini ,Stephane Canu ,Asja Fischer ,Tias Guns ,Petra Kralj Novak ,Grigorios Tsoumakas

1st Edition

3031264118, 978-3031264115

More Books

Students also viewed these Databases questions

Question

What is a verb?

Answered: 1 week ago