Develop a dynamic programming algorithm

Assignment Help Data Structure & Algorithms
Reference no: EM132001056

Assignment 1

For a given n, a sum tree for n is a full binary tree whose root is labeled whose leaves are labeled 1, and in which the children of a node labeled j have labels that sum to j. Every node should have a label > 0.

Given a cost table c[i], the cost of a node labeled i is c[i], and the cost of the tree is the sum of the cost of its nodes.
a. What is the cost of a sum tree for 1? (in terms of c[1])
b. What is the cost of a sum tree for 2? (in terms of c[1] and c[2]421)
c. An optimal sum tree for i is a sum tree for i of minimum cost. What is an optimal sum tree for 8 if c[1] to c[7] are 1,3,11,20,20,21,26,27?
d. Write down a formula that expresses the cost of an optimal sum tree in terms of the cost of smaller optimal sum trees. (Hint: In an optimal sum tree, the trees rooted at the left and right children of the root form optimal sum trees.)
e. Use the dynamic programming technique to design an algorithm that finds the cost of the optimal sum tree for n, given it and c[i), for 1 ≤ i ≤ n.
f. Analyse the time that your algorithm takes (asymptotic notation).

Problem 1

We want to find an optimal binary search tree for keys that have the following probabilities: (.3, .2, .1, .05, .35). We have started our dynamic programming solution and have partially filled the following e, w and root arrays as shown below. Compute the final solution and draw the optimal binary search tree. Explain your calculations.


0 1 2 3 4 5
1
0.3 0.5 1 1.15
2

0.2 0.4 0.55 1.35
3


0.1 0.2 0.95
4



0.05 0.45
5




0.35
6





 

0 1 2 3 4 5
1 0.3 0.5 0.6 0.65 1
2
0.2 0.3 0.35 0.7
3

0.1 0.15 0.5
4


0.05 0.4
5



0.35
6




 


1 2 3 4 5
1 1 1 1 2
2
2 2 2 2
3

3 3 3
4


4 5
5



5

Assignment 2

1. For each of the following non-standard (inefficient) minimum finding algorithms, give the asymptotic best and worst case time analysis. Assume the array has no duplicates. In the algorithms, i and j are the first and last index of the array to be considered. The problem is to find the smallest value among A[i]...A[j]. (The algorithms are intended to be correct. If there is an unintentional error, attempt to fix it before answering.)

(a) Algorithm 1 integer minimum1(A: array of integer; i, j: integer):

begin
if j - i ≤ 5 sort and return A[i];
m1 = minimum1(A, i, i + |(j - i)/5∫;
m2 = minimum1(A, i + |(j - i)/5∫ + 1, j); return the minimum of m1 and m2;
end;

(b) Algorithm 2
integer minimum2(A: array of integer; i, j: integer): begin
if j - i ≤ 5 sort and return A[i];
separate elements of A from i to j in |(j - i)/5| groups of 5 (with one group that may have less than 5);
sort each group of 5 using insertion sort;
form an array with the minimum of each group;
make a recursive call on the new array and return the result; end

(c) Algorithm 3
integer minimum3(A: array of integer; i, j: integer): begin
if j - i ≤ 5 sort and return A[i]; m1 = minimum3(A, i and j - 1); m2 = minimum3(A, i + 1, j);
return the minimum of m1 and m2; end;

2. For an edge (u, v), in a depth first search, indicate if d[u] < d[v] and if f [u] < f [v]. In each box, write True, False or Depends. Writing "Depends" means that it is true in some cases and false in other cases.

 

d[u] < d[v]

f [u] < f [v]

tree edge

 

 

forward edge

 

 

back edge

 

 

cross edge

 

 

3. We define the depth cost of a heap as Σi(di ∗ ki), where ki is the key and di is the depth of the node in the heap. Given a set of key values in arbitrary order, we are interested in constructing a min heap with minimum depth cost.

(a) Give two heaps of size 6, one with minimum depth cost and one which is not optimal. Compute the depth cost of each.

(b) Give a proof (or a convincing argument) that if for every level of a heap, the minimum key value is ≥ the value of every key value in the level above it, then the heap has minimum depth cost.

(c) One way to produce a minimum depth cost heap is to sort the keys. Develop an algorithm that is more efficient than sorting. Hint: Find out how many elements are at the bottom level of the heap, use the linear time selection algorithm to find the set of keys at the bottom level, and recursively apply the algorithm on the rest of the keys.

(d) Analyse the time of your algorithm.

4. You have to develop an algorithm to compute how to give change with the minimum number of coins. The input is a sorted array of coin values c = {c0, c1, c2, ..., cn} with c0 = 1 and a target value v. There is an unlimited number of each coin available. The output is an array
{v0, v1, v2, ..., vn} such that ∑i ci ∗ vi = v, and such that ∑i vi is minimum. For example, with US coins c = {1, 5, 10, 25} and v = 61, the solution is {1, 0, 1, 2}.

(a) Although the greedy approach to this problem does not work in general, develop a greedy algorithm to solve this problem. Analyse the time complexity of your algorithm.

(b) Show an example where your greedy approach does not give the optimal solution. (With the most obvious greedy algorithm, the set c = {1, 4, 5} does not give optimal solutions.)

(c) This bonus part has an elaborate solution and only worth 4 point, solve only if you have finished the rest of the exam.)
Develop a dynamic programming algorithm to solve this problem.

