cis 351 final

Ace your homework & exams now with Quizwiz!

If final int SIZE = 15 and int[] x = new int[SIZE], what would be the range of subscript values that could be used with x[]?

0-14

If the sequence of operations - push (5), push (0), pop, push (9), push (2), pop, pop, pop, push (2), pop are performed on an initially empty stack, the sequence of popped out values is:

02952

In a binary tree, the level of the children of the root node is ____.

1

What is the postfix version of the infix expression 12 / 3 * (50 / 3 * (3 / 4)) / 2 * 10

12 3 / 50 3 / 3 4 / * * 2 / 10 *

A stack S of integers initially contains the following data: 6 (top) 273 The following code is then executed: int x = S.pop(); int y = S.pop(); int z = S.pop(); S.push(x + y); int w = S.pop(); S.push(w + z);After this code has been executed, what are the contents of the stack?

15 3

What will be the output of the program? ---Code--- class Output { final static short i = 2; public static int j = 0; public static void main(String [] args){ for (int k = 0; k < 3; k++) { switch (k) { case i: System.out.print(" 0 "); case i-1: System.out.print(" 1 "); case i-2: System.out.print(" 2 "); } } } } ---Code---

2 1 2 0 1 2

What is the value of the variable x after the following Java commands are executed, assuming they compile and run without an exception? double x; x = (5 / 4) * Math.abs(-257) + 3.0;

260

The following numbers are inserted into an empty binary search tree in the given order: 10, 1, 3, 5, 15, 12, 16. What is the height of the binary search tree (the height is the maximum distance of a leaf node from the root)?

3

What is the value of the following prefix expression " ++ 26 + - 1 3 2 4" ? (consider spaces between the last 4 digits. Treat them as an individual number)

30

How many arguments are passed to the printf method? System.out.printf("Hello %s, the time is %02d:%02d.\n", first + " " + last, hour - 2, minute);

4

Given a 5 element queue Q (from front to back: 1, 3, 5, 7, 9), and an empty stack S, remove the elements one-by-one from Q and insert them into S, then remove them one-by-one from S and re-insert them into Q. Select, what are the contents of the queue now look like (from front to back)?

9, 7, 5, 3, 1

Assume that you want to create an array containing ten Die objects. Which of the following code segment accomplishes this correctly? A: ---Code--- Die[] dice = new Die[10];for (int i = 0; i < dice.length; i++) { dice[i] = new Die(); } ---Code--- B: ---Code--- Die[] dice = new Die[10];Die die = new Die();for (int i = 0; i < dice.length; i++) { dice[i] = die; } ---Code---

A

Which of the following is true?

A class may implement any number of interfaces.

What is the output of a cryptographic hash function?

A fixed set of bits, derived from one-way mathematical operations

Which of the following statements is true?

A reference variable my hold object references of non-matching types, as long as the object type is a subclass of the variable type.

Which of the following is true of superclass constructors? Check all that are true.

A superclass constructor is always called before the subclass constructor. The "super" keyword may be used to explicitly call a superclass constructor from the subclass.

What is the correct postfix version of the infix expression A * (B + C * D) + E

ABCD*+*E+

What is the Postfix version of the following expression: ((AX+(B*CY))/(D E))

AXBCY*+DE /

Which of the following statements is true?

Abstract classes may have constructors, even though they cannot be instantiated.

Which of the following statements is true?

Abstract classes may include both abstract and non-abstract methods.

Assume that class A does not define a toString method, and does not explicitly extend any other class. What will happen if we call toString on an object of class A?

All classes implicitly inherit from Object, so the toString method defined by Object will be called.

Which of the following best describes an interface in Java?

An interface is similar to an abstract class that has only abstract methods.

What is the need for a circular array compared to a non-circular array-based implementation of a queue?

Effective usage of memory

In a heap, the left child of a node is always less than the right child of a node (T or F)

False

In a preorder traversal of a binary search tree, the first item printed out is always the smallest one. (T or F)

False

The maximum number of nodes in a tree that has L levels is 2L (T or F)

False

Tree operations typically run in O(d) times where d is the number of nodes in the tree. (T or F)

False

Which of the following is true about linked list implementation of queue?

In push operation, if new nodes are inserted at the beginning of linked list, then in pop operation, nodes must be removed from end. In push operation, if new nodes are inserted at the end, then in pop operation, nodes must be removed from the beginning.

Which of the following traversal outputs the data in sorted order in a BST?

Inorder

Which one of the following is true for Markle Tree?

It allows efficient mapping of huge data and small changes made to the data can be easily identified. If we want to know where data change has occurred then we can check if data is consistent with root hash and we will not have to traverse the whole structure but only a small part of the structure. The root hash is used as the fingerprint for the entire data.

What is the role of the protected keyword in Java?

It is an access specifier that provides a level of access somewhere between public and private.

Assuming that A is an interface, which of the following is true?

It is possible to declare a variable of type A.

What structure might be useful in storing a chain of blocks for a large dataset?

Markle tree

What is the output of the following code? for ( int count = 0; count < 9; ) System.out.print( count + " " ); count++ ; System.out.println( );

Nothing --- the program will not compile.

Given a collection of algorithms that runs on O(1), O(n log n), O(n), O(n2 ), O(log n), O(n!), order the algorithms from fastest to slowest.

O(1), O(log n), O(n), O(n log n), O(n2 ), O(n!)

For the following code, count the number of operations where some_statement is executed based on the loops for (int j = 1 ; j < n ; j *= 2) { for (int I = 1; i < n ; i++) { some_statement ; } }

O(n logn)

What is the worst case time complexity for search, insert and delete operations in a general Binary Search Tree?

O(n) for all

Finding the max element in an unordered stack would require

O(n) operations

What is the BigO notation (in terms of n) for the following code: void f2(int n) { for(int i=0; i < n; i++) { for(int j=0; j < 10; j++) { for(int k=0; k < n; k++) { for(int m=0; m < 10; m++) { System.out.println("!"); } } } } }

O(n2)

Which of the following are properties of cryptographic function?

One way function and collision free

Which of the following statements about stacks is incorrect?

Stacks are first-in, first-out (FIFO) data structures.

Which of the following is described as "dynamic binding"?

The JVM dynamically determines which method to call based on the object's type at run-time.

How do we indicate in a UML diagram that a class is abstract?

The class name is in italics.

All blocks contain a link to the previous block, except for:

The first block.

Which of the following is an important difference between arrays and ArrayLists in Java?

The size of an array cannot change. ArrayLists can grow or shrink as needed.

Which of the following accurately describe the relationship between a subclass and a superclass.

The subclass is a specialized version of the superclass. There is an "is a" relationship between the subclass and the superclass. An instance of the subclass "is a" instance of the superclass as well.

Which of the following best describes the difference between overloading and overriding a method?

When one method overrides another, both methods will have the same signature.

What will be printed by the following code snippet, assuming that letters is an initially empty? ---Code--- letters.add("A"); letters.add("B"); letters.add("C"); letters.add(1, "D"); System.out.println(letters.toString()); ---Code---

[ A, D, B, C]

What will be the output of the following program? ---Code--- class W { static int c = 0; public static void main(String[] args) { W w1 = c(); W w2 = c(w1); W w3 = c(w2); W w4 = c(w3); } private W() { System.out.println("c = " + c); } static W c() { return c++ <= 0 ? new W() : null; } static W c(W w) { return w.c++ == 1 ? new W() : null; } } ---Code---

c = 1 c = 2

What will be the output of the following program? public class Time { int a = 50; int b = 10; public static void main(String args[]) { a += b--; System.out.println(a); } }

compilation error or runtime error

Which of the following is valid, given that the following variables are declared: int cost, double taxRate, float interestRate, long count

cost=count;

The diagram below suggests how we could implement a double-ended linked list, in which we maintain a reference to both the first and last nodes in the linked list. Which one of the following operations would be inefficient to carry out when there are a large number of elements in the linked list?

deletion from the end to which rear refers

Say that class Person has a child class Student and anothr child class Staff. Class Staff has a child class HourlyStaff. Examine the following Person p; Student su_student = new Stduent(); Staff su_staff = new Staff(); HourlyStaff h_staff = new HourlyStaff(); Which one of the following will cause a compiler error?

h_staff = su_student;

Assume that the following method header is for a method in class A. public void displayValue(int value) Assume that the following code segments appear in another method, also in class A. Which contains a legal call to the displayValue method?

int x = 7; displayValue(x);

Consider the following partially completed class public class Hat { private int size; //other code goes here } Which of the constructors below will function correctly?

public Hat(int size) { this.size = size; }

You have a singly linked list constructed out of nodes defined as follows: public class Node { public int datum; public Node next; } 0 out of 10 points In all of functions shown below, the parameter first refers to the first node in the linked list, if there is one, and has the value null otherwise. Which of the following functions correctly inserts a value x at the front of the linked list and returns a reference to the new front of the linked list?

public Node insertFront(Node first, int x) { first = new Node(); first.datum = x; first.next = first; return first; } or public Node insertFront(Node first, int x) { Node n = new Node(); n.datum = x; n.next = first; return n; }

The stack data type is restrictive in a sense that you cannot

remove the bottom element

What is the reason for using a "circular queue" instead of a regular one?

reuse empty spaces

Every node (except of the last node) in a singly linked list contains

the address of the next node

The postfix expression 14 2 5 + = will generate an error, because

there will be too many elements in the stack when the equal sign is encountered

Examine the following code: String str = "Hot Java"; boolean switch = str instanceof String; What value is placed in switch?

true

How would you access elements of an aggregated object (think of a collection) sequentially without exposing the underlying structure of the object?

using an iterator

Classes with static methods are sometimes referred to as

utility classes


Related study sets

CH 5: Theories of Motivation at Work

View Set

Chapter 11 - Organizational Design: Structure, Culture, and Control

View Set

4.3.5 Quiz: The Globalization of Culture

View Set

Unit 4 (Chapter 13-16 [Module 9-10])

View Set

Chapter 2 The Organizational Context: Strategy, Structure, and Culture

View Set

Ch. 10 Prompting and Transfer of Stimulus Control

View Set

Chapter 10: Substance use and addictive disorders

View Set

chapter 4 chemistry test 1. Why do Li, Na, K, Rb, Cs, and Fr all react with Cl in a 1:1 ratio forming sub

View Set