Forum Code Workbook

Assignment 1 (ICS-214)

There are four problems in this assignment.

Do your best to solve each one. Always explain your reasoning – what concepts you draw on, how you move from step to step, and

why your conclusions are plausible. Even if you can’t completely solve a problem, describe how you would approach it and why.

You may submit your answers as text in the response boxes here. If it is easier to write up answers to some or all of the problems

using another platform/tool, you can produce a single PDF, which you can submit below. If the solution to a given problem is in a

PDF submission, please note that in the response box for that problem (e.g., “See PDF”).

A few code cells are included if you want to do anything with Python while working on these problems.

• Problem 1 Change Simulation

• Problem 2 Chess Tree

• Problem 3 DAGs

• Problem 4 Being Lucky in Cards

Question 1 of 5

Problem 1: Change Simulation

A charity event is organized in Dubai, and a ten dirham “donation” is required per attendee. Suppose that every person who comes to

the event pays with either a 10 Dhs note or a 20 Dhs note. The team that collects payment at the door has a limited number of 10 Dhs

notes to give as change.

Suppose 10 people come to the event, and everyone pays for their “ticket.” Half of the attendees pay with a 10 Dhs note, and the

other half pay with a 20 Dhs note.

Answer the following questions.

1a. How many 10 Dhs notes must the team start with to ensure that they can give a change to everyone who pays with a 20 Dhs note,

regardless of the order in which people arrive?

1b. What could be the total number sequence of possible arrivals of 5 people with 10 Dhs note and 5 people with 20 Dhs note?

1c. Perform a data generation through simulations to calculate the probability that the team will run out of 10 Dhs notes if they start

with only 1 note and attendees arrive randomly. Explain each step of your code.

Normal

PyCthoodne 3Ce(3ll814oMf B5 RAM) | Edit Run All Cells Kernel Ready | Restart | Interrupt

9/20/24, 12:55 PM Assignment 1 (ICS-214)

https://sle-collaboration.minervaproject.com/?id=213045f7-5857-4313-894d-72fd42feaac2&userId=24632&name=Abdulla+Abdelraheem+Jasem+Yousuf+Alm… 1/5

Run Code

In [ ]

Question 2 of 5

Problem 2: Chess Tree

In a chess tournament, players compete in 3 matches against other participants. A win earns 2 points, a draw (tie) earns 1 point, and

a loss earns 0 points. Suppose there are four players, A, B, C, and D, and player A wins all three matches.

Through the tree diagram, discuss all the possibilities of point distributions for players B, C, and D. Summarize your findings at the

end.

Normal

Question 3 of 5

Problem 3: DAGs

Run the code cell below, which will give you two DAGs (Graph 1 and Graph 2) comprising six nodes: A, B, C, D, E, and F. Your task is

to answer the following question:

(a) Discuss the connectivity of node A in both graphs.

(b) Which directed path in Graph 1 has the highest number of edges?

(c) Take one graph and choose one node in it: list its parents, children, and ancestors.

Normal

# For data generation process and simulated probabilities in Python. Justify each step by using comments in

code lines.

1

Python 3 (384MB RAM) | Edit Run All Cells Kernel Ready | |

9/20/24, 12:55 PM Assignment 1 (ICS-214)

https://sle-collaboration.minervaproject.com/?id=213045f7-5857-4313-894d-72fd42feaac2&userId=24632&name=Abdulla+Abdelraheem+Jasem+Yousuf+Alm… 2/5

Run Code

Code Cell 2 of 5

In [ ]

Question 4 of 5

Problem 4: Being Lucky in Cards

Suppose you have a deck of 52 playing cards, and you draw 3 cards at random (without replacement).

a. The probability that all three cards drawn are of the same suit (e.g., all hearts, all spades, etc.) equals 0.0518. Verify it using the data

generation process and simulation. Explain each step.

import networkx as nx

import matplotlib.pyplot as plt

G1 = nx.DiGraph()

G1.add_edges_from([

(‘A’, ‘B’),

(‘A’, ‘C’),

(‘B’, ‘D’),

(‘C’, ‘D’),

(‘B’, ‘E’),

(‘D’, ‘E’),

(‘C’, ‘F’),

(‘E’, ‘F’)

])

G2 = nx.DiGraph()

G2.add_edges_from([

(‘A’, ‘B’),

(‘A’, ‘C’),

(‘B’, ‘D’),

(‘C’, ‘E’),

(‘D’, ‘F’),

(‘E’, ‘F’),

(‘B’, ‘E’),

(‘C’, ‘D’)

])

pos1 = nx.spring_layout(G1, seed=42)

pos2 = nx.spring_layout(G2, seed=42)

plt.figure(figsize=(12, 6))

plt.subplot(1, 2, 1)

nx.draw(G1, pos1, with_labels=True, node_color=’lightblue’, node_size=1000, font_size=12,

font_weight=’bold’, arrows=True)

plt.title(‘Graph 1′)

plt.subplot(1, 2, 2)

nx.draw(G2, pos2, with_labels=True, node_color=’lightcoral’, node_size=1000, font_size=12,

font_weight=’bold’, arrows=True)

plt.title(‘Graph 2’)

plt.show()

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

Python 3 (384MB RAM) | Edit Run All Cells Kernel Ready | |

9/20/24, 12:55 PM Assignment 1 (ICS-214)

https://sle-collaboration.minervaproject.com/?id=213045f7-5857-4313-894d-72fd42feaac2&userId=24632&name=Abdulla+Abdelraheem+Jasem+Yousuf+Alm… 3/5

Drop or upload a file here

Run Code

Run Code

Run Code

b. Suppose you draw 5 cards at random (without replacement). What is the probability that you will draw a full house OR four of a

kind?

Reminder: A full house means 3 of one value card and 2 of another value card (for example, three kings and two 8s); four of a kind

means 4 cards of the same value.

Normal

Question 5 of 5

You may submit one PDF with solutions for all problems not answered in the text boxes in the workbook.

Code Cell 3 of 5

In [ ]

Code Cell 4 of 5

In [ ]

Code Cell 5 of 5

In [ ]

# In case you want to do anything with python code

# In case you want to do anything with python code

# In case you want to do anything with python code

1

1

1

Python 3 (384MB RAM) | Edit Run All Cells Kernel Ready | |

9/20/24, 12:55 PM Assignment 1 (ICS-214)

https://sle-collaboration.minervaproject.com/?id=213045f7-5857-4313-894d-72fd42feaac2&userId=24632&name=Abdulla+Abdelraheem+Jasem+Yousuf+Alm… 4/5

Python 3 (384MB RAM) | Edit Run All Cells Kernel Ready | |

9/20/24, 12:55 PM Assignment 1 (ICS-214)

https://sle-collaboration.minervaproject.com/?id=213045f7-5857-4313-894d-72fd42feaac2&userId=24632&name=Abdulla+Abdelraheem+Jasem+Yousuf+Alm… 5/5