Dhaka Mass Transit Company Limited (DMTCL) Assistant Engineer (ICT) Exam: 27.01.2023প্রশ্ন ও সমাধান
- Set by
- DMTCL
- Post
- Assistant Engineer (ICT)
- Exam date
- 27 Jan 2023
- Questions
- 9 (0 MCQ, 9 written)
- Exam guide
- Government IT officer posts · সরকারি প্রতিষ্ঠানের আইটি পদ
- Networking · নেটওয়ার্কিং 2
- Algorithms · অ্যালগরিদম 1
- Cloud & Emerging Tech · ক্লাউড ও উদীয়মান প্রযুক্তি 1
- Cyber Security · সাইবার নিরাপত্তা 1
- Data Structures · ডেটা স্ট্রাকচার 1
- Database · ডেটাবেজ 1
- Operating Systems · অপারেটিং সিস্টেম 1
- Programming · প্রোগ্রামিং 1
What is Dynamic programming? Explain with example.
Model answer
Direct answer: dynamic programming (DP) solves a problem by breaking it into overlapping subproblems, solving each only once, and storing (memoizing) the result for reuse — applicable whenever a problem has optimal substructure (the best overall solution is built from the best solutions to its subproblems) and overlapping subproblems (the same subproblem recurs many times in a naive recursive solution).
Why plain recursion is not enough: naive recursive Fibonacci recomputes fib(2) many times across different branches of its call tree:
graph TD
F5["fib(5)"] --> F4["fib(4)"]
F5 --> F3a["fib(3)"]
F4 --> F3b["fib(3)"]
F4 --> F2a["fib(2)"]
F3a --> F2b["fib(2)"]
F3a --> F1a["fib(1)"]
F3b --> F2c["fib(2)"]
F3b --> F1b["fib(1)"]
fib(3) and fib(2) are each recomputed from scratch multiple times — this redundant work is exactly what DP eliminates.
DP (tabulation) solution:
def fibonacci(n):
if n <= 1:
return n
table = [0] * (n + 1)
table[1] = 1
for i in range(2, n + 1):
table[i] = table[i - 1] + table[i - 2] # reuse stored results
return table[n]
Complexity comparison:
| Approach | Time | Space |
|---|---|---|
| Naive recursion | O(2^n) — exponential, massive redundant recomputation | O(n) (call stack) |
| Dynamic programming (tabulation) | O(n) — each value computed exactly once | O(n) (or O(1) keeping only the last two values) |
Two DP strategies:
- Memoization (top-down): keep the natural recursive structure, but cache each subproblem's result the first time it's computed.
- Tabulation (bottom-up): build an iterative table from the smallest subproblems upward, as shown above.
Exam takeaway: apply DP only when a problem exhibits both optimal substructure and overlapping subproblems; classic exam examples besides Fibonacci include the 0/1 Knapsack, Longest Common Subsequence, and matrix-chain multiplication, all solved by the same store-and-reuse principle.
What is firewall and why it is used?
Sign up free to see the model answer · উত্তর দেখতে বিনামূল্যে সাইন আপ করুন
SQL query for employee table. (Approximate)
Sign up free to see the model answer · উত্তর দেখতে বিনামূল্যে সাইন আপ করুন
Max heap:
Sign up free to see the model answer · উত্তর দেখতে বিনামূল্যে সাইন আপ করুন
Describe SaaS, IaaS and PaaS.
Sign up free to see the model answer · উত্তর দেখতে বিনামূল্যে সাইন আপ করুন
Write down the difference between gateway and firewall.
Sign up free to see the model answer · উত্তর দেখতে বিনামূল্যে সাইন আপ করুন
What is the purpose of VPN used in computer security?
Sign up free to see the model answer · উত্তর দেখতে বিনামূল্যে সাইন আপ করুন
Why virtual memory needed?
Sign up free to see the model answer · উত্তর দেখতে বিনামূল্যে সাইন আপ করুন
Output problem:
Sign up free to see the model answer · উত্তর দেখতে বিনামূল্যে সাইন আপ করুন
Question text is from the public recruitment exam; answers and explanations are written by ARBS Academy. All past papers · Government IT officer posts guide