CS502 – Fundamentals of Algorithms: Midterm Important Subjective (39 Solved Q&As)

Computer Science • Read every solved subjective question with its model answer directly on this page. Free, no login required.

All 664 Midterm Packs · CS502 Course Page · CS502 MCQ Pack (239 MCQs)

  1. Whether each of the following sorting algorithms is stable and in-place or not? Fill the table: Merge Sort, Heapsort, Quicksort, Counting Sort, Bubble Sort — Stable (Yes/No), In-Place (Yes/No). (Marks: 5)
    Topic: Sorting Algorithms: Identification, Stability & Decision Trees

    Merge Sort — Stable: Yes; In-Place: No. Merge sort preserves the relative order of equal elements (when merging, the element from the left half is taken first on a tie), but it needs an auxiliary array of size Θ(n) for merging, so it is not in-place. Heapsort — Stable: No; In-Place: Yes. Heap operations (extract-max and heapify) swap elements over long distances, which can change the relative order of equal keys; it sorts within the array itself using only O(1) extra space. Quicksort — Stable: No; In-Place: Yes. Partitioning swaps elements across the pivot, so equal elements may be reordered; it needs no extra array (only O(log n) stack space for recursion on average). Counting Sort — Stable: Yes; In-Place: No. It is made stable by placing elements into the output array from right to left using the cumulative counts, but it requires a separate output array and a count array, so it is not in-place. Bubble Sort — Stable: Yes; In-Place: Yes. Adjacent elements are swapped only when they are strictly out of order, so equal elements never cross each other, and sorting happens inside the same array.

  2. What will be the sorting techniques by analyzing the followings? (i) Whenever two consecutive items are found in an array that is out of order, swap them. (ii) Assume that A[1...i-1] have already been sorted. Add A[i] into its proper position in this sub array. Create this position by shifting all larger elements to the right. (iii) Assume that A[1...i-1] contain the i-1 smallest elements in sorted order. Find the smallest element in A[i...n]. Swap it with A[i]. (Marks: 3)
    Topic: Sorting Algorithms: Identification, Stability & Decision Trees

    (i) Bubble Sort — it works by repeatedly comparing each pair of adjacent (consecutive) items and swapping them if they are out of order, so the largest unsorted element 'bubbles up' to its correct position in every pass. (ii) Insertion Sort — the array is divided into a sorted part A[1...i-1] and an unsorted part; the next element A[i] is inserted into its proper position in the sorted part by shifting all larger elements one position to the right. (iii) Selection Sort — in each step the smallest element is selected from the unsorted part A[i...n] and swapped with A[i], so after i-1 steps A[1...i-1] hold the i-1 smallest elements in sorted order.

  3. Consider sorting three numbers a1, a2 and a3 with comparison-based sorting algorithms, then how many combinations are possible? Write the possible combinations. (Marks: 2–3 (2 marks in File 2, 3 marks in File 3))
    Topic: Sorting Algorithms: Identification, Stability & Decision Trees

    There are 3! = 6 possible combinations (permutations) of the three numbers: 1) a1 a2 a3 2) a1 a3 a2 3) a2 a1 a3 4) a2 a3 a1 5) a3 a1 a2 6) a3 a2 a1 A comparison-based sorting algorithm must be able to distinguish all 6 possible orderings of the input, so its decision tree must have at least 6 leaves. Therefore at least ceil(log2 6) = 3 comparisons are necessary in the worst case to sort three numbers.

  4. What is the essential constraint for the Counting Sort? (Marks: 2)
    Topic: Counting Sort & Linear-Time Sorting

    The essential constraint is that the values to be sorted must be integers (or keys that can be mapped to integers) lying in a known, limited range, say 0 to k, where k is not much larger than the number of elements n. Counting sort counts the occurrences of each value, so it needs an auxiliary count array of size k+1; if the range k is very large compared with n, the Θ(n + k) time and Θ(k) space make it impractical. When k = O(n), it runs in linear time Θ(n).

  5. What is the idea behind counting sort algorithm, to sort the elements without comparisons in linear time? (Marks: 2)
    Topic: Counting Sort & Linear-Time Sorting

    The basic idea is to sort by counting rather than by comparing elements. For each input element we count how many elements are equal to it (frequency count), and then compute the cumulative (prefix) sums of these counts, which directly give the exact position of each element in the sorted output. Each element is then placed into its computed position in an output array. Because positions are calculated arithmetically from the counts — no key comparisons are ever made — the comparison-sort lower bound of Ω(n log n) does not apply, and the algorithm runs in Θ(n + k) time, i.e. linear time when k = O(n).

  6. Solve it: T(n) = (1/2) * Σ (q = 1 to 2) of [ T(q - 1) + T(2 - q) + 2 ] (Marks: 3)
    Topic: Recurrences, Catalan Numbers & Complexity Analysis

    This is the average-case recurrence of quicksort written for n = 2. Expanding the summation: q = 1: T(0) + T(1) + 2 q = 2: T(1) + T(0) + 2 T(2) = (1/2) [ (T(0) + T(1) + 2) + (T(1) + T(0) + 2) ] = (1/2) [ 2T(0) + 2T(1) + 4 ] = T(0) + T(1) + 2. Using the base cases T(0) = 0 and T(1) = 0 (an array of size 0 or 1 is already sorted and needs no comparisons): T(2) = 0 + 0 + 2 = 2.

  7. The following summation form represents quick sort, so what will be the outcome after solving this recurrence in terms of asymptotic notation? Σ (i = 1 to n+1) of i = (n + 1)(n + 2) / 2 (Marks: 5)
    Topic: Recurrences, Catalan Numbers & Complexity Analysis

    Expanding the closed form: (n + 1)(n + 2) / 2 = (n² + 3n + 2) / 2 = (1/2)n² + (3/2)n + 1. Keeping only the dominant (highest-order) term and dropping constants, the result is Θ(n²). This summation comes from the worst case of quicksort: when the pivot is always the smallest or the largest element, the partition is maximally unbalanced (0 and n-1 elements), the partitioning costs add up as n + (n-1) + ... which is Θ(n²). Hence quicksort in the worst case runs in Θ(n²) time (its average case is Θ(n log n)).

  8. What are Catalan numbers? Give the formula to find Catalan numbers. (Marks: 3)
    Topic: Recurrences, Catalan Numbers & Complexity Analysis

    Catalan numbers form a sequence of natural numbers (1, 1, 2, 5, 14, 42, 132, ...) that counts many combinatorial structures. In this course they appear as the number of ways to fully parenthesize a product of n+1 matrices (the number of alternative ways of parenthesizing a chain in the matrix chain multiplication problem), and they also count the number of binary tree shapes with n nodes, the number of ways to triangulate a polygon, etc. Formula: C(n) = (1 / (n + 1)) * binom(2n, n) = (2n)! / ( (n + 1)! n! ) Equivalently, by the recurrence: C(0) = 1 and C(n) = Σ (i = 0 to n-1) of C(i) * C(n - 1 - i). Catalan numbers grow exponentially (roughly 4^n / n^(3/2)), which is why a brute-force search over all parenthesizations of a matrix chain is infeasible and dynamic programming is used instead.

  9. Write down the steps of dynamic programming strategy. (Marks: 5)
    Topic: Dynamic Programming: Strategy, Knapsack & Matrix Chain

    Dynamic programming is applied in four steps: 1. Characterize the structure of an optimal solution — show that the problem has optimal substructure, i.e. an optimal solution can be built from optimal solutions of its subproblems. 2. Recursively define the value of an optimal solution — write a recurrence expressing the value of the optimal solution in terms of the values of smaller subproblems. 3. Compute the value of an optimal solution in a bottom-up fashion — fill a table starting from the smallest subproblems, so that when a subproblem is solved all its (overlapping) sub-subproblems are already computed; each distinct subproblem is solved only once. 4. Construct an optimal solution from the computed information — trace back through the table (using an auxiliary choice table, where kept) to recover the actual solution, not just its value.

  10. True or False: A sequence of values in a row of the dynamic programming table for an instance of the knapsack problem is always non-decreasing. Give a brief description. (Marks: 3)
    Topic: Dynamic Programming: Strategy, Knapsack & Matrix Chain

    True. In the 0/1 knapsack table, the entry V[i, w] is the maximum value obtainable using the first i items with capacity w. Within a fixed row i, as the capacity w increases, the maximum achievable value can never decrease: any selection of items that fits in a smaller capacity also fits in a larger capacity (the extra space may simply be left unused), and a larger capacity can only add more feasible choices. Hence the values along every row of the table are non-decreasing with w.

  11. What is the time complexity of the following algorithm? KNAPSACK(n, W): for w = 0 to W do V[0, w] ← 0; for i = 0 to n do V[i, 0] ← 0; for i = 1 to n do for w = 0 to W do if (w_i ≤ w and v_i + V[i-1, w-w_i] > V[i-1, w]) then V[i, w] ← v_i + V[i-1, w-w_i] else V[i, w] ← V[i-1, w]. (Marks: 5)
    Topic: Dynamic Programming: Strategy, Knapsack & Matrix Chain

    The algorithm fills a table V with (n + 1) rows and (W + 1) columns, i.e. Θ(nW) entries in total. Filling each entry requires only a constant amount of work (one comparison and taking the maximum of two already-computed values), and the initialization loops also cost Θ(n + W). Hence the total running time is Θ(nW), and the space is also Θ(nW) for the table. Note that Θ(nW) is only pseudo-polynomial: it is polynomial in the numeric value W, but exponential in the size (number of bits, log W) needed to represent W.

  12. How we proceed with m entries in cost table for chain matrix multiplication problem? (Marks: 2)
    Topic: Dynamic Programming: Strategy, Knapsack & Matrix Chain

    The cost table m[1..n, 1..n] is filled only in its upper-triangular part (entries m[i, j] with i ≤ j), and the entries are computed diagonal by diagonal, in order of increasing chain length. First the main diagonal is set: m[i, i] = 0 (a chain of a single matrix needs no multiplication). Then chains of length 2 are computed, then length 3, and so on up to length n, using m[i, j] = min over k (i ≤ k < j) of { m[i, k] + m[k+1, j] + p(i-1) * p(k) * p(j) }. Filling in increasing-length order guarantees that the smaller subchain costs needed for an entry are already available. The final answer (minimum number of scalar multiplications) is m[1, n]; a companion table s[i, j] records the value of k at which the optimum is achieved, so that the optimal parenthesization can be reconstructed.

  13. Which one is the better approach to cope with chain matrix multiplication? (Marks: 2)
    Topic: Dynamic Programming: Strategy, Knapsack & Matrix Chain

    Dynamic programming (bottom-up tabulation) is the better approach. A plain recursive / brute-force search tries all possible parenthesizations — their number is given by the Catalan numbers and grows exponentially — and it recomputes the same overlapping subproblems again and again. Dynamic programming instead solves each of the Θ(n²) distinct subchains exactly once and stores the results in the cost table m, giving an overall Θ(n³) time and Θ(n²) space. (A top-down recursion with memoization achieves the same efficiency.)

  14. Draw the final Max-Heap structure for the following array: 50, 31, 45, 30, 2, 7, 40, 12, 28, 1. You can show the final result (tree) only. (Marks: 5)
    Topic: Heaps & Heap Sort

    First check the heap property level by level (parent ≥ children): 50 ≥ 31, 45; 31 ≥ 30, 2; 45 ≥ 7, 40; 30 ≥ 12, 28; 2 ≥ 1. Every parent is already greater than or equal to its children, so the given array already satisfies the max-heap property and build-max-heap leaves it unchanged. The final max-heap (array form: 50, 31, 45, 30, 2, 7, 40, 12, 28, 1) as a tree is: 50 / \ 31 45 / \ / \ 30 2 7 40 / \ / 12 28 1

  15. How edit distance is used for speech recognition? (Marks: 2)
    Topic: Edit Distance & Its Applications

    In speech recognition, the sound of a spoken word is first converted into a sequence of phonemes (basic sound units). To decide which word was spoken, the system computes the edit distance between this phoneme sequence and the stored phoneme sequence of every candidate word in its dictionary/vocabulary — i.e. the minimum number of insertions, deletions and substitutions needed to convert one sequence into the other. The dictionary word with the smallest edit distance is selected as the recognized word. Because a small distance tolerates minor errors in pronunciation or in the captured sounds, this makes recognition robust (the same idea is used in spell checkers).

  16. Describe three solution paths for edit distance of these two given words: 1. MATHS 2. ARTS (Marks: 5)
    Topic: Edit Distance & Its Applications

    The edit distance between MATHS and ARTS is 3. Three different optimal solution paths (each using exactly 3 operations) are: Path 1 — Delete, Substitute, Substitute: Delete M → ATHS; substitute T with R → ARHS; substitute H with T → ARTS. (1 deletion + 2 substitutions = 3 operations) Path 2 — Delete, Delete, Insert: Delete M → ATHS; delete H → ATS; insert R after A → ARTS. (2 deletions + 1 insertion = 3 operations) Path 3 — Substitute, Substitute, Delete: Substitute M with A → AATHS; substitute the second A with R → ARTHS; delete H → ARTS. (2 substitutions + 1 deletion = 3 operations) In every path the matching letters A, T (in order) and S are kept, and no solution with fewer than 3 operations exists, so the edit distance E(MATHS, ARTS) = 3.

  17. What is an algorithm? Write down the essential elements (properties) of an algorithm. (Marks: 3)
    Topic: Core Concepts: Algorithms, Analysis & Strategies

    An algorithm is a finite, step-by-step procedure (a well-defined sequence of instructions) for solving a problem, which takes some input and produces the desired output. The essential elements/properties of an algorithm are: (1) Input — it takes zero or more inputs; (2) Output — it produces at least one output; (3) Definiteness — every step is precisely and unambiguously defined; (4) Finiteness — it must terminate after a finite number of steps; (5) Effectiveness — every operation is basic enough to be carried out exactly, in finite time. An algorithm should also be general enough to solve a class of problems, not just one instance.

  18. Define the asymptotic notations Big-O, Big-Omega (Ω) and Big-Theta (Θ), and give one example of each. (Marks: 3)
    Topic: Core Concepts: Algorithms, Analysis & Strategies

    Big-O (O): an upper bound on the growth rate. f(n) = O(g(n)) if there exist constants c > 0 and n0 such that f(n) ≤ c·g(n) for all n ≥ n0. Example: 3n² + 5n = O(n²). Big-Omega (Ω): a lower bound on the growth rate. f(n) = Ω(g(n)) if there exist constants c > 0 and n0 such that f(n) ≥ c·g(n) for all n ≥ n0. Example: 3n² + 5n = Ω(n²). Big-Theta (Θ): a tight bound — both an upper and a lower bound. f(n) = Θ(g(n)) if f(n) = O(g(n)) and f(n) = Ω(g(n)). Example: 3n² + 5n = Θ(n²).

  19. What is the divide and conquer strategy? Write its steps and give examples. (Marks: 3)
    Topic: Core Concepts: Algorithms, Analysis & Strategies

    Divide and conquer is an algorithm design strategy that solves a problem in three steps: (1) Divide — break the problem into smaller subproblems of the same type; (2) Conquer — solve the subproblems recursively (a subproblem small enough is solved directly as a base case); (3) Combine — merge the solutions of the subproblems into the solution of the original problem. Examples: merge sort (combine step does the real work), quicksort (divide step — partitioning — does the real work), binary search, and Strassen's matrix multiplication.

  20. Differentiate between the greedy approach and dynamic programming. (Marks: 3)
    Topic: Core Concepts: Algorithms, Analysis & Strategies

    Greedy approach: at each step it makes the locally optimal (best-looking) choice and never reconsiders it; it does not require optimal substructure solutions to be combined from all possibilities, and it is not guaranteed to give an optimal solution for every problem (e.g. it fails on the 0/1 knapsack). It is simple and fast. Dynamic programming: it solves overlapping subproblems once, stores their results in a table, and combines optimal subproblem solutions to build the optimal solution of the whole problem (bottom-up or memoized). It always gives the optimal solution when the problem has optimal substructure and overlapping subproblems, at the cost of extra table space (e.g. matrix chain multiplication, 0/1 knapsack, edit distance).

  21. What is the sieve technique? How does it differ from divide and conquer? (Marks: 3)
    Topic: Core Concepts: Algorithms, Analysis & Strategies

    The sieve technique is a special case of divide and conquer in which we are interested in only ONE of the subproblems produced by the division, and the others are simply discarded ('sieved out') without being solved. At each step the input is partitioned into groups/subsets, a decision is made about which single subset contains the answer, and the rest are thrown away. Example: finding the k-th smallest element (selection) — after partitioning around a pivot, only the side containing the k-th element is processed further. Difference from divide and conquer: in ordinary divide and conquer ALL subproblems are solved and their solutions are combined; in the sieve technique only one subproblem is pursued and no combine step is needed, which makes it more efficient for selection-type problems.

  22. Solve the recurrence T(n) = 2T(n/2) + Θ(n), which is the recurrence of merge sort. (Marks: 3)
    Topic: Core Concepts: Algorithms, Analysis & Strategies

    Using the Master Theorem: here a = 2, b = 2 and f(n) = Θ(n). Compute n^(log_b a) = n^(log2 2) = n^1 = n. Since f(n) = Θ(n) = Θ(n^(log_b a)), Case 2 of the Master Theorem applies, giving T(n) = Θ(n log n). (The same result follows from a recursion tree: there are log2 n levels, each level costs Θ(n) in total merging work, so the total cost is Θ(n) × Θ(log n) = Θ(n log n).) Hence merge sort runs in Θ(n log n) time.

  23. Define optimal substructure and overlapping subproblems. Why are these two properties essential for dynamic programming? (Marks: 3)
    Topic: Core Concepts: Algorithms, Analysis & Strategies

    Optimal substructure: a problem has optimal substructure if an optimal solution to the problem can be constructed from optimal solutions of its subproblems (e.g. the optimal parenthesization of a matrix chain contains optimal parenthesizations of its subchains). Overlapping subproblems: the same subproblems recur many times in the recursion, so a naive recursive algorithm would solve them repeatedly (exponential work), while the total number of distinct subproblems is only polynomial. These two properties are exactly what dynamic programming exploits: optimal substructure lets us define the value recursively and combine sub-solutions, and overlapping subproblems make it worthwhile to compute each distinct subproblem once and reuse the stored result, turning an exponential recursion into a polynomial-time algorithm.

  24. What is the worst case of quicksort, when does it occur, and how can it be avoided? (Marks: 3)
    Topic: Core Concepts: Algorithms, Analysis & Strategies

    The worst case of quicksort is Θ(n²). It occurs when the pivot is always the smallest or the largest element of the subarray (for example when the first/last element is chosen as pivot and the input is already sorted or reverse sorted), so every partition is maximally unbalanced — one side has 0 elements and the other has n-1 — giving the recurrence T(n) = T(n-1) + Θ(n) = Θ(n²). It can be avoided (with high probability) by choosing the pivot randomly (randomized quicksort) or by using the median-of-three rule, which makes the expected/average running time Θ(n log n) regardless of the input order.

  25. How would you modify QUICKSORT to sort into non-increasing order? (Marks: 2)
    Topic: Sorting Algorithms: Identification, Stability & Decision Trees

    To make QUICKSORT sort in non-increasing (descending) order, we only need to modify the PARTITION procedure. In the ordinary PARTITION, elements smaller than the pivot are placed in the left sub-array and elements larger than the pivot in the right sub-array. For non-increasing order we reverse this: elements larger than the pivot are placed in the left sub-array and elements smaller than the pivot in the right sub-array (i.e., the comparisons in PARTITION are reversed). The rest of the QUICKSORT procedure remains exactly the same, and the array ends up sorted in non-increasing order.

  26. Describe bubble sort. (Marks: 2)
    Topic: Sorting Algorithms: Identification, Stability & Decision Trees

    In bubble sort, we scan the array and whenever two consecutive items are found that are out of order, we swap them. The scan is repeated again and again until all consecutive items are in order, i.e., a complete pass is made with no swaps. In each pass the largest remaining element 'bubbles up' to its correct position at the end of the array. Bubble sort is simple to implement but slow: its worst-case (and average) running time is Θ(n^2). It is in-place and stable.

  27. What is the necessary assumption for the average-case analysis of quicksort? (Marks: 2)
    Topic: Sorting Algorithms: Identification, Stability & Decision Trees

    Average-case analysis normally depends on some assumption about the distribution of inputs. In the case of quicksort, however, the analysis does not depend on the distribution of the input at all. It only depends upon the random choices of pivots that the algorithm makes. The necessary assumption is that the pivot is chosen randomly (equivalently, that all permutations of the input are equally likely), which makes the expected running time of quicksort Θ(n log n).

  28. What is sorting? Describe slow running sorting algorithms. (Marks: 5)
    Topic: Sorting Algorithms: Identification, Stability & Decision Trees

    Sorting is the process of arranging items in some sequence (in increasing or decreasing order) according to a key value. There are a number of well-known slow sorting algorithms that run in O(n^2) time in the worst case. These include: Bubble sort: Scan the array. Whenever two consecutive items are found that are out of order, swap them. Repeat until all consecutive items are in order. Insertion sort: Assume that A[1..i-1] have already been sorted. Insert A[i] into its proper position in this sub-array, creating this position by shifting all larger elements to the right. Selection sort: Assume that A[1..i-1] contain the i-1 smallest elements in sorted order. Find the smallest element in A[i..n] and swap it with A[i]. These algorithms are easy to implement, but they run in Θ(n^2) time in the worst case, so they are practical only for small inputs.

  29. Suggest how we can make improvements in the Quick Sort algorithm. (Marks: 5)
    Topic: Sorting Algorithms: Identification, Stability & Decision Trees

    Quick sort can be improved in several ways: 1. Better pivot selection: choose the pivot randomly, or use the median-of-three (first, middle and last elements), so that badly unbalanced partitions — and hence the Θ(n^2) worst case — become very unlikely. 2. Use insertion sort for small sub-arrays: when a sub-array becomes small (say fewer than 10–20 elements), insertion sort is faster in practice because of its low overhead. 3. Recurse on the smaller sub-array first and handle the larger one iteratively (tail recursion), which keeps the recursion stack depth to O(log n). 4. Use three-way partitioning (splitting the array into elements less than, equal to, and greater than the pivot) when the input contains many duplicate keys, so equal elements are not partitioned again and again.

  30. How do we heapify? (Marks: 2)
    Topic: Heaps & Heap Sort

    If an element in the heap is not at its proper place, i.e., it is violating the heap order, the HEAPIFY procedure is used to fix it and place it at its proper position. In HEAPIFY, the element is compared with its two children; if it is smaller than the larger child, it is swapped with that larger child. This step is repeated (the element sifts down) until the element becomes larger than both of its children or it reaches a leaf. Each level takes Θ(1) time for the comparison, so HEAPIFY takes O(log n) time overall.

  31. Describe the heap sort algorithm. (Marks: 3)
    Topic: Heaps & Heap Sort

    Heap sort works in two phases: 1. Build a max-heap from the unsorted array by calling HEAPIFY on all internal nodes, starting from the last parent node up to the root (BUILD-HEAP). After this step, the largest element is at the root of the heap. 2. Swap the root (the maximum element) with the last element of the heap, decrease the heap size by one, and call HEAPIFY on the new root to restore the heap property. Repeat this step until the heap contains only one element. At the end, the array is sorted in increasing order. Heap sort runs in Θ(n log n) time; it is in-place but not stable.

  32. What is a heap and what is heap order? (Marks: 2)
    Topic: Heaps & Heap Sort

    A heap is a left-complete binary tree — a binary tree in which all levels are completely filled, except possibly the last level, which is filled from left to right — that conforms to the heap order. The heap order property states that the key stored at a node is greater than or equal to the keys stored in its children (max-heap order), so the largest element is always at the root. In a min-heap, the order is reversed: the key at a node is smaller than or equal to the keys of its children.

  33. Define worst-case time and average-case time. (Marks: 2)
    Topic: Recurrences, Catalan Numbers & Complexity Analysis

    Worst-case time is the maximum running time of an algorithm over all (legal) inputs of size n. Average-case time is the average running time of an algorithm over all inputs of size n (taken over some assumed distribution of inputs).

  34. How can we avoid unnecessary repetitions for recursive calls? (Marks: 2)
    Topic: Dynamic Programming: Strategy, Knapsack & Matrix Chain

    We can avoid these unnecessary repetitions by writing down (storing) the results of recursive calls and looking them up again if we need them later, instead of computing them again. This process is called memoization. It is the key idea that turns an exponential-time recursive algorithm with overlapping sub-problems (such as the naive Fibonacci algorithm) into an efficient one.

  35. Write a pseudo code for Fibonacci with memoization. (Marks: 3)
    Topic: Dynamic Programming: Strategy, Knapsack & Matrix Chain

    MEMOFIB(n) 1. if (n < 2) then return n 2. if (F[n] is undefined) then F[n] ← MEMOFIB(n - 1) + MEMOFIB(n - 2) 3. return F[n] The array F stores each Fibonacci number the first time it is computed. When the value is needed again, it is simply looked up in the array, so every value is computed only once and the total running time becomes Θ(n).

  36. How is edit distance used in spelling correction? (Marks: 3)
    Topic: Edit Distance & Its Applications

    If a text contains a word that is not in the dictionary, a 'close' word, i.e., one with a small edit distance from the typed word, may be suggested as a correction. Most word processing applications, such as Microsoft Word, have a spelling checking and correction facility: when such an application finds an incorrectly spelled word, it searches the dictionary for words at a minimum edit distance (obtained by insertions, deletions and substitutions of characters) from the typed word and suggests them as the most likely corrections.

  37. What is the total number of entries in the matrix for edit distance? (Marks: 2)
    Topic: Edit Distance & Its Applications

    There are Θ(n^2) entries in the edit distance matrix (for two strings of length n; in general (m+1) x (n+1) entries for strings of lengths m and n). Each entry E(i, j) takes Θ(1) time to compute, so the total running time of the edit distance algorithm is Θ(n^2).

  38. Illustrate how Radix Sort works on the following words: COW, DOW, SEA, RUG, ROW, MOB, BOX, TAB, BAR, EAR, TAR, DIG, BIG, TEA, NOW, FOX. Show the result of the first 2 passes only. (Marks: 5)
    Topic: Counting Sort & Linear-Time Sorting

    Radix sort sorts the words letter by letter, starting from the least significant (last) letter, using a stable sort in each pass. Original list: COW, DOW, SEA, RUG, ROW, MOB, BOX, TAB, BAR, EAR, TAR, DIG, BIG, TEA, NOW, FOX Pass 1 (sort by the 3rd letter): SEA, TEA, MOB, TAB, RUG, DIG, BIG, BAR, EAR, TAR, COW, DOW, ROW, NOW, BOX, FOX Pass 2 (sort by the 2nd letter): TAB, BAR, EAR, TAR, SEA, TEA, DIG, BIG, MOB, COW, DOW, ROW, NOW, BOX, FOX, RUG (A third pass on the 1st letter would complete the sorting.)

  39. What is a better approach of multiplication rather than the straight form of multiplication? Name and describe it. (Marks: 3)
    Topic: Divide and Conquer

    The better approach is the divide and conquer approach to (large integer) multiplication. Each n-digit number is split into two halves: a high part and a low part of n/2 digits each. The product of the two numbers is then expressed in terms of products of these halves, which are computed recursively. The straight form of this idea needs four multiplications of half size, but with an algebraic trick only three half-size multiplications are needed, giving the recurrence T(n) = 3T(n/2) + Θ(n), whose solution is Θ(n^1.58) — clearly better than the Θ(n^2) time of the straight (grade-school) multiplication method.

