Assignment 4

Deadline 15/10/2023 23:59

Important Notice

• File name: assignment_4.py

Q1

• Imaging that you have n cards, which will be stored as a string s. each of the card have an upper case letter on it. Return the number of possible non-empty sequences of letters you can make using the cards.
Runtime: 5s
Test case:
• 1 ≤ n ≤ 15
Input: string

Output: integer

Q1 (Cont’)

• Example 1:
Input: ‘XXY’
Output: 8
Analysis: you can make ‘X’, ‘Y’, ‘XY’, ‘YX’,

‘XX’, ‘XXY’, ‘XYX’, ‘YXX’

Q1 (Cont’)

• Example 2:
Input: ‘M’
Output: 1
Analysis: The only possibility is ‘M’.Q2
• You are given a directed acyclic graph (graph with no loop), the nodes named from 0 to n-1, return a set that contains all the paths from source src to destination dest.
Runtime: 5s
Test case:
• 2 ≤ n ≤ 20
Input: list of list, integer, integer
Output: set of tuples (no need to follow the order)Q2 (Cont’)
• Example 1:
Input: [[1, 2], [3], [3], []], 0, 3
Output: {(0, 1, 3), (0, 2, 3)}

Q2 (Cont’)
• Example 2:
Input: [[1, 3, 4], [2, 4], [3, 4], [4], []], 1, 4
Output: {(1, 4), (1, 2, 4), (1, 2, 3, 4)}
Q2 (Cont’)
• Example 3:
Input: [[], []], 0, 1
Output: {}
Analysis: Graph with no edges.