SlideShare a Scribd company logo
1 of 3
Download to read offline
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 Questionsmrwilliams
 
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 1Haider 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
 
stem and leaf diagrams
 stem and leaf diagrams stem and leaf diagrams
stem and leaf diagramsblockmath
 

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 ChatbotRex 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 devicesRex 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 ?鍾誠 陳鍾誠
 
那些年、我們還沒學會就已經過時的那些技術
那些年、我們還沒學會就已經過時的那些技術那些年、我們還沒學會就已經過時的那些技術
那些年、我們還沒學會就已經過時的那些技術鍾誠 陳鍾誠
 

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

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 Classsmit5008
 
Discrete_Matrices
Discrete_MatricesDiscrete_Matrices
Discrete_Matricesguest78c418
 
karnaughmaprev1-130728135103-phpapp01.ppt
karnaughmaprev1-130728135103-phpapp01.pptkarnaughmaprev1-130728135103-phpapp01.ppt
karnaughmaprev1-130728135103-phpapp01.pptmichaelaaron25322
 

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 BehaviorRex Yuan
 
圖文作業
圖文作業圖文作業
圖文作業Rex Yuan
 
Maximum Flow
Maximum FlowMaximum Flow
Maximum FlowRex Yuan
 
Huffman Code Decoding
Huffman Code DecodingHuffman Code Decoding
Huffman Code DecodingRex Yuan
 
Longest Common Sequence Algorithm Analysis
Longest Common Sequence Algorithm AnalysisLongest Common Sequence Algorithm Analysis
Longest Common Sequence Algorithm AnalysisRex Yuan
 
Convex Hull Algorithm Analysis
Convex Hull Algorithm AnalysisConvex Hull Algorithm Analysis
Convex Hull Algorithm AnalysisRex 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 ShareRex Yuan
 
計概:Programming Paradigm
計概:Programming Paradigm計概:Programming Paradigm
計概:Programming ParadigmRex 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

Neurodevelopmental disorders according to the dsm 5 tr
Neurodevelopmental disorders according to the dsm 5 trNeurodevelopmental disorders according to the dsm 5 tr
Neurodevelopmental disorders according to the dsm 5 trssuser06f238
 
Scheme-of-Work-Science-Stage-4 cambridge science.docx
Scheme-of-Work-Science-Stage-4 cambridge science.docxScheme-of-Work-Science-Stage-4 cambridge science.docx
Scheme-of-Work-Science-Stage-4 cambridge science.docxyaramohamed343013
 
Call Girls in Hauz Khas Delhi 💯Call Us 🔝9953322196🔝 💯Escort.
Call Girls in Hauz Khas Delhi 💯Call Us 🔝9953322196🔝 💯Escort.Call Girls in Hauz Khas Delhi 💯Call Us 🔝9953322196🔝 💯Escort.
Call Girls in Hauz Khas Delhi 💯Call Us 🔝9953322196🔝 💯Escort.aasikanpl
 
Cytokinin, mechanism and its application.pptx
Cytokinin, mechanism and its application.pptxCytokinin, mechanism and its application.pptx
Cytokinin, mechanism and its application.pptxVarshiniMK
 
Behavioral Disorder: Schizophrenia & it's Case Study.pdf
Behavioral Disorder: Schizophrenia & it's Case Study.pdfBehavioral Disorder: Schizophrenia & it's Case Study.pdf
Behavioral Disorder: Schizophrenia & it's Case Study.pdfSELF-EXPLANATORY
 
Microphone- characteristics,carbon microphone, dynamic microphone.pptx
Microphone- characteristics,carbon microphone, dynamic microphone.pptxMicrophone- characteristics,carbon microphone, dynamic microphone.pptx
Microphone- characteristics,carbon microphone, dynamic microphone.pptxpriyankatabhane
 
Twin's paradox experiment is a meassurement of the extra dimensions.pptx
Twin's paradox experiment is a meassurement of the extra dimensions.pptxTwin's paradox experiment is a meassurement of the extra dimensions.pptx
Twin's paradox experiment is a meassurement of the extra dimensions.pptxEran Akiva Sinbar
 
Analytical Profile of Coleus Forskohlii | Forskolin .pdf
Analytical Profile of Coleus Forskohlii | Forskolin .pdfAnalytical Profile of Coleus Forskohlii | Forskolin .pdf
Analytical Profile of Coleus Forskohlii | Forskolin .pdfSwapnil Therkar
 
TOPIC 8 Temperature and Heat.pdf physics
TOPIC 8 Temperature and Heat.pdf physicsTOPIC 8 Temperature and Heat.pdf physics
TOPIC 8 Temperature and Heat.pdf physicsssuserddc89b
 
TOTAL CHOLESTEROL (lipid profile test).pptx
TOTAL CHOLESTEROL (lipid profile test).pptxTOTAL CHOLESTEROL (lipid profile test).pptx
TOTAL CHOLESTEROL (lipid profile test).pptxdharshini369nike
 
Recombinant DNA technology( Transgenic plant and animal)
Recombinant DNA technology( Transgenic plant and animal)Recombinant DNA technology( Transgenic plant and animal)
Recombinant DNA technology( Transgenic plant and animal)DHURKADEVIBASKAR
 
Call Us ≽ 9953322196 ≼ Call Girls In Lajpat Nagar (Delhi) |
Call Us ≽ 9953322196 ≼ Call Girls In Lajpat Nagar (Delhi) |Call Us ≽ 9953322196 ≼ Call Girls In Lajpat Nagar (Delhi) |
Call Us ≽ 9953322196 ≼ Call Girls In Lajpat Nagar (Delhi) |aasikanpl
 
zoogeography of pakistan.pptx fauna of Pakistan
zoogeography of pakistan.pptx fauna of Pakistanzoogeography of pakistan.pptx fauna of Pakistan
zoogeography of pakistan.pptx fauna of Pakistanzohaibmir069
 
Call Us ≽ 9953322196 ≼ Call Girls In Mukherjee Nagar(Delhi) |
Call Us ≽ 9953322196 ≼ Call Girls In Mukherjee Nagar(Delhi) |Call Us ≽ 9953322196 ≼ Call Girls In Mukherjee Nagar(Delhi) |
Call Us ≽ 9953322196 ≼ Call Girls In Mukherjee Nagar(Delhi) |aasikanpl
 
Call Girls in Munirka Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Munirka Delhi 💯Call Us 🔝8264348440🔝Call Girls in Munirka Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Munirka Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
insect anatomy and insect body wall and their physiology
insect anatomy and insect body wall and their  physiologyinsect anatomy and insect body wall and their  physiology
insect anatomy and insect body wall and their physiologyDrAnita Sharma
 
Best Call Girls In Sector 29 Gurgaon❤️8860477959 EscorTs Service In 24/7 Delh...
Best Call Girls In Sector 29 Gurgaon❤️8860477959 EscorTs Service In 24/7 Delh...Best Call Girls In Sector 29 Gurgaon❤️8860477959 EscorTs Service In 24/7 Delh...
Best Call Girls In Sector 29 Gurgaon❤️8860477959 EscorTs Service In 24/7 Delh...lizamodels9
 
Harmful and Useful Microorganisms Presentation
Harmful and Useful Microorganisms PresentationHarmful and Useful Microorganisms Presentation
Harmful and Useful Microorganisms Presentationtahreemzahra82
 
Forest laws, Indian forest laws, why they are important
Forest laws, Indian forest laws, why they are importantForest laws, Indian forest laws, why they are important
Forest laws, Indian forest laws, why they are importantadityabhardwaj282
 
Speech, hearing, noise, intelligibility.pptx
Speech, hearing, noise, intelligibility.pptxSpeech, hearing, noise, intelligibility.pptx
Speech, hearing, noise, intelligibility.pptxpriyankatabhane
 

Recently uploaded (20)

Neurodevelopmental disorders according to the dsm 5 tr
Neurodevelopmental disorders according to the dsm 5 trNeurodevelopmental disorders according to the dsm 5 tr
Neurodevelopmental disorders according to the dsm 5 tr
 
Scheme-of-Work-Science-Stage-4 cambridge science.docx
Scheme-of-Work-Science-Stage-4 cambridge science.docxScheme-of-Work-Science-Stage-4 cambridge science.docx
Scheme-of-Work-Science-Stage-4 cambridge science.docx
 
Call Girls in Hauz Khas Delhi 💯Call Us 🔝9953322196🔝 💯Escort.
Call Girls in Hauz Khas Delhi 💯Call Us 🔝9953322196🔝 💯Escort.Call Girls in Hauz Khas Delhi 💯Call Us 🔝9953322196🔝 💯Escort.
Call Girls in Hauz Khas Delhi 💯Call Us 🔝9953322196🔝 💯Escort.
 
Cytokinin, mechanism and its application.pptx
Cytokinin, mechanism and its application.pptxCytokinin, mechanism and its application.pptx
Cytokinin, mechanism and its application.pptx
 