MIHORA VU – Virtual University Assignment Solutions 2026, Solved Past Papers & All 455+ Courses

Official MIHORA TECH academic repository offering 28,328+ verified study documents for all 455+ Virtual University of Pakistan courses. Access VU Assignment Solution 2026 (Latest Session), Moaaz & Waqar Siddhu solved midterm & final papers, lecture handouts, and quizzes with 100% direct high-speed links.

SPRING 2026 / FALL 2026 ACTIVE SESSION

VU Assignment Solution 2026 (Latest Solved Assignments, GDBs & Quizzes)

Get high-scoring solutions for Assignment 1, Assignment 2, and Graded Discussion Boards across Computer Science, Mathematics, Management, English, and Economics. Compliant with Turnitin similarity limits (< 19%) and official 24-hour grace periods.

Open VU Assignment Solution 2026 Hub →

Popular Virtual University Courses (2026 Solved Papers & Solutions):

CS101 – Introduction to Computing CS201 – Introduction to Programming CS301 – Data Structures CS302 – Digital Logic Design CS401 – Computer Architecture & Assembly Language CS402 – Theory of Automata CS403 – Database Management Systems CS501 – Advance Computer Architecture CS502 – Fundamentals of Algorithms CS504 – Software Engineering - I CS506 – Enterprise Application Development CS601 – Data Communication CS602 – Computer Graphics CS604 – Operating Systems CS605 – Software Engineering - II CS607 – Artificial Intelligence CS610 – Computer Networks CS619 – Final Year Project MTH101 – Calculus & Analytical Geometry MTH202 – Discrete Mathematics MTH301 – Calculus II (Multivariable Calculus) MTH302 – Business Mathematics & Statistics MTH501 – Linear Algebra ENG101 – English Comprehension ENG201 – Business and Technical English Writing MGT101 – Financial Accounting MGT211 – Introduction to Business MGT301 – Principles of Marketing MGT501 – Human Resource Management ACC311 – Fundamentals of Auditing ACC501 – Business Finance STA301 – Statistics and Probability ECO401 – Economics (Micro & Macro) ISL202 – Islamic Studies / Ethics PAK301 – Pakistan Studies PHY101 – Physics - Mechanics & Waves

Complete Directory of All 455 Virtual University Courses & Codes

Browse the complete curriculum of all 455 accredited courses across 27 faculties of Virtual University of Pakistan. Every course includes verified lecture handouts, Moaaz & Waqar Siddhu solved papers, and 2026 assignment solution templates.

Accounting & Finance (16 Courses)

ACC301 – Financial Accounting ACC311 – Fundamentals of Auditing ACC501 – Business Finance BNK601 – Banking Laws & Practices BNK603 – Consumer Banking BNK604 – Commercial Banking BNK610 – Credit & Risk Management in Banking EFIN623 – Economics of Financial Markets FIN611 – Advanced Financial Accounting FIN621 – Financial Statement Analysis FIN622 – Corporate Finance FIN623 – Taxation Management FIN624 – Islamic Banking & Finance FIN625 – Credit & Risk Management FIN630 – Investment Analysis & Portfolio Management FIN722 – Advanced Corporate Finance

Bioinformatics (7 Courses)

BIF101 – Basic Bioinformatics BIF401 – Introduction to Bioinformatics BIF402 – Computational Biology Methods BIF501 – Genomics & Proteomics BIF601 – Bioinformatics Algorithms BIF602 – Structural Bioinformatics BIF604 – Systems Biology

Biological Sciences (16 Courses)

