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

22 Look at the following method. public static int Test2(int x, int y) { if ( x

ID: 3548169 • Letter: 2

Question

22
    Look at the following method.

public static int Test2(int x, int y)
{
  if ( x < y)
  {
  return -5;
  }
  else
  {
  return (Test2(x - y, y + 5) + 6);
  }
}

What is the base case for the method?

    Test2(x - y, y + 5) + 6

    -5

    +6

    x < y

23
    Look at the following method.

public static int test2(int x, int y)
{
  if ( x < y)
  {
  return -5;
  }
  else
  {
  return (test2(x - y, y + 5) + 6);
  }
}

What is the recursive case for the method?

    x != y

    x < y

    x >= y

    -5

24
    Look at the following method.

public static int test2(int x, int y)
{
  if ( x < y)
  {
  return -5;
  }
  else
  {
  return (test2(x - y, y + 5) + 6);
  }
}

What is returned for test2(10, 20)?

    1

    10

    6

    -5


25
    Look at the following method.

public static int test2(int x, int y)
{
  if ( x < y)
  {
  return -5;
  }
  else
  {
  return (test2(x - y, y + 5) + 6);
  }
}

What is returned for test2(18,5)?

    7

    -5

    6

    1


26
    Look at the following method.

public static int test2(int x, int y)
{
  if ( x < y)
  {
  return -5;
  }
  else
  {
  return (test2(x - y, y + 5) + 6);
  }
}

What is the depth of test2(18,5)?

    0

    1

    2

    3


27
    Look at the following pseudocode algorithm.

Algorithm Test3(int a, int b)
  if (a < b)
  return 5
  else if ( a == b)
  return -5;
  else
  return (a + Test3(a - 1, b)
end Test3

What is the base case for the algorithm?

    a == b

    a < b

    Both A and B

    Neither A nor B


28
    Look at the following pseudocode algorithm.

Algorithm Test3(int a, int b)
  if (a < b)
  return 5
  else if ( a == b)
  return -5;
  else
  return (a + Test3(a - 1, b)
end Test3

What is the recursive case for the algorithm?

    a > b

    a < b

    a == b

    None of the above


29
    Look at the following pseudocode algorithm.

Algorithm gcd(x, y)
  if (x < y)
  gcd (y, x)
  else
  if (y = 0)
  return x
  else
  return gcd(y, x mod y)
end gcd

What is the base case for the algorithm gcd?

    x == 0

    y > x

    y == 0

    x < y


30
    Look at the following pseudocode algorithm.

Algorithm gcd(x, y)
  if (x < y)
  gcd (y, x)
  else
  if (y = 0)
  return x
  else
  return gcd(y, x mod y)
end gcd

What is returned from gcd(60, 24)?

    24

    60

    66

    12


31
    Look at the following pseudocode algorithm.

algorithm Test14(int x)
  if (x < 8)
  return (2 * x)
  else
  return (3 * Test14(x - 8) + 8)
end Test14

What is the base case for the algorithm?

    3 * Test14(x - 8) + 8

    2 * x

    x >= 8

    x < 8

32
    Look at the following pseudocode algorithm.

algorithm Test14(int x)
  if (x < 8)
  return (2 * x)
  else
  return (3 * Test14(x - 8) + 8)
end Test14

What is the recursive case for the algorithm?

    2 * x

    3 * Test14(x - 8) + 8

    x < 8

    x >= 8


33
    Look at the following pseudocode algorithm.

algorithm Test14(int x)
  if (x < 8)
  return (2 * x)
  else
  return (3 * Test14(x - 8) + 8)
end Test14

What is the depth of Test14(7)?

    7

    1

    0

    6


34
    Look at the following pseudocode algorithm.

algorithm Test14(int x)
  if (x < 8)
  return (2 * x)
  else
  return (3 * Test14(x - 8) + 8)
end Test14

What value is returned for Test14(7)?

    14

    0

    7

    -5


35
    Look at the following pseudocode algorithm.

algorithm Test14(int x)
  if (x < 8)
  return (2 * x)
  else
  return (3 * Test14(x - 8) + 8)
end Test14

What is the depth of Test14(16)?

    0

    1

    2

    3


36
    Look at the following pseudocode algorithm.

algorithm Test14(int x)
  if (x < 8)
  return (2 * x)
  else
  return (3 * Test14(x - 8) + 8)
end Test14

What value is returned for Test14(16)?

    8

    16

    24

    32



50
What is the value of scores[2][3] in the following array?

int [] [] scores = { {88, 80, 79, 92}, {75, 84, 93, 80},
{98, 95, 92, 94}, {91, 84, 88, 96} };

93

94

84

95


51
What will be returned from the following method?

public static float[] getValue(int x)


A float value

A reference to an array of integers

A reference to an array of float values

An int value


52
What will be the value of x[8] after the following code has been executed?

final int SUB = 12;
int[] x = new int[SUB];
int y = 100;
for(int i = 0; i < SUB; i++)
{
x[i] = y;
y += 10;
}

190

200

170

180


53
A basic step is

one that is implemented in a library package

an operation that is used only in the simplest algorithms

an operation that can be executed within a constant amount of time

None of the above


54
A computational problem is

one that arises when a program runs out of memory, or has some other kind of runtime error

a problem that can be solved using an algorithm

one that arises in the writing of computer programs

None of the above


55
A contigous segment of an array is given by specifying two subscripts, lower and upper. Which of the following expressions gives the subscript of the array element that is three quarters of the way from lower to upper?

lower /3 + upper

(upper lower) * 3 /4

lower + 3 * upper /4

lower + (upper lower) * 3 / 4


56
A contiguous segment of an array is specified using two subscripts, lower and upper. Which expression gives the position of the element in the middle of the array segment?

lower + (upper - lower) / 2

lower /2 + upper

lower + upper / 2

(upper - lower)/2


57
A search for an item X in a portion of a sorted array works by repeatedly selecting the middle item and comparing it to X. If X is not found there, the search method selects either the portion of the array to the left of the middle item, or the portion of the array to the right of the middle item, and continues the search. This method is called

selection search

sequential search

binary search

None of the above



58
A search for an item X in an array starts at the lower end of the array, and then looks for X by comparing array items to X in order of increasing subscript. Such a method is called

selection search

binary search

sequential search

lower to upper search


59
If lower is the first subscript in a contiguous portion of an array, and upper is the last subscript, then the array item in the middle of that array portion is at subscript

(lower + upper)/2

(upper lower)/2

lower + upper/2

(lower upper)/2


60
If an array is known to be sorted, it can be searched very quickly by using

binary search

sequential search

selection search

None of the above

61
A queue is a container that allows elements to be stored and removed

in a first-in-first-out fashion

quickly and efficiently

in a first-in-last-out fashion

in a last-in-first-out fashion


62
A stack is a container that allows elements to be stored and removed

in a first-in-first-out fashion

according to priority

last-in-last-out fashion

in a last-in-first-out fashion


63
A stream of cars going through a toll booth is an example of a

stack

priority queue

queue

hash set


64
Compilers of modern programming languages support method calls and returns with an internal

hash set

queue

priority queue

stack


65
Consider a class that uses the following variables to implement an array-based stack:
String [ ] s = new String[100];
int top = 0;
The boolean method to check for an empty stack can be written as:

if (s == null)
return true;
else
return false;

if (top == 0)
return true;
else
return false;

return top;

if (s.length == 0)
return true;
else
return false;


66
Consider a class that uses the following variables to implement an array-based stack:
String [ ] s = new String[100];
int top = 0;
a method for adding an item x to the stack can be written as

if (top < s.length)
{
s[top] = x;
top ++;
}
else
throw new RuntimeException("Overflow");

if (top == s.length)
throw new RuntimeException("Overflow");
else
{
top ++;
s[top] = x;
}

s.add(top, x);

if (top < 0) throw new IndexOutBoundsException()
s[top] = x;
top ++;


67
Consider a class that uses the following variables to implement an array-based stack:
String [ ] s = new String[100];
int top = 0;
a method that implements the String peek() operation can be written as

if (top == 0)
throw new RuntimeException("Underflow");
else
return s[top];

return s[top-1];

if (top == 0)
throw new RuntimeException("Underflow");
else
return s[top-1];

return s[top];


68
Consider a class that uses the following variables to implement an array-based stack:
String [ ] s = new String[100];
int top = 0;
a method that implements the String pop() operation can be written as

if (top == 0)
throw new RuntimeException("Underflow");
String temp = s[top];
top--;
s[top] = null;
return temp;

top--;
return s[top];

if (top == 0)
throw new RuntimeException("Underflow");
return s[top-1];
top --;
s[top] = null;

if (top == 0)
throw new RuntimeException("Underflow");
top--;
String temp = s[top];
s[top] = null;
return temp;


69
Consider a class that uses the following variables to implement an array-based stack:
String [ ] s = new String[100];
int top = -1; //Note top == -1 indicates stack is empty
a method that implements a void push(String x) operation can be written as

if (top == s.length)
throw new RuntimeException("Overflow");
top ++;
s[top] = x;

if (top == s.length)
throw new RuntimeException("Overflow");
s[top] = x;
top ++;

if (top == s.length-1)
throw new RuntimeException("Overflow");
s[top] = x;
top ++;

if (top == s.length-1)
throw new RuntimeException("Overflow");
top ++;
s[top] = x;


70
Consider a class that uses the following variables to implement an array-based stack:
String [ ] s = new String[100];
int top = -1; // Note top == -1 indicates stack is empty
a method that implements a String pop() operation can be written as

if (top == -1)
throw new RuntimeException("Empty Stack");
String temp = s[top];
s[top] = null;
top--;
return temp;

if (top == -1)
throw new RuntimeException("Empty Stack");
s[top] = null;
top--;
return s[top ];

if (top == -1)
throw new RuntimeException("Empty Stack");
top --;
String temp = s[top];
s[top] = null;
return temp;

None of the above


71
Consider a class that uses the following variables to implement an array-based stack:
String [ ] s = new String[100];
int top = -1; // Note top == -1 indicates stack is empty
a method that implements a String peek() operation can be written as

if (top == 0)
throw new RuntimeException("Empty Stack");
else
{
top --;
return s[top];
}

top --;
if (top == -1)
throw new RuntimeException("Empty Stack");
else
return s[top];

if (top > -1)
return s[top];
else
throw new RuntimeException("Empty Stack");

if (top == -1)
throw new RuntimeException("Empty Stack");
else
return s[top -1];


72
In a list implementation of a queue, the end of the list at which elements are added is called

the bottom of the queue

the head of the queue

the front of the queue

the rear of the queue


73
In a list implementation of a queue, the end of the list from which elements are removed is called

the bottom of the queue

the top of the queue

the front of the queue

the rear of the queue


74
In a list implementation of a stack, the end of the list at which elements are added and removed is called

the head of the stack

the active end of the stack

the top of the stack

the bottom of the stack


75
In an array-based implementation of a stack, an operation that needs to add a new element to the stack may not be able to complete because the array is full. In this case, the failed operation should

print an error message and return from the method

alert the user before continuing execution

throw some appropriately defined exception

print an error message and exit


76
The operation for adding an item to a queue is called

enqueue

dequeue

proqueue

requeue


77
The operation for removing an item from a queue is called

extract

disqueue

enqueue

dequeue


78
The stack empty operation

checks to see if there is at least one item on the stack

destroys the stack and creates a new empty one in its place

removes all elements from the stack

None of the above


79
The stack peek operation

adds a single item to the stack

checks a stack to see if there are any elements in it

removes and returns an item from the stack

returns the item at the top of the stack, but does not remove it


80
The stack pop operation

does not exist: There is no such stack operation

removes all items currently on the stack

removes from the stack the number of elements specified by its integer parameter

extracts one element from the stack and returns it

81
The stack pull operation

brings two stacks together and combines their elements

does not exist: There is no such stack operation

extracts one element from the stack and returns it

increases the capacity of a stack that is about to fill up


82
The stack push operation

adds a single item to the stack

returns the item at the top of the stack, but does not remove it

is normally implemented through a hash set

removes and returns an item from the stack


83
A binary tree is a collection of nodes in which

each node has at most one predecessor and at most two successors

each node has at most one predecessor and at most one successor

each node has at most one predecessor and exactly two successors

each node has at least one predecessor and at most two successors


84
A binary tree stores items that have a natural order in such a way that at each node X, all items stored in the left subtree of X are less than the item stored at X, and all items stored in the right subtree are greater than the item stored at X. Such a binary tree is called

an ordered binary tree

an AVL tree

a binary search tree

a priority queue


85
A binary tree with height 1 must have

two or three nodes

one or two nodes

exactly three nodes

exactly two nodes


86
A binary tree with just one node has height

-1

0

1

None of the above

87
A binary tree with no root

must have exactly two nodes

must be empty

must have only one node

None of the above

88
A node in a binary tree that has no children is called

a leaf

a single node

barren

a twig

89
A priority queue is

a binary search tree in which the heights of the subtrees at each node differ by at most one

is an AVL tree in which the root is the minimum element

is a binary search tree that stores elements according to their natural order

is a collection that allows elements to be added, but only allows the minimum element to be removed


90
A ternary tree is like a binary tree, except each node may have up to three successors. Write a TNode class that can be used to represent a ternary tree. Define a notion of preorder and postorder traversal for ternary trees, and write methods void postorder(TNode tree) and void preorder(TNode tree) that implements your notion of those traversals.


91
Adding all items from a list to a certain data structure and then removing them one at a time yields a sorted version of the list. The data structure is a

priority queue

complete binary tree

binary sort tree

binary search tree

92
An AVL tree is

a binary tree in which each child is greater than its parent

a binary tree in which the left and right subtree have heights that differ by at most one

a binary search tree in which the heights of the subtrees at each node differ by at most one

a priority queue with a balance condition


93
An empty binary tree has height

0

1

-1

None of the above: the height of an empty binary tree is not defined.

94
Assuming a Node class
class Node
{
int element;
Node left, right;
Node(int el, Node left, Node right)
{
element = el;
this.left = left;
this.right = right;
}
}
Write a method int numberLeaves(Node tree) that returns the number of leaves in the binary tree whose root is tree.




95
Assuming a Node class
class Node
{
int element;
Node left, right;
Node(int el, Node left, Node right)
{
element = el;
this.left = left;
this.right = right;
}
}
Write a method int size(Node tree) that returns the number of nodes in the binary tree whose root is tree.


96
Assuming a Node class
class Node
{
int element;
Node left, right;
Node(int el, Node left, Node right)
{
element = el;
this.left = left;
this.right = right;
}
}
Write a method int depth(Node tree) that returns the length of the longest path that begins at the node tree and ends at any leaf of the binary tree.


97
To find the minimum node in a binary search tree

you should look at the root of the binary tree

you should start at the root, and then keep passing from each node to its right child until you come to a node with no right child

you need to examine every node, and then pick the one with the least value

you should start at the root, and then keep passing from each node to its left child until you come to a node with no left child

98
The successor of a node in a binary tree is called its

child

descendant

neighbor

neighbor

99
The predecessor of a node in a binary tree is called its

parent

progenitor

precursor

ancestor

100
The length of the longest path from the root of a binary tree to a leaf is called

the max-path length of the tree

the height of the tree

the level of the tree

the peak length of the tree

Explanation / Answer

x<y

x >= y

-5

7

3

Both A and B

a > b

x < y

12

x < 8

x >= 8

1

14

3

8


93

A reference to an array of float values

180

an operation that can be executed within a constant amount of time

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote