Practice

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

describe the state of processing before a program unit is executed. describe the state of processing after a program unit is executed.

preconditions Postconditions

An array is an appropriate data structure for organizing homogeneous data collections.

true

Using a const reference parameter avoids making a copy of the corresponding argument but yet protects that argument from being changed.

true

C++ notation p->x abbreviates

(*p).x

The current object is represented by

*this

Which of the following operations can be used on a pointer variable in C++?

++

A program that uses the STL algorithms must contain the directive #include

<algorithm>

What is a hash table?

A structure that maps keys to values

Which data structure is used by the compiler to implement function calls?

Stack

STL is an acronym for

Standard Template Library

A(n) is a binary digit; a(n) is a group of eight binary digits.

bit byte

The of data and basic operations within a single entity is one of the key properties of ADTs.

encapsulation

A class declaration is usually put in a(n) ___ file whose name has the form ClassName.h.

header

The problem of dynamically-allocated memory getting marooned is called a memory ______

leak

To create an executable program, each function call in a program must be ______ to the definition of that function, which may be in a library.

linked

Which phase of the software life-cycle is usually the most expensive?

maintenance

In the floating-point representation 1.011 x 25, 1.011 is called the _____.

mantissa

The worst case computing time of linear search is O( )

n

Which of the following functions grows fastest?

n^2

The operator is used to request memory during program execution. If enough memory is available, it returns the address of a block of memory.

new address

Which of the following stack operations could result in stack underflow?

pop

Assume that each value of type int is stored in 4 bytes, if an array is declared as "int t[10];" and the base address of this array is 100. What is the address of t[2]?

108

Binary trees are trees in which each node has at most children.

2

Given that d is an double number array starting at location 2000, dPtr is a pointer to d, and each double is stored in 8 bytes of memory, what location does dPtr + 1 point to?

2008

The following items are inserted into a binary search tree: 3, 9, 7, 2, 5, 11, 1, which node is the deepest?

5

The value of 5 4 - 3 2 + * is ______

5

If the characters 'D', 'C', 'B', 'A' are placed in a queue (in that order), and then removed one at a time, in what order will they be removed?

DCBA

What is direct addressing?

Distinct array position for every possible key

In simple chaining, what data structure is appropriate?

Doubly linked list

C(const C original) is a prototype for the copy constructor of a class named C. (True or false)

False

Formulating a specification for most real-world problems is usually quite easy and straightforward.

False

Members of different structures must have unique names.

False

Structures may contain variables of only one data type.

False

When an ADT is implemented as a C++ class, which of the following should normally be true?

Function members are public, data members are private

What is the result of the following? double x[2] = {5, 2}; double * y = x; cout << *(y+1);

It prints 2

What term is used to describe an O(n) algorithm.

Linear

Which data structure represents a waiting line and limits insertions to be made at the back of the data structure and limits removals to be made from the front?

Queue.

A chained hash table has an array size of 512. What is the maximum number of entries that can be placed in the table?

There is no maximum.

Given a hash table with M = 13, and hash function h(k) = k mod 13, if collision happens the next three positions for K=21 under the chainning is: 8, 8, 8 (in a linked list pointed from 8)

True

vector objects are self-contained.

True

Suppose you have the following function prototype and variable declaration: void foo(int z[ ]); int x[10]; Suppose that this foo function changes the value of z[1]. Does this change effect the value of the actual argument?

Yes

Can two classes contain member functions with the same name?

Yes, this is always allowed

A pointer variable stores a(n) _____

address

Assume the declarations and that double values are stored in 8 bytes of memory. double * x, y = 1.1; The value of &y will be a(n) _____

address

#include<iostream> using std::cout; using std::endl; using std::ostream; #include<string> using std::string; class MyClass{ private: long x_,y_; string s_; public: MyClass(long x, long y, string s="unknown") : x_(x), y_(y), s_(s) {}; string f1(long, long); friend ostream& operator<<(ostream&, MyClass&); }; string MyClass::f1(long x, long y){ if(x > x_ && y > y_) s_ = "unset"; else if (x < x_ && y < y_) s_ = "set"; else s_ = "unknown"; return s_; } ostream& operator<<(ostream &out, MyClass &c){ // LINE 1 out << "(" << c.x_ << "," << c.y_ << "," << c.s_<< ")"; return out; } int main (){ MyClass c1(100,300); MyClass c2(10, 30); // LINE 2 cout << c1 << endl; // LINE 3 cout << c2.f1(1000,3000)<<endl; // LINE 4 } For the program shown in Figure 1 which is true about operator<< on Line 1?

all of the listed answers

Which of the following operators cannot be overloaded?

all of the listed answers

The address of the first element is called the of the array and the name of the array is actually a(n) to this element.

base address constant address

In a software life cycle, what is produced after the design phase?

coding

The operation ____ is used to release memory during program execution.

delete

In a software life cycle, what is produced just after the specification phase?

design

Suppose you have the following function prototype and variable declaration: void foo(int z[ ]); int x[10]; Which is the correct way to call the foo function with x as the argument:

foo(&x);

A nonmember function must be declared as a(n) __________ of a class to have access to that class's private data members.

friend

In the case of ___________ function, arguments may be passed either by value or by reference.

friend

A non-member function that is given access to all members of a class within it is declared, is called

friend function

When we define and implement operator overloading in C++:

it may or may not be a class member

A particular instance of a class is called a(n) ___

object

Iterators are

objects that support uniform access to elements in different STL containers

Keyword __________ introduces an overloaded-operator function definition.

operator

An attempt to store an integer greater than the maximum allowed will result in _____.

overflow

Class members specified as ___ are accessible only to member functions of the class and friends of the class.

private

Members of a base class declared as can be accessed in a derived class but not by other classes or programs.

protected

Class members specified as ___ are accessible anywhere an object of the class is in scope.

public

make it possible for classes and functions to receive not only data values to be stored or operated on via parameters but also to receive the type of data via a parameter.

templates

Which of the following is a difference between vectors and arrays?

the ability to change size dynamically

A deep copy refers to

the duplicates of pointees

timePtr is a pointer to an object mealTime of class Time (i.e. Time * timePtr;) with data member myHours in the class. Which of the following is equivalent to myHours?

timePtr->myHours

#include<iostream> using std::cout; using std::endl; using std::ostream; #include<string> using std::string; class MyClass{ private: long x_,y_; string s_; public: MyClass(long x, long y, string s="unknown") : x_(x), y_(y), s_(s) {}; string f1(long, long); friend ostream& operator<<(ostream&, MyClass&); }; string MyClass::f1(long x, long y){ if(x > x_ && y > y_) s_ = "unset"; else if (x < x_ && y < y_) s_ = "set"; else s_ = "unknown"; return s_; } ostream& operator<<(ostream &out, MyClass &c){ // LINE 1 out << "(" << c.x_ << "," << c.y_ << "," << c.s_<< ")"; return out; } int main (){ MyClass c1(100,300); MyClass c2(10, 30); // LINE 2 cout << c1 << endl; // LINE 3 cout << c2.f1(1000,3000)<<endl; // LINE 4 } For the program shown in Figure 1, what output is produced by Line 4?

unset

A popular model of software development in which the phases are carried out sequentially, moving from one phase to the next, is known as the____ model.

waterfall

The main difference between structures and classes in C++ is

whether they are defaulted to public or private access.

In the following program segment #ifndef X #define X rest of program #endif

will evaluate the rest of the program if X is not already included.

#include<iostream> using std::cout; using std::endl; using std::ostream; #include<string> using std::string; class MyClass{ private: long x_,y_; string s_; public: MyClass(long x, long y, string s="unknown") : x_(x), y_(y), s_(s) {}; string f1(long, long); friend ostream& operator<<(ostream&, MyClass&); }; string MyClass::f1(long x, long y){ if(x > x_ && y > y_) s_ = "unset"; else if (x < x_ && y < y_) s_ = "set"; else s_ = "unknown"; return s_; } ostream& operator<<(ostream &out, MyClass &c){ // LINE 1 out << "(" << c.x_ << "," << c.y_ << "," << c.s_<< ")"; return out; } int main (){ MyClass c1(100,300); MyClass c2(10, 30); // LINE 2 cout << c1 << endl; // LINE 3 cout << c2.f1(1000,3000)<<endl; // LINE 4 } For the program shown in Figure 1, what output is produced by Line 3?

(100,300, unknown)

If data is a circular array of CAPACITY elements, and last is an index into that array, what is the formula for the index after last?

(last + 1) % CAPACITY

Which of the following is the value of the one digit postfix expression: 4 8 + 4 / 5 - 4 *

-8

At most, how many comparisons are required to search a sorted vector of 1023 elements using the binary search algorithm?

10

An algorithm that requires __________ operations to complete its task on n data elements is said to have a linear runtime.

2n+1

The following items are inserted into a binary search tree in this order: 8, 4, 3, 2, 5, 9, 6, 1, 7. Which item is placed at a root?

8

What is a hash function?

A function that computes the location of the key in the array

If a class contains a pointer to dynamically allocated memory, which of the following defaults is likely to be unacceptable?

All of the above

Which of the following is not a dynamic data structure?

Array.

In the linked list implementation of the stack class, where does the push member function place the new entry on the linked list?

At the head

In the linked list implementation of the queue class, where does the push member function place the new entry on the linked list?

At the tail

If T(n) > 5000n3 for all n < 100000, then T(n) cannot be O(n3). (True or false)

False

If the computing time of an algorithm is O(2n), it should not be acceptable for most large inputs.

False

Most of the STL algorithms operate on specific containers.

False

One of the strengths of linked lists is to access to each element faster than array. (True or false)

False

The array-based implementation of a list works well for lists with many insertions and deletions. (True or false)

False

The following function prototypes may be in the same library. int f(int x, int y); char f(int x, int y);

False

n-2 *2n/1000 + 100n100 + 250 = O(n100)

False

static (or early) binding is done at run time; dynamic (or late) binding is done at compile time.

False

Linear search is highly inefficient compared to binary search when dealing with:

Large, sorted arrays.

If a node has no successor, its link is set to a special ______ value.

NULL

When is a function a pure virtual function?

No reasonable default can be provided, and it must be defined in the inheritance hierarchy

In the array based implementation of a stack, which has size n, the pop operation has computing times.

O(1)

What is the search complexity in direct addressing?

O(1)

The computing times of the recursive algorithm to solve the Towers of Hanoi problem is.

O(2^n)

In the array based implementation of a list, which has size n, insertion in the worst case has computing time

O(n)

The height of a Binary Search Tree with n nodes in the worse case is

O(n)

The worst-case runtime complexity of a postorder traversal of a BST with n nodes

O(n)

Which of the following formulas in big-O notation best represent the expression n^2+35n+6?

O(n^2)

One difference between a queue and a stack is:

Queues use two ends of the structure; stacks use only one.

Which of the following data structures yields an efficient sort?

STL set

What is the primary purpose of template functions?

To allow a single function to be used with varying types of arguments

In C++, only existing operators can be overloaded

True

The following function prototypes may be in the same library. char f(int x, int y); char f(int x, char y);

True

State whether the following statements are True or False for overloading operators. i) Only existing operators can be overloaded. ii) We can change the basic meaning of an operator

True, True

What is the best definition of a collision in a hash table?

Two entries with different keys have the same exact hash value.

________________ overloaded through a member function take one explicit argument and those which are overloaded through a friend function take two explicit arguments.

Unary operators

Inheritance allows you to start with ___________ and derive ___________ from it,which will share common characteristics with is.

a class, other classes

Suppose you see this line (ie, this exact line of text): template in a C++ program. What is T?

a data type

An algorithm is

a standalone function that operates on containers

The Standard Template Library contains more than 80 function templates known as generic

algorithm

Suppose bag is a template class, what is the syntax for declaring a bag b of integers?

bag<int> b;

A collision strategy in which the hash table is an array or vector of linked lists that store the items is known as

chaining