BIO101 – Basic Biology BIO102 – Introductory Biology & Diversity BIO201 – Cell Biology BIO202 – Biochemistry BIO203 – General Genetics BIO204 – Biochemical Techniques BIO301 – Molecular Biology BIO302 – Animal Physiology BIO303 – Developmental Biology BIO401 – Ecology & Evolutionary Biology BIO502 – Immunology & Pathology BIO503 – Pharmacology & Toxicology BIO504 – Applied Microbiology BIO505 – Environmental Biotechnology BIO506 – Forensic Biology BIO731 – Advanced Molecular Genetics

Virtual University of Pakistan (43 Courses)

BNK611 – Economic Ideology in Islam BT613T – Agricultural Biotechnology CS306 – Introduction to Python CS441 – Big Data Concepts CS442 – Introduction to Data Science CS620 – Modeling & Simulation CS701 – Theory of Computation CS703 – Operating Systems CS704 – Advanced Computer Architecture ECO302 – Microeconomics EDU407 – EDU407 ENG401 – Introduction to Literature: Short Story and Poetry GSC201 – Teaching of General Science MCM516 – TV News Reporting and Production MGMT611 – Human Relations MGMT629 – Crisis Management MGT201 – Financial Management MGT401 – Financial Accounting II MGT404 – MGT404 MGT504 – Organization Theory & Design MGT520 – International Business MGT522 – MGT522 MGT601 – SME Management MGT603 – Strategic Management MGT613 – Production and Operations Management MGT703 – Strategic Management MGT705 – Advanced Cost and Management Accounting MGT713 – Production / Operations Management MTH102 – Basic Algebra and Trigonometry MTH201 – Multivariable Calculus MTH304 – Mechanics MTH403 – MTH403 MTH404 – MTH404 MTH405 – MTH405 MTH621 – Real Analysis I MTH633 – Group Theory MTH642 – Fluid Mechanics MTH643 – MTH643 PAK303 – PAK303 PSC401 – Public International Law PSY409 – Positive Psychology SE601 – Software Construction & Development SE602 – Software Re—engineering

Bio-Technology (34 Courses)

BT101 – Ecology, Biodiversity & Evolution BT102 – Microbiology BT201 – Biotechnology Fundamentals BT301 – Recombinant DNA Technology BT302 – Cell and Tissue Culture BT401 – Genetic Engineering BT402 – Fermentation Technology BT403 – Agricultural Biotechnology BT404 – Medical Biotechnology BT405 – Industrial Biotechnology BT406 – Nanobiotechnology BT501 – Biochemical Engineering BT502 – Biosafety & Bioethics BT503 – Molecular Diagnostics BT504 – Stem Cell Technology BT505 – Food Biotechnology BT511 – Vaccine Technology BT512 – Drug Design & Development BT513 – Genomics & Functional Proteomics BT514 – Enzyme Technology BT601 – Advanced Genetic Engineering BT602 – Bioinformatics in Biotechnology BT603 – Bioprocess Engineering BT604 – Aquatic Biotechnology BT605 – Environmental Bioremediation BT611 – Synthetic Biology BT612 – Metabolic Engineering BT613 – Biofuels and Bioenergy BT614 – Clinical Research in Biotechnology BT693 – Research Project in Biotechnology BT732 – Advanced Molecular Biology Seminar BT734 – Advanced Cellular Biotechnology BT735 – Current Topics in Biotechnology NTBT301 – Nanotechnology in Biotechnology

Chemistry (2 Courses)

CHE201 – General Chemistry CHE301 – Organic Chemistry

Computer Science (55 Courses)

CS000 – Introduction to Computer Fundamentals CS001 – Computer Proficiency License CS101 – Introduction to Computing CS201 – Introduction to Programming CS202 – Web Design & Development CS204 – Cyber Law & Intellectual Property CS205 – Information Security Management CS206 – Ethical Hacking & Defense CS301 – Data Structures CS302 – Digital Logic Design CS304 – Object Oriented Programming CS310 – Introduction to Programming (Python) CS311 – Introduction to Web Services Development CS312 – Mobile Application Development CS314 – Embedded Systems & IoT CS315 – Web Engineering CS401 – Computer Architecture & Assembly Language CS402 – Theory of Automata CS403 – Database Management Systems CS405 – Mobile Computing CS407 – Cloud Computing Fundamentals CS408 – Human Computer Interaction CS409 – Ethical & Legal Issues in Computing CS410 – Design & Analysis of Algorithms CS411 – Visual Programming CS420 – Game Design and Development CS432 – Network Security CS435 – Cloud Computing Infrastructure CS501 – Advance Computer Architecture CS502 – Fundamentals of Algorithms CS505 – Agile Software Development CS506 – Enterprise Application Development CS507 – Information Systems CS508 – Modern Programming Languages CS510 – Compiler Construction CS511 – Distributed Systems CS521 – Data Science Principles CS601 – Data Communication CS602 – Computer Graphics CS603 – Software Architecture CS604 – Operating Systems CS606 – Compiler Design & Construction CS607 – Artificial Intelligence CS608 – Digital Signal Processing CS609 – System Programming CS610 – Computer Networks CS614 – Data Warehousing CS619 – Final Year Project CS621 – Information Retrieval Techniques CS625 – Formal Methods in Software Engineering CS627 – Computer Vision & Pattern Recognition CS636 – Big Data Analytics CS708 – Advanced Computer Graphics CS713 – Advanced Software Architecture CS718 – Advanced Artificial Intelligence

Software Engineering (4 Courses)

CS504 – Software Engineering - I CS605 – Software Engineering - II CS611 – Software Quality Assurance CS615 – Software Project Management

Statistics (18 Courses)

DSTA630 – Data Science Research Methods STA000 – Basic Statistics Fundamentals STA100 – Foundations of Statistics STA301 – Statistics and Probability STA304 – Statistical Inference STA404 – Experimental Design STA406 – Sampling Techniques STA408 – Biostatistics and Epidemiology STA630 – Research Methods in Social Sciences STA631 – Advanced Statistical Methods STA632 – Multivariate Analysis STA641 – Non-Parametric Methods STA642 – Econometric Models STA730 – Advanced Research Methodology in Statistics STAT100 – Statistics Fundamentals STAT404 – Applied Statistical Modeling STAT408 – Statistical Computing STAT730 – Advanced Biostatistics

Education (44 Courses)

ECE101 – Introduction to Early Childhood Care & Education EDU101 – Foundations of Education EDU201 – Learning Theories & Applications EDU205 – Classroom Management EDU301 – General Methods of Teaching EDU302 – Human Development & Learning EDU303 – School, Community and Teacher EDU304 – Educational Assessment & Evaluation EDU305 – Curriculum Development & Instruction EDU306 – Contemporary Trends in Education EDU401 – Critical Thinking and Reflective Practices EDU402 – Educational Leadership & Management EDU403 – Art, Craft & Calligraphy in Education EDU404 – Teaching of English EDU405 – Teaching of Mathematics EDU406 – Teaching of General Science EDU410 – ICT in Education EDU411 – Teaching of Social Studies EDU430 – Information & Communication Technology in Teaching EDU431 – Test Development & Measurement EDU433 – Educational Statistics EDU501 – Educational Psychology EDU505 – Guidance and Counseling in Schools EDU510 – Qualitative Research in Education EDU512 – Comparative Education EDU514 – Special Education Principles EDU515 – Early Childhood Education Curriculum EDU516 – Educational Technology & Media EDU601 – Philosophy of Education EDU602 – Educational Planning and Policy EDU604 – Educational Administration & Supervision EDU630 – Research Methods in Education EDU654 – Teacher Education in Pakistan EDU702 – Advanced Seminar in Educational Leadership EDU705 – Advanced Educational Policy Analysis EDUA305 – Applied Curriculum Development EDUA403 – Elementary Arts Education EDUA405 – Pedagogy of Mathematics EDUA516 – Educational Media Design EDUA630 – Action Research in Educational Settings MEDU402 – Master Level Educational Leadership MEDU406 – Science Teaching Pedagogies MEDU430 – Advanced ICT in Education MEDU601 – Advanced Philosophy of Education

Economics (11 Courses)

ECO401 – Economics (Micro & Macro) ECO402 – Microeconomics Analysis ECO403 – Macroeconomics Analysis ECO404 – Managerial Economics ECO406 – Development Economics ECO501 – Monetary Economics ECO601 – International Economics ECO603 – Public Sector Economics ECO606 – Agricultural Economics ECO607 – Environmental & Resource Economics ECO610 – Econometrics Principles

Management Sciences (26 Courses)

EMG525 – Engineering Project Management MGMT614 – Leadership & Team Building MGMT615 – Project Management Practices MGMT617 – Project Management Methodologies MGMT622 – Operations Management MGMT623 – Supply Chain Management MGMT625 – Knowledge Management Systems MGMT627 – Global Business Strategy MGMT628 – Strategic Management MGMT630 – Business Strategy & Policy MGMT631 – Innovation Management MGT101 – Financial Accounting MGT111 – Introduction to Public Administration MGT211 – Introduction to Business MGT301 – Principles of Marketing MGT402 – Cost & Management Accounting MGT411 – Money & Banking MGT501 – Human Resource Management MGT502 – Organizational Behaviour MGT503 – Principles of Management MGT510 – Total Quality Management MGT602 – Entrepreneurship MGT604 – Management of Financial Institutions MGT610 – Business Ethics & Corporate Governance MGT611 – Business & Labor Law MGTE630 – Business Management Strategy

English (34 Courses)

ENG001 – Basic English Grammar & Composition ENG101 – English Comprehension ENG201 – Business and Technical English Writing ENG301 – Business Communication ENG501 – History of English Language ENG502 – Introduction to Linguistics ENG503 – English Morphology and Syntax ENG504 – Sociolinguistics ENG505 – Phonetics & Phonology ENG506 – World Englishes ENG507 – Psycholinguistics ENG508 – Semantics & Pragmatics ENG509 – English for Specific Purposes (ESP) ENG510 – Language Testing & Evaluation ENG511 – Syllabus Design & Materials Development ENG512 – Stylistics & Literary Analysis ENG513 – Second Language Acquisition (SLA) ENG514 – Classical Poetry ENG515 – Classical Drama ENG516 – Research Methodology in Linguistics ENG517 – Modern Poetry ENG518 – Modern Drama ENG519 – Classical Novel ENG520 – Modern Novel ENG521 – American Literature ENG522 – Postcolonial Literature ENG523 – Continental Literature & Criticism ENG524 – Literary Criticism & Theory ENG525 – Discourse Analysis ENG526 – Applied Linguistics in Education ENG527 – Creative Writing & Composition ENG528 – Corpus Linguistics ENG529 – Translation Studies & Theory FENG301 – Functional English for Professionals

Islamic Studies (4 Courses)

ETH100 – Ethics (For Non-Muslim Students) ETH201 – Ethics & Moral Philosophy (For Non-Muslims) ISL201 – Islamic Studies ISL202 – Islamic Studies / Ethics

General Guides (1 Courses)

GENERAL – General University Resources, Guides & Handbooks

General Sciences (1 Courses)

GSC101 – General Science

Human Resources (4 Courses)

HRM613 – Human Resource Development HRM617 – Compensation & Benefits Management HRM624 – Conflict & Negotiation Management HRM627 – Strategic Human Resource Management

Information Technology (4 Courses)

IT430 – E-Commerce & Digital Business IT601 – Network Administration IT602 – Database Administration ITU430 – E-Commerce Systems

Microbiology (4 Courses)

MB501 – General Microbiology & Microbial Diversity MB502 – Microbial Physiology & Metabolism MB504 – Medical Microbiology MIC501 – Applied Microbiology

Mass Communication (22 Courses)

MCD401 – Media Content Development MCD403 – Media Ethics & Professional Standards MCM000 – Introduction to Communication Fundamentals MCM101 – Introduction to Mass Communication MCM301 – Communication Skills MCM304 – Mass Media in Pakistan MCM310 – Radio Broadcasting & Audio Media MCM311 – Radio & Television Production MCM401 – Fundamentals of Public Relations MCM404 – Electronic Media Content Creation MCM411 – News Writing and Reporting MCM431 – Digital Media & Online Journalism MCM501 – Development Support Communication MCM511 – Media Ethics, Cyber Laws & Regulation MCM514 – Feature, Column & Editorial Writing MCM517 – Advertising Strategy & Campaigns MCM520 – Print Media Design & Layout MCM531 – International & Cross-Cultural Communication MCM601 – Theories of Mass Communication MCM604 – Communication Research Methodology MCM610 – Cyber Journalism & Web Publishing MCMP310 – Radio & Audio Production Practical

Marketing (5 Courses)

MKT501 – Marketing Management MKT530 – Consumer Behaviour MKT610 – Customer Relationship Management (CRM) MKT621 – Advertising & Brand Management MKT630 – International Marketing Strategy

Mathematics (20 Courses)

MTH001 – Elementary Mathematics MTH100 – General Mathematics MTH101 – Calculus & Analytical Geometry MTH104 – Sets & Logic MTH202 – Discrete Mathematics MTH301 – Calculus II (Multivariable Calculus) MTH302 – Business Mathematics & Statistics MTH401 – Differential Equations MTH501 – Linear Algebra MTH601 – Operations Research MTH603 – Numerical Analysis MTH622 – Vector & Tensor Analysis MTH631 – Real Analysis MTH632 – Complex Analysis MTH634 – Topology MTH641 – Functional Analysis MTH644 – Mathematical Methods MTH645 – Mechanics MTH646 – Differential Geometry MTH647 – Fluid Mechanics

Social Studies (3 Courses)

PAK301 – Pakistan Studies PAK302 – History of Pakistan PAK522 – Ideology & Constitution of Pakistan

Physics (3 Courses)

PHY000 – Foundational Physics PHY101 – Physics - Mechanics & Waves PHY301 – Circuit Theory

Psychology (23 Courses)

PSY101 – General Psychology PSY401 – Clinical Psychology Fundamentals PSY402 – Social Psychology PSY403 – Developmental Psychology PSY404 – Abnormal Psychology PSY405 – Personality Theories & Assessment PSY406 – Educational Psychology Applications PSY407 – Experimental Psychology & Lab Methods PSY408 – Health Psychology PSY502 – History and Systems of Psychology PSY504 – Cognitive Psychology PSY505 – Psychological Testing & Measurement PSY510 – Positive Psychology & Well-being PSY511 – Counseling Psychology Principles PSY512 – Organizational & Industrial Psychology PSY513 – Neuropsychology Fundamentals PSY515 – Forensic & Criminal Psychology PSY516 – Cross-Cultural Psychology PSY610 – Neurological Basis of Behavior PSY611 – Psychopathology & Diagnostics PSY631 – Psychological Assessment Practicum PSY632 – Research Methods in Psychology PSYP631 – Psychological Assessment Lab Practical

Sociology (14 Courses)

SOC101 – Introduction to Sociology SOC201 – Pakistani Society and Culture SOC301 – Social Psychology & Society SOC302 – Cultural Anthropology SOC401 – Social Research Methods SOC402 – Classical Sociological Theories SOC403 – Social Change & Modernization SOC404 – Urban Sociology SOC601 – Rural Sociology & Community Development SOC602 – Gender Studies & Society SOC605 – Criminology & Juvenile Delinquency SOC608 – Sociology of Development SOC609 – Sociology of Health & Medicine SOC610 – Demography & Population Dynamics

Urdu Literature (2 Courses)

URD101 – Functional Urdu (Urdu Zaban-o-Adab) URDU101 – Urdu Language & Literature

Zoology (35 Courses)

ZOO101 – Principles of Animal Life I ZOO102 – Principles of Animal Life II ZOO103 – Animal Diversity: Invertebrates ZOO111 – Fundamentals of Zoology ZOO201 – Animal Diversity: Chordates ZOO202 – Animal Form & Function I ZOO203 – Animal Form & Function II ZOO301 – Animal Physiology ZOO302 – Cell & Molecular Biology in Zoology ZOO307 – Principles of Ecology ZOO401 – Evolution & Principles of Systematics ZOO403 – Animal Behavior & Sociobiology ZOO404 – Biostatistics for Zoologists ZOO405 – General Developmental Biology ZOO501 – Developmental Biology ZOO502 – Environmental Biology ZOO503 – Biostatistics in Zoological Research ZOO504 – Zoogeography & Paleontology ZOO505 – Wildlife of Pakistan & Conservation ZOO506 – Endocrinology ZOO507 – Animal Diversity & Behavior ZOO509 – Fish Biology & Fisheries Science ZOO510 – General Microbiology & Immunology ZOO511 – Immunology & Serology ZOO512 – Parasitology & Vectors ZOO513 – Applied Entomology ZOO514 – Biochemistry of Animals ZOO515 – Genetics & Population Biology ZOO516 – Aquaculture & Fisheries Management ZOO517 – Toxicology & Environmental Health ZOO518 – Comparative Vertebrate Anatomy ZOO519 – Mammalogy ZOO520 – Ornithology (Bird Biology) ZOO603 – Applied Parasitology & Vector Biology ZOO630 – Research Methodology in Zoology

Core Student Calculators & Rules Handbooks

Frequently Asked Questions – MIHORA VU Study Library

Where can I download VU Assignment Solution 2026 for CS101, CS201, MTH101, and all subjects?

MIHORA VU (https://study.mihora.tech/vu-assignment-solution-2026) offers verified 2026 assignment solutions, GDB answers, quiz files, and Dev-C++ code templates for all 455 Virtual University courses with 100% free direct downloads.

What is the 24-hour assignment grace period in Virtual University?

Virtual University gives students an automatic 24-hour grace period after the official assignment deadline. Submissions during this grace window are awarded full credit with 0 marks deduction.

How to avoid zero marks in VU assignments due to Turnitin plagiarism?

Never copy-paste solutions directly from YouTube or public groups. Keep Turnitin similarity under 19% by renaming code variables, rearranging logical statements, and writing custom explanations.

Where can I get Moaaz and Waqar Siddhu solved midterm and final past papers?

MIHORA VU hosts over 28,328 verified documents including complete Moaaz and Waqar Siddhu past paper collections for all 455 VU subjects, available via direct download without registration.

What is the 20% Two-Half passing rule in Virtual University?

Students must score at least 20% in the First Half (Quizzes, Assignments, GDBs, and Midterms) AND independently at least 20% in the Final Term exam paper to pass any course.