# In stores, boxes should be placed in an organized way otherwise it will be messy. Given a collection of boxes, it is requested to place them on top of each other to reach the minimum possibl

Question 1:
In stores, boxes should be placed in an organized way otherwise it will be messy. Given a
collection of boxes, it is requested to place them on top of each other to reach the
minimum possible height. There is a condition, where a box cannot be placed on top of another box unless the area of its 2D base is smaller or equal of the 2D base of the lower box. It is allowed to rotate any box to use any two sides as its base.
For example, consider below 4 boxes where each box has the following dimensions
Input:
Box 1: (2,1,3), Box 2:(6,3,8) Box 3: (4,2,5), Box 4:(3,1,6),
Output:
From bottom to top as follows:
In the bottom Æ Box 2 on the base (6,8) and height 3,
On top of it Æ Box 3 on the base (4,5) and height 2,
Then Æ Box 4 on the base (6,3) and height 1,
Finally Æ Box 1 on the base (2,3) and height 1.
The total height is 7
[Explanation: as we can see that the first box in the bottom is the box 2 with base 6×8 and height 3, then box3 with base 4×5 and height 2, and so on. This arrangement of boxes fulfils the constraint mentioned above: “the dimensions of the 2D base of the lower box are each strictly larger than those of the 2D base of the higher box”. This solution also satisfies the shortest possible stack]
a) Describe how a brute-force approach algorithm would solve the above problem (4
marks), and explain its complexity .
b) Design an algorithm to solve the above scenario for N boxes., and analyze the complexity
c) Develop a python code to implement your efficient algorithm.

d) Prepare a brief report (250 words) comparing the two algorithms

Question 2: (30 Marks)
There is a group of n children standing in a queue, where their ages are listed in
the array A[ ]. The children are standing randomly in the queue. Most probably,
their ages in the array A[ ] are randomly listed too. For each child, you are
required to search for the next older child in the queue and to print the difference of
their ages. Print all the outputs in an array
Out[ ].
Note:
x The last kid in the queue is then compared with the first kid in the queue as if it is a
circular queue.
x Print -1 if no one is eldest than the kid under consideration.
Example 1:
A[ ]={11, 10, 7, 13, 14, 12,
9,15,8}
Output:
Out[ ]=
{2, 3, 6, 2, 1, 3, 6, -1, 3}
Example 2:
A[]={8,5,9,4,10}
Output:
Out[ ]={1, 4, 1, 6, -1}
Explanation of example 1:
The given array A[] of heights is as follows:
A[0] A[1] A[2] A[3] A[4] A[5] A[6] A[7] A[8]
11 10 7 13 14 12 9 15 8
The kid at the starting point of the queue 11 years old (i.e.,
A[0]). The next older kid in the queue at A[3] with age 13
years. The difference between their heights is 13 – 11 = 2,
therefore 2 is printed. The second kid is 10 years old (i.e.,
A[1]) has also the same kid as the next first older kid.
Therefore 3 is printed and so on.
Remember that the queue is circular. Therefore, the last kid
in the queue with age 8 (i.e., A[8]) is compared with the kid
at the starting point of the queue, where the kid with 11
years old (i.e., A[0]) is the next older taller kid, and hence,
3 is printed.
Output: Out[ ]={2, 3, 6, 2, 1, 3, 6, -1, 3}
a) Design an efficient algorithm to solve this problem. (10 marks) [The efficiency of your
algorithm is the main driver of the mark], and analyze the complexity of your solution.
b) Develop a python code to implement your efficient algorithm. (10 marks) [The marks
depend on the correctness of the code, indentation, comments, test-case]
c) Prepare a brief report (250 words) comparing the two algorithms (6 marks)
Question 3: (30 Marks)
Given three groups of boxes A, B, and C of n boxes each, where the shapes of the boxes
are different. The capacity of each box is measured in milliliter (ml). The list of boxes’
capacities in Group A is exactly randomly repeated in Group B and C. This means that for
each box in Group A there exist a corresponding box in Group B and C that hold the same
capacity, but we do not know which box would match with the other in group A, B and C.
Your mission is to find a smart way to match these boxes.
For example:
Input: capacity in milliliter
Group 1 2 3 4 5 6 7 8
A 140 120 150 100 170 200 90 180
B 170 150 140 90 100 120 180 200
C 120 90 200 150 180 140 100 170
Output:
A[1] with B[3] with C[6]
A[2] with B[6] with C[1]
A[3] with B[2] with C[4]
… and so on
a) Using a brute-force approach, design an algorithm to solve this problem, and analyze
its complexity (3+2 marks)
b) Design a more efficient algorithm to solve this problem, and analyze its complexity
[Hint: you can use any data-structure] (6+4 marks)
c) Implement your efficient algorithm using Python (10 marks)
d) Prepare a brief report (250 words) comparing the two algorithms (5 marks)

Question 4: (30 Marks)
The following algorithm examines all the components in a given array to check for the
existence of any two numbers, where one of them is the square of the other, in the given
array or not.
For example 1: input: A[9,5,28,25,47, 55] Æ output: true
For example 2: input: A[24,15,18,18,42, 22] Æ output: false
In example 1 the output is True because (5 and 25), where 25 is the square value of 5,
while the output of example 2 is False because there is no any pair of numbers that meets
this condition.
• Input: An array A[0…n-1]
• Output: Return True if there exist any two numbers, where one of them is the square
of the other in the array, False otherwise
a) Design a brute force algorithm to solve this problem and analyze its
complexity.
b) Design a more efficient algorithm to do the same job analyze the