Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8755965
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:57:36+00:00 2026-06-13T13:57:36+00:00

Hello I am writing and testing a recursive dynamic programmed knapsack (0-1) (the following

  • 0

Hello I am writing and testing a recursive dynamic programmed knapsack (0-1) (the following code is the main file and the function) I keep getting the error (which is posted after the code)…I am really confused as to what the error is so any help will be much appreciated!

MAIN FILE

import Knapsack_Test

size = 10
W = 2**size
knapsack = Knapsack_Test.Knapsack_Test()

for i in range(1, 10):
    knapsack.recursive_knapsack_test(size, W)
size = size + 100*i

W = 2**size

FUNCTION CALLING (WHICH IS IN CLASS Knapsack_Test.py

def recursive_dynamic_knap(self, v, w, i, W):
    n = len(v) - 1
    if i == n:
        if W < w[n]:
            return 0
        else:
            return v
    elif W < w[i]:
        return self.recursive_dynamic_knap(v, w, i+1, W)

    return max(self.recursive_dynamic_knap(v, w, i+1,W), self.recursive_dynamic_knap(v, w, i+1, W-w[i]) + v[i])

ERROR

Traceback (most recent call last):
  File "\\minerfiles.mst.edu\dfs\users\asadmb\Desktop\Programming 3\Knapsack_Main.py", line 9, in <module>
    knapsack.recursive_knapsack_test(size, W)
  File "\\minerfiles.mst.edu\dfs\users\asadmb\Desktop\Programming 3\Knapsack_Test.py", line 19, in recursive_knapsack_test
    self.knapsack.recursive_dynamic_knap(v, w, j, W)
  File "\\minerfiles.mst.edu\dfs\users\asadmb\Desktop\Programming 3\KnapsackClass.py", line 22, in recursive_dynamic_knap
    return max(self.recursive_dynamic_knap(v, w, i+1,W), self.recursive_dynamic_knap(v, w, i+1, W-w[i]) + v[i])
  File "\\minerfiles.mst.edu\dfs\users\asadmb\Desktop\Programming 3\KnapsackClass.py", line 22, in recursive_dynamic_knap
    return max(self.recursive_dynamic_knap(v, w, i+1,W), self.recursive_dynamic_knap(v, w, i+1, W-w[i]) + v[i])
  File "\\minerfiles.mst.edu\dfs\users\asadmb\Desktop\Programming 3\KnapsackClass.py", line 22, in recursive_dynamic_knap
    return max(self.recursive_dynamic_knap(v, w, i+1,W), self.recursive_dynamic_knap(v, w, i+1, W-w[i]) + v[i])
  File "\\minerfiles.mst.edu\dfs\users\asadmb\Desktop\Programming 3\KnapsackClass.py", line 22, in recursive_dynamic_knap
    return max(self.recursive_dynamic_knap(v, w, i+1,W), self.recursive_dynamic_knap(v, w, i+1, W-w[i]) + v[i])
  File "\\minerfiles.mst.edu\dfs\users\asadmb\Desktop\Programming 3\KnapsackClass.py", line 22, in recursive_dynamic_knap
    return max(self.recursive_dynamic_knap(v, w, i+1,W), self.recursive_dynamic_knap(v, w, i+1, W-w[i]) + v[i])
  File "\\minerfiles.mst.edu\dfs\users\asadmb\Desktop\Programming 3\KnapsackClass.py", line 22, in recursive_dynamic_knap
    return max(self.recursive_dynamic_knap(v, w, i+1,W), self.recursive_dynamic_knap(v, w, i+1, W-w[i]) + v[i])
  File "\\minerfiles.mst.edu\dfs\users\asadmb\Desktop\Programming 3\KnapsackClass.py", line 22, in recursive_dynamic_knap
    return max(self.recursive_dynamic_knap(v, w, i+1,W), self.recursive_dynamic_knap(v, w, i+1, W-w[i]) + v[i])
TypeError: unorderable types: int() > list()
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T13:57:38+00:00Added an answer on June 13, 2026 at 1:57 pm

    I believe the problem is that in return max(self.recursive_dynamic_knap(v, w, i+1,W), self.recursive_dynamic_knap(v, w, i+1, W-w[i]) + v[i]) one of the calls to recursive_dynamic_knap is returning v, which is a list, and which makes no sense as an argument to max() because it is “unorderable” (can’t sensibly be judged to be greater than or less than an int)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello I am new to android programming, I haven't started writing the code for
I am reading Hello Android book and I am writing the code from the
I'm just writing some code to test the D3DXVec3Project function, trying to get it
Hello Fellow stackoverflowers, I´m stuck writing a piece of code. I have application with
Hello stackoverflow community, I am writing a batch file to do some automatic computer
Hello there i'm writing a code for c2dm with php this is the code
Hello Im currently writing a product syncronisation script for magento. I know how to
Hello I am writing some data structures in C, and I've realized that their
Hello again, stackoverflow community! I'm working on writing a simple blog system in Rails,
I'm writing a network app, where each Client has a Singleton ClientManager. For testing

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.