Q56Comprehension5 Marks2 Apr 2023
Passage
The following pseudocode is executed using the Shopping Bills dataset. Answer the given subquestions.
```
D = {}
while(Pile 1 has more cards) {
Read the top card X in Pile 1
foreach Y in X.ItemList {
if(isKey(D, Y.Category)) {
if(isKey(D[Y.Category], Y.ItemName)) {
D[Y.Category][Y.ItemName] = D[Y.Category][Y.ItemName] ++ [Y.Price]
}
else {
D[Y.Category][Y.ItemName] = [Y.Price]
}
}
else {
D[Y.Category] = {Y.ItemName : [Y.Price]}
}
}
Move card X to Pile 2
}
```
Consider the dictionary `D` created in the previous question. What will the value of `L` represent at the end of execution of the following pseudocode?
```
A = 0, L = []
foreach i in keys(D) {
foreach j in keys(D[i]) {
B = findRange(D[i][j])
if(B == 0) {
L = L ++ [j]
}
if(B > A) {
A = B
L = [j]
}
}
}
Procedure findRange(Y)
p = first(Y), q = first(Y)
foreach k in Y {
if(k > p) {
p = k
}
if(k < q) {
q = k
}
}
return(p - q)
End findRange
```