Data Structures Chapter 13

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

Given two initially empty queues, queue1 and queue2 and the following commands. queue1.enqueue(1) queue1.enqueue(2) queue2.enqueue(3) queue1.enqueue(4) queue1.dequeue() queueFront = queue1.peekFront() queue1.enqueue(queueFront) queue2.enqueue(5) queue1.dequeue() queue2.enqueue(7) What is the sum of the contents of queue2? a. 4 b. 15 c. 19 d. none of these

15

Given the following queue operations on an empty existing queue called nameQueue. nameQueue.enqueue(Bob) nameQueue.enqueue(Bill) nameQueue.enqueue(Bud) nameQueue.dequeue() nameQueue.enqueue(Boo) What is now the contents of the queue (with front of the queue listed leftmost)? a. Bob, Bill, Bud b. Bob, Bud, Boo c. Bill, Bud, Boo d. Boo, Bud, Bill

Bill, Bud, Boo

Describe the similarities of the queue and the stack.

Both keep items in order. Both have methods for getting the length, inserting, removing, and looking at entries in the structure (top or front)

Given the following queue operations on an empty existing queue called nameQueue. nameQueue.enqueue(Sid) nameQueue.enqueue(Sal) nameQueue.enqueue(Sue) nameQueue.enqueue(Sam) nameQueue.dequeue() display (nameQueue.peekFront()) What name is displayed? a. Sid b. Sal c. Sue d. Sam

Sal

You are put on hold when you call customer service. The automated system tells you an approximation of how long a wait you will have. This is most likely being modeled by a queue. True or False

True

We are simulating customers arriving at a bank and their transactions being processed. How do we determine when and how long these events occur?

We study real world systems (such as the bank) and model events using techniques from probability theory. This statistical information is incorporated into the mathematical model of the system. Events are generated in a way that reflects the real world.

Describe how tracking your assignments can be accomplished by a special ADT.

You would use a priority queue. You list all assignments and order them by date due. Alternatively you make an estimate of how many hours each would take and if two assignments are due on the same day but one would require 5 hours and the other only 30 minutes, you start work on the longer assignment sooner before it is due.

Which of the following is not an ADT Queue operation as presented by the author? a. test if queue is empty b. add new entry to back of queue c. add new entry to front of queue d. get entry that was added earliest to the queue

add new entry to front of queue

In an event driven simulation, how is simulated time advanced? a. by a single time unit b. by a stop watch c. advanced to the time of the next event d. by a calendar

advanced to the time of the next event

Which of the following are not position-oriented ADTs? a. bag b. stack c. list d. queue

bag

Which of the following is not a similarity between a stack and a queue as described by the text? a. both have an isEmpty method b. both can retrieve an item from any position c. both can insert an entry at one end of the structure d. both can retrieve an entry from one end of the structure

both can retrieve an item from any position

According to the text, the first step in simulating a system is to do what? a. write a computer program b. time events with a stopwatch c. construct a mathematical model d. hire a lawyer

construct a mathematical model

An event list contains all future arrival events and what else? a. departure events b. event loops c. clock time d. externally generated events

departure events

For a stack, the push method places a new item onto the stack. What method for the queue would do a similar task? a. dequeue b. isEmpty c. enqueue d. peek

enqueue

Which of the following ADT Queue operators has a parameter? a. isEmpty b. dequeue c. peekFront d. enqueue

enqueue

An algorithm performing simulation of an oft repeated cycle, measuring the times and generating statistics is called what? a. customer loop b. timing loop c. statistical loop d. event loop

event loop

You wish to model who gets to land first as airplanes arrive at a busy airport. What kind of simulation would this be? a. time-driven simulation b. customer-driven simulation c. a sorted list d. event-driven simulation

event-driven simulation

Which of the following ADT Queue operators does not have return type specified as bool? a. isEmpty b. dequeue c. peekFront d. enqueue

peekFront

For a queue, the dequeue removes the first item. What method for the stack is used to remove the appropriate item? a. peek b. poke c. enqueue d. pop

pop

Which of the following would be an example of a value-oriented ADT? a. bag b. priority queue c. list d. stack

priority queue

You are making a "to do" list for this week. You brainstorm all the things which need your attention, then you arrange them from most important to least. You have just used what kind of ADT? a. list b. sorted list c. stack d. priority queue

priority queue

A priority queue orders its items by ______. a. position b. value c. priority value d. size

priority value

Lining up to buy a movie ticket or being put on hold by a computerized phone system are both examples of what type of ADT? a. queue b. stack c. list d. sorted list

queue

Which ADT would be best use to model the customers at a bakery who take numbers to mark their turn? a. queue b. stack c. list d. bag

queue

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? a. Stack. b. tree. c. linked list d. queue.

queue

Which of the following tasks would be a good application of the ADT Queue? a. generating random numbers for a game b. reading a string of characters c. keeping a grocery list d. parsing a mathematical expression such as (9 + 5) * 7^ 2

reading a string of characters

A large corporation is facing financial troubles and finds that they must do a reduction in force (RIF). The people who were most recently hired must be let go. This is an example of which ADT? a. bag b. list c. stack d. queue

stack