Behavioral Disorder: Schizophrenia & it's Case Study.pdf
Behavioral Disorder: Schizophrenia & it's Case Study.pdfBehavioral Disorder: Schizophrenia & it's Case Study.pdf
Behavioral Disorder: Schizophrenia & it's Case Study.pdf
 
Microphone- characteristics,carbon microphone, dynamic microphone.pptx
Microphone- characteristics,carbon microphone, dynamic microphone.pptxMicrophone- characteristics,carbon microphone, dynamic microphone.pptx
Microphone- characteristics,carbon microphone, dynamic microphone.pptx
 
Twin's paradox experiment is a meassurement of the extra dimensions.pptx
Twin's paradox experiment is a meassurement of the extra dimensions.pptxTwin's paradox experiment is a meassurement of the extra dimensions.pptx
Twin's paradox experiment is a meassurement of the extra dimensions.pptx
 
Analytical Profile of Coleus Forskohlii | Forskolin .pdf
Analytical Profile of Coleus Forskohlii | Forskolin .pdfAnalytical Profile of Coleus Forskohlii | Forskolin .pdf
Analytical Profile of Coleus Forskohlii | Forskolin .pdf
 
TOPIC 8 Temperature and Heat.pdf physics
TOPIC 8 Temperature and Heat.pdf physicsTOPIC 8 Temperature and Heat.pdf physics
TOPIC 8 Temperature and Heat.pdf physics
 
TOTAL CHOLESTEROL (lipid profile test).pptx
TOTAL CHOLESTEROL (lipid profile test).pptxTOTAL CHOLESTEROL (lipid profile test).pptx
TOTAL CHOLESTEROL (lipid profile test).pptx
 
Recombinant DNA technology( Transgenic plant and animal)
Recombinant DNA technology( Transgenic plant and animal)Recombinant DNA technology( Transgenic plant and animal)
Recombinant DNA technology( Transgenic plant and animal)
 
Call Us ≽ 9953322196 ≼ Call Girls In Lajpat Nagar (Delhi) |
Call Us ≽ 9953322196 ≼ Call Girls In Lajpat Nagar (Delhi) |Call Us ≽ 9953322196 ≼ Call Girls In Lajpat Nagar (Delhi) |
Call Us ≽ 9953322196 ≼ Call Girls In Lajpat Nagar (Delhi) |
 
zoogeography of pakistan.pptx fauna of Pakistan
zoogeography of pakistan.pptx fauna of Pakistanzoogeography of pakistan.pptx fauna of Pakistan
zoogeography of pakistan.pptx fauna of Pakistan
 
Call Us ≽ 9953322196 ≼ Call Girls In Mukherjee Nagar(Delhi) |
Call Us ≽ 9953322196 ≼ Call Girls In Mukherjee Nagar(Delhi) |Call Us ≽ 9953322196 ≼ Call Girls In Mukherjee Nagar(Delhi) |
Call Us ≽ 9953322196 ≼ Call Girls In Mukherjee Nagar(Delhi) |
 
Call Girls in Munirka Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Munirka Delhi 💯Call Us 🔝8264348440🔝Call Girls in Munirka Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Munirka Delhi 💯Call Us 🔝8264348440🔝
 
insect anatomy and insect body wall and their physiology
insect anatomy and insect body wall and their  physiologyinsect anatomy and insect body wall and their  physiology
insect anatomy and insect body wall and their physiology
 
Best Call Girls In Sector 29 Gurgaon❤️8860477959 EscorTs Service In 24/7 Delh...
Best Call Girls In Sector 29 Gurgaon❤️8860477959 EscorTs Service In 24/7 Delh...Best Call Girls In Sector 29 Gurgaon❤️8860477959 EscorTs Service In 24/7 Delh...
Best Call Girls In Sector 29 Gurgaon❤️8860477959 EscorTs Service In 24/7 Delh...
 
Harmful and Useful Microorganisms Presentation
Harmful and Useful Microorganisms PresentationHarmful and Useful Microorganisms Presentation
Harmful and Useful Microorganisms Presentation
 
Forest laws, Indian forest laws, why they are important
Forest laws, Indian forest laws, why they are importantForest laws, Indian forest laws, why they are important
Forest laws, Indian forest laws, why they are important
 
Speech, hearing, noise, intelligibility.pptx
Speech, hearing, noise, intelligibility.pptxSpeech, hearing, noise, intelligibility.pptx
Speech, hearing, noise, intelligibility.pptx
 

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