(a)
To finds the correct values in the extracted array of sequence
(a)
Explanation of Solution
The EXTRACT-MIN
The INSERT algorithm is used to insert the value after the minimum value in the off-line minimum problem.
The algorithm takes the sequence of number and generates the corresponding values. The correct values in the extracted array are given in table below:
INDEX | VALUE |
1 | 4 |
2 | 3 |
3 | 2 |
4 | 6 |
5 | 8 |
6 | 1 |
The algorithm picks the minimum from the sequence by considering the sequence and then it remove that value then add to the extracted array and the remaining keys are added to the old sequence by using insert algorithm.
(b)
To argue the array extracted returned by OFF-LINE-MINIMUM is correct.
(b)
Explanation of Solution
The OFF-LINE-MINIMUM algorithm find the minimum number from the available sequence by using the extract min and then it add the remaining number to the sequence using insert operation.
The algorithm pick the smallest element from the available element then removed it from the sequence then it checks that the extracted value is minimum or not and combine the set of elements that needs to inserted in the sequence that is remaining elements other than min is combined to the original sequence.
Every iteration of the algorithm is extracted the minimum one by one and added to the extracted array until the last is extracted and stored to the array.
Therefore, the output returns from the algorithm is correct and have finite sequence.
(c)
To describe the implementation of OFF-LINE-MINIMUM algorithm for disjoint set data structure and also gives a tight bound of the implementation.
(c)
Explanation of Solution
The algorithm pick the smallest element from the available element then removed it from the sequence then it checks that the extracted value is minimum or not and combine the set of elements that needs to inserted in the sequence that is remaining elements other than min is combined to the original sequence.
The implementation of the disjoint set of data structure through OFF-LINE-MINIMUM algorithm is given below:
Step 1: Select the disjoint sets.
Step 2: Check that
Step 3: Then add all the values of
Step 4: Find the appropriate value of
Step 5: For every
After removing
For the every value of
Therefore, the total running time of the implementation of algorithm for disjoint set is
Want to see more full solutions like this?
- The off-line minimum problem maintains a dynamic set T of elements from the domain {1, 2,...,n}under the operations INSERT and EXTRACT-MIN. A sequence S of n INSERT and m EXTRACT-MIN calls are given, where each key in {1, 2,...,n} is inserted exactly once. Let a sequence S berepresented by I1 , E, I2, E, ... , E, Im+1 , where each Ij stands for a subsequence (possibly empty) ofINSERT and each E stands for a single EXTRACT-MIN. Let Kj be the set of keys initially obtainedfrom insertions in Ij. The algorithm to build an array extracted[1..m], where for i = 1, 2, ..., m,extracted[i] is the key returned by the ith EXTRACT-MIN call is given below: Off-Line-Minimum(m, n)for i = 1 to n determine j such that i ∈ Kj if j ≠ m + 1 extracted[j] = i let L be the smallest value greater than j for which KL exists KL = KL U Kj, destoying Kjreturn extracted Given the operation sequence 9, 4, E, 6, 2, E, E, 5, 8, E, 1, 7, E, E, 3; where eachnumber stands for its insertion.…arrow_forwardThe off-line minimum problem maintains a dynamic set T of elements from the domain {1, 2,...,n}under the operations INSERT and EXTRACT-MIN. A sequence S of n INSERT and m EXTRACT-MIN calls are given, where each key in {1, 2,...,n} is inserted exactly once. Let a sequence S berepresented by I1 , E, I2, E, ... , E, Im+1 , where each Ij stands for a subsequence (possibly empty) ofINSERT and each E stands for a single EXTRACT-MIN. Let Kj be the set of keys initially obtainedfrom insertions in Ij. The algorithm to build an array extracted[1..m], where for i = 1, 2, ..., m,extracted[i] is the key returned by the ith EXTRACT-MIN call is given below: Off-Line-Minimum(m, n)for i = 1 to n determine j such that i ∈ ?? if j ≠ m + 1 extracted[j] = i let L be the smallest value greater than j for which KL exists KL = KL U Kj, destroying ????return extracted (1) Given the operation sequence 9, 4, E, 6, 2, E, E, 5, 8, E, 1, 7, E, E, 3; where eachnumber stands for its…arrow_forward13) A linked list is given and the number of the nodes in this linked list is not known. You have to find the sum of the last "x" nodes of the linked list in a single traversal. Assume that size of the linked list is larger than "x". Explain your approach in brief. What is Big-O notation of this solution?arrow_forward
- 3. Unimodal Sequence Given n2 1, a sequence of n integers a[0],. . ., a[n-1] is unimodal if there exists t (with 0 st a[t+1] > . . . > a[n=1] The element a[t] is called the top of the sequence. For example, the sequence 1, 3, 5, 9, 4, 1 is unimodal, and its top is 9 (t = 3). Write a function get Toplndex_UnimodelSequence that takes a unimodal sequence & returns the index of the top of the sequence. The solution must have cost O(log(n)) in time in the worst case.arrow_forwardQuestion 2: The game of "FastestPath" consists of a path (a 1-D array) with n positive integers to represent n cities in a path (except the first index which has always value 0). The aim of the game is to move from the source city (located at index 0) to destination (located at last index) in the shortest time. The value at each index shows the travel time to enter the city located in the corresponding index. Here is a sample path where there are 6 cities (n is 6): |0 5 |90 | 7 61 | 12 Always start the game from the first city and there are two types of moves. You can either move to the adjacent city or jump over the adjacent city to land two cities over. The total travel time of a game is the sum of the travel times of the visited cities. In the path shown above, there are several ways to get to the end. Starting in the first city, our time so far is 0. We could travel to city 2, then travel to city 4, then travel to last city for a total travel time of 90 + 61 + 12 = 163. However, a…arrow_forwardTitle: Comparison of Exhaustive, Greedy, and Dynamic Programming approaches for the Partition problem.Description: In this assignment, we are given a set S containing n integers and we are expected to output a partition with two subsets such that they have the minimumdifference in their sums. For this purpose, we can use the simple exhaustive approach, which takes every subset A of S and compare the difference d of the sums: d =sum(A)-sum(S-A). The greedy approach is to use the numbers in S in pairs in descending order as described in class (you can also see the Wikipedia entry for thepartition problem). The dynamic programming algorithm that we covered in class is also to be implemented.We are also asked to compare the three algorithms in their runtime (in msecs) and difference found (d) for various values of k=log2(n). Your program will produce theseperformance measures, and then using any utility such as Excel, draw the plots of their runtimes versus k and d versus k (use…arrow_forward
- In pythion with numpy I have code in a for loop that creates a vecor of 12 elements:x = 1 2 3 4 5 6 7 8 9 10 11 12 The loop iterates 10 times. The second iteration generates a new vector x = 12 11 10 9 8 7 6 5 4 3 2 1 etc. At the end of the loop I need to have a 12 X 10 matrix x x x x x x x x x x x x x x x x x x x xx x x x x x x x x x x x x x x x x x x xx x x x x x x x x x x x x x x x x x x xx x x x x x x x x x x x x x x x x x x xx x x x x x x x x x x x x x x x x x x xx x x x x x x x x x x x x x x x x x x x I cannot figure out how to createa matrix where it takes the output and uses the output as rowarrow_forwardThe vector x ∈ R N has L different entries. For example, L = 4 for x = [3,4,4,5,3,1,5,3]T . One can express x as x = S u, where u ∈ R L satisfies (u)i < (u)j if i < j and S is a matrix that contains only zeros and ones. Write the function repeated_entries, which takes x as input and returns S and u.arrow_forwardWrite the algorithm that finds and returns how many paths in k units of length between any given two nodes (source node, destination node; source and target nodes can also be the same) in a non-directional and unweighted line of N nodes represented as a neighborhood matrix. (Assume that each side in the unweighted diagram is one unit long.) Note: By using the problem reduction method of the Transform and Conquer strategy, you have to make the given problem into another problem. Algorithm howManyPath (M [0..N-1] [0..N-1], source, target, k)// Input: NxN neighborhood matrix, source, target nodes, k value.// Ouput: In the given line, there are how many different paths of k units length between the given source and target node.arrow_forward
- Let x = (x,, X2X,) and y = (y,Y2.-Ym) to be two linked lists. Assume that in each list, the nodes are in non- decreasing order of their data field values. Write an algortihm to merge the two lists together to obtain a new linked list z in which the nodes are also in this order. Following the merge, x and y do not exist as individual lists. Each node initially in x or y is now in z. No additional nodes may be used. What is the time complexity of your algorithm?arrow_forwardDesign of algorithms - divide-and-conquer: (a) Design a divide-and-conquer algorithm DC_PROD that receives as input an array A with n>0 integers and returns the product of the elements in A. You may assume n is a power of 2. In your algorithm identify the relevant parts of a divide-and-conquer strategy: (i) divide, (ii) conquer, and (iii) combine. (b) Establish the recurrence relation for the running time, T(n), of DC_PROD. (c) Apply the Master Theorem to give a tight bound for T(n).arrow_forwardFor the word count example, for the input of the Map function, keys are document IDs and values are document contents. For the output of the Map function, keys are words and values are counts of words (e.g., (a, 1)). After shuffling via a hashing function on keys of the output, we combine those values with the same key into a list, for example, (a, {1, 5}), which are used as the input of the Reduce function. Within the reduce function, it will count (sum up) the numbers in the value list of a key, and return the key/value pair (e.g., (a, 6)). How to Implement the WordCount example on Hadoop?arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education