• Shuffle
    Toggle On
    Toggle Off
  • Alphabetize
    Toggle On
    Toggle Off
  • Front First
    Toggle On
    Toggle Off
  • Both Sides
    Toggle On
    Toggle Off
  • Read
    Toggle On
    Toggle Off
Reading...
Front

Card Range To Study

through

image

Play button

image

Play button

image

Progress

1/39

Click to flip

Use LEFT and RIGHT arrow keys to navigate between flashcards;

Use UP and DOWN arrow keys to flip the card;

H to show hint;

A reads text to speech;

39 Cards in this Set

  • Front
  • Back

One difference between a queue and a stack is:

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

In the circular array version of the queue class (with a fixed-sized array), which operations require linear time for their worst-case behavior?

None of these operations require linear time.

Suppose you are exploring a rectangular maze containing 10 rows and 20 columns. What is the maximum depth of recursion that can result if you start at the entrance and call traverse_maze?

The number of unexplored spaces in the maze.

What are the traditional names for the queue operations that add an item?

enqueue

Which C++ library provides isalpha function?

cctype

What C++ function determines if a character is alphabetic?

isalpha

Which one of the following is the best statement to describe cin.peek( ) function?

It is part of the iostream library.It returns the next character in the input sequence, without extracting it: The character is left as the next character to be extracted from the stream.

Which description about the following statement (pal.cxx(section 8.2)) is correct?if (q.front( ) != s.top( )) ++mismatches;

q is a queue object and s is a stack object. The statement is comparing the q's front eleement to the s's top element, if they are not the same, mismatches increases by 1, and if they are the same, does not do anything.

What does isalpha function do?

It returns true if its single argument is one of the alphabetic characters

What would be the best pseudocode for an algorithm to do the following? It reads an even number of characters then prints the first character, third character, fifth character, and so on. On a second output line, it prints the second character, fourth character, sixth character, and so on. Use two queues to store the characters.

Read the characters two at a time. Each pair of characters has the first character placed in queue number 1 and the second character placed in queue number 2. After all the reading is done, print all characters from queue number 1 on one line, and print all characters from queue number 2 on a second line.

Suppose you are storing the items of a deque(section 8.4) in an array. Why do we need to use a circular array rather than putting all the items at the front?

If all items were kept at the front of the array, then it would be time-consuming to add or remove at the front.

What is the possible variant expression of random_fractal function in section 9.2?

width/epsilon

What is the output produced by the function call exercise(3), for the following definition?void exercise(int n) { cout << n << endl; if (n > 1) exercise(n-1); }

321

What is the best statement about the following function, f1?void f1(unsigned int n){ if (n > 0) { cout << '*'; f1(n-1); cout << '!'; }}

The f1 is a recursive function that has one parameter that is a non-negative integer. The function writes out that number of asterisks ('*') to the screen, followed by that number of exclamation points ('!').

What information does an activation record(section 9.1) contain?

The activation record contains the return location of the function after it is finished. It also contains the values of the function’s local variables and parameters.

What is the output produced by the function call exercise(3), for the following definition?void exercise(int n){ cout << n << endl; if (n > 1) exercise(n-1); cout << n-1 << endl;}

321012

What statement of the following is the most appropriate?

A recursive algorithm for a function implementation contains two kinds of cases: one or more cases that include a recursive call and one or more stopping cases in which the problem is solved without the use of any recursive calls.

What is the output produced by the function call exercise(3), for the following definition?void exercise(int n){ if (n > 1) exercise(n-1); cout << n << endl;}

123

Which of the description of the super_write_vertical function in section 9.1 is the most appropriate?

The digits of the number have been written, stacked vertically. If a number is negative, then a negative sign appears on top.

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

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]

Suppose you are exploring a rectangular maze containing 10 rows and 20 columns. What is the maximum number of calls to traverse_maze that can be generated if you start at the entrance and call traverse_maze?

200

What is the relationship between the maximum depth of recursion for traverse_maze and the length of an actual path found from the entrance to the tapestry?

The maximum depth is always greater than or equal to the path length.

What should we modify the palindromes program(section 8.2) so that uppercase and lowercase versions of letters are considered different?

We change the following two statements:q.push(toupper(letter));s.push(toupper(letter));toq.push(letter);s.push(letter);

What statement of the following is the most appropriate?

When implementing a stack, you need only keep track of one end of the list of entries, but when implementing a queue, you need to keep track of both ends of the list entries.

Which statement about queue is accurate?

A queue is a data structure of ordered entries such that entries can only be inserted at one end and removed at the other end .

Which one of the following assumption we made about the real-world car wash in order to make the simulation more manageable?

We assumed that no more than one customer arrives during any particular second.

What is RAND_MAX in C++?

It is an integral constant expression. It specifies the largest return value of the rand function.

What informaton can weget when the car wash simulation finishes?

1. Number of customers served2. An average of waiting time

Suppose you are using a linked list to implement a deque(Section 8.4). What statement about linked list would be the most appropriate?

For inserting at both ends, an ordinary linked list is fine; but for removing at both ends, a doubly linked list is better.

How are time stamps used in simulations(section 8.2)?

Time stamps are used to record arrival and waiting times for the items in a simulation.The time stamp is the number of simulated seconds that have passed since the start of the simulation.The waiting time of an item is the total number of seconds simulated so far, minus the time stamp.

What is the output produced by the function call exercise(4), for the following definition?void exercise(int n){ if (n > 1) exercise(n-1); cout << n << endl;}

1234

What is the threshold of f1 function?int f1(int n){ if (n < 10) && (n > -10)) return 1; else return 1 + f1(n/10);}

1

What is the output of the following function with an argument of 3?void cheers(int n){ if (n <= 1) cout << "Hurrah" << endl; else { cheers(n-1); cout << "Hip" << endl; }}

HurrahHipHip

If, on the other hand, every recursive call produces another recursive call, then a recursive call will, in theory, run forever. This is called _______________.

infinite recursion

What is the output of the following function with an argument of 3?void cheers(int n){ if (n <= 1) cout << "Hurrah" << endl; else { if (n % 2 == 0) cout << "Hip" << endl; cheers(n-1); if (n % 2 == 1) cout << "Hip"<< endl; }}

HipHurrahHip

What is the output of the following function with an argument of 3?void cheers(int n){ if (n <= 1) cout << "Hurrah" << endl; else { if (n % 2 == 0) cout << "Hip" << endl; cheers(n-1); if (n % 2 == 1) cout << "Hop" << endl; }

HipHurrahHop

Suppose we call random_fractal with a width of 8 and an epsilon of 0.5. Then random_fractal will make two recursive calls, and each of those will make two more calls, and so on until width is less than or equal toepsilon. How many total calls will be made of random_fractal, including the original call?

31

What is the output of the following function with an argument of 4?void cheers(int n){ if (n <= 1) cout << "Hurrah" << endl; else { if (n % 2 == 0) cout << "Hip" << endl; cheers(n-1); if (n % 2 == 1) cout << "Hip" << endl; }}

HipHipHurrahHip