SlideShare a Scribd company logo
Box Problem
Rex Yuan
May 31, 2015
Dynamic Programming Approach
This algorithm reads in a list of data with each element representing a box
and containing the width, length, and height in sorted decreasing order of the
box and the volume of the box. Then we create a list, box table to store the
data and sort it in the decreasing order of volume of the box. Then we iterate
through box table, finding all the boxes that can fit inside a box and create an
adjacency matrix, matrix, to store the information. Then we create an empty
table, table, which is filled with 0s except for the ones lying on the diagonal line
from top-left corner to bottom-right corner which are willed with 1s. We iterate
through table bottom to top and right to left. Iterating through table, we find
boxes that can fit inside a box of index i according to matrix and by checking
their sides. We store the maximum number of boxes the box of the index of
i can fit inside of in table[i][i]. Finally we create a list, results, which stores
all the element on the top-left bottom-right line of table. Then we return the
element with maximum value in results.
Time Complexity
In creating the table for dynamic programming approach, we iterate through
the table both vertically and horizontally. So the time complexity is
O(n2
)
where n is the number of input boxes.
1
Algorithm 1 Box Problem DP Algorithm
procedure Box(boxes)
box table = sorted boxes by decreasing order of volume
matrix = empty adjacency filled with 0s matrix for a graph of possible
box sequence
for p box in boxes do
for c box in boxes do
if p box != c box and p box.side1 ¿ c box.side1 and p box.side2 ¿
c box.side2 and p box.side3 ¿ c box.side3 then
matrix[p box][c box.index] = 1
end if
end for
end for
dp table = empty table filled with 0s and for each element in the diagonal
line from top-left corner to bottom-right corner with 1s
for i in range(len(boxes), −1, −1) do max in i = table
for j in range(i + 1, len(boxes)) do
if matrix[i][j] == 1 then
table[i][j] = max(table[i][j − 1], table[i][i] + table[i][j]
if table[i][j] ¿ max in i then max in i = table[i][j]
end if
else
table[i][j] = table[i][j − 1]
end if
end fortable[i][i] = max in i
end for
results = []
for n in range(len(boxes)) do
results.append(table[n][n])
end for
return max(results)
end procedure
2
Run Time Stats
I created the following table using UNIX POSIX time function and round the
mean time of 10 trials to five digits after decimal point to calculate the time
past. All samples have the ten possible characters to be encoded, that is 0 9.
Variable input length implies the length of the sequence to be decoded.
Run Time Stats
Sample Input Size Box DP
1 9 0.00023
2 500 0.25236
3 750 0.57245
3

More Related Content

What's hot

Benchmark 3 Most Missed Questions
Benchmark 3 Most Missed QuestionsBenchmark 3 Most Missed Questions
Benchmark 3 Most Missed Questions
mrwilliams
 
Geometry vocabulary list (1)
Geometry vocabulary list (1)Geometry vocabulary list (1)
Geometry vocabulary list (1)
CarolinaDay3
 
Integers numberline
Integers numberlineIntegers numberline
Integers numberlineAmro Soliman
 
Integers numberline
Integers numberlineIntegers numberline
Integers numberlineitherrera
 
Integers numberline (1)
Integers numberline (1)Integers numberline (1)
Integers numberline (1)Girlie Tacuban
 
Math class 3 geometry part 1
Math class 3 geometry part 1Math class 3 geometry part 1
Math class 3 geometry part 1
Haider Shishmahal
 
Geometry: Area and Equality & The Pythagorean Theorem Revisited
Geometry: Area and Equality & The Pythagorean Theorem RevisitedGeometry: Area and Equality & The Pythagorean Theorem Revisited
Geometry: Area and Equality & The Pythagorean Theorem RevisitedSri Handayani
 
History of pie
History of pieHistory of pie
History of pie
Anand Sapru
 
Real numbers system
Real numbers systemReal numbers system
Real numbers system
Pradeep Agrawal
 
Pi
PiPi
Pi powerpoint
Pi  powerpointPi  powerpoint
Pi powerpoint
Natasa Liri
 
Number Systems
Number SystemsNumber Systems
Number Systems
美晴 福田
 
stem and leaf diagrams
 stem and leaf diagrams stem and leaf diagrams
stem and leaf diagramsblockmath
 
Boxplot
BoxplotBoxplot
Boxplot
Kelly Jans
 

What's hot (18)

Benchmark 3 Most Missed Questions
Benchmark 3 Most Missed QuestionsBenchmark 3 Most Missed Questions
Benchmark 3 Most Missed Questions
 
Unit 1. day 15b
Unit 1. day 15bUnit 1. day 15b
Unit 1. day 15b
 
Pie
PiePie
Pie
 
Geometry vocabulary list (1)
Geometry vocabulary list (1)Geometry vocabulary list (1)
Geometry vocabulary list (1)
 
Integers numberline
Integers numberlineIntegers numberline
Integers numberline
 
Integers numberline
Integers numberlineIntegers numberline
Integers numberline
 
Integers numberline (1)
Integers numberline (1)Integers numberline (1)
Integers numberline (1)
 
Math class 3 geometry part 1
Math class 3 geometry part 1Math class 3 geometry part 1
Math class 3 geometry part 1
 
Geometry: Area and Equality & The Pythagorean Theorem Revisited
Geometry: Area and Equality & The Pythagorean Theorem RevisitedGeometry: Area and Equality & The Pythagorean Theorem Revisited
Geometry: Area and Equality & The Pythagorean Theorem Revisited
 
History of pie
History of pieHistory of pie
History of pie
 
Real numbers system
Real numbers systemReal numbers system
Real numbers system
 
Pi
PiPi
Pi
 
What I Spi
What I SpiWhat I Spi
What I Spi
 
Pi powerpoint
Pi  powerpointPi  powerpoint
Pi powerpoint
 
Number Systems
Number SystemsNumber Systems
Number Systems
 
Real Numbers
Real NumbersReal Numbers
Real Numbers
 
stem and leaf diagrams
 stem and leaf diagrams stem and leaf diagrams
stem and leaf diagrams
 
Boxplot
BoxplotBoxplot
Boxplot
 

Viewers also liked

A Brief Intro to Chatbot
A Brief Intro to ChatbotA Brief Intro to Chatbot
A Brief Intro to Chatbot
Rex Yuan
 
CSOP 第一週:上課簡報
CSOP 第一週:上課簡報CSOP 第一週:上課簡報
CSOP 第一週:上課簡報
Rex Yuan
 
計概:Programming Paradigm (Notes)
計概:Programming Paradigm (Notes)計概:Programming Paradigm (Notes)
計概:Programming Paradigm (Notes)
Rex Yuan
 
A review of consumer brain computer interface devices
A review of consumer brain computer interface devicesA review of consumer brain computer interface devices
A review of consumer brain computer interface devices
Rex Yuan
 
Brain computer interface
Brain computer interfaceBrain computer interface
Brain computer interfacePranav Kulkarni
 
邏輯語的文法 -- Lojban grammar
邏輯語的文法 -- Lojban grammar邏輯語的文法 -- Lojban grammar
邏輯語的文法 -- Lojban grammar
鍾誠 陳鍾誠
 
程式人 為何學邏輯語 Lojban ?
程式人 為何學邏輯語 Lojban ?程式人 為何學邏輯語 Lojban ?
程式人 為何學邏輯語 Lojban ?
鍾誠 陳鍾誠
 
那些年、我們還沒學會就已經過時的那些技術
那些年、我們還沒學會就已經過時的那些技術那些年、我們還沒學會就已經過時的那些技術
那些年、我們還沒學會就已經過時的那些技術
鍾誠 陳鍾誠
 
Making Linux do Hard Real-time
Making Linux do Hard Real-timeMaking Linux do Hard Real-time
Making Linux do Hard Real-time
National Cheng Kung University
 

Viewers also liked (9)

A Brief Intro to Chatbot
A Brief Intro to ChatbotA Brief Intro to Chatbot
A Brief Intro to Chatbot
 
CSOP 第一週:上課簡報
CSOP 第一週:上課簡報CSOP 第一週:上課簡報
CSOP 第一週:上課簡報
 
計概:Programming Paradigm (Notes)
計概:Programming Paradigm (Notes)計概:Programming Paradigm (Notes)
計概:Programming Paradigm (Notes)
 
A review of consumer brain computer interface devices
A review of consumer brain computer interface devicesA review of consumer brain computer interface devices
A review of consumer brain computer interface devices
 
Brain computer interface
Brain computer interfaceBrain computer interface
Brain computer interface
 
邏輯語的文法 -- Lojban grammar
邏輯語的文法 -- Lojban grammar邏輯語的文法 -- Lojban grammar
邏輯語的文法 -- Lojban grammar
 
程式人 為何學邏輯語 Lojban ?
程式人 為何學邏輯語 Lojban ?程式人 為何學邏輯語 Lojban ?
程式人 為何學邏輯語 Lojban ?
 
那些年、我們還沒學會就已經過時的那些技術
那些年、我們還沒學會就已經過時的那些技術那些年、我們還沒學會就已經過時的那些技術
那些年、我們還沒學會就已經過時的那些技術
 
Making Linux do Hard Real-time
Making Linux do Hard Real-timeMaking Linux do Hard Real-time
Making Linux do Hard Real-time
 

Similar to Box Problem

Catalan Numbers
Catalan NumbersCatalan Numbers
Catalan Numbers
Dave Auckly
 
Merge radix-sort-algorithm
Merge radix-sort-algorithmMerge radix-sort-algorithm
Merge radix-sort-algorithm
Rendell Inocencio
 
Merge radix-sort-algorithm
Merge radix-sort-algorithmMerge radix-sort-algorithm
Merge radix-sort-algorithm
Rendell Inocencio
 
Math Project for Mr. Medina's Class
Math Project for Mr. Medina's ClassMath Project for Mr. Medina's Class
Math Project for Mr. Medina's Class
smit5008
 
Maths number system
Maths   number systemMaths   number system
Maths number system
Sanjay Crúzé
 
Calculator strategies
Calculator strategiesCalculator strategies
Calculator strategies
MartinEduSanchez
 
Karnaugh map
Karnaugh mapKarnaugh map
Karnaugh map
Vanitha Chandru
 
Discrete_Matrices
Discrete_MatricesDiscrete_Matrices
Discrete_Matricesguest78c418
 
karnaughmaprev1-130728135103-phpapp01.ppt
karnaughmaprev1-130728135103-phpapp01.pptkarnaughmaprev1-130728135103-phpapp01.ppt
karnaughmaprev1-130728135103-phpapp01.ppt
michaelaaron25322
 

Similar to Box Problem (9)

Catalan Numbers
Catalan NumbersCatalan Numbers
Catalan Numbers
 
Merge radix-sort-algorithm
Merge radix-sort-algorithmMerge radix-sort-algorithm
Merge radix-sort-algorithm
 
Merge radix-sort-algorithm
Merge radix-sort-algorithmMerge radix-sort-algorithm
Merge radix-sort-algorithm
 
Math Project for Mr. Medina's Class
Math Project for Mr. Medina's ClassMath Project for Mr. Medina's Class
Math Project for Mr. Medina's Class
 
Maths number system
Maths   number systemMaths   number system
Maths number system
 
Calculator strategies
Calculator strategiesCalculator strategies
Calculator strategies
 
Karnaugh map
Karnaugh mapKarnaugh map
Karnaugh map
 
Discrete_Matrices
Discrete_MatricesDiscrete_Matrices
Discrete_Matrices
 
karnaughmaprev1-130728135103-phpapp01.ppt
karnaughmaprev1-130728135103-phpapp01.pptkarnaughmaprev1-130728135103-phpapp01.ppt
karnaughmaprev1-130728135103-phpapp01.ppt
 

More from Rex Yuan

8/9 RLDM for Prosocial Behavior
8/9 RLDM for Prosocial Behavior8/9 RLDM for Prosocial Behavior
8/9 RLDM for Prosocial Behavior
Rex Yuan
 
圖文作業
圖文作業圖文作業
圖文作業
Rex Yuan
 
Maximum Flow
Maximum FlowMaximum Flow
Maximum Flow
Rex Yuan
 
Huffman Code Decoding
Huffman Code DecodingHuffman Code Decoding
Huffman Code Decoding
Rex Yuan
 
Longest Common Sequence Algorithm Analysis
Longest Common Sequence Algorithm AnalysisLongest Common Sequence Algorithm Analysis
Longest Common Sequence Algorithm Analysis
Rex Yuan
 
Convex Hull Algorithm Analysis
Convex Hull Algorithm AnalysisConvex Hull Algorithm Analysis
Convex Hull Algorithm Analysis
Rex Yuan
 
台灣大學聯盟第一學期
台灣大學聯盟第一學期台灣大學聯盟第一學期
台灣大學聯盟第一學期
Rex Yuan
 
Word and Phrases: Improv Everywhere - Gotta Share
Word and Phrases: Improv Everywhere - Gotta ShareWord and Phrases: Improv Everywhere - Gotta Share
Word and Phrases: Improv Everywhere - Gotta Share
Rex Yuan
 
計概:Programming Paradigm
計概:Programming Paradigm計概:Programming Paradigm
計概:Programming Paradigm
Rex Yuan
 
LinkedIn, the Serious Network 繁體中文版
LinkedIn, the Serious Network  繁體中文版LinkedIn, the Serious Network  繁體中文版
LinkedIn, the Serious Network 繁體中文版
Rex Yuan
 

More from Rex Yuan (10)

8/9 RLDM for Prosocial Behavior
8/9 RLDM for Prosocial Behavior8/9 RLDM for Prosocial Behavior
8/9 RLDM for Prosocial Behavior
 
圖文作業
圖文作業圖文作業
圖文作業
 
Maximum Flow
Maximum FlowMaximum Flow
Maximum Flow
 
Huffman Code Decoding
Huffman Code DecodingHuffman Code Decoding
Huffman Code Decoding
 
Longest Common Sequence Algorithm Analysis
Longest Common Sequence Algorithm AnalysisLongest Common Sequence Algorithm Analysis
Longest Common Sequence Algorithm Analysis
 
Convex Hull Algorithm Analysis
Convex Hull Algorithm AnalysisConvex Hull Algorithm Analysis
Convex Hull Algorithm Analysis
 
台灣大學聯盟第一學期
台灣大學聯盟第一學期台灣大學聯盟第一學期
台灣大學聯盟第一學期
 
Word and Phrases: Improv Everywhere - Gotta Share
Word and Phrases: Improv Everywhere - Gotta ShareWord and Phrases: Improv Everywhere - Gotta Share
Word and Phrases: Improv Everywhere - Gotta Share
 
計概:Programming Paradigm
計概:Programming Paradigm計概:Programming Paradigm
計概:Programming Paradigm
 
LinkedIn, the Serious Network 繁體中文版
LinkedIn, the Serious Network  繁體中文版LinkedIn, the Serious Network  繁體中文版
LinkedIn, the Serious Network 繁體中文版
 

Recently uploaded

What is greenhouse gasses and how many gasses are there to affect the Earth.
What is greenhouse gasses and how many gasses are there to affect the Earth.What is greenhouse gasses and how many gasses are there to affect the Earth.
What is greenhouse gasses and how many gasses are there to affect the Earth.
moosaasad1975
 
Leaf Initiation, Growth and Differentiation.pdf
Leaf Initiation, Growth and Differentiation.pdfLeaf Initiation, Growth and Differentiation.pdf
Leaf Initiation, Growth and Differentiation.pdf
Renu Jangid
 
SAR of Medicinal Chemistry 1st by dk.pdf
SAR of Medicinal Chemistry 1st by dk.pdfSAR of Medicinal Chemistry 1st by dk.pdf
SAR of Medicinal Chemistry 1st by dk.pdf
KrushnaDarade1
 
Observation of Io’s Resurfacing via Plume Deposition Using Ground-based Adapt...
Observation of Io’s Resurfacing via Plume Deposition Using Ground-based Adapt...Observation of Io’s Resurfacing via Plume Deposition Using Ground-based Adapt...
Observation of Io’s Resurfacing via Plume Deposition Using Ground-based Adapt...
Sérgio Sacani
 
如何办理(uvic毕业证书)维多利亚大学毕业证本科学位证书原版一模一样
如何办理(uvic毕业证书)维多利亚大学毕业证本科学位证书原版一模一样如何办理(uvic毕业证书)维多利亚大学毕业证本科学位证书原版一模一样
如何办理(uvic毕业证书)维多利亚大学毕业证本科学位证书原版一模一样
yqqaatn0
 
Oedema_types_causes_pathophysiology.pptx
Oedema_types_causes_pathophysiology.pptxOedema_types_causes_pathophysiology.pptx
Oedema_types_causes_pathophysiology.pptx
muralinath2
 
The use of Nauplii and metanauplii artemia in aquaculture (brine shrimp).pptx
The use of Nauplii and metanauplii artemia in aquaculture (brine shrimp).pptxThe use of Nauplii and metanauplii artemia in aquaculture (brine shrimp).pptx
The use of Nauplii and metanauplii artemia in aquaculture (brine shrimp).pptx
MAGOTI ERNEST
 
DERIVATION OF MODIFIED BERNOULLI EQUATION WITH VISCOUS EFFECTS AND TERMINAL V...
DERIVATION OF MODIFIED BERNOULLI EQUATION WITH VISCOUS EFFECTS AND TERMINAL V...DERIVATION OF MODIFIED BERNOULLI EQUATION WITH VISCOUS EFFECTS AND TERMINAL V...
DERIVATION OF MODIFIED BERNOULLI EQUATION WITH VISCOUS EFFECTS AND TERMINAL V...
Wasswaderrick3
 
Unveiling the Energy Potential of Marshmallow Deposits.pdf
Unveiling the Energy Potential of Marshmallow Deposits.pdfUnveiling the Energy Potential of Marshmallow Deposits.pdf
Unveiling the Energy Potential of Marshmallow Deposits.pdf
Erdal Coalmaker
 
Toxic effects of heavy metals : Lead and Arsenic
Toxic effects of heavy metals : Lead and ArsenicToxic effects of heavy metals : Lead and Arsenic
Toxic effects of heavy metals : Lead and Arsenic
sanjana502982
 
Eukaryotic Transcription Presentation.pptx
Eukaryotic Transcription Presentation.pptxEukaryotic Transcription Presentation.pptx
Eukaryotic Transcription Presentation.pptx
RitabrataSarkar3
 
Nucleophilic Addition of carbonyl compounds.pptx
Nucleophilic Addition of carbonyl  compounds.pptxNucleophilic Addition of carbonyl  compounds.pptx
Nucleophilic Addition of carbonyl compounds.pptx
SSR02
 
THEMATIC APPERCEPTION TEST(TAT) cognitive abilities, creativity, and critic...
THEMATIC  APPERCEPTION  TEST(TAT) cognitive abilities, creativity, and critic...THEMATIC  APPERCEPTION  TEST(TAT) cognitive abilities, creativity, and critic...
THEMATIC APPERCEPTION TEST(TAT) cognitive abilities, creativity, and critic...
Abdul Wali Khan University Mardan,kP,Pakistan
 
NuGOweek 2024 Ghent programme overview flyer
NuGOweek 2024 Ghent programme overview flyerNuGOweek 2024 Ghent programme overview flyer
NuGOweek 2024 Ghent programme overview flyer
pablovgd
 
20240520 Planning a Circuit Simulator in JavaScript.pptx
20240520 Planning a Circuit Simulator in JavaScript.pptx20240520 Planning a Circuit Simulator in JavaScript.pptx
20240520 Planning a Circuit Simulator in JavaScript.pptx
Sharon Liu
 
Remote Sensing and Computational, Evolutionary, Supercomputing, and Intellige...
Remote Sensing and Computational, Evolutionary, Supercomputing, and Intellige...Remote Sensing and Computational, Evolutionary, Supercomputing, and Intellige...
Remote Sensing and Computational, Evolutionary, Supercomputing, and Intellige...
University of Maribor
 
Travis Hills' Endeavors in Minnesota: Fostering Environmental and Economic Pr...
Travis Hills' Endeavors in Minnesota: Fostering Environmental and Economic Pr...Travis Hills' Endeavors in Minnesota: Fostering Environmental and Economic Pr...
Travis Hills' Endeavors in Minnesota: Fostering Environmental and Economic Pr...
Travis Hills MN
 
bordetella pertussis.................................ppt
bordetella pertussis.................................pptbordetella pertussis.................................ppt
bordetella pertussis.................................ppt
kejapriya1
 
Shallowest Oil Discovery of Turkiye.pptx
Shallowest Oil Discovery of Turkiye.pptxShallowest Oil Discovery of Turkiye.pptx
Shallowest Oil Discovery of Turkiye.pptx
Gokturk Mehmet Dilci
 
DMARDs Pharmacolgy Pharm D 5th Semester.pdf
DMARDs Pharmacolgy Pharm D 5th Semester.pdfDMARDs Pharmacolgy Pharm D 5th Semester.pdf
DMARDs Pharmacolgy Pharm D 5th Semester.pdf
fafyfskhan251kmf
 

Recently uploaded (20)

What is greenhouse gasses and how many gasses are there to affect the Earth.
What is greenhouse gasses and how many gasses are there to affect the Earth.What is greenhouse gasses and how many gasses are there to affect the Earth.
What is greenhouse gasses and how many gasses are there to affect the Earth.
 
Leaf Initiation, Growth and Differentiation.pdf
Leaf Initiation, Growth and Differentiation.pdfLeaf Initiation, Growth and Differentiation.pdf
Leaf Initiation, Growth and Differentiation.pdf
 
SAR of Medicinal Chemistry 1st by dk.pdf
SAR of Medicinal Chemistry 1st by dk.pdfSAR of Medicinal Chemistry 1st by dk.pdf
SAR of Medicinal Chemistry 1st by dk.pdf
 
Observation of Io’s Resurfacing via Plume Deposition Using Ground-based Adapt...
Observation of Io’s Resurfacing via Plume Deposition Using Ground-based Adapt...Observation of Io’s Resurfacing via Plume Deposition Using Ground-based Adapt...
Observation of Io’s Resurfacing via Plume Deposition Using Ground-based Adapt...
 
如何办理(uvic毕业证书)维多利亚大学毕业证本科学位证书原版一模一样
如何办理(uvic毕业证书)维多利亚大学毕业证本科学位证书原版一模一样如何办理(uvic毕业证书)维多利亚大学毕业证本科学位证书原版一模一样
如何办理(uvic毕业证书)维多利亚大学毕业证本科学位证书原版一模一样
 
Oedema_types_causes_pathophysiology.pptx
Oedema_types_causes_pathophysiology.pptxOedema_types_causes_pathophysiology.pptx
Oedema_types_causes_pathophysiology.pptx
 
The use of Nauplii and metanauplii artemia in aquaculture (brine shrimp).pptx
The use of Nauplii and metanauplii artemia in aquaculture (brine shrimp).pptxThe use of Nauplii and metanauplii artemia in aquaculture (brine shrimp).pptx
The use of Nauplii and metanauplii artemia in aquaculture (brine shrimp).pptx
 
DERIVATION OF MODIFIED BERNOULLI EQUATION WITH VISCOUS EFFECTS AND TERMINAL V...
DERIVATION OF MODIFIED BERNOULLI EQUATION WITH VISCOUS EFFECTS AND TERMINAL V...DERIVATION OF MODIFIED BERNOULLI EQUATION WITH VISCOUS EFFECTS AND TERMINAL V...
DERIVATION OF MODIFIED BERNOULLI EQUATION WITH VISCOUS EFFECTS AND TERMINAL V...
 
Unveiling the Energy Potential of Marshmallow Deposits.pdf
Unveiling the Energy Potential of Marshmallow Deposits.pdfUnveiling the Energy Potential of Marshmallow Deposits.pdf
Unveiling the Energy Potential of Marshmallow Deposits.pdf
 
Toxic effects of heavy metals : Lead and Arsenic
Toxic effects of heavy metals : Lead and ArsenicToxic effects of heavy metals : Lead and Arsenic
Toxic effects of heavy metals : Lead and Arsenic
 
Eukaryotic Transcription Presentation.pptx
Eukaryotic Transcription Presentation.pptxEukaryotic Transcription Presentation.pptx
Eukaryotic Transcription Presentation.pptx
 
Nucleophilic Addition of carbonyl compounds.pptx
Nucleophilic Addition of carbonyl  compounds.pptxNucleophilic Addition of carbonyl  compounds.pptx
Nucleophilic Addition of carbonyl compounds.pptx
 
THEMATIC APPERCEPTION TEST(TAT) cognitive abilities, creativity, and critic...
THEMATIC  APPERCEPTION  TEST(TAT) cognitive abilities, creativity, and critic...THEMATIC  APPERCEPTION  TEST(TAT) cognitive abilities, creativity, and critic...
THEMATIC APPERCEPTION TEST(TAT) cognitive abilities, creativity, and critic...
 
NuGOweek 2024 Ghent programme overview flyer
NuGOweek 2024 Ghent programme overview flyerNuGOweek 2024 Ghent programme overview flyer
NuGOweek 2024 Ghent programme overview flyer
 
20240520 Planning a Circuit Simulator in JavaScript.pptx
20240520 Planning a Circuit Simulator in JavaScript.pptx20240520 Planning a Circuit Simulator in JavaScript.pptx
20240520 Planning a Circuit Simulator in JavaScript.pptx
 
Remote Sensing and Computational, Evolutionary, Supercomputing, and Intellige...
Remote Sensing and Computational, Evolutionary, Supercomputing, and Intellige...Remote Sensing and Computational, Evolutionary, Supercomputing, and Intellige...
Remote Sensing and Computational, Evolutionary, Supercomputing, and Intellige...
 
Travis Hills' Endeavors in Minnesota: Fostering Environmental and Economic Pr...
Travis Hills' Endeavors in Minnesota: Fostering Environmental and Economic Pr...Travis Hills' Endeavors in Minnesota: Fostering Environmental and Economic Pr...
Travis Hills' Endeavors in Minnesota: Fostering Environmental and Economic Pr...
 
bordetella pertussis.................................ppt
bordetella pertussis.................................pptbordetella pertussis.................................ppt
bordetella pertussis.................................ppt
 
Shallowest Oil Discovery of Turkiye.pptx
Shallowest Oil Discovery of Turkiye.pptxShallowest Oil Discovery of Turkiye.pptx
Shallowest Oil Discovery of Turkiye.pptx
 
DMARDs Pharmacolgy Pharm D 5th Semester.pdf
DMARDs Pharmacolgy Pharm D 5th Semester.pdfDMARDs Pharmacolgy Pharm D 5th Semester.pdf
DMARDs Pharmacolgy Pharm D 5th Semester.pdf
 

Box Problem

  • 1. Box Problem Rex Yuan May 31, 2015 Dynamic Programming Approach This algorithm reads in a list of data with each element representing a box and containing the width, length, and height in sorted decreasing order of the box and the volume of the box. Then we create a list, box table to store the data and sort it in the decreasing order of volume of the box. Then we iterate through box table, finding all the boxes that can fit inside a box and create an adjacency matrix, matrix, to store the information. Then we create an empty table, table, which is filled with 0s except for the ones lying on the diagonal line from top-left corner to bottom-right corner which are willed with 1s. We iterate through table bottom to top and right to left. Iterating through table, we find boxes that can fit inside a box of index i according to matrix and by checking their sides. We store the maximum number of boxes the box of the index of i can fit inside of in table[i][i]. Finally we create a list, results, which stores all the element on the top-left bottom-right line of table. Then we return the element with maximum value in results. Time Complexity In creating the table for dynamic programming approach, we iterate through the table both vertically and horizontally. So the time complexity is O(n2 ) where n is the number of input boxes. 1
  • 2. Algorithm 1 Box Problem DP Algorithm procedure Box(boxes) box table = sorted boxes by decreasing order of volume matrix = empty adjacency filled with 0s matrix for a graph of possible box sequence for p box in boxes do for c box in boxes do if p box != c box and p box.side1 ¿ c box.side1 and p box.side2 ¿ c box.side2 and p box.side3 ¿ c box.side3 then matrix[p box][c box.index] = 1 end if end for end for dp table = empty table filled with 0s and for each element in the diagonal line from top-left corner to bottom-right corner with 1s for i in range(len(boxes), −1, −1) do max in i = table for j in range(i + 1, len(boxes)) do if matrix[i][j] == 1 then table[i][j] = max(table[i][j − 1], table[i][i] + table[i][j] if table[i][j] ¿ max in i then max in i = table[i][j] end if else table[i][j] = table[i][j − 1] end if end fortable[i][i] = max in i end for results = [] for n in range(len(boxes)) do results.append(table[n][n]) end for return max(results) end procedure 2
  • 3. Run Time Stats I created the following table using UNIX POSIX time function and round the mean time of 10 trials to five digits after decimal point to calculate the time past. All samples have the ten possible characters to be encoded, that is 0 9. Variable input length implies the length of the sequence to be decoded. Run Time Stats Sample Input Size Box DP 1 9 0.00023 2 500 0.25236 3 750 0.57245 3