Introduction to Algorithms
3rd Edition
ISBN: 9780262033848
Author: Thomas H. Cormen, Ronald L. Rivest, Charles E. Leiserson, Clifford Stein
Publisher: MIT Press
expand_more
expand_more
format_list_bulleted
Question
Chapter 15, Problem 5P
(a)
Program Plan Intro
To describe an
(b)
Program Plan Intro
To explain the cost problem of finding an optimal alignment as edit distance problem using operation copy, delete, insert, kill and twiddle .
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Given an integer n and an array a of length n, your task is to apply the following mutation to a:
Array a mutates into a new array b of length n. For each i from 0 to n - 1, b[i] = a[i - 1] + a[i] + a[i + 1]. If some element in the sum a[i - 1] + a[i] + a[i + 1] does not exist, it should be set to 0. For example, b[0] should be equal to 0 + a[0] + a[1].
Given an array as follows5 4 9 10 2 8 1 3 7 6
Suppose we partition this array using quicksort's partition function and using 5 for the pivot.
A) Draw the resulting array after the partition finishes.B) The following is an array which has just been partitioned by the first step of quicksort:3 0 2 4 5 8 7 6 9Give all the elements that could be the pivot?
(There may be more than one possibility!)
PLEASE HELP WITH PART A AND B AND SHOW WORK!!
Consider a hallway in a building, with N equally sized rooms, numbered 1,..., N. Several meetings are planned, which require different numbers of adjacent rooms. You are given a list of meeting requests with the number of rooms need for each. The requests are represented by the array r[1, ..., k]. For example, meeting j requires r[j] adjacent rooms. You are offered a programmatic tool, which requires n steps to partition a set of n rooms, to accommodate two meeting requests of sizes s1 and s2, where s1+s2 = N.
Describe an algorithm that receives a set of meeting requests s1, s2, ..., etc., and calculates the rooms allocations in the least number of steps.
Formally prove that the algorithm is correct and that the solution it provides requires the lowest cost (in computational steps).
Explain your solution with a concrete example.
There was a similar question, but I did not understand the answer the expert gave. It had almost no details, and I could not follow it.
Chapter 15 Solutions
Introduction to Algorithms
Ch. 15.1 - Prob. 1ECh. 15.1 - Prob. 2ECh. 15.1 - Prob. 3ECh. 15.1 - Prob. 4ECh. 15.1 - Prob. 5ECh. 15.2 - Prob. 1ECh. 15.2 - Prob. 2ECh. 15.2 - Prob. 3ECh. 15.2 - Prob. 4ECh. 15.2 - Prob. 5E
Ch. 15.2 - Prob. 6ECh. 15.3 - Prob. 1ECh. 15.3 - Prob. 2ECh. 15.3 - Prob. 3ECh. 15.3 - Prob. 4ECh. 15.3 - Prob. 5ECh. 15.3 - Prob. 6ECh. 15.4 - Prob. 1ECh. 15.4 - Prob. 2ECh. 15.4 - Prob. 3ECh. 15.4 - Prob. 4ECh. 15.4 - Prob. 5ECh. 15.4 - Prob. 6ECh. 15.5 - Prob. 1ECh. 15.5 - Prob. 2ECh. 15.5 - Prob. 3ECh. 15.5 - Prob. 4ECh. 15 - Prob. 1PCh. 15 - Prob. 2PCh. 15 - Prob. 3PCh. 15 - Prob. 4PCh. 15 - Prob. 5PCh. 15 - Prob. 6PCh. 15 - Prob. 7PCh. 15 - Prob. 8PCh. 15 - Prob. 9PCh. 15 - Prob. 10PCh. 15 - Prob. 11PCh. 15 - Prob. 12P
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- 1) Consider an integer array a of length n with indexing starting at 0, where n is a positive integer.If the elements of array a are to be written out in reverse order, which of the following C++ code fragment does NOT do the job? Question options: a. int i=n-1; while (i>=1){cout << a[i] << endl; i = i-1;} cout << a[i] << endl; b. int i=n-1; while (i>=1){cout << a[i] << endl; i = i-1;} c. int i=n-1; while (i>=0){cout << a[i] << endl; i = i-1;} d. int i=n; while (i>0){cout << a[i-1] << endl; i = i-1;} 2) Assume we use 8-bit cell to store floating point numbers, 1 bit for sign, 3 bits for excessed exponent, and 4 bits for significand. What is the decimal value for a cell with bit pattern 0 111 1101 Question options: a. 125 b. 224…arrow_forwards algorithm for finding all occurrences of a sequence in anothersequence using the suffix array of the latter sequence can be implemented inPerl in a straightforward way, as shown in the following Perl script. Recallthat the suffix array of a sequence of length n will be a permutation of arraypositions 0, 1, . . . , n − 1, because Perl arrays do not start with position 1 but,rather, with position 0.arrow_forwardFollowing is the partition function for quicksort, where we have used the leftmost number as a pivot. Assume that our array, ARR = {14, 8, 7, 38, 22, 15, 9}, which is 7 in size. What will be the array ARR after we apply "partition(A, 0, 6)"* 9, 15, 22, 38, 7, 8, 14 7, 8, 9, 14, 15, 22, 38 9, 8, 14, 7, 22, 15, 38 9, 8, 7, 14, 22, 15, 38 7, 9, 15, 22, 38, 14, 6 38, 22, 15, 14, 9, 8, 7arrow_forward
- use c++ by Using dynamic arrays, implement a polynomial class with polynomial addition,subtraction, and multiplication. Discussion: A variable in a polynomial does nothing but act as a placeholder forthe coefficients. Hence, the only interesting thing about polynomials is the arrayof coefficients and the corresponding exponent. Think about the polynomialx*x*x + x + 1Where is the term in x*x ? One simple way to implement the polynomial class is touse an array of doubles to store the coefficients. The index of the array is theexponent of the corresponding term. If a term is missing, then it simply has a zerocoefficient.There are techniques for representing polynomials of high degree with many missingterms. These use so-called sparse matrix techniques. Unless you already knowthese techniques, or learn very quickly, do not use these techniques.Provide a default constructor, a copy constructor, and a parameterized constructorthat enables an arbitrary polynomial to be constructed.Supply an…arrow_forwardTo get the necessary excess space down to max(M, N/M), create a merging implementation based on the following concept: Divide the array into N/M blocks of size M in order to keep things simple, and assume that N is a multiple of M. The blocks are then (i) sorted using selection sort, which treats them as items and uses their first key as the sort key, and (ii) merged as the array is iterated through. The first block is merged with the second, the second block with the third, and so on.arrow_forwardCode only_Given an unsorted array A of size N that contains only positive integers, find a continuous sub-array that adds to a given number S and return the left and right index(1-based indexing) of that subarray. In case of multiple subarrays, return the subarray indexes which come first on moving from left to right. Note:- You have to return an ArrayList consisting of two elements left and right. In case no such subarray exists return an array consisting of element -1..arrow_forward
- Create a bottom-up mergesort that takes advantage of array order by doing the following each time it has to identify two arrays to merge: locate a sorted subarray (by incrementing a pointer until it finds an entry in the array that is smaller than its predecessor), then locate the next, and finally merge them. Examine the algorithm's running time in terms of array size and the number of maximal rising sequences in the array.arrow_forwardImagine that we want to keep track of friendships between n people. We can do this with an array of size nXn. Each row of the array represents the friends of an individual, with the columns indicating who has that individual as a friend. For example, if person j is a friend of person i, then we place a mark in column j of row i in the array. Likewise, we should also place a mark in column i of row j if we assume that friendship works both ways. What will be the space complexity of this problemarrow_forwardModify the Partition function so that after running it, any input array A is partitioned into three parts: the left part consisting of all elements < pivot, the middle part consisting of all elements = pivot, and the right part consisting of the rest Write down the pseudo-code for this modified version of the Partition function. (must be an in-place algorithm with Θ(n) time complexity.) Hint: Define three indices: i as the end of the left part, k as the end of the middle part, and j denoting the current index which is used in the for-loop.arrow_forward
- A set of integers 0..MAX may be implemented using an array of boolean values. This particular implementation is called a bit-vector implementation of a Set. Since C doesn’t have the Boolean data type, then substitute TRUE with 1 and FALSE with 0, or define 1 and 0 as TRUE and FALSE, respectively.For example, if the integer 3 is an element of the set, then the array element indexed by 3 is TRUE. On the other hand, if 3 is not an element, then the array element indexed by 3 is FALSE. For example, if the integer 3 is an element of the set, then the array element indexed by 3 is TRUE. On the other hand, if 3 is not an element, then the array element indexed by 3 is FALSE.For example: if s = {3,4,6,8}, the array looks like this: Implement a programmer-defined data type called BitSet to represent a set as follows:typedef int BitSet[MAX];Implement the following functions:void initialize(BitSet s); - set all array elements to FALSEvoid add(int elem,BitSet s);- set the item indexed by elem to…arrow_forwardA dynamic array has a capacity (the number of elements it can currently hold) and a size (the number of elements it actually holds). Consider a dynamic array where we always want the capacity to be a Fibonacci number. Suppose that its current capacity is Fk. We will use the following strategy: • If, after inserting an element, the size reaches Fk-1, we will make an array with capacity Fk+1 and copy our current array there. • If, after deleting an element, the size reaches Fk-3, we will make an array with capacity Fk-1 and copy our current array there. If the array is initially empty and its capacity is 2 = F2, show for every sequence of operations, add and delete will happen in the amortized run-time is O(1), even with the array copying going on in the background. Explanation needed .. code is not requiredarrow_forwardMaking ChangeAssume we have a set of N>0 tokens each of different value {v1, v2, …, vN} with an unlimited supply of each tokenfrom which we have to give a customer some change.What is the minimum number of tokens to return as change?Write a functionint mintokens(int c, int a[], int len)wherec is the amount of change owed to the customera[] is a 1-dimensonal array of token valueslen is the number of elements (i.e., number of different token values) in a[]and returns the minimum number of tokens it takes to return change due cor -1 if change is not possible or if len,c<1File you must submit: soln_func.ccExamples:c = 30 a[] = {5, 10, 25}Returns: 2Explanation: 1x5 + 1x25c = 11 a[] = {5, 9, 1, 6}Returns: 2Explanation: 1x5 + 1x6c = 15 a[] = {3, 17, 1, 21, 4}Returns: 4Explanation: 1x3 + 3x4c = 7 a[] = {5, 9, 3, 6}Returns: -1Explanation: Not possible to make change.c = 7 a[] = {}c = 0, a[]={1, 2}Each returns: -1Explanation: For each, at least one of the following is true; len,c<1arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Programming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Definition of Array; Author: Neso Academy;https://www.youtube.com/watch?v=55l-aZ7_F24;License: Standard Youtube License