CS502-MIDTERM-SOLVED-SUBJECTIVE-PAPERS.pdf
Verified academic study resource for CS502 (Fundamentals of Algorithms) under the Computer Science at Virtual University of Pakistan. This PDF document (Midterm Solved Past Paper & Revision File) covers Mid-Term Exam Scope (Lectures 1 to 22) spanning approximately 240 pages across 4 curriculum modules, and is indexed for student examination review with instant in-browser preview and 100% free direct download.
- Course
- CS502 – Fundamentals of Algorithms
- Faculty
- Computer Science
- Format
- Type
- Midterm
- Coverage
- Mid-Term Exam Scope (Lectures 1 to 22)
- Tags
- SUBJECTIVE, SOLVED, MIDTERM
Focus on core definitions and repeated MCQs from Lectures 1–22. Remember that scoring in the First Half builds your safety buffer toward the mandatory 20% Two-Half passing rule in CS502.
What this file covers — CS502 syllabus roadmap
- Core Architecture, Syntax & Primitive Data Structures — Lectures 1 to 6 (Pages 1 to 65). 15% Objective Marks (8–10 MCQs)
- Conditional Branching, Loops & Logical Control Flow — Lectures 7 to 12 (Pages 66 to 140). 18% Exam Marks (MCQs + 2-Mark Short Questions)
- Memory Management, Pointers, Arrays & Functions — Lectures 13 to 18 (Pages 141 to 215). 22% Exam Marks (High Yield for Midterms)
- Midterm Consolidation, Strings & Algorithm Synthesis — Lectures 19 to 22 (Pages 216 to 280). Midterm Exam Culmination (Lectures 1–22 Scope)
Frequently asked questions
Where can I download CS502-MIDTERM-SOLVED-SUBJECTIVE-PAPERS.pdf for free?
You can preview and download "CS502-MIDTERM-SOLVED-SUBJECTIVE-PAPERS.pdf" (CS502 PDF, ~240 pages) directly from the MIHORA VU Study Library (https://study.mihora.tech/doc/cs502-midterm-solved-subjective-papers-pdf) with 100% free high-speed downloads and zero registration requirements.
What syllabus chapters and lectures are covered in this CS502 file?
This document covers Mid-Term Exam Scope (Lectures 1 to 22) across 4 distinct lecture units (Lectures 1 to 6, Lectures 7 to 12, Lectures 13 to 18, Lectures 19 to 22), featuring comprehensive definitions, solved objective questions, and examiner marking rubrics.
What is the passing criteria for CS502 under the VU 20% Two-Half Rule?
Under official Virtual University regulations, students must score at least 20% in the First Half (Quizzes, Assignments, GDBs, and Midterm combined) AND independently at least 20% in the Final-Term examination paper. Scoring under 20% in the final exam results in an automatic F grade regardless of earlier marks.
Are CS502 solved past papers and handouts verified for 2026 exams?
Yes. All CS502 materials on MIHORA VU—including Moaaz, Waqar Siddhu, and team archives—are reviewed against the current VU syllabus to help students prepare for 2026 Midterm, Final-Term, and online quiz examinations.
Inside this file
CS502 - Fundamental of Algorithm
Short- Question Answer
QNo.1 What is heap and what is heap order? (Mark2)
Answer:-
The heap is the section of computer memory where all the variables created or
initialized at runtime are stored. The heap order property: in a
(min) heap, for every node X, the key in the parent is smaller than or equal to the key in
X.
Ref: Handouts Page no. 40
QNo.2 Quick sort such that sort the array in to non-increasing order? (Mark2)
Answer:-
Quick sorting, an array A[1..n] of n numbers We are to reorder these elements into
increasing (or decreasing) order. More generally, A is an array of objects and we sort
them based on one of the attributes - the key value. The key value need not be a
number. It can be any object from a totally ordered domain. Totally ordered domain
means that for any two elements of the domain, x and y, either x < y, x = y or x > y.
Ref: Handouts Page no. 40
QNo.3 Draw the cost table for chain multiplication problem with initial states(Mark3)
Answer:-
(A1)(A2A3A4 . . .An)
or (A1A2)(A3A4 . . .An)
or (A1A2A3)(A4 . . .An)
......
or (A1A2A3A4 . . .An−1)(An)
Ref: Handouts Page no. 90
QNo.4 we can avoid unnecessary repetitions for recursive calls? (Mark3)
Answer:-
We can avoid these unnecessary repetitions by writing down the results of recursive
calls and looking them up again if we need them later. This process is called
memorization
Ref: Handouts Page no. 49
Worst case for edit distance algorithm? What is the simple change that can change the
worst case time ? 5 marks
Answer:-
Analysis of DP edit distance
There are (n ) entries in the matrix. Each entry E(i,j) takes (1) time to compute. The
2
total running is (n ) Recursion clearly leads to the same repetitive call pattern that we
2
saw in Fibonnaci sequence. To avoid this, we will use the DP approach. We will build the
solutionb bottom-up. We will use the base case E(0,j) to fill first row and the base case
E(I,0) to fill first column. We will fill the remaining E matrix row by row.
Ref: Handouts Page no. 14
Describe an efficient algorithm to find the median of a set of 106 integers; it is known
that there are fewer than 100 distinct integers in the set
Solution:-
Step1:Start
Step2:Find the 100 distinct numbers among 10^6 integers.
Step3:Sort the 100 distinct numbers
Step4:Count the distinct numbers
Step5: if count is odd,middle number is the median
Step6:if count is even,add the middle two numbers then divide by 2,the result is the
median Step5:End
number.
Ref: Handouts Page no. 34
What is the formula for generating Catalan numbers?
Solution
Equation (22) is a recurrence relation.
C_(n+1) = C_n * [2(2n+1)] / (n+2)
we have the values of n in one column and the values of C_n in another, then to put this
formula in Excel, on the (n+1)-th row just replace C_n and n with the appropriate cells
from the previous row.
Ref: Handouts Page no. 85
What are Catalan numbers? Give the formula.
Catalan numbers form a sequence of natural numbers that occur in variouscounting
problems, often involving recursively defined objects
Formula is C(n) = 2n Cn / (n+1)
Ref: Handouts Page no. 85
Q-Write a pseudo code Fibonacci With memorization? -- (3)
Sol
MEMOFIB(n)
1 if (n < 2)
2 then return n
3 if (F[n] is undefined)
4 then F*n+ MEMOFIB(n − 1) + MEMOFIB(n − 2)
5 return F[n]
Ref: Handouts Page no. 12, 74
Q – Write Down the steps of Dynamic programming (5)
Dynamic programming is essentially recursion without repetition. Developing a dynamic
programming
algorithm generally involves two separate steps:
Formulate problem recursively. Write down a formula for the whole problem
as a simple
combination of answers to smaller sub problems.
Build solution to recurrence from bottom up. Write an algorithm that starts
with base cases and works its way up to the final solution.
Dynamic programming algorithms need to store the results of intermediate sub
problems. This is often but not always done with some kind of table. We will now cover
a number of examples of problems in which the solution is based on dynamic
programming strategy.
Ref: Handouts Page no. 74 – 77
How we build heap
We build a max heap out of the given array of numbers A[1..n]. We repeatedly extract
the maximum item from the heap. Once the max item is removed, we are left with a
hole at the root.
Ref: Handouts Page no. 41
Write Pseudo code for KNAPSACK algorithm? 5 marks
Solution:
KNAPSACK (n, W)
1 for w=0,W
2 do V[0,w]0
3 for i=0,n
4 do V[i,0]0
5 for w=0,W
6 do if(wi w& vi +V[i-1,w- wi ]>V[i-1,w])
7 then V[I,w] vi +V[i-1,w]
8 else V[i,w]V[i-1,w]
The time complexity is clearly O(n,W), it must be cautioned that as n and W get large,
both time and space complexity become significant.
Ref: Handouts Page no. 96
Spelling correction in edit distance? 3 marks
A better way to display this editing process is to place the words above the other:
S D I M D M
MA - T H S
A - R T - S
THE FIRST WORD HAS AGAP FOR EVERY INSERTION (1)AND THE SECOND WORD HAS A
GAP FOR EVERY DELETION (D). MATHES (M) DO NOT COUNT. THE EDIT TRANSCRIPT IS
DEFINED AS A STRING OVER THE ALPHABETM,S,I,d THAT DESCRIBES A
TRANSFORMATION OF ONE STRING INTO OTHER. FOR EXAMPLE
SDIMDM
1+1+1+0+1+0+=4
Ref: Handouts Page no. 77
Differentiate b/w Bubble sort, insertion sort and selection sort? 3 marks
SOLUTION:
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. Create 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
in A*i….n+ swap it with A*i+.
Ref: Handouts Page no. 54
Write down the steps of dynamic programming strategy. (2 marks)
Solution:More CS502 files
- CS502 MIDTERM FILE 1 SOLVED BY TEAM HADI-1.pdf (PDF · Midterm)
- CS502 MIDTERM FILE 1 SOLVED BY TEAM HADI.pdf (PDF · Midterm)
- CS502 MIDTERM FILE 1 SOLVED BY TEAM HADI.pdf (PDF · Midterm)
- CS502 MIDTERM FILE 1 SOLVED BY TEAM HADI.pdf (PDF · Midterm)
- CS502 MIDTERM FILE 10 SOLVED BY TEAM HADI.pdf (PDF · Midterm)
- CS502 MIDTERM FILE 2 SOLVED BY TEAM HADI-1.pdf (PDF · Midterm)
- CS502 MIDTERM FILE 2 SOLVED BY TEAM HADI.pdf (PDF · Midterm)
- CS502 MIDTERM FILE 2 SOLVED BY TEAM HADI.pdf (PDF · Midterm)