Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Point p = new Point (1, 2); Study carefully the options given below and decide w

ID: 3538107 • Letter: P

Question

Point p = new Point (1, 2);

Study carefully the options given below and decide which one is a deep copy of point p.

public void operation(int pos)
{
    for ( int i = pos; i < numberOfItems - 1; i++ )
        listArray[i] = listArray[i+1];
    
    numberOfItems--;
}

public operation()
{
    first = new Node();
}

public void operation(int item)
{
    Node old = first.getNext(),
    p = first;

    boolean found = false;
    while (old != null && !found)
    {
        if (old.getInfo() == item) found = true;
        else
        {
            p = old;
            old = p.getNext();
        }
    }

    if (found) p.setNext(old.getNext());
}

void operation(int c)
{
     list[n] = c;
     n++;
}

Stack s;
s.push(1);
s.push(2);
s.push(3);
s.pop();
System.out.println(s.peek());

What is the value displayed by the System.out.println statement?

void operation(int e)
{
    back = (back+1)%size;
    list[back] = e;
    count++;
}

1. If the numbers 17, 21, 34, 9 are inserted, in that order, in a stack, which will be the first element to be removed? A. 9
B. 17
C. 21
D. 34

2. If the numbers 9, 17, 21, 34 are inserted, in that order, in a queue, which will be the second element to be removed? A. 9
B. 17
C. 21
D. 34

3. In the following binary tree, 37 is the ____ of 20.


A. left child
B. right child
C. sibling
D. parent

4. Consider the code:

Point p = new Point (1, 2);

Study carefully the options given below and decide which one is a deep copy of point p.


A. Point q = p;
B. Point q = null;
C. double x = p.getX(), y = p.getY(); Point q = new Point(x, y);
D. Point q = new Point();

5. Analyze the operation method given below. What list operation does the method define?

public void operation(int pos)
{
    for ( int i = pos; i < numberOfItems - 1; i++ )
        listArray[i] = listArray[i+1];
    
    numberOfItems--;
}


A. removeAt
B. remove
C. insert
D. display

6. Analyze the operation method given below. What linked list operation does the method define?

public operation()
{
    first = new Node();
}


A. it initializes the linked list
B. it determines if the list is empty
C. it inserts an element in the linked list
D.  it displays the list elements

7. (TCO D) Analyze the operation method given below. What linked list operation does the method define?

public void operation(int item)
{
    Node old = first.getNext(),
    p = first;

    boolean found = false;
    while (old != null && !found)
    {
        if (old.getInfo() == item) found = true;
        else
        {
            p = old;
            old = p.getNext();
        }
    }

    if (found) p.setNext(old.getNext());
}


A. it displays the list elements
B. it finds if item is contained in the linked list
C. it inserts item in the linked list
D. it removes item from the linked list

8. What is the stack operation implemented in the following function? The variable n represents the stack top.

void operation(int c)
{
     list[n] = c;
     n++;
}


A. peek
B. push
C. pop
D. the constructor of the class Stack

9. Consider the following program fragment:

Stack s;
s.push(1);
s.push(2);
s.push(3);
s.pop();
System.out.println(s.peek());

What is the value displayed by the System.out.println statement?


A. 0
B. 1
C. 2
D. 3

10. Which is the queue operation implemented in the following function? The variable count represents the number of elements in the queue.

void operation(int e)
{
    back = (back+1)%size;
    list[back] = e;
    count++;
}


A. enqueue
B. dequeue
C.  getFront
D. the constructor of the Queue class

Explanation / Answer

1)d

2)b

3)a

4)d

5)d

6)b

7)b

8)c

9)a

10)c