What ADT would be used along with a queue to determine if a string is a palindrome? a. list b. sorted list c. stack d. priority queue

stack

You are writing a simple word processor. What ADT would be best to use which would allow the typist to correct typing errors by using the Backspace key. a. queue b. stack c. list d. sorted list

stack

The first item to be removed from a priority queue is the item ______. a. at the front of the priority queue b. at the end the priority queue c. with the highest value d. with the highest priority value

with the highest priority value

The ADT bag does not order its entries. True or False

True

Give an example the difference between externally and internally generated events in an event-driven simulation.

Bank customers arriving are externally generated events. Bank customers completing their transactions and departing are internally generated events.

You are watching old reruns of M.A.S.H. You notice that when a group of casualties arrive, the doctors and nurses are, in effect using an ADT stack to determine who goes to the operating room first. True or False

False

Given two initially empty queues, queue1 and queue2 and the following commands. queue1.enqueue(1) queue1.enqueue(2) queue2.enqueue(3) queue2.enqueue(4) queue1.dequeue() queueFront = queue2.peekFront() queue1.enqueue(queueFront) queue1.enqueue(5) queue2.dequeue() queue2.enqueue(6) What are now the contents of What is now the contents of queue1 (with front of the queue listed leftmost)? a. 2, 3, 5 b. 5, 3, 2 c. 4, 6 d. 6, 4

2, 3, 5

Give a definition of a priority queue.

A finite number of objects, not necessarily distinct, having the same data type and ordered by priority.

What queues were required for the bank simulation algorithm as described in the text?

A queue for the arrivals for the customers and a queue for the events, arrivals and departures.

Give some examples of a applications in computer science where a queue useful.

A queue is used when sending characters from a word processor to the printer. When multiple documents from multiple users is sent to a single printer, they are placed into a queue.

In a simulation, what does an event list contain?

An event list contains all future arrival events and departure events.

Describe how you would use a queue and a stack to evaluate if a string is a palindrome.

As you traverse a string from left to right, you can add each character to both a queue and a stack. Now pop characters off the stack and dequeue characters off the queue. If each pair is the same, you have a palindrome.

Give some examples where the importance of an object depends on criteria other than when it is placed into a container. What is the best ADT choice for that container?

Examples include: the severity of medical emergency when a person comes to the ER, the importance of a computer task as to which program a multitasking operating system lets go first, VIP's get to meet the president a lot quicker than a tourist, people with reservations or important regular customers get seats at a restaurant quicker than a walk in customer.

Which of the following characterizes a queue? a. FIFO b. LIFO c. FILO d. LILO

FIFO

An even driven simulation simulates the ticking of a clock. True or False

False

Queue is a First-in-Last-out data structure. That is, the last element inserted into a queue is removed first. True or False

False

The goal of simulation is to generate reports of transactions. True or False

False

The isEmpty function for a stack does a much different task than the same function for a queue. True or False

False

What is the goal of a computer simulation?

Generally, the goal of a simulation is to generate statistics that summarize the performance of an existing system or to predict the performance of a proposed system. Note that the goal is to reflect the long-term average behavior of the system rather than to predict occurrences of specific events

What kind of operations would be required for accessing items in a priority queue?

It would require operations to place items in the queue according to both priority and arrival sequence. It would also need operations to retrieve or remove the item with the highest priority and (if the same high priority) at the front of the queue.

Which of the following characterizes a stack? a. FIFO b. LIFO c. FILO d. LILO

LIFO

List differences between the list as opposed to the stack or queue.

List insert can place an item anywhere in the structure, stacks and queues can have items added only at one end of the structure. Methods pop and dequeue can remove only from one end or the other, the list remove can do so anywhere in the list. Similarly with the getEntry, it can do so anywhere in the structure but peek and peekFront can access only specific locations.

Given two initially empty queues, queue1 and queue2 and the following commands. queue1.enqueue(4) queue1.enqueue(3) queue2.enqueue(7) queue1.enqueue(6) queue1.dequeue() queue1.enqueue(queue2.peekFront()) queue2.enqueue(queue1.peekFront()) queue1.dequeue() queue2.enqueue(7) List the contents of both queues with the front of the queue leftmost.

Q1 = 6, 7 Q2 = 7, 3, 7

Describe the difference between a queue and a priority queue.

The queue has the data ordered by when they were added. The priority queue data items are ordered by some other value which specifies the priority (date, importance, etc.) When an item is removed from a queue, it is the item that was the first one entered by time. When an item is removed from a priority queue, it is the one with the highest priority (and first entered, if the same priority).

If you create a queue of assignments and access the queue by due dates of the assignments this is called a priority queue. True or False

True

It is possible to use a queue in conjunction with a stack to reverse the order of occurrences of a sequence of items. True or False

True

Queues are important in simulating and analyzing the behavior of complex systems. True or False

True


Kaugnay na mga set ng pag-aaral

Medical Sociology Quiz 1: Chapters 1-5

View Set

Flashcards for Types of Contractions

View Set

DP-900: Microsoft Azure Fundamentals

View Set

Herpangina/Hand-foot-mouth/Pertussis/Rheumatic Fever

View Set