Sunday, April 2, 2023

Digest for comp.lang.c++@googlegroups.com - 4 updates in 2 topics

Kunal Goswami <20cs06014@iitbbs.ac.in>: Apr 02 12:24PM -0700

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 <20cs06014@iitbbs.ac.in>: Apr 02 01:17PM -0700

On Monday, April 3, 2023 at 12:54:50 AM UTC+5:30, Kunal Goswami wrote:
> intended recipient you are notified that disclosing, copying, distributing
> or taking any action in reliance on the contents of this information is
> strictly prohibited.
do not use 2-d vector
 
--
*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.
Christian Gollwitzer <auriocus@gmx.de>: Apr 02 11:17PM +0200

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
Bonita Montero <Bonita.Montero@gmail.com>: Apr 02 07:23PM +0200


> or perhaps
 
> for(auto [,s2,]: v) .....
 
> It would only be a small gain in efficiency but might be useful.
 
There's no gain in efficiency with that since ignoring parts
of the tuple is only declarative.
You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page.
To unsubscribe from this group and stop receiving emails from it send an email to comp.lang.c+++unsubscribe@googlegroups.com.

No comments: