< Free Open Study > |
A priority queue containing characters is implemented as a heap stored in an array. The precondition states that this priority queue cannot contain duplicate elements. Currently, the priority queue holds 10 elements, as shown on the next page. What values might be stored in array positions 7-9 so that the properties of a heap are satisfied?
A minimum heap has the following order property: The value of each element is less than or equal to the value of each of its children. What changes must be made in the heap operations given in this chapter?
Write a nonrecursive version of ReheapDown.
Write a nonrecursive version of ReheapUp.
Describe the nonrecursive versions of these operations in terms of Big-O notation.
A priority queue is implemented as a heap:
Show how the heap would look after this series of operations:
What would the values of x, y, and z be after the series of operations in part (a)?
A priority queue is implemented as a linked list, sorted from largest to smallest element.
How would the definition of PQType change?
Write the Enqueue operation, using this implementation.
Write the Dequeue operation, using this implementation.
Compare the Enqueue and Dequeue operations to those for the heap implementation, in terms of Big-O notation.
A priority queue is implemented as a binary search tree.
How would the definition of PQType change?
Write the Enqueue operation, using this implementation.
Write the Dequeue operation, using this implementation.
Compare the Enqueue and Dequeue operations to those for the heap implementation, in terms of Big-O notation. Under what conditions would this implementation be better or worse than the heap implementation?
A priority queue is implemented as a sequential array-based list. The highest-priority item is in the first array position, the second-highest priority item is in the second array position, and so on.
Write the declarations in the private part of the priority queue class definition needed for this implementation.
Write the Enqueue operation, using this implementation.
Write the Dequeue operation, using this implementation.
Compare the Enqueue and Dequeue operations to those for the heap implementation, in terms of Big-O notation. Under what conditions would this implementation be better or worse than the heap implementation?
A stack is implemented using a priority queue. Each element is time-stamped as it is put into the stack. (The time stamp is a number between 0 and INT_MAX. Each time an element is pushed onto the stack, it is assigned the next larger number.)
A FIFO queue is implemented using a priority queue. Each element is time-stamped as it is put into the queue. (The time stamp is a number between 0 and INT_MAX. Each time an element is enqueued, it is assigned the next larger number.)
A priority queue of strings is implemented using a heap. The heap contains the following elements:
What feature of these strings is used to determine their priority in the priority queue?
Show how this priority queue is affected by adding the string "interviewing."
Use the following description of an undirected graph in Exercises 11-14.
EmployeeGraph |
= |
(V, E) |
V(EmployeeGraph) |
= |
{Susan, Darlene, Mike, Fred, John, Sander, Lance, Jean, Brent, Fran} |
E(EmployeeGraph) |
= |
{(Susan, Darlene), (Fred, Brent), (Sander, Susan), (Lance, Fran), (Sander, Fran), (Fran, John), (Lance, Jean), (Jean, Susan), (Mike, Darlene), (Brent, Lance), (Susan, John)} |
Draw a picture of EmployeeGraph.
Draw EmployeeGraph, implemented as an adjacency matrix. Store the vertex values in alphabetical order.
Using the adjacency matrix for EmployeeGraph from Exercise 12, describe the path from Susan to Lance
using a breadth-first strategy.
using a depth-first strategy.
Which one of the following phrases best describes the relationship represented by the edges between the vertices in EmployeeGraph?
"works for"
"is the supervisor of"
"is senior to"
"works with"
Use the following specification of a directed graph in Exercises 15-18.
ZooGraph |
= |
(V, E) |
V(ZooGraph) |
= |
{dog, cat, animal, vertebrate, oyster, shellfish, invertebrate, crab, poodle, monkey, banana, dalmatian, dachshund} |
E(ZooGraph) |
= |
{(vertebrate, animal), (invertebrate, animal), (dog, vertebrate), (cat, vertebrate), (monkey, vertebrate), (shellfish, invertebrate), (crab, shellfish), (oyster, shellfish), (poodle, dog), (dalmatian, dog), (dachshund, dog)} |
Draw a picture of ZooGraph.
Draw the adjacency matrix for ZooGraph. Store the vertices in alphabetical order.
To tell if one element in ZooGraph has relation X to another element, you look for a path between them. Show whether the following statements are true, using the picture or adjacency matrix.
dalmatian X dog
dalmatian X vertebrate
dalmatian X poodle
banana X invertebrate
oyster X invertebrate
monkey X invertebrate
Which of the following phrases best describes relation X in Exercise 17?
"has a"
"is an example of"
"is a generalization of"
"eats"
Use the following graph for Exercises 19-21.
Describe the graph pictured above, using the formal graph notation.
V(StateGraph) =
E(StateGraph) =
Is there a path from Oregon to any other state in the graph?
Is there a path from Hawaii to every other state in the graph?
From which state(s) in the graph is there a path to Hawaii?
Show the adjacency matrix that would describe the edges in the graph. Store the vertices in alphabetical order.
Show the array-of-pointers adjacency lists that would describe the edges in the graph.
Extend the class GraphType in this chapter to include a Boolean EdgeExists operation, which determines whether two vertices are connected by an edge.
Write the declaration of this function. Include adequate comments.
Using the adjacency matrix implementation developed in the chapter and the declaration from part (a), implement the body of the function.
Extend the class GraphType in this chapter to include a DeleteEdge operation, which deletes a given edge.
Extend the class GraphType in this chapter to include a DeleteVertex operation, which deletes a vertex from the graph. Deleting a vertex is more complicated than deleting an edge from the graph. Discuss why.
The DepthFirstSearch operation can be implemented without a stack by using recursion.
Name the base case(s). Name the general case(s).
Write the algorithm for a recursive depth-first search.
Distinguish between set representations that are implicit and those that are explicit.
Finish designing the algorithms for the explicit set representation.
Finish designing the algorithms for the implicit set representation.
Implement the copy constructor for PQType.
Did you notice that we did not include a copy constructor from GraphType? Discuss the issues involved in implementing this copy constructor.
< Free Open Study > |
Converted from CHM to HTML with chm2web Pro 2.85 (unicode) |