In the tree structure, nodes that are directly accessible from a given node (by using only one directed arc) are called the of that node.

children

What C++ syntax is used to declare that a class B is derived from class A?

class B : public A { ... };

If several elements are competing for the same bucket in the hash table, what is it called?

collision

Suppose that f is a function with a prototype like this: void f(________ head_ptr); // Precondition: head_ptr is a head pointer for a linked list. // Postcondition: The function f has done some computation with // the linked list, but the list itself is unchanged. What is the best data type for head_ptr in this function?

const node*

Which of the following should not be declared virtual function?

constructorss

Suppose cursor points to a node in a linked list (using the node definition with members called data and next). What statement changes cursor so that it points to the next node?

cursor = cursor->next;

Suppose we have an array implementation of the stack class, with ten items in the stack stored at data[0] through data[9]. The CAPACITY is 42. Where does the push member function place the new entry in the array?

data[10]

Suppose we have a circular array implementation of the queue class, with ten items in the queue stored at data[2] through data[11]. The CAPACITY is 42. Where does the push member function place the new entry in the array?

data[12]

Operator overloading provides a flexible option for the creation of new ___________ for most of the C++ operations.

definitions

When an object's lifetime is over, the object's ______ is called automatically.

destructor

Consider this prototype for a template function: template <class Item> void foo(Item x); Which is the right way to call the foo function with an integer argument i?

foo( i );

The method of achieving reusability that most distinguishes OOP from other approaches is based on

inheritance

The process of constructing a function from a function template or a class from a class template is called

instantiation

The primary idea governing the use of public inheritance is the relationship.

is-a

For the declarations below, which expression is FALSE if it1 and it2 refer to the same object? vector::iterator it1, it2;

it1 == *it2

provide the interface between STL algorithms and STL containers.

iterators

A name that is used for different functions is said to be

overloaded

The word means "many forms."

polymorphism

A node that has no incoming arcs but from which every other node in the tree can be reached by following a unique sequence of consecutive arcs is called a(n)

root

Which of the following is not a sequential container provided by the STL?

string

A shallow copy refers to

the duplicates of pointers.

#include<iostream> using std::cout; using std::endl; using std::ostream; #include<string> using std::string; class MyClass{ private: long x_,y_; string s_; public: MyClass(long x, long y, string s="unknown") : x_(x), y_(y), s_(s) {}; string f1(long, long); friend ostream& operator<<(ostream&, MyClass&); }; string MyClass::f1(long x, long y){ if(x > x_ && y > y_) s_ = "unset"; else if (x < x_ && y < y_) s_ = "set"; else s_ = "unknown"; return s_; } ostream& operator<<(ostream &out, MyClass &c){ // LINE 1 out << "(" << c.x_ << "," << c.y_ << "," << c.s_<< ")"; return out; } int main (){ MyClass c1(100,300); MyClass c2(10, 30); // LINE 2 cout << c1 << endl; // LINE 3 cout << c2.f1(1000,3000)<<endl; // LINE 4 } For the program shown in Figure 1, what is Line 2 called?

the three-arg constructor with a default on the third arg

Given a hash table with M = 13, and hash function h(k) = k mod 13, if collision happens the next three positions for K=21 under the Linear Probing is: 9, 10, 11

true

If T(n) <= 5000n3 for all n >= 100000, then T(n) is O(n3) (True or false)

true

The compiler supplies a default copy constructor that simply copies an object member by member (shallow copy). (True or false)

true

The infix expression: (a - (b - c)) * d is converted to the postfix expression: a b c - - d *

true

The linear probing is that if a collision occurs at index i, examine the locations i + 1, i + 2, i + 3, .... with all operations done modulo the table size, continuing until an empty slot is found where the item can be stored.

true

~C() is a prototype for the destructor of a class named C.(True or false)

true

template < T>is an example of a template declaration.

typename


Conjuntos de estudio relacionados

Chapter 1: Nurse's Role in Health Assessment: Collecting and Analyzing Data PrepU

View Set

Respiratory Failure and Acute Respiratory Distress Syndrome

View Set