Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

iterative to recursive

33 views
Skip to first unread message

Kunal Goswami

unread,
Apr 2, 2023, 3:24:50 PM4/2/23
to
Hiii !

Can someone change below iterative code snippet to recursive call ?

int knapSack(int W, int wt[], int val[], int n)
{
vector <int> dp (W+1) ;
//int dp[W + 1] = {0} ;

for (int i=1 ; i<n+1 ; i++)
{
for (int j=W ; j>0 ; j--)
{
if (wt[i-1] <= j)
dp[j] = max (dp[j] , dp[j-wt[i-1]]+val[i-1]) ;
}
}
return dp[W] ;
}

--
*Disclaimer: *This email and any files transmitted with it are confidential
and intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify the
system manager. This message contains confidential information and is
intended only for the individual named. If you are not the named addressee
you should not disseminate, distribute or copy this e-mail. Please notify
the sender immediately by e-mail if you have received this e-mail by
mistake and delete this e-mail from your system. If you are not the
intended recipient you are notified that disclosing, copying, distributing
or taking any action in reliance on the contents of this information is
strictly prohibited.

Kunal Goswami

unread,
Apr 2, 2023, 4:17:44 PM4/2/23
to
do not use 2-d vector

Christian Gollwitzer

unread,
Apr 2, 2023, 5:17:50 PM4/2/23
to
Am 02.04.23 um 21:24 schrieb Kunal Goswami:

> Can someone change below iterative code snippet to recursive call ?
>

Why should anyone want to do that? In C++, iterative code is typically
more efficient than recursive code. If it ain't broken, don't fix it.

Christian

Scott Lurndal

unread,
Apr 2, 2023, 7:41:39 PM4/2/23
to
My suspicion is that the OP is trying to get someone to do their homework.

Scott Lurndal

unread,
Apr 2, 2023, 7:47:14 PM4/2/23
to
Particularly given the email domain which is from the Indian Institute of
Technology.

Öö Tiib

unread,
Apr 3, 2023, 2:58:28 AM4/3/23
to
Also its *Disclaimer* apparently asked to contact system manager of Indian
Institute of Technology on case the confidential information about
homework of Kunal Goswami that it contains leaked into Usenet
(or something like that).

Vir Campestris

unread,
Apr 3, 2023, 7:28:10 AM4/3/23
to
It's tempting to contact them and point them to this thread...

Andy

Dan Purgert

unread,
Apr 3, 2023, 7:41:04 AM4/3/23
to
On 2023-04-03, Öö Tiib wrote:
> Also its *Disclaimer* apparently asked to contact system manager of Indian
> Institute of Technology on case the confidential information about
> homework of Kunal Goswami that it contains leaked into Usenet
> (or something like that).

I did always find those disclaimers slightly amusing, as in order to see
them in the first place, one needs to have the email "envelope"
addressed to them ...


--
|_|O|_|
|_|_|O| Github: https://github.com/dpurgert
|O|O|O| PGP: DDAB 23FB 19FA 7D85 1CC1 E067 6D65 70E5 4CE7 2860

red floyd

unread,
Apr 3, 2023, 9:10:30 PM4/3/23
to
On 4/2/2023 12:24 PM, Kunal Goswami wrote:
> [homework problem redacted]
>

I believe the solution is known as "do your own homework".

0 new messages