5. Closed notes, closed book question

Select the best answer to each question.
(a) expected running time
A. when we consider the average time to perform a sequence of operations (like a sequence of inserts and deletes)
B. when we consider the probability distribution of possible inputs
C. when we consider the probability distribution of random values generated by a randomized algorithm
D. when we consider the time on the most likely input

(b) binary search tree
A. supports search, insert, delete, minimum in O(lg n) average case
B. supports search, insert, delete, minimum in O(lg n) worst case
C. when the root key is less or equal to the root key of each subtree
D. when node keys are expressed in binary

(c) dynamic programming
A. a technique that allows the algorithm to modify itself
B. combines solutions of subproblems, and keeps solutions of subproblems in a table
C. separates a problem recursively into subproblems of equal size
D. when the algorithm requires dynamic allocation of memory

(d) prefix code
A. a code where all codewords must have the same length
B. a code where all codewords start by the same prefix string of at least one char- acter
C. a code where no codeword is also a prefix of some other codeword
D. a code where some of the codewords have different lengths

(e) greedy algorithm
A. an algorithm that always makes the choice that looks best at the moment
B. an algorithm that computes the best profit at the possible expense of running time
C. an algorithm that uses more space for the purpose of a better running time
D. an algorithm that makes use of all the available processors

(f) strongly connected component
A. any maximal set of vertices such that for each pair u and v, there is an edge from u to v and from v to u
B. any maximal set of vertices such that for each pair u and v, there is a path from
u to v and from v to u
C. any maximal set of vertices such that for each pair u and v, there is an edge from u to v or from v to u
D. any maximal set of vertices such that for each pair u and v, there is a path from
u to v or from v to u

(g) minimum spanning tree
A. a subset of the edges that connects all vertices with minimum cost
B. a subset of the edges that connects a given pair of vertices with minimum cost
C. a subset of the edges of minimum size that connects all vertices
D. a subset of the edges of minimum size that connects a given pair of vertices

(h) Dijkstra's algorithm
A. an algorithm to compute the shortest path for every pair of vertices that works on graphs with positive edge weights
B. an algorithm to compute the shortest path from a vertex to every other vertices on graphs with positive edge weights
C. an algorithm to compute the shortest path for every pair of vertices that works on graphs where negative edge weights are allowed
D. an algorithm to compute the shortest path from a vertex to every other vertices on graphs where negative edge weights are allowed

(i) span of a multithreaded algorithm
A. a multithreaded algorithm that finds a subset of edges that connects the network of processors
B. the longest time to execute the algorithm when we have an unlimited number of processors
C. the maximum number of processors used by a multithreaded algorithm
D. the time to execute the algorithm on a single processor

