1. Repeat the previous problem using a singly linked list for storage, and a maximum capacity specified as a parameter to the constructor.2. Give a complete implementation of the Deque ADT using a...
Recent Questions
The introduction of Section 6.1 notes that stacks are often used to provide “undo” support in applications like a Web browser or text editor. While support for undo can be implemented with an...
Design an ADT for a two-color, double-stack ADT that consists of two stacks— one “red” and one “blue”—and has as its operations color-coded versions of the regular stack ADT operations. For example,...
When a share of common stock of some company is sold, the capital gain (or, sometimes, loss) is the difference between the share’s selling price and the price originally paid to buy it. This rule is...
Implement a program that can input an expression in postfix notation (see Exercise C-6.19) and output its value.Exercise C-6.19Postfix notation is an unambiguous way of writing an arithmetic...
Suppose Bob has four cows that he wants to take across a bridge, but only one yoke, which can hold up to two cows, side by side, tied to the yoke. The yoke is too heavy for him to carry across the...
Alice has two circular queues,C and D, which can store integers. Bob gives Alice 50 odd integers and 50 even integers and insists that she stores all 100 integers in C and D. They then play a game...
1. Give an implementation of the stack ADT using an array list for storage.2. Give an implementation of the deque ADT using an array list for storage.3. Give a justification of the running times...
Suppose you have two nonempty stacks S and T and a deque D. Describe how to use D so that S stores all the elements of T below all of its original elements, with both sets of elements still in their...
1. Implement the clone( ) method for the ArrayQueue class. (See Section 3.6 for a discussion of cloning data structures.)2. Implement a method with signature concatenate(LinkedQueue Q2) for the...
1. When implementing the ArrayQueue class, we initialized f = 0 (at line 5 of Code Fragment 6.10). What would happen had we initialized that field to some other positive value? What if we had...
Describe how to implement the stack ADT using a single queue as an instance variable, and only constant additional local memory within the method bodies. What is the running time of the push(),...
1. Show how to use a stack S and a queue Q to generate all possible subsets of an n-element set T nonrecursively.2. Suppose you have a stack S containing n elements and a queue Q that is initially...
1. Describe a nonrecursive algorithm for enumerating all permutations of the numbers {1,2,…,n} using an explicit stack.2. Alice has three array-based stacks, A, B, and C, such that A has...
Suppose you have three nonempty stacks R, S, and T. Describe a sequence of operations that results in S storing all elements originally in T below all of S’s original elements, with both sets of...
Postfix notation is an unambiguous way of writing an arithmetic expression without parentheses. It is defined so that if “(exp1)op(exp2)” is a normal fully parenthesized expression whose operation...
1. Give a pseudocode description for an array-based implementation of the doubleended queue ADT. What is the running time for each operation?2. Describe how to implement the deque ADT using two...
In Code Fragment 6.8 we assume that opening tags in HTML have form as with more generally, HTML allows optional attributes to be expressed as part of an opening tag. The general form used for...
Suppose Alice has picked three distinct integers and placed them into a stack S in random order. Write a short, straightline piece of pseudocode (with no loops or recursion) that uses only one...
1. Repeat the previous problem using the deque D and an initially empty stack S.2. Augment the ArrayQueue implementation with a new rotate( ) method having semantics identical to the combination,...
Suppose you have a deque D containing the numbers (1,2,3,4,5,6,7,8), in this order. Suppose further that you have an initially empty queue Q. Give a code fragment that uses only D and Q (and no...
1. Give a simple adapter that implements the stack ADT while using an instance of a deque for storage.2. Give a simple adapter that implements the queue ADT while using an instance of a deque for...
What values are returned during the following sequence of queue operations, if executed on an initially empty queue? enqueue(5), enqueue(3), dequeue(), enqueue(2), enqueue(8), dequeue(), dequeue(),...
Had the queue of the previous problem been an instance of the ArrayQueue class, from Code Fragment 6.10, with capacity 30 never exceeded, what would be the final value of the instance variable...
Suppose an initially empty queue Q has performed a total of 32 enqueue operations, 10 first operations, and 15 dequeue operations, 5 of which returned null to indicate an empty queue. What is the...
1. Give a recursive method for removing all the elements from a stack.2. Give a precise and complete definition of the concept of matching for grouping symbols in an arithmetic expression. Your...
Show how to use the transfer method, described in Exercise R-6.4, and two temporary stacks, to replace the contents of a given stack S with those same elements, but in reversed order.Exercise...
Implement a method with signature transfer(S, T) that transfers all elements from stack S onto stack T, so that the element that starts at the top of S is the first to be inserted onto T, and the...
1. Suppose an initially empty stack S has performed a total of 25 push operations, 12 top operations, and 10 pop operations, 3 of which returned null to indicate an empty stack. What is the current...
Write a program that can solve instances of the Tower of Hanoi problem (from Exercise C-5.16).Exercise C-5.16In the Towers of Hanoi puzzle, we are given a platform with three pegs, a, b, and c,...
Provide a nonrecursive implementation of the drawInterval method for the English ruler project of Section 5.1.2. There should be precisely 2c − 1 lines of output if c represents the length of the...
1. Implement a recursive method with calling signature find(path, filename) that reports all entries of the file system rooted at the given path having the given file name.2. Write a program for...
1. Describe a fast recursive algorithm for reversing a singly linked list L, so that the ordering of the nodes becomes opposite of what it was before.2. Give a recursive definition of a singly...
1. Describe a recursive algorithm that will check if an array A of integers contains an integer A[i] that is the sum of two integers that appear earlier in A, that is, such that A[i] = A[ j] +A[k]...
Suppose you are given an array, A, containing n distinct integers that are listed in increasing order. Given a number k, describe a recursive algorithm to find two integers in A that sum to k, if...
Given an unsorted array, A, of integers and an integer k, describe a recursive algorithm for rearranging the elements in A so that all elements less than or equal to k come before any elements...
What values are returned during the following series of stack operations, if executed upon an initially empty stack? push(5), push(3), pop(), push(2), push(8), pop(), pop(), push(9), push(1), pop(),...
1. Use recursion to write a Java method for determining if a string s has more vowels than consonants.2. Write a short recursive Java method that rearranges an array of integer values so that all...
You own the following portfolio of stocks. What is the portfolioweight of stock C?StockNumber ofSharesPrice perShareA120$21B650$17C400$41D180$4049.10 percent19.37 percent55.88 percent44.12...
Which of the following may be responsible for a fair share ofthe perennial “project cost overruns”?Rapidly rising inflationDelays in obtaining contracts and permitsLack of raw...
Recent Comments