
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
problem 2 please
Ans to problem 1 is
#include <bits/stdc++.h>
using namespace std;
{
int n = a.size();
for(int i = 0 ; i < n - 1 ; i++)
for(int j = i + 1 ; j < n ; j++)
{
if(a[i] + a[j] == target)
return {i + 1 , j + 1};
}
return {};
}
int main()
{
vector <int> a = {1 , 4 , 5 , 11 , 12};
int target = 9;
for(int &x : targetSum(a , target))
cout << x << " ";
cout << '\n';
}

Transcribed Image Text:Problem 1. Assume that you were given N cents (N is an integer) and you were asked to
break up the N cents into coins consisting of 1 cent, 2 cents and 5 cents. Write a dynamic-
programming based recursive algorithm, which returns the smallest (optimal) number of
coins needed to solve this problem. For example, if your algorithm is called A, and N = 13,
then A(N) = A(13) returns 4, since 5+5+2+1 = 13 used the smallest (optimal) number of
coins. In contrast, 5+5+1+1+1 is not an optimal answer.
Problem 2. Draw the recursion tree for algorithm in Problem 1, where N = 7. Derive the
complexity bound of the algorithm in Problem 1. You do not need to prove the complexity
bound formally, just derive it by analyzing each component in your algorithm.
Problem 3. Construct a memoized algorithm for the problem described in Problem 1 and
derive its time complexity. You do not need to prove the complexity bound formally, just
derive it by analyzing each component in your algorithm.
Problem 4. Assume that you were given N cents (N is an integer) and you were asked
to break up the N cents into coins consisting of 1 cent, 2 cents and 5 cents. Prove that a
greedy algorithm always gives the optimal solution.
Problem 5. Assume that you were given N cents (N is an integer) and you were asked
to break up the N cents into coins consisting of 1 cent, 6 cents and 7 cents. Prove that a
greedy algorithm may not always give the optimal solution.
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by stepSolved in 2 steps

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
- Provide simple explanationarrow_forwardi am getting segmentation core dump. I don't know how to fix this please help. PLEASE HELP!! #include <bits/stdc++.h> #define lli long long int #define pb push_back #define mod 1000000007 #define INF 1e18 #define SIZE 100001 using namespace std; vector<lli> adj[SIZE];//adjacency list bool visited[SIZE];//used in dfs and bfs lli dist[SIZE],discover[SIZE],finish[SIZE];//dist for bfs,intime,outtime for dfs lli t = 1;//time used for the dfs void dfs(lli s) { visited[s] =1;//making it visited discover[s] = t++;//assigning and incrementing time lli i,v; for(i =0; i <adj[s].size(); i++) { v = adj[s][i]; if(!visited[v])//if vertex is not visited then visit dfs(v); } finish[s] = t++;//assigning the outtime } int main() { lli u ,v,i,j,k,N = 0; pair<lli,lli> current; ifstream iFile("input.txt");//reading the input file string str,num; //read until the end of file while(!iFile.eof()) { getline(iFile,str);//read the current line stringstream ss; ss << str;…arrow_forwardEvery data structure that we use in computer science has its weaknesses and strengthsHaving a full understanding of each will help make us better programmers!For this experiment, let's work with STL vectors and STL dequesFull requirements descriptions are found in the source code file Part 1Work with inserting elements at the front of a vector and a deque (30%) Part 2Work with inserting elements at the back of a vector and a deque (30%) Part 3Work with inserting elements in the middle, and removing elements from, a vector and a deque (40%) Please make sure to put your code specifically where it is asked for, and no where elseDo not modify any of the code you already see in the template file This C++ source code file is required to complete this problemarrow_forward
- 4. Complete the function :- a) vector count (string s) { //store the count of uppercase alphabets in s at the Oth index of the vector //store the count of lowercase alphabets in s at the 1st index of the vector }arrow_forwardplease help solve this code using c++ arrays and pointers, and incorporate the following code: for (int i = 0 ; i < course ; i++) { // tell user which course is at cout << "Course "<< i+1 << endl ; // make pointer point to row arr[i] = new float [i+1] ; and then record assignment marks adding to the total for (int j = 0 ; j < entry ; j++) { // prompt for each course's entry cout << "Enter entry " <<j+1<< ": " ; cin >> score ; // store the score to each row arr[i][j] = score ; courseTol += score; }arrow_forwardcan someone help me with this in C++ You'll need to complete the following two step: implement bubble sort algorithms as a function. call the bubble sort function in the main.this is the code I have so far #include <iostream> #include <vector> using namespace std; void get_value(int *ptr, int size){ for(int i=0; i < size; i++){ ptr[i] = rand() % 100; }} void bubble_sort(int *ptr, int size){ //complete the code } int main(){ int *myarray = new int[10]; get_value(myarray, 10); //implement a bubble sort function to sort the array return 0;}arrow_forward
arrow_back_ios
arrow_forward_ios
Recommended textbooks for you
- 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

Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON

Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education