(j) What is the span of multithreaded merge (merging two sorted lists of length n) and the span of multithreaded merge sort, as covered in the textbook and in class?
A. Θ(log n) for multithreaded merge and Θ(log2 n) for merge sort.
B. Θ(log2 n) for multithreaded merge and Θ(log3 n) for merge sort.
C. Θ(log n) for multithreaded merge and Θ(n) for merge sort.
D. Θ(n) for multithreaded merge and Θ(n log n) for merge sort.

Verified Expert

This assignment is related to the Algorithm for Data Analysis. This includes the algorithm like the minimum integer finding, Depth first search (DFS) and to compute how to give change with the minimum number of coins. At the end there was some multiple choice questions related to the above task. All the solutions were provided to the question in the word document.

Reference no: EM132001056

Questions Cloud

How did it benefit the connection between school and home : What experiences have you had (as a child, parent, or educator) with family literacy nights? How did it benefit the connection between school and home?
How the campaign positively influenced your personal opinion : Reflect on the impact of the marketing campaign on your own health care decision making. Consider how the campaign positively or negatively influenced.
Does there appear to be a problem with autocorrelation : If the price of a portrait during month 21 is $10, what would you predict for sales in month 21?
Show how deferred income taxes will appear : Show how deferred income taxes will appear on the B/S of Seminole at the end of each year. Just give me the caption (DTA and/or DTL)
Develop a dynamic programming algorithm : You have to develop an algorithm to compute how to give change with the minimum number of coins - develop a greedy algorithm to solve problem
Describe the sales promotions that will be used entice : Describe the sales promotions that will be used entice both consumers and trade channel partners. Determine whether the firm will use salespeople or sales agent
Suppose this action will increase sales : Suppose this action will increase sales. What is the incremental costs associated with producing an extra 54,500 jars of sauce?
Expansion for everything in the financial about the dental : You need expansion for everything in the financial about the dental and every detail with sources. show how to earn for a year, day, or a Month.
Revenue associated with price reduction of sauce : What is the incremental revenue associated with the price reduction of sauce?

Reviews

Write a Review

Data Structure & Algorithms Questions & Answers

  Homogeneous array

Assume that a homogeneous array with six rows and eight columns, is stored in row major order starting at address 20. If each entry in the array requires only one memory cell.

  Explain pros and cons of algorithm

You can start by taking 3-4 schemes for example and then show each step of the GA based algorithm numerically. Explain each step (selection, cross-over, mutation) in detail. You can show in any way as long as each step is shown and explained numer..

  Identify the basic operation of the algorithm

Identify the basic operation of the algorithm and count number of times basic operation is performed by the algorithm, to confirm its predicted order of growth.

  C++ program to evaluate expressions combining set union

Create a C++ program to evaluate expressions combining set union, set intersection and parentheses

  Write a program that creates an array of structures

Write a program that creates an array of structures of type Student. The structures must include the following data members.

  Explaining the DS or a MAC algorithm

In this problem we will compare the security services that are provided by digital signatures (DS) and message authentication codes (MAC).

  Write a program that reads the records in used file

Write a program that reads the records in Used File (described at the end of Chapter 4) and stores them in an array or vector.

  Database nested queries

Display the book title and the number of books sold where the profit from the book is more the 70%. The resulting list should display highest quantity of books title sold first in the list. Profit for a book is calculated as (retail - cost) / c..

  Draw one child diagram using the level 0 diagram

As a systems analyst or knowledgeable end-user, you must learn how to draw data flow diagrams to model business process requirements.

  Communicationa significant distinction between online and

communicationa significant distinction between online and face-to-face classes lies in the area of

  Create a scatter plot of computer price and hard drive size

Create a boxplot of the comparing the computer price and premium category. Create a scatter plot of computer price and hard drive size.

  What is the running time of your algorithm

Give an ef?cient algorithm to determine if there exists an integer i such that Ai = i in an array of integers A1

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd