Petrobangla Assistant Manager (IT) Exam 16 September 2022 — Question Solution | পেট্রোবাংলা সহকারী ব্যবস্থাপক (আইটি) নিয়োগ পরীক্ষা ২০২২ — প্রশ্ন সমাধান
- Petrobangla
- Assistant Manager (IT)
- 16 September 2022
- 6 questions · 0 MCQ, 6 written
Page updated
ARBS Academy · itjobs.arbsacademy.com
About this exam paper · প্রশ্নপত্র পরিচিতি
The Petrobangla Assistant Manager (IT) exam was held on 16 September 2022, conducted by BUET. The paper had 6 written questions. The subjects asked most were Algorithms (3), Digital Logic (1) and Networking (1). This page lists every question, with 2 answered and explained; the rest of the answers open with a free ARBS Academy account, where the paper can also be practised as a timed test.
পেট্রোবাংলা সহকারী ব্যবস্থাপক (আইটি) নিয়োগ পরীক্ষার (২০২২) এই প্রশ্নপত্রে ৬টি প্রশ্ন ছিল, বেশিরভাগ অ্যালগরিদম ও ডিজিটাল লজিক থেকে। এখানে ২টি প্রশ্নের ব্যাখ্যাসহ উত্তর দেওয়া আছে; বাকিগুলো ফ্রি অ্যাকাউন্টে খোলে।
- Organisation
- Petrobangla
- Post
- Assistant Manager (IT)
- Exam date
- 16 September 2022
- Conducted by
- BUET
- Questions
- 6 (0 MCQ, 6 written)
- Exam guide
- Government IT officer posts · সরকারি প্রতিষ্ঠানের আইটি পদ
Write a C/C++ program for binary search.
Given IP: 168.20.96.63, Subnet mask: 255.255.192.0 Find network address, broadcast address and number of host.
Sign up free to see the model answers to written questions 1–2 · উত্তর দেখতে বিনামূল্যে সাইন আপ করুন
What is black box testing? Consider a program which computes the square root of an input integer between 0 and 5000. Determine the equivalence class test cases. Determine the test cases using boundary value analysis also.
Model answer
Black-box testing
Black-box testing is a testing method in which test cases are designed only from the requirements or specification. The tester gives inputs and compares the actual output with the expected output, without knowing (or using) the program's internal code, logic or paths. It is also called behavioural or specification-based testing.
It is good at finding missing or incorrect functions, interface errors, wrong handling of invalid input and errors at the edges of input ranges. Its main techniques are equivalence class partitioning (ECP), boundary value analysis (BVA), decision tables and state-transition testing.
flowchart LR
Spec["Specification"] --> Exp["Expected output"]
In["Test input"] --> SUT["Program under test (code hidden)"] --> Act["Actual output"]
Exp --> Cmp{"Actual = expected?"}
Act --> Cmp
Cmp -->|"yes"| P["Pass"]
Cmp -->|"no"| F["Fail: defect"]
Equivalence class test cases
The specification says the input is an integer n with 0 ≤ n ≤ 5000 and the output is √n. Every value inside one class should be treated the same way by the program, so one representative per class is enough.
| Class | Condition | Type | Test input | Expected output |
|---|---|---|---|---|
| E1 | n < 0 | Invalid | −25 | Error: "input out of range" |
| E2 | 0 ≤ n ≤ 5000 | Valid | 1600 | 40 |
| E3 | n > 5000 | Invalid | 7200 | Error: "input out of range" |
ECP test suite = {−25, 1600, 7200} (3 test cases). If the program also reads raw keyboard input, a fourth invalid class, non-integer input such as 12.5 or "abc", adds one more case.
Boundary value analysis test cases
Errors cluster at the edges of classes, so BVA tests on, just below and just above each boundary (0 and 5000), plus one nominal value.
| Test case | Input | Position | Expected output |
|---|---|---|---|
| B1 | −1 | just below minimum | Error |
| B2 | 0 | minimum | 0 |
| B3 | 1 | just above minimum | 1 |
| B4 | 2500 | nominal | 50 |
| B5 | 4999 | just below maximum | ≈ 70.7036 |
| B6 | 5000 | maximum | ≈ 70.7107 |
| B7 | 5001 | just above maximum | Error |
- Normal BVA (valid values only, 4n + 1 rule with n = 1 input): {0, 1, 2500, 4999, 5000} = 5 cases.
- Robust BVA (adds the invalid neighbours, 6n + 1 rule): all 7 cases above.
- The four values sitting exactly on the class edges are {−1, 0, 5000, 5001}.
Exam tip: ECP picks one value from each valid and invalid class; BVA picks values on and either side of every boundary. Always write the expected output beside each test input.
How to find single source shortest path from negative weighted cycle. Justify and how you find it is negative weighted graph.
Model answer
Answer: use the Bellman–Ford algorithm. It finds single-source shortest paths when some edge weights are negative, and it also detects a negative-weight cycle reachable from the source. Dijkstra's algorithm cannot be used, because it finalises a vertex once and never corrects it, which a later negative edge can make wrong.
Algorithm (V vertices, E edges, source s)
- dist[s] = 0, dist[v] = ∞ for every other v; pred[v] = none.
- Repeat V − 1 times: for every edge (u, v, w), relax it: if dist[u] + w < dist[v], set dist[v] = dist[u] + w and pred[v] = u.
- Check pass (the V-th pass): if any edge (u, v, w) still satisfies dist[u] + w < dist[v], report "negative-weight cycle reachable from s"; otherwise dist[] holds the shortest distances and pred[] gives the paths.
Time O(V·E), space O(V).
Justification
- Why V − 1 passes are enough. If no negative cycle is reachable, every shortest path can be taken simple (removing a cycle of weight ≥ 0 never makes a path longer), so it has at most V − 1 edges. By induction, after pass i every vertex whose shortest path uses ≤ i edges has its correct distance, because the edges of that path are relaxed in order across passes 1, 2, …, i. dist[v] is always the length of some real path, so it never drops below the true distance. Hence after V − 1 passes all distances are final.
- Why the V-th pass detects a negative cycle. If the distances are final, no edge can relax. Conversely, suppose a cycle v₀ → v₁ → … → vₖ = v₀ is reachable and no edge on it relaxes: dist[vᵢ] ≤ dist[vᵢ₋₁] + w(vᵢ₋₁, vᵢ) for each i. Adding these k inequalities, the dist terms cancel and 0 ≤ total cycle weight. So if the cycle is negative, at least one edge must still relax.
- With a reachable negative cycle there is no shortest path to any vertex reachable from the cycle: going round it again lowers the cost without limit (distance −∞).
How we find that the graph is negative-weighted: a negative edge is seen by checking w < 0 while reading the edges; a negative cycle is found by step 3. To print the cycle, take the vertex whose distance dropped in the check pass, follow pred[] V times (this lands on the cycle), then follow pred[] until the same vertex returns.
Example (directed; Graph 1 = solid edges, Graph 2 = Graph 1 plus the dashed edge D → B = −4)
graph LR
S((S)) -->|"6"| A((A))
S -->|"4"| B((B))
B -->|"-3"| A
A -->|"-2"| C((C))
B -->|"5"| D((D))
C -->|"3"| D
D -.->|"-4"| B
Edges are relaxed in the order A→C, B→D, C→D, B→A, S→A, S→B (then D→B in Graph 2). dist after each pass, in the order S, A, B, C, D:
| Pass | Graph 1 | Graph 2 |
|---|---|---|
| 1 | 0, 6, 4, ∞, ∞ | 0, 6, 4, ∞, ∞ |
| 2 | 0, 1, 4, 4, 7 | 0, 1, 3, 4, 7 |
| 3 | 0, 1, 4, −1, 2 | 0, 0, −2, −1, 2 |
| 4 (= V − 1) | 0, 1, 4, −1, 2 | 0, −5, −3, −2, 1 |
| Check pass | no edge relaxes → distances final | A→C and B→A still relax → negative cycle |
Graph 1 shortest paths: S→B→A = 1, S→B = 4, S→B→A→C = −1, S→B→A→C→D = 2. In Graph 2 the cycle B → A → C → D → B has weight −3 − 2 + 3 − 4 = −6 < 0.
C implementation
#include <stdio.h>
#include <limits.h>
#define INF INT_MAX
typedef struct { int u, v, w; } Edge;
/* Bellman-Ford from src. Returns -1 if no negative cycle is reachable,
otherwise a vertex that lies on a negative cycle. */
int bellmanFord(int V, int E, const Edge e[], int src, int dist[], int pred[])
{
for (int i = 0; i < V; i++) { dist[i] = INF; pred[i] = -1; }
dist[src] = 0;
for (int pass = 1; pass <= V - 1; pass++) /* V-1 rounds of relaxation */
for (int j = 0; j < E; j++)
if (dist[e[j].u] != INF && dist[e[j].u] + e[j].w < dist[e[j].v]) {
dist[e[j].v] = dist[e[j].u] + e[j].w;
pred[e[j].v] = e[j].u;
}
for (int j = 0; j < E; j++) /* V-th round: check only */
if (dist[e[j].u] != INF && dist[e[j].u] + e[j].w < dist[e[j].v]) {
int x = e[j].v;
pred[x] = e[j].u;
for (int i = 0; i < V; i++) x = pred[x]; /* walk back onto the cycle */
return x;
}
return -1;
}
void run(const char *title, int V, int E, const Edge e[], const char *name)
{
int dist[10], pred[10];
int c = bellmanFord(V, E, e, 0, dist, pred);
printf("%s\n", title);
if (c == -1) {
for (int i = 0; i < V; i++) printf(" dist[%c] = %d\n", name[i], dist[i]);
} else {
int cyc[10], k = 0, x = c;
do { cyc[k++] = x; x = pred[x]; } while (x != c);
printf(" Negative cycle: ");
for (int i = k - 1; i >= 0; i--) printf("%c -> ", name[cyc[i]]);
printf("%c\n", name[cyc[k - 1]]);
}
}
int main(void)
{
const char *name = "SABCD"; /* S=0, A=1, B=2, C=3, D=4 */
Edge g[] = { {1,3,-2}, {2,4,5}, {3,4,3}, {2,1,-3}, {0,1,6}, {0,2,4} };
run("Graph 1 (negative edges, no negative cycle):", 5, 6, g, name);
Edge h[] = { {1,3,-2}, {2,4,5}, {3,4,3}, {2,1,-3}, {0,1,6}, {0,2,4}, {4,2,-4} };
run("Graph 2 (Graph 1 plus edge D->B = -4):", 5, 7, h, name);
return 0;
}
Output
Graph 1 (negative edges, no negative cycle):
dist[S] = 0
dist[A] = 1
dist[B] = 4
dist[C] = -1
dist[D] = 2
Graph 2 (Graph 1 plus edge D->B = -4):
Negative cycle: C -> D -> B -> A -> C
Exam tip: "negative edges" → Bellman–Ford with V − 1 relaxation passes; "is there a negative cycle?" → one extra pass, and any further relaxation proves a reachable negative cycle (then shortest paths through it are undefined).
Draw an ADC converter circuit which convert an analog signal to digital signal.
Recurrence equation of binary search and solve it.
Sign up free to see the model answers to written questions 5–6 · উত্তর দেখতে বিনামূল্যে সাইন আপ করুন
Explanations © ARBS Academy
Keep going with a free account · ফ্রি অ্যাকাউন্টে যা যা করতে পারবেন
4 more answers from this paper open with a free account.
এই প্রশ্নপত্রের আরও ৪টি উত্তর, ধাপে ধাপে ব্যাখ্যাসহ, ফ্রি অ্যাকাউন্টে খুলবে।
Free account · 1 day of Premium free
Paper analysis · প্রশ্নপত্র বিশ্লেষণ
Its questions come from 5 syllabus chapters; the biggest is Searching, in Algorithms, with 2 questions. Searching is asked in 39 other papers too (2016–2026).
Its biggest topics · প্রধান টপিক
Questions in this paper, and how many of our other papers ask the topic
- Searching Algorithms · 39 other papers, 2016–20262
- IP Addressing & Subnetting Networking · 133 other papers, 2012–20261
- Testing & Quality Software Engineering · 52 other papers, 2016–20261
- Graph Algorithms Algorithms · 18 other papers, 2018–20251
- Sequential Circuits Digital Logic · 13 other papers, 2018–20251
From our own past papers: each question filed under one syllabus chapter. Practice and held questions are not counted.
Questions about this paper · সাধারণ প্রশ্ন
- How many questions were in the Petrobangla Assistant Manager (IT) exam (2022)?
- 6 written questions.
- Which subjects were asked most in the Petrobangla Assistant Manager (IT) exam (2022)?
- Algorithms (3), Digital Logic (1) and Networking (1), out of 6 questions.
- When was the Petrobangla Assistant Manager (IT) exam held?
- On 16 September 2022, conducted by BUET.
- Where can I find the Petrobangla Assistant Manager (IT) exam (2022) question solution?
- On this page: 2 of the 6 questions are shown with worked answers. The rest of the answers open with a free ARBS Academy account, where the paper can also be practised as a timed test.
Question text is from the public recruitment exam; answers and explanations are written by ARBS Academy. All past papers