Exam 1 Data Structures

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

Write the method isEmpty() for a ListArrayBased class. It needs to return a boolean type. Assume we have a "private int numItems" variable.

public boolean isEmpty() { return (numItem == 0) {

A language-independent specification for a group of values and operations on those values is called a/an: a. primitive b. abstract data type c. collection d. data structure

d

Given the following infix expression, which one of the following is the corresponding postfix expression? w+x*y/z a. wx+ yz*/ b. wxyq+*/ c. none of the above d. wxy*z/+

d

If the following nodes are added in order, what does the resultant chain look like? "L", "A", "R", "X", "J" a. null, "J", "X", "R", "A", "L" b. null, "L", "A", "R", "X", "J" c. "L", "A", "R", "X", "J", null d. "J", "X", "R", "A", "L", null

d

In a linked-chain implementation of a Stack ADT, when a node is popped from the stack a. the original first node will no longer be referenced b. the original first node will be deallocated c. the new first node will reference what was the second node in the chain d. all of the above

d

In order to resize an array to accommodate a larger bag, you must a. define an alias that references the original array b. create a new array that is larger than the original array and make the alias reference it c. copy the contents of the original array reference by the alias to the new array and discard the original array d. all of the above

d

In the ADT, when an item is deleted from position i of the list, ______. a. the position of all items is decreased by 1 b. the position of each item that was at a position smaller than i is increased by 1 while position of each item that was at a position greater than i is decreased by 1 c. the position of each item that was at a position smaller than i is decreased by 1 d. the position of each item that was at a position greater than i decreased by 1

d

In the following list: John Kate Fred Mark Jon Adam Drew Which element is the head of the list? a. Drew b. Kate c. Mark d. John

d

In the remove method, setting the last entry of the array to null a. flags the removed object for garbage collection b. prevents malicious code from accessing it c. is a good security practice d. all of the above

d

Which behaviors change the contents of a bag? a. clear() b. remove() c. add() d. all of the above

d

Which method can be used to retrieve all of the elements of a bag? a. displayBag() b. printBag() c. getAllItems() d. toArray()

d

Which of the following is the postfix form of the infix expression: a * b - (c + d)? a. a b c -* d + b. a b c - d + * c. a b c d +-* d. a b * c d +-

d

Which of the following is the prefix form of the infix expression: (8 + 6) / (16 - 4)? a. / 8 6 +- 16 4 b. /+- 8 6 16 4 c. + 8 6 / - 16 4 d. /+8 6 - 16 4

d

Which of the following operations could be identified as the basic operation of an algorithm? a. addition b. multiplication c. division d. all of the above

d

Perform radix sort on the following numbers(Steps are needed): 0123, 2154, 0222, 0004, 0283, 1560, 1061, 2150

1560 2150 0123 2154 0222 0004 0283 1061 1560 2150 1061 0123 2154 0222 0004 0283 1560 2150 1061 0222 0123 2154 0004 0283 1560 2150 1061 0222 0123 0283 2154 0004 2150 1560 1061 0222 0123 0283 0004 2154

What is an abstract data type(ADT)?

ADT is a collection of data and a set of operation on that data.

True/False In an array-based implementation of the Stack ADT, spreading the cost of the push operation when the stack is full yields a performance of O(n).

False

True/False In an array-based implementation of the Stack ADT, it is more efficient to have the first array location reference the top of the stack.

False

True/False The head of a list does not have a successor.

False

True/False You should implement all methods of an ADT implementation before testing to make testing easier.

False

Explain why null is a potential return value for the remove operation.

It is a value that cannot be in the bag and therefore signals is a problem if, for example, a client tries to remove an entry from an empty bag.

Describe in your own words the language defined by this recursive definition: <S>= @ | <W> | @ <S> <W>= aab | aa < W > b

The language <S> contains a character "@" or contains <W> or begins by "@" and followed by an existing <S>. In addition, the grammar <W> contains the string "aab" or start by string "aa" followed by existing <W> and end by character "b". For Example, <S>= @ <S>= @@ <S>= aab <S>= aaaabb <S>= @aaaabb

What are the three types of operations on data?

Three types of operations on data is: 1. add 2. remove 3. ask question if the list is empty

Draw the resultant stack after the following operations. Label the top entry of your stack. push(F), pop(), push(G), push(K), push(E), pop().

Top -> K G

True/False In an array-based implementation of the Stack ADT, the cost of doubling the array size is amortized over all additions to the stack.

True

True/False Pull is an alias for the pop method.

True

True/False A class should not return a reference to an array that is private data field.

True

True/False An application can use the operations of an ADT without knowing how the ADT is implemented.

True

True/False The empty string is a palindrome.

True

True/False The structure the definition of a language, the easier it is for a compiler to recognize a syntactically legal expression.

True

True/False To sort numeric data, the radix sort treats a number as a character string.

True

When removing a node from a chain, what case should we consider? a. the node is at the beginning of the chain b. the node is at the end of the chain c. both a and b d. none of the above

a

Which code correctly adds the first entry to an empty bag? a. Node newNode = new Node(newEntry); firstNode = newNode; b. Node newNode = new Node(); newNode = newEntry; firstNode = newNode; c. both a & b d. none

a

Which of the following is a prefix expression? a. / a + b c b. a b c +/ c. a * b + c d. a / (b + c)

a

A program that uses an ADT is called a(n) ______. a. client b. data structure c. interface d. inheritance

a

Consider an algorithm that contains loops of the form: for (x = 1 through n) { for (y = 1 through x) { for (z = 1 through 10) { Task T } // end for }// end for }// end for If task T requires t time units, the innermost loop on z requires ____ time units. a. 10 * t b. 10 c. z*t d. y

a

Given the following array: 4 15 8 3 28 21 Which of the following represents the array after the second swap of the selection sort? a. a. 4 15 8 3 21 28 b. a. 4 3 8 15 21 28 c. a. 21 4 3 8 15 28 d. a. 3 4 8 15 21 28

a

In the recursive solution to the Eight Queens problem, the problem size decreases by ______ at each recursive step. a. one column b. two column c. one square d. two square

a

Ordinary algebraic expressions are also known as a. all of the choices b. prefix expressions c. postfix expressions d. infix expressions

a

The correct grammar for the following language L: L = {w: w is of the form S^n D^n for some n 0} is ___. a. <legal-word> = empty string | S <legal-word> D b. <legal-word> = S <legal-word> D c. <legal-word> = empty string | S | <legal-word> | D d. <legal-word> = S | <legal-word> | D

a

The inception operation of the ADT array can insert new items _____. a. into any position of the list b. only at the front of the list c. only at the end of the list d. only at the middle of the list

a

The symbol A^n B^n is standard notation for the string that consists of _____. a. n consecutive A's, followed by n consecutive B's b. a pair of an A and a B, followed another pair of an A and a B c. an equal number of A's and B's, arranged in a random order d. an A, followed by an n, followed by a B, followed by an n

a

The value of which of the following growth-rate functions grows the slowest? a. O(1) b. O(log2n) c. O(n^2) d. O(n)

a

What happens when you remove a node from a chain with only one node? a. the firstNode reference will become null t b. he firstNode reference will become invalid c. an IllegalOperationException is thrown d. none of the above

a

Algorithm analysis should be independent of all of the following EXCEPT_____. a. the test data used to test a program which implements an algorithm b. the number of significant operations in an algorithm c. the computer used to run a program which implements an algorithm d. the programming style used in the implementation of the algorithm

b

Algorithm efficiency is typically a concerting for _______. a. medium sized problems only b. large problems only c. small problems only d. problems of all sizes

b

An algorithm's execution time is related to the number of _____ it requires. a. test data sets b. operations c. parameters d. data fields

b

Consider an algorithm that contains loops of the form: for (x = 1 through n) { for (y = 1 through x) { for (z = 1 through 10) { Task T } // end for } // end for } // end for If task T requires t time units, the innermost loop on y requires ____ time units. a. 10*t b. 10 * t * x c. (10*t)+x d. t*x

b

Data structures are part of an ADT's ____. a. defintion b. implementation c. usage d. specification

b

Given the fact that a selection sort of n items requires n^2 / 2 + 5 * n / 2 - 3 major operations, the selection sort is ______. a. O(n) b. O(n^2) c. O(n^2/2) d. O(1)

b

If a problem of a size n requires time that is directly proportional to n, the problem is ________. a. O(n^2) b. O(n) c. O(1) d. O(2n)

b

In the following list: John Kate Fred Mark Jon Adam Drew Which element is the tail of the list? a. John b. Drew c. Jon d. Kate

b

In the worst case, a binary search is ______. a. O(b) b. O(log2n) c. O(1) d. O(n^2)

b

The effect of doubling the input size on an algorithm with time complexity O(n3) is a. double b. 8 times c. negligible d. 3 times

b

The remove method replaces the removed entry with null because a. the client expects a null return value b. the entry could potentially be scheduled for garbage collection c. otherwise it could be considered a duplicate value d. it is a fail-safe programming practice

b

Using the evaluatePostfix algorithm, evaluate the following postfix expression. 72+4* a. 13 b. 36 c. 15 d. 18

b

Where is a new node added to a linked list? a. at the end b. at the beginning c. in a random place d. in the middle

b

Which of the following strings is a palindrome? a. "bottle" b. "r" c. "beep" d. "coco"

b

In a grammar, the symbol x | y means a. x out of y b. x divided by y c. x or y d. x followed by y

c

In the Eight Queens problem, each column can contains _____. a. exactly two queens b. at most two queens c. exactly one queen d. at most three queens

c

The effect of doubling the input size on an algorithm with time complexity O(log n) is a. 2 * log n b. there is no effect c. negligible d. double

c

The items in the ADT list are referenced by _____. a. position name b. value c. position number d. name

c

The statement: JavaPrograms = {strings w: w is a syntactically correct Java program} signifies that _______. a. a. all strings are syntactically correct Java programs b. a. a string is a language c. a. all syntactically correct Java programs are strings d. a. the JavaPrograms language consists of all the possible strings

c

When adding an item to a bag, which of the following statements are true? a. You can specify the item will be placed as the first in the bag. b. None of the above. c. You cannot specify the position of the item in the bag. d. You can specify the item will be placed as the last in the bag

c

the specifications of an ADT's operations indicate ______. a. how to implement the operations b. how to store the data in the ADT c. what the operations do d. how to carry out the operations

c

If the string w is a palindrome, which of the following is true? a. a. w minus its first character is a palindrome b. a. the second half of w is a palindrome c. a. w minus its last character is a palindrome d. a. the first half of w is a palindrome e. a. w minus its first and last characters is a palindrome

e

Given f(n)=4n+63+5n2+3nlogn what is g(n)?

g(n) = 6n2 + 3nlogn + 4n + 63 => O(n2)

Order the following growth rates from smallest to largest. n2 n! nlogn 2n n logn

log n < n < nlogn < n2 < 2n< n!

Why is it a bad programming practice for the Stack ADT clear method to simply set the topIndex to -1 in an array-based implementation?

the objects in the stack remain allocated.

What are the two base cases in a recursive description of a palindrome?

the two base case in a recursive description of a palindrome is the length of string is 0 and 1.


Ensembles d'études connexes

Spanish Vocabulary - Lección 17

View Set

Supply Chain: Chapter 6 Questions

View Set

Negative and Positive Connotations

View Set

Special Topics In Medical (CT): Quiz 5

View Set

5.3 Optical Media, 5.3.5 Practice Questions

View Set

Graded Homework - Chapter 10: Introduction to Economic Fluctuations

View Set