BCSE204L FAT Model Question
BCSE204L FAT Model Question
Instructions:
1. The set of all real numbers that lie between an integer a and an integer b ( a and b are also included in
the set), a < b, is represented as [a, b] and is called as interval a,b. Given [a1 , b1 ], [a2 , b2 ], ...[an , bn ], design
a greedy pseudocode to identify the maximum number of intervals (among the given n intervals ) such
that the intersection of any two intervals (among the intervals identified by you ) is always empty. Your
design component should contain all the required steps. Analyse the algorithm with all the required
steps. [10 marks]
2. Consider the 2-dimensional plane where the points are represented by a pair of integers. A line with
the end-points pi and pj is represented as l(pi , pj ). A polygon P = {p1 , p2 , ..., pm } is a set of points that
form a closed figure with the edges p1 − p2 , p2 − p3 , p3 − p4 , ..., p(m−1) − pm , pm − p1 . Edges of the polygon
can also be called as the line connecting the points. For example, the edge p1 − p2 can be called as a
line l whose end-points are p1 and p2 . A polygon is said to be a simple polygon if none of its edges
cross itself. Given a polygon P = {p1 , p2 , ..., pm }, design a pseudocode to decide whether the polygon is
a simple polygon or not. [10 marks]
3. (a) Consider the problem P : Given a positive integer N , task is to check whether the sum of the
factors of N except N equals N or not. For example, factors of 6 (other than 6) are 1,2,3. So, sum
of the factors of 6 (other than 6) is equal to 6. Identify the complexity-class (P/NP/NPC) of the
problem Q with justification. [5 marks]
(b) Consider the problem P1 : Given a set S of positive integers, does there exist two disjoint subsets
S1 , S2 of S such that the sum of the integers in S1 equals the sum of the intgers of S2 . For the input
S = {3, 4, 2, , 5}, the solution to the problem is ‘yes’ since there exist two subsets S1 = {3, 4}, S2 =
{2, 5} such that the sum of the elements of S1 equals the sum of the elements of S2 . Identify the
complexity-class (P/NP/NPC) of the problem P1 with justification. [5 marks]
4. Understand the Algorithm and answer the following questions .
f2(B):
– q = B mod 10
– If (q mod 2) == 0 then return B
– return B
– else return 0
f1(A, l, h)
– if l==h then return f2(A[l])
– m = (l+h)/2
– return f1(A, l, m) + f1(A, m+1, h)
Algorithm XXXX(A)
– n = A.length
– f1(A,1,n)
(a) Compute the output of the Algorithm when [123, 45, 52, 61] is given as an input. [2 marks]
(b) Describe the functionality of the Algorithm [2 marks]
(c) Is it possible to remove any lines in functions f1 or f2 such that the functionality of the algorithm
does not change. If so, identify the lines. [2 marks]
(d) Compute the time complexity of the algorithm [2 marks]
(e) If the algorithm returns zero for an input array L, comment on the elements of L? [2 marks]
6. Consider a grid of size m × n, with m rows and n columns. Every cell is referred with a pair [i, j] which
conveys that the cell is at the intersection of the ith row and the j th column. You have to fill the cells
of the grid with the numbers from the set A = {1, 2, ...9}. Given an m × n grid, design a pseudocode to
fill the cells with the elements of A such that no row contains more than two even numbers, no column
contains more than two odd numbers and the diagonal contains no two same numbers. Your pseudocode
should return m × n array, R such that R[i, j] = x if the cell [i, j] contains the number x. [15 marks]
7. Given a graph G = (V, E, s, c, t), where V is the set of vertices, E is the set of edges, s ∈ V is a vertex
designated as a source vertex, c is the set of capacities of all the edges of G, t is a vertex designated
as the target vertex. Let |f | denote the maximum flow of the network G with s as the source vertex
and t as the target vertex. Given the graph G = (V, E, s, c, t), design a pseudocode to identify the
edges (u, v) for which [c[(u, v)] − f [(u, v)]] ̸= 0, when the flow across the network is |f |. For the purpose
of the illustration, you have to take a graph with a minimum of six vertices and a minimum of eight
edges. Your design component should contain all the required steps. Analyze the pseudocode with all
the required steps. [15 marks]
8. A string is said to be symmetrical if both halves of the string are the same. For example strings aa, abab,
abaaba are a symmetrical string of length 2,4, and 6 respectively. Given a string S, develop an algorithm
to determine the longest symmetrical substring of S. For example, given a string S1 = aababaacabacab,
the longest symmetrical substring is acabacab which starts at index 7. [15 marks]
⇐⇒ ⇐⇒ ⇐⇒