All Matches
Solution Library
Expert Answer
Textbooks
Search Textbook questions, tutors and Books
Oops, something went wrong!
Change your search query and then try again
Toggle navigation
FREE Trial
S
Books
FREE
Tutors
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
Hire a Tutor
AI Study Help
New
Search
Search
Sign In
Register
study help
computer science
introduction to algorithms
Questions and Answers of
Introduction to Algorithms
Compute a topological ordering for the directed graph drawn with solid edges in Figure 14.3d. BOS ORD JFK SFO (DFW (LAX MIA (d)
If the vertices of the graph from Figure 14.11 are ordered as (JFK, LAZ, MIA, BOS, ORD, SFO, DFW), in what order would edges be added to the transitive closure during the Floyd-Warshall algorithm?
How many edges are in the transitive closure of a graph that consists of a simple directed path of n vertices?
Given an n-node complete binary tree T, rooted at a given position, consider a directed graph G having the nodes of T as its vertices. For each parent-child pair in T, create a directed edge in G
Repeat Exercise R-14.28 for Figures 14.22 through 14.24 that illustrate Kruskals algorithm.Figures 14.22Figures 14.24Repeat ExerciseDescribe the meaning of the graphical conventions used
Say that a maze is constructed correctly if there is one path from the start to the finish, the entire maze is reachable from the start, and there are no loops around any portions of the maze. Given
Computer networks should avoid single points of failure, that is, network vertices that can disconnect the network if they fail. We say an undirected, connected graph G is biconnected if it contains
A graph G is bipartite if its vertices can be partitioned into two sets X and Y such that every edge in G has one end vertex in X and the other in Y. Design and analyze an efficient algorithm for
A company named RT&T has a network of n switching stations connected by m high-speed communication links. Each customer’s phone is directly connected to one station in his or her area. The
The time delay of a long-distance call can be determined by multiplying a small fixed constant by the number of communication links on the telephone network between the caller and callee. Suppose the
TamarindoUniversity andmany other schoolsworldwide are doing a joint project on multimedia. A computer network is built to connect these schools using communication links that form a tree. The
An independent set of an undirected graph G = (V,E) is a subset I of V such that no two vertices in I are adjacent. That is, if u and v are in I, then (u,v) is not in E. A maximal independent set M
Consider the following greedy strategy for finding a shortest path from vertex start to vertex goal in a given connected graph.1: Initialize path to start.2: Initialize set visited to {start}.3: If
Let G be a graph with n vertices and m edges such that all the edge weights in G are integers in the range [1,n]. Give an algorithm for finding a minimum spanning tree for G in O(mlog∗ n) time.
Consider a diagram of a telephone network, which is a graph G whose vertices represent switching centers, and whose edges represent communication lines joining pairs of centers. Edges are marked by
Inside the Castle of Asymptopia there is a maze, and along each corridor of the maze there is a bag of gold coins. The amount of gold in each bag varies. A noble knight, named Sir Paul, will be given
Suppose we are given a directed graph G with n vertices, and let M be the nÃn adjacency matrix corresponding to G.a. Let the product of M with itself (M2) be defined, for
Karen has a new way to do path compression in a tree-based union/find partition data structure starting at a position p. She puts all the positions that are on the path from p to the root in a set S.
Consider an initially empty memory cache consisting of four pages. How many page misses does the FIFO algorithm incur on the following page request sequence: (2,3,4,1,2,5,1,3,5,4,1,2,3)?
Suppose T is a multiway tree in which each internal node has at least five and at most eight children. For what values of a and b is T a valid (a,b) tree?
For what values of d is the tree T of the previous exercise an order-d B-tree?
Describe an external-memory data structure to implement the queue ADT so that the total number of disk transfers needed to process a sequence of k enqueue and dequeue operations is O(k/B).
Describe an external-memory version of the PositionalList ADT (Section 7.3), with block size B, such that an iteration of a list of length n is completed using O(n/B) transfers in the worst case, and
Suppose we are given a sequence S of n elements with integer keys such that some elements in S are colored “blue” and some elements in S are colored “red.” In addition, say that a red element
Consider the page caching strategy based on the least frequently used (LFU) rule, where the page in the cache that has been accessed the least often is the one that is evicted when a new page is
Suppose that instead of having the node-search function f (d) = 1 in an orderd B-tree T, we have f (d) = logd. What does the asymptotic running time of performing a search in T now become?
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
Give a recursive method for removing all the elements from a stack.
Give a precise and complete definition of the concept of matching for grouping symbols in an arithmetic expression. Your definition may be recursive.
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
Had the queue of the previous problembeen 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 f?
What values are returned during the following sequence of deque ADT operations, on an initially empty deque? addFirst(3), addLast(8), addLast(9), addFirst(1), last( ), isEmpty( ), addFirst(2),
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 other
Repeat the previous problem using the deque D and an initially empty stack S.Previous problemSuppose you have a deque D containing the numbers (1,2,3,4,5,6,7,8), in this order. Suppose further that
Augment the ArrayQueue implementation with a new rotate( ) method having semantics identical to the combination, enqueue(dequeue( )). But, your implementation should be more efficient than making two
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
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.
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
Alice has three array-based stacks, A, B, and C, such that A has capacity 100, B has capacity 5, and C has capacity 3. Initially, A is full, and B and C are empty. Unfortunately, the person who
Suppose you have a stack S containing n elements and a queue Q that is initially empty. Describe how you can use Q to scan S to see if it contains a certain element x, with the additional constraint
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(),
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 initialized
Implement the clone( ) method for the ArrayStack class. (See Section 3.6 for a discussion of cloning data structures.)
Implement a method with signature concatenate(LinkedQueue Q2) for the LinkedQueue class that takes all elements of Q2 and appends them to the end of the original queue. The operation should run in
Give an implementation of the deque ADT using an array list for storage.
In Section 7.5.3, we demonstrated how the Collections.shuffle method can be adapted to shuffle a reference-type array. Give a direct implementation of a shuffle method for an array of int values. You
Consider a variant of Exercise C-7.29, in which an array of capacity N, is resized to capacity precisely that of the number of elements, any time the number of elements in the array goes strictly
Describe how to implement the queue ADT using two stacks as instance variables, such that all queue operations execute in amortized O(1) time. Give a formal proof of the amortized bound.
Suppose we want to extend the PositionalList interface to include a method, positionAtIndex(i), that returns the position of the element having index i (or throws an IndexOutOfBoundsException, if
Redo the previous problem, but providing an implementation within the class LinkedPositionalList that does not create or destroy any nodes.
Page 281 describes an array-based representation for implementing the positional list ADT. Give a pseudocode description of the addBefore method for that representation. |(1,BWI) (2,PVD) |(0,JFK)
How might the LinkedPositionalList class be redesigned to detect the error described in Exercise R-7.14.
Describe a scheme for creating list iterators that fail fast, that is, they all become invalid as soon as the underlying list changes.
Describe an efficient method for maintaining a favorites list L, with the move-tofront heuristic, such that elements that have not been accessed in the most recent n accesses are automatically purged
Suppose we have an n-element list L maintained according to the move-to-front heuristic. Describe a sequence of n2 accesses that is guaranteed to take Ω(n3) time to perform on L.
What is the running time of a call to T.height(p) when called on a position p distinct from the root of tree T? /** Returns the height of the subtree rooted at Position p. */ public int
What are the minimum and maximum number of internal and external nodes in an improper binary tree with n nodes?
Draw an arithmetic expression tree that has four external nodes, storing the numbers 1, 5, 6, and 7 (with each number stored in a distinct external node, but not necessarily in this order), and has
Justify Table 8.2, summarizing the running time of the methods of a tree represented with a linked structure, by providing, for each method, a description of its implementation, and an analysis of
In what order are positions visited during a postorder traversal of the tree of Figure 8.6? 3 3 5 4
Let T be an ordered tree with more than one node. Is it possible that the preorder traversal of T visits the nodes in the same order as the postorder traversal of T? If so, give an example;
Draw a binary tree T that simultaneously satisfies the following:• Each internal node of T stores a single character.• A preorder traversal of T yields EXAMFUN.• An inorder traversal of T
Consider the example of a breadth-first traversal given in Figure 8.15. Using the annotated numbers from that figure, describe the contents of the queue before each pass of the while loop in Code
Let T be a (possibly improper) binary tree with n nodes, and let D be the sum of the depths of all the external nodes of T. Describe a configuration for T such that D is Ω(n2). Such a
For a tree T, let nI denote the number of its internal nodes, and let nE denote the number of its external nodes. Show that if every internal node in T has exactly 3 children, then nE = 2nI +1.
Give an efficient algorithm that computes and prints, for every position p of a tree T, the element of p followed by the height of p’s subtree.
Add support in LinkedBinaryTree for a method, pruneSubtree(p), that removes the entire subtree rooted at position p, making sure to maintain an accurate count of the size of the tree. What is the
Design algorithms for the following operations for a binary tree T:• PreorderNext(p): Return the position visited after p in a preorder traversal of T (or null if p is the last node visited).•
The balance factor of an internal position p of a proper binary tree is the difference between the heights of the right and left subtrees of p. Show how to specialize the Euler tour traversal of
Give an O(n)-time algorithm for computing the depths of all positions of a tree T, where n is the number of nodes of T.
Describe, in pseudocode, a nonrecursivemethod for performing an inorder traversal of a binary tree in linear time.
We can define a binary tree representation T² for an ordered general tree T as follows (see Figure 8.21):¢ For each position p of T, there is an associated position
Let the rank of a position p during a traversal be defined such that the first element visited has rank 1, the second element visited has rank 2, and so on. For each position p in a tree T, let
Let T be a tree with n positions. Define the lowest common ancestor (LCA) between two positions p and q as the lowest position in T that has both p and q as descendants (where we allow a position to
The indented parenthetic representation of a tree T is a variation of the parenthetic representation of T (see Code Fragment 8.26) that uses indentation and line breaks as illustrated in Figure 8.22.
What does each removeMin call return within the following sequence of priority queue ADT operations: insert(5, A), insert(4, B), insert(7, F), insert(1, D),removeMin( ), insert(3, J), insert(6, L),
An airport is developing a computer simulation of air-traffic control that handles events such as landings and takeoffs. Each event has a time stamp that denotes the time when the event will occur.
The min method for the UnsortedPriorityQueue class executes in O(n) time, as analyzed in Table 9.2. Give a simple modification to the class so that min runs in O(1) time. Explain any necessary
Give an example of a worst-case sequence with n elements for insertion-sort, and show that insertion-sort runs in Ω(n2) time on such a sequence.
At which positions of a heap might the largest key be stored?
Let T be a complete binary tree such that position p stores an element with key f (p), where f (p) is the level number of p (see Section 8.3.2). Is tree T a heap? Why or why not?
Explain why the description of down-heap bubbling does not consider the case in which position p has a right child but not a left child.
Is there a heap H storing seven entries with distinct keys such that a preorder traversal of H yields the entries of H in increasing or decreasing order by key? How about an inorder traversal? How
Show that the sum nΣi=1 logi, appearing in the analysis of heap-sort, is Ω(nlogn).
Bill claims that a preorder traversal of a heap will list its keys in nondecreasing order. Draw an example of a heap that proves him wrong.
Hillary claims that a postorder traversal of a heap will list its keys in nonincreasing order. Draw an example of a heap that proves her wrong.
Show how to implement the stack ADT using only a priority queue and one additional integer instance variable.
Show how to implement the FIFO queue ADT using only a priority queue and one additional integer instance variable.
Assume that we are using a linked representation of a complete binary tree T, and an extra reference to the last node of that tree. Show how to update the reference to the last node after operations
We can represent a path from the root to a given node of a binary tree by means of a binary string, where 0 means go to the left child and 1 means go to the right
Given a heap H and a key k, give an algorithm to compute all the entries in H having a key less than or equal to k. For example, given the heap of Figure 9.12a and query k =7, the algorithmshould
Give an alternative analysis of bottom-up heap construction by showing the following summation is O(1), for any positive integer h: Συ/2)
Suppose two binary trees, T1 and T2, hold entries satisfying the heap-order property (but not necessarily the complete binary tree property). Describe a method for combining T1 and T2 into a binary
Tamarindo Airlines wants to give a first-class upgrade coupon to their top logn frequent flyers, based on the number of miles accumulated, where n is the total number of the airlines’ frequent
Explain how the k largest elements from an unordered collection of size n can be found in time O(nlogk) using O(k) auxiliary space.
Write a comparator for nonnegative integers that determines order based on the number of 1’s in each integer’s binary expansion, so that i < j if the number of 1’s in the binary
Assuming the input to the sorting problem is given in an array A, describe how to implement the insertion-sort algorithm using only the array A and at most six additional (base-type) variables.
A group of children want to play a game, called Unmonopoly, where in each turn the player with the most money must give half of his/her money to the player with the least amount of money. What data
The use of null values in a map is problematic, as there is then no way to differentiate whether a null value returned by the call get(k) represents the legitimate value of an entry (k,null), or
What would be a good hash code for a vehicle identification number that is a string of numbers and letters of the form “9X9XX99X9XX999999,”where a “9” represents a digit and an “X”
Showing 1300 - 1400
of 1549
First
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16