New Semester
Started
Get
50% OFF
Study Help!
--h --m --s
Claim Now
Question Answers
Textbooks
Find textbooks, questions and answers
Oops, something went wrong!
Change your search query and then try again
S
Books
FREE
Study Help
Expert Questions
Accounting
General Management
Mathematics
Finance
Organizational Behaviour
Law
Physics
Operating System
Management Leadership
Sociology
Programming
Marketing
Database
Computer Network
Economics
Textbooks Solutions
Accounting
Managerial Accounting
Management Leadership
Cost Accounting
Statistics
Business Law
Corporate Finance
Finance
Economics
Auditing
Tutors
Online Tutors
Find a Tutor
Hire a Tutor
Become a Tutor
AI Tutor
AI Study Planner
NEW
Sell Books
Search
Search
Sign In
Register
study help
computer science
introduction to algorithms
Data Structures and Algorithms in Java 6th edition Michael T. Goodrich, Roberto Tamassia, Michael H. Goldwasser - Solutions
Describe a sequence of n insertions in a heap that requires Ω(nlogn) time to process.
Draw an example of a heap whose keys are all the odd numbers from 1 to 59 (with no repeats), such that the insertion of an entry with key 32 would cause up-heap bubbling to proceed all the way up to a child of the root (replacing that child’s key with 32).
Illustrate all the steps of the adaptable priority queue call replaceKey(e, 18) for entry e storing (5, A) in the heap of Figure 9.1. (4,C) (5,A) (6,Z) (15,К) (9,F) (7,Q) (20,B) (16,X) (25,J) (14,E) (12,H) (11,S) (13,W)
Illustrate all the steps of the adaptable priority queue call remove(e) for entry e storing (16,X) in the heap of Figure 9.1. (4,C) (5,A) (6,Z) (15,К) (9,F) (7,Q) (20,B) (16,X) (25,J) (14,E) (12,H) (11,S) (13,W)
Let H be a heap storing 15 entries using the array-based representation of a complete binary tree. What is the sequence of indices of the array that are visited in a preorder traversal of H? What about an inorder traversal of H? What about a postorder traversal of H?
Illustrate the execution of the in-place heap-sort algorithm on the following input sequence: (2, 5, 16, 4, 10, 23, 39, 18, 26, 15).
At which positions of a heap might the third smallest key be stored?
When Bob wants to send Alice a message M on the Internet, he breaks M into n data packets, numbers the packets consecutively, and injects them into the network. When the packets arrive at Alice’s computer, they may be out of order, so Alice must assemble the sequence of n packets in order before
A useful operation in databases is the natural join. If we view a database as a list of ordered pairs of objects, then the natural join of databases A and B is the list of all ordered triples (x,y, z) such that the pair (x,y) is in A and the pair (y, z) is in B. Describe and analyze an efficient
Redo Exercise C-7.51 assuming L is implemented with an array list.Exercise C-7.51There is a simple algorithm, called bubble-sort, for sorting a list L of n comparable elements. This algorithm scans the list n−1 times, where, in each scan, the algorithm compares the current element with the next
There is a simple algorithm, called bubble-sort, for sorting a list L of n comparable elements. This algorithm scans the list n−1 times, where, in each scan, the algorithm compares the current element with the next one and swaps them if they are out of order. Give a pseudocode description of
Design a circular positional list ADT that abstracts a circularly linked list in the same way that the positional list ADT abstracts a doubly linked list.
An array is sparse if most of its entries are null. A list L can be used to implement such an array, A, efficiently. In particular, for each nonnull cell A[i], we can store a pair (i,e) in L, where e is the element stored at A[i]. This approach allows us to represent A using O(m) storage, where m
Modify the LinkedPositionalList class to support amethod swap(p, q) that causes the underlying nodes referenced by positions p and q to be exchanged for each other. Relink the existing nodes; do not create any new nodes.
Describe a method for performing a card shuffle of a list of 2n elements, by converting it into two lists. A card shuffle is a permutation where a list L is cut into two lists, L1 and L2, where L1 is the first half of L and L2 is the second half of L, and then these two lists are merged into one by
Describe a nonrecursive method for reversing a positional list represented with a doubly linked list using a single pass through the list.
Repeat the previous problem, but use knowledge of the size of the list to traverse from the end of the list that is closest to the desired index.Previous problemSuppose we want to extend the PositionalList interface to include a method, positionAtIndex(i), that returns the position of the element
Prove that when using a dynamic array that grows and shrinks as in the previous exercise, the following series of 2n operations takes O(n) time: n insertions at the end of an initially empty list, followed by n deletions, each from the end of the list.
Complete the previous exercise, except using a dynamic array to provide unbounded capacity.
Let L be a list of n items maintained according to the move-to-front heuristic. Describe a series of O(n) accesses that will reverse L.
Demonstrate how to use the java.util.Colletions.reverse method to reverse an array of objects.
Describe how to implement a method, alternateIterator( ), for a positional list that returns an iterator that reports only those elements having even index in the list.
Consider an implementation of the array list ADT using a dynamic array, but instead of copying the elements into an array of double the size (that is, fromN to 2N) when its capacity is reached, we copy the elements into an array with ⌈N/4⌉ additional cells, going from capacity N to N
Give an implementation of the stack ADT using an array list for storage.
Give a complete implementation of the Deque ADT using a fixed-capacity array, so that each of the update methods runs in O(1) time.
Repeat the previous problem using a singly linked list for storage, and a maximum capacity specified as a parameter to the constructor.Previous problemThe introduction of Section 6.1 notes that stacks are often used to provide “undo” support in applications like aWeb browser or text editor.
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, this ADT should support both a redPush operation and a bluePush operation. Give an
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 easy to understand for a single share, but if we sell multiple shares of stock bought over a long
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 original order.
Describe how to implement the deque ADT using two stacks as the only instance variables. What are the running times of the methods?
Give a pseudocode description for an array-based implementation of the doubleended queue ADT. What is the running time for each operation?
Show how to use a stack S and a queue Q to generate all possible subsets of an n-element set T nonrecursively.
Describe a nonrecursive algorithm for enumerating all permutations of the numbers {1,2, . . . ,n} using an explicit stack.
Postfix notation is an unambiguousway of writing an arithmetic expressionwithout parentheses. It is defined so that if “(exp1)op(exp2)” is a normal fully parenthesized expression whose operation is op, the postfix version of this is “pexp1 pexp2 op”, where pexp1 is the postfix version of
Give a simple adapter that implements the queue ADT while using an instance of a deque for storage.
Give a simple adapter that implements the stack ADT while using an instance of a deque for storage.
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 center tick. If incrementing a counter from 0 to 2c−2, the number of dashes for each tick line
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.
Give a recursive definition of a singly linked list class that does not use any Node class.
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] for j,k < i.
Use recursion to write a Javamethod for determining if a string s hasmore vowels than consonants.
Write a short recursive Java method that determines if a string s is a palindrome, that is, it is equal to its reverse. Examples of palindromes include 'racecar' and 'gohangasalamiimalasagnahog'.
In the Towers of Hanoi puzzle, we are given a platform with three pegs, a, b, and c, sticking out of it. On peg a is a stack of n disks, each larger than the next, so that the smallest is on the top and the largest is on the bottom. The puzzle is to move all the disks from peg a to peg c, moving
Write a recursive method that will output all the subsets of a set of n elements (without repeating any subsets).
Describe an efficient recursive algorithm for solving the element uniqueness problem, which runs in time that is at most O(n2) in the worst case without using sorting.
Describe a recursive algorithm to compute the integer part of the base-two logarithm of n using only addition and integer division.
Describe a way to use recursion to compute the sum of all the elements in an n×n (two-dimensional) array of integers.
Draw the recursion trace for the execution of method PuzzleSolve(3,S,U), from Code Fragment 5.11, where S is empty and U = {a,b,c,d}. Algorithm PuzzleSolve(k, S, U): Input: An integer k, sequence S, and set U Output: An enumeration of all k-length extensions to S using elements in U without
For each of the algorithms unique1 and unique2, which solve the element uniqueness problem, perform an experimental analysis to determine the largest value of n such that the given algorithm runs in one minute or less.
Perform an experimental analysis to test the hypothesis that Java’s Array.sort method runs in O(nlogn) time on average.
An array A contains n integers taken from the interval [0,4n], with repetitions allowed. Describe an efficient algorithm for determining an integer value k that occurs the most often in A. What is the running time of your algorithm?
Let p(x) be a polynomial of degree n, that is, p(x) = Σni=0 aixi.a. Describe a simple O(n2)-time algorithm for computing p(x).b. Describe an O(nlogn)-time algorithm for computing p(x), based upon a more efficient calculation of xi.c. Now consider a rewriting of p(x) asp(x) =
Let S be a set of n lines in the plane such that no two are parallel and no three meet in the same point. Show, by induction, that the lines in S determine Θ(n2) intersection points.
Consider the following “justification” that the Fibonacci function, F(n) is O(n): Base case (n ≤ 2): F(1) = 1 and F(2) = 2. Induction step (n > 2): Assume claim true for n′ < n. Consider n. F(n) = F(n−2)+F(n−1). By induction, F(n−2) is O(n−2) and F(n−1) is O(n−1). Then,
Determine the total number of grains of rice requested by the inventor of chess.
There is a well-known city (which will go nameless here) whose inhabitants have the reputation of enjoying a meal only if that meal is the best they have ever experienced in their life. Otherwise, they hate it. Assuming meal quality is distributed uniformly across a person’s life, describe the
Given an n-element array X of integers, AlgorithmC executes an O(n)-time computation for each even number in X, and an O(logn)-time computation for each odd number in X. What are the best-case and worst-case running times of Algorithm C?
Given an n-element array X, Algorithm B chooses logn elements in X at random and executes an O(n)-time calculation for each. What is the worst-case running time of Algorithm B?
Algorithm A executes an O(logn)-time computation for each entry of an array storing n elements. What is its worst-case running time?
Show that ⌈ f (n)⌉ is O( f (n)), if f (n) is a positive nondecreasing function that is always greater than 1.
Show that n2 is W(nlogn).
Show that if p(n) is a polynomial in n, then log p(n) is O(logn).
Show that f (n) is O(g(n)) if and only if g(n) is Ω( f (n)).
Show that O(max{ f (n),g(n)}) = O( f (n)+g(n)).
Show that if d(n) is O( f (n)) and f (n) is O(g(n)), then d(n) is O(g(n)).
Show that if d(n) is O( f (n)) and e(n) is O(g(n)), then d(n)−e(n) is not necessarily O( f (n)−g(n)).
Show that if d(n) is O( f (n)) and e(n) is O(g(n)), then d(n)+e(n) is O( f (n) + g(n)).
Graph the functions 8n, 4nlogn, 2n2, n3, and 2n using a logarithmic scale for the x- and y-axes; that is, if the function value f (n) is y, plot this as a point with x-coordinate at logn and y-coordinate at logy.
In the children’s game, Duck, Duck, Goose, a group of children sit in a circle. One of them is elected “it” and that person walks around the outside of the circle. The person who is “it” pats each child on the head, saying “Duck” each time, until randomly reaching a child that the
Design a RandomCipher class as a subclass of the SubstitutionCipher from Exercise P-3.40, so that each instance of the class relies on a random permutation of letters for its mapping.Exercise P-3.40Implement a class, SubstitutionCipher, with a constructor that takes a string with the 26 uppercase
Implement a class, SubstitutionCipher, with a constructor that takes a string with the 26 uppercase letters in an arbitrary order and uses that as the encoder for a cipher (that is, A is mapped to the first character of the parameter, B is mapped to the second, and so on.) You should derive the
Write a program that can perform the Caesar cipher for English messages that include both upper- and lowercase characters.
Perform the previous project, but use a doubly linked list. Moreover, your implementation of remove(i) should make the fewest number of pointer hops to get to the game entry at index i.
Write a Java program for a matrix class that can add and multiply arbitrary twodimensional arrays of integers.
Implement the clone( ) method for the DoublyLinkedList class.
Implement the clone( ) method for the CircularlyLinkedList class.
Solve the previous problemusing inheritance, such that a DoublyLinkedList class inherits from the existing CircularlyLinkedList, and the DoublyLinkedList.Node nested class inherits from CircularlyLinkedList.Node.
Implement a circular version of a doubly linked list, without any sentinels, that supports all the public behaviors of the original as well as two new update methods, rotate( ) and rotateBackward( ).
Our implementation of a doubly linked list relies on two sentinel nodes, header and trailer, but a single sentinel node that guards both ends of the list should suffice. Reimplement the DoublyLinkedList class using only one sentinel node.
Given a circularly linked list L containing an even number of nodes, describe how to split L into two circularly linked lists of half the size.
Suppose you are given two circularly linked lists, L and M. Describe an algorithm for telling if L and M store the same sequence of elements (but perhaps with different starting points).
Write a Java method that takes two three-dimensional integer arrays and adds them componentwise.
Write a method, shuffle(A), that rearranges the elements of array A so that every possible ordering is equally likely. You may rely on the nextInt(n) method of the java.util.Random class, which returns a random number between 0 and n−1 inclusive.
Implement the equals( ) method for the DoublyLinkedList class.
Implement the equals( ) method for the CircularlyLinkedList class, assuming that two lists are equal if they have the same sequence of elements, with corresponding elements currently at the front of the list.
What is the difference between a shallow equality test and a deep equality test between two Java arrays, A and B, if they are one-dimensional arrays of type int? What if the arrays are two-dimensional arrays of type int?
Implement a rotate( ) method in the SinglyLinkedList class, which has semantics equal to addLast(removeFirst( )), yet without creating any new node.
Write a Java method that repeatedly selects and removes a random entry from an array until the array holds no more entries.
Write a Java program that can “make change.” Your program should take two numbers as input, one that is a monetary amount charged and the other that is a monetary amount given. It should then return the number of each kind of bill and coin to give back as change for the difference between the
Write a Java program that inputs a list of words, separated by whitespace, and outputs how many times each word appears in the list. You need not worry about efficiency at this point, however, as this topic is something that will be addressed later in this book.
Define a Polygon interface that has methods area( ) and perimeter( ). Then implement classes for Triangle, Quadrilateral, Pentagon, Hexagon, and Octagon, which implement this interface, with the obvious meanings for the area( ) and perimeter( ) methods. Also implement classes, IsoscelesTriangle,
Write a Java program that simulates a system that supports the functions of an ebook reader. You should include methods for users of your system to “buy” new books, view their list of purchased books, and read their purchased books. Your system should use actual books, which have expired
Write a simulator as in the previous project, but add a boolean gender field and a floating-point strength field to each Animal object. Now, if two animals of the same type try to collide, then they only create a new instance of that type of animal if they are of different genders. Otherwise, if
Write a Java programto simulate an ecosystem containing two types of creatures, bears and fish. The ecosystemconsists of a river, which is modeled as a relatively large array. Each cell of the array should contain an Animal object, which can be a Bear object, a Fish object, or null. In each time
Write a Java program that inputs a document and then outputs a bar-chart plot of the frequencies of each alphabet character that appears within that document.
Write a Java program that inputs a polynomial in standard algebraic notation and outputs the first derivative of that polynomial.
Write a set of Java classes that can simulate an Internet application in which one party, Alice, is periodically creating a set of packets that she wants to send to Bob. An Internet process is continually checking if Alice has any packets to send, and if so, it delivers them to Bob’s computer;
Use a solution to Exercise C-2.25 to reimplement the FibonacciProgression subclass to rely on the BigInteger class, in order to avoid overflows all together.Exercise C-2.25Redesign the Progression class to be abstract and generic, producing a sequence of values of generic type T, and supporting a
Use a solution to Exercise C-2.25 to create a new progression class for which each value is the square root of the previous value, represented as a Double. You should include a default constructor that has 65,536 as the first value and a parametric constructor that starts with a specified number as
Redesign the Progression class to be abstract and generic, producing a sequence of values of generic type T, and supporting a single constructor that accepts an initial value. Make all corresponding modifications to the rest of the classes in our hierarchy so that they remain as nongeneric classes,
Showing 300 - 400
of 1549
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Last
Step by Step Answers