CS 235 Final Exam

¡Supera tus tareas y exámenes ahora con Quizwiz!

Which of the following should be used to allow you to use cout in your c++ program?

#include <iostream>

Suppose we want to get the address of a variable named x. Which of the following would provide that?

&x

With an iterator named iter, how would the data in the iterator be accessed?

*iter

Which of the following stack configurations are correct in terms of precedence? Let the far left be the bottom of the stack, and the right be the top.

+ %

Suppose set A contains the strings "apples", "oranges", and "pineapples". Then the strings "apples" and "grapes" are inserted. How many items are in A after these two insertions?

. 4

A Huffman tree for an alphabet of 15 distinct characters has _____ leaf nodes.

15 (and 14 internal nodes)

What is the matching postfix expression to the following infix expression: 7 + ( 2 * 3 ) / 9?

7 2 3 * 9 / +

What is the result of the postfix expression: 4 7 * 20 - ?

8

If a particular binary tree is full and has 100 leaf nodes, how many internal nodes does it have?

99

What is a C++ concept?

A C++ concept serves as a constraint by limiting the set of arguments that are accepted as template parameters.

What things are necessary in a recursive function?

A base case and a recursive call.

What is the relationship between a class and an object?

A class is general; an object is specific

Which of the following would not be a good application for a binary tree?

A family tree.

Pick the best statement

A full binary tree need not be complete and a complete binary tree need not be full.

Which of the following is an example of an \'is-a\' relationship?

A jet plane is a plane.

Suppose you want to make a priority queue where smaller numbers have the highest priority. Which of the following would be the best underlying data structure?

A min-heap

What happens when a recursive function calls itself?

A new instance of the function is called.

What kind of pointer should be included in a singly linked node?

A pointer to the next node.

What is recursion?

A problem solving approach that causes functions to call themselves with different arguments.

All of the following are true of Big-O analysis EXCEPT what?

A simple way to determine the Big-O of an algorithm or program is to look at the loops invariants.

What is the advantage of placing the word const in the function declaration and in the function definition?

A. Any operation that could modify the object is flagged. B. It facilitates optimizations in the machine code. C. This tells the user that the function will not modify the associated object.

Which of the following is a true about Binary Trees?

A. Every binary tree is either complete or full. B. Every complete binary tree is also a full binary tree. C. Every full binary tree is also a complete binary tree. D. No binary tree is both complete and full. E. None of the above. (CORRECT)

What best describes Namespaces?

A. The entire C++ standard library is contained in the namespace std. B. Namespaces are used to organize code into logical groups and to prevent name collisions. C. All names introduced by declarations within a namespace-body become members of the current namespace identifier. D. All of the above are true. (CORRECT)

Polymorphism expects _______.

A. functions with common signatures at different levels in a hierarchy B. functions with common signatures at different levels, with at least the highest-level function declared virtual C. pointers to objects (probably to objects higher in the hierarchy) D. All of the the above. (CORRECT)

Which of the following is TRUE concerning abstract classes and concrete classes?

Abstract classes can declare abstract member functions, but concrete classes cannot.

Which of the following is NOT a reason to use a linked list over a vector?

Accessing any given element in a linked list is more efficient.

Pick the best statement:

An ADT is represented by a class consisting of abstract functions

A Priority Queue is an extension of queue with following properties:

An element with high priority is dequeued before an element with low priority.

What is true of an Iterator?

An iterator is an object pointer to an item that is part of a larger container of items.

What is true of C++ pointer variables?

Array pointers enable us to conveniently process groups of data such as vectors, lists, and strings.

What is the difference between const and the preprocessor directive #define?

As a general rule you should give the compiler preference to the preprocessor.

Suppose the following operations are performed on an empty queue: Push A, push B, push C, push E, pop, and push D. What would be the next value to be accessed from this queue?

B

Why is Node typically defined as a struct in the private part of the host class?

Because a struct's data members are public by default.

What best describes a C++ template?

C++ uses a class template as a pattern to create a new class of a specified type.

Which of the following functions is the <b>least</b> efficient when implemented recursively?

Calculating the nth Fibonacci number.

Which representation of a queue has the most favorable Big Ohs for the operations (as discussed in class)?

Circular array

Suppose the following operations are performed on an empty stack: push A, push B, push C, push E, pop, and push D. What would be the next value to be accessed from this stack?

D

What is C++ object delegation?

Delegation allows exposure to some functionality of a pre-existing class, but still control access through your own interface.

With the recursive linear search algorithm given in the book, how many items in the list need to be checked if the item is not in the list?

Every item in the list.

True or false: a heap can only be represented with a linked data structure.

False

Which of the following most accurately describes the behavior of a queue?

First in, first out (FIFO).

Which strategy is most likely to be successful?

Implementing a stack by using an underlying linked list.

Suppose you have a binary search tree. Which kind of traversal would print the contents in increasing order?

Inorder.

Which of the following describes testing the interactions among smaller units?

Integration testing

What is the fundamental flaw with the Waterfall software development model?

It assumes that each stage can be completed correctly and fully before advancing to the next stage.

Why are Iterators useful?

Iterators isolate the user from the internal structure of a container.

What is the principal advantage of a template class?

Its ability to contain different types of data (determined at compile time.)

Which of the following most accurately describes the behavior of a stack?

Last in, first out

_______ errors probably exist in a significant portion of commercial software.

Logic

Which of the following is NOT a disadvantage of a singly linked list compared to a doubly linked list?

Nodes in a singly linked list contain more data that nodes in a doubly linked list.

With the recursive binary search algorithm given in the book, how many items in the list need to be checked if the item is not in the list?

O log(n)

What is the expected run time for inserting into a hash table?

O(1)

If N = size / 2 and M = size * size, what is the Big-O of the following: for (i=0; i < N; i++) { // sequence of statements } for (j=0; j < M; j++) { // sequence of statemnets }

O(n2)

__________ traversal doesn't exist.

Outorder

If one class has two functions with the same name, but that take different arguments, this is an example of _______.

Overloading

For which type of error are try and catch most appropriate?

Run-time errors.

What is regression testing?

Testing to make sure a change did not have an unintended consequence.

What is the downside of recursion?

The function may result in a run-time error when there is no more memory available.

A map consists of a set of keys, each with one or more values. Which typically is/are unique?

The keys

When a recursive function returns after three iterations because it hits a base case, where does it return to?

The previous iteration, right after it called the next iteration.

What happens if an exception is thrown in a program and not caught?

The program aborts.

Why is the list class required to have a push_front function, but the vector is not?

The push_front function would be O(n) in a vector, and functions must be at least amortized constant time to be required.

When comparing recursion and iteration, all of the following are true EXCEPT

There is always an recursive solution to a problem that is solvable by iteration.

What is NOT TRUE about switch statements?

They must contain a break.

Which of the following describes testing the smallest testable piece of the software?

Unit testing.

Unlike a vector, a set does not support the subscript operator (e.g. mySet[0]). If someone still wanted to iterate through each item in a set, they should __________.

Use an iterator

Suppose we are writing a program with polymorphism, but only our base class functions are being called! What is likely the source of our bug?

We have forgotten to make our base class functions virtual.

Should a new Huffman tree be built for each file you create? Why or why not?

Yes, because different files may contain symbols with different frequencies.

Which of the following is NOT a consequence of calling by reference?

You get a pointer to the argument so you must dereference it

What would be the Big Oh of a reserve function which creates a new array that is twice the size of the current array for an object of class Vector, and copies the contents from the old array into the new array?

amortized order 1

An abstract data type (ADT) has all of the following EXCEPT __________________.

an implementation

Both the client and programmer can do _________ testing. Typically only the _________ does _______ testing.

black box; programmer; white box

What is the proper relationship between class List and class Ordered_List?

class Ordered_List has-a List

Recursion typically is justified when it reduces ______________.

design and coding time

A template class typically ______________.

facilitates the same set of operations on a variety of data types

Compared with a linked list, a binary tree ________.

has nodes with two child nodes instead of one next node

A private data member is visible __________________

in the class in which it is declared

If the size of a heap is n, the performance

is O(log n) for insertion.

A Priority Queue

is a container adapter that uses a specific underlying container, e.g. vector or deque.

Software practitioners sometimes object to the term "bugs" because ______.

it tends to trivialize potentially serious consequences of program defects

What kind of mapping is used in a map from keys to values?

many-to-one

Inserting at the head of a single-linked list is _______ inserting at the tail.

more efficient than

A vector is _____________ efficient than an array _______________.

more, in terms of coding time, but not execution time or memory usage

Searching for an item in a linked list is O(___). Searching in a binary search tree is O(___).

n, log(n)

As a first guess, the order of complexity of three nested loops is probably__________.

n3

A queue differs from a stack in __________.

only one operation

To convert from infix (without parentheses) to postfix, use a stack of

operators

To check for balanced parentheses, use a stack of

parentheses

When a queue is represented using a single-linked list, the links should

point from the front toward the rear.

An iterator functions most like a(n)

pointer

A heap

requires every subtree to be a heap

In a class that contains a pointer to a dynamically allocated int, the destructor ________ delete the pointer because __________.

should, the memory pointed to by the pointer must be freed to prevent memory leaks

When collisions are resolved using linear probing, ______.

the insertion occurs at the first available slot that was not previously occupied

What typically happens as a consequence of the "++iter" component of for (list<Item_Type>::iterator iter = a_list.begin(); iter != a_list.end(); ++iter) {...}

the iterator pointer advances to the next element of the list

'The "order of complexity" of an algorithm expresses ____________.

the limiting behavior of a function when the argument tends towards infinity

In tail recursion, ____________.

the recursive call is the last executable statement in the function

Suppose you want to access the next element of a stack. Which function would you call?

top()

The reallocate function for class Queue

typically does not copy elements to identical index positions.

There are two general ways to implement ADT Stack. These are __________________,

using a contiguous structure or a linked structure

The default copy constructor may be used EXCEPT ________________________________.

when a deep copy is required


Conjuntos de estudio relacionados

Physics Rotational Kinematics and Dynamics

View Set

Chapter 9 QUIZ: Patient Assessment

View Set

Peds Test 2 Book questions and 2 evolve chapters

View Set

115 PrepU Ch.66 Management of Patients with Infectious Diseases

View Set

Comparing and Contrasting Security Controls

View Set