CMI Data Science
    Test Series
    Verified Solutions Included
    Algebra & Number Theory, Functions & Calculus, Combinatorics & Induction… Test for CMI Data Science: 40 Questions with Solutions & Analysis

    Attempt the Algebra & Number Theory, Functions & Calculus, Combinatorics & Induction… test for CMI Data Science: 40 exam-level questions, detailed solutions a

    40 Qs

    Total Questions

    88 Marks

    Total Marks

    131.11 Mins

    Duration

    +3 / -1 / 0

    Marking Scheme

    Section-wise Paper Structure

    School Level Mathematics

    20 Qs

    50% of total marks

    Probability Theory

    9 Qs

    23% of total marks

    Discrete Mathematics

    7 Qs

    18% of total marks

    Programming

    4 Qs

    10% of total marks

    Free Solved Questions with Step-by-Step Solutions

    Authentic examination problems with detailed derivations and answer keys.

    Question 1
    2026 PYQ
    Level 3: Exam Standard

    Common Description:

    Questions (3) and (4) are based on the following information

    Let be a continuous function that satisfies

    and that . The following two questions are based on this information.

    Assuming that holds for all real , determine all values of for which is strictly increasing.

    Question 2
    2022 PYQ
    Level 3: Exam Standard
    A stick is fixed on the ground at an angle of 60 degrees as shown in Figure 1. The part of the stick which is above the ground—which is the part that is shown in Figure 1—has a length of 10 metres. At a certain time during the day, the sun is directly overhead at this location and its rays strike the ground at an angle of 90 degrees. This is shown in Figure 2. At a certain later time the sun’s rays strike the ground at an angle of 60 degrees as shown in Figure 3. While Figures 2 and 3 show only the sun’s rays for the sake of clarity, the stick is present at this location at times and .
    Stick60°GroundFigure 1Sunrays90°GroundFigure 2Sunrays60°GroundFigure 3
    What are the lengths of the shadows of the stick at times and , respectively?
    Question 3
    Level 3: Exam Standard

    Let . The tangent line to the graph of at intersects the graph at exactly one other point. What is the x-coordinate of this other point?

    Question 4
    2022 PYQ
    Level 3: Exam Standard
    Common Description: Description for the next four questions:
    Dasholytics Inc runs an online analytics dashboard. The company employs three machines—Server 1, Server 2, and Server 3—to serve the data for the dashboard. At any point in time one of these three machines has the job of serving the data, and the other two are kept in standby mode. Dasholytics uses a server scheduler (software) that decides which of the three machines should serve the data at any given point of time. The scheduler switches between data servers without disrupting the data feed to the dashboard.
    The machine which is serving the data sometimes fails to do so; in this case an alert is sent out to the Dasholytics team and they investigate and fix the problem. The time for which a machine fails to serve data is accounted as service outage caused by that machine. For technical reasons the server scheduler is deactivated when there is such an outage: the outage gets over only when the issue with the server is fixed and it is put back online.
    The figures below describe the server usage and outage statistics as compiled over the last one year (365 days). Please use this information to answer the questions that follow.
    Server 1 Server 2 Server 3 0 1 2 3 4 5 Outage Percentage (%) Fig. (a) Server 1: 40% Server 3: 30% Server 2: 30% Fig. (b)
    Figure 1: Figure (a) shows the total service outage caused by each server, as a percentage of the total time that it served data. Figure (b) shows the total time that each server served data, as a percentage of the total duration over which this information was collected. An alert that a service outage has been caused by one of the three servers was sent out to the Dasholytics team. What is the probability that this outage was caused by Server 1?
    Question 5
    2026 PYQ
    Level 3: Exam Standard

    Common Description:

    Question (6) and (7) are based on the following information

    A list is an arrangement of natural numbers in a random order, with all orderings equally likely. We say that a position is a new maximum if for all . For example, in the list

    positions 1,3,5 are new maxima. Note that position 1 is always a new maximum. Now answer the two questions below based on this information.

    What is the expected number of new maxima in a list?

    Question 6
    2022 PYQ
    Level 3: Exam Standard
    Consider the following code, in which is an integer array of length indexed from 0, and is an integer.
    function foo(A,x,n) {
        found = False;

        while(found != True) {
            i = randInt(0,n);

            if (A[i] == x) {
                found = True;
            }
        }

        return(i);
    }
    Here, randInt(0,n) returns an integer picked uniformly at random from the range .
    All integers present in array are distinct, and integer is present in array . Suppose we make the call foo(). What is the expected number of times that the call randInt(0, n) is made from within this call to foo()?
    Question 7
    2026 PYQ
    Level 3: Exam Standard

    How many binary strings of length 8 contain exactly three 1s such that no two 1s are adjacent.

    Question 8
    2023 PYQ
    Level 3: Exam Standard
    A domino is a sheet of paper with one number from printed on each half. For example, a domino has 4 printed on both halves. A domino has 0 printed on one half and 4 on the other half. The order is not important, so a domino is the same as a domino.
    A complete set of dominos is a set of dominos containing exactly one copy of each different domino.
    (a) How many dominos are there in a complete set of dominos?
    (b) In how many ways can you select 2 dominos from a complete set so that at least one of the dominos has a 0 on it and at least one of the dominos has a 9 on it.
    Question 9
    Level 3: Exam Standard

    From a group of 10 people including persons , , and , a committee of 5 is to be formed such that person must serve on the committee, and persons and cannot both serve on the committee. From the committee, a chairperson is to be chosen. The number of ways to form the committee and choose the chairperson is

    Question 10
    2024 PYQ
    Level 3: Exam Standard

    Common Description:

    Questions 4 and 5 are based on the following description.

    The following question appeared in a quiz:

    “Write the code for a function SecondBest() that takes an array and a positive integer as arguments. The elements of are all integers, and is the number of elements in . The call SecondBest() should return the second largest element in . If has no second largest element, then the function should return the special value None.”

    A student submitted the code below as the answer to this question. In the code the array is indexed from 0.

    function SecondBest(A, n) {

    if n == 1 {

    return(None);

    }

    first = A[0];

    second = A[1];

    for i from 2 to (n-1) {

    if (A[i] >= first) and (A[i] >= second) {

    second = first;

    first = A[i];

    } else {

    if A[i] >= second {

    second = A[i];

    }

    }

    }

    if first != second {

    return(second);

    } else {

    return(None);

    }

    }

    This answer turned out to be wrong; this function gives the correct answer for some valid inputs, and wrong answers for other valid inputs. Answer the next two questions about this function.

    Give one example of an input array with exactly 3 elements for which the call SecondBest(, 3) returns a wrong answer. What is this wrong answer? What is the correct answer?

    Question 11
    2025 PYQ
    Level 3: Exam Standard
    Common Description: Questions 10 and 11 are based on the following description.
    The following question appeared in a quiz:
    “Write the pseudocode for a function Closest() that takes an array , a positive integer , and an integer as arguments. The elements of are all integers less than , and is the number of elements in . The call Closest() should return an integer such that: (i) , (ii) is present in , and (iii) there is no in where holds. If has no such element , then the function should return the special value None.”
    A student submitted the code below as the answer to this question. In the code the array is indexed from 0, and MAXINT = . The call abs() returns the absolute value of integer .
    function Closest(A, n, x) { minVal = MAXINT; for i from 0 to (n-1) { absDiff = abs(x - A[i]); if (absDiff < minVal) { minVal = absDiff; y = A[i]; } } if (minVal != MAXINT) { return(y); } else { return(None); } }
    This answer turned out to be wrong; this function gives the correct answer for some valid inputs, and wrong answers for other valid inputs. Answer the next two questions about this function. What do the following function calls return?
    (a) Closest([-10,2,10], 3, 8)
    (b) Closest([0,-5,4], 3, 7)
    Question 12
    Level 3: Exam Standard

    Match the flawed post-loop check of a SecondBest algorithm in Column P with its specific behavior when executed on the provided test array in Column Q. Which of the following matchings is completely correct?

    Column P (Flawed Post-Loop Check)

    P1: if n == 1: return NULL

    P2: if A[0] == A[n-1]: return NULL

    P3: if second_largest == -\infty: return 0

    P4: if second_largest == -\infty: return n

    Column Q (Behavior on Specific Test Array)

    Q1: Fails to return NULL for , because the length condition is not met.

    Q2: Incorrectly returns NULL for , due to a structural boundary check mismatch.

    Q3: Incorrectly returns for , due to a value-domain mismatch.

    Q4: Incorrectly returns for , due to a unit mismatch (returning length instead of NULL).

    Unlock All 40 Questions in Real Examination Mode

    Practice with the authentic timer, on-screen calculator, instant percentile ranking, and section-wise analytics.

    More CMI Data Science Test Series

    Free preview ends here

    Login to view the complete test and solutions

    Creating an account is free. You get the rest of this chapter, step-by-step solutions, and a study plan built around the topics you are actually weak at.

    Why MastersUp

    Personalised first. High quality throughout.

    Most platforms hand everyone the same content. Here the content moves with your performance, topic by topic.

    Built around you, not around a syllabus PDF

    Every answer you give moves your topic-level intelligence rate. The next question, the next revision card and tomorrow's plan all change with it.

    Revision that hits your weak spots

    We only revise topics you have actually attempted and are still below the safe bar on — never the same chapter on repeat.

    Questions calibrated to the real exam

    Each question carries a measured toughness. You are served a rung above your current level, so practice keeps stretching you.

    Notes written for recall, not for volume

    Full lesson cards for first study, curated short-note cards for the last mile — with derivations, traps and exam patterns marked.

    One place for everything

    Notes, chapter practice, previous-year questions, test series and full-length papers — all feeding one picture of your preparation.

    Honest progress

    No vanity streaks. Progress here means chapters mastered and accuracy that held up on harder questions.

    Unlock the whole course

    Full notes and short notes, the complete question bank with worked solutions, mock tests, full-length papers, and an adaptive plan that rebuilds itself as you improve.

    Algebra & Number Theory, Functions & Calculus, Combinatorics & Induction… Test for CMI Data Science: 40 Questions with Solutions & Analysis

    Attempt the Algebra & Number Theory, Functions & Calculus, Combinatorics & Induction… test for CMI Data Science: 40 exam-level questions, detailed solutions and performance analysis. First questions free.

    Paper breakdown

    40 questions · 88 marks · 131.11 minutes. School Level Mathematics: 20 · Probability Theory: 9 · Discrete Mathematics: 7 · Programming: 4

    Free sample questions from Algebra & Number Theory, Functions & Calculus, Combinatorics & Induction…

    Question 1 · School Level Mathematics · 2026 SUB

    Common Description:

    Questions (3) and (4) are based on the following information

    Let be a continuous function that satisfies

    and that . The following two questions are based on this information.

    Assuming that holds for all real , determine all values of for which is strictly increasing.

    Correct Answer:

    none

    Step-by-Step Solution

    Insight: With granted, the problem reduces to asking when (with ) is strictly increasing, which happens exactly when .

    Exam route: Set . Positivity forces . The exponential is strictly increasing iff .

    Learning route:

    This is an exponential-type functional equation question, recognisable by with and the explicit assumption .

    Step 1: Let . The problem grants for all real .

    Step 2: Prove . From . If for some , then , contradiction. Hence for all , so .

    Step 3: Classify monotonicity of for :

    • : , so is strictly increasing.
    • : for all , constant, not strictly increasing.
    • : , so is strictly decreasing.

    Step 4: Conclude is strictly increasing if and only if .

    Wrong path: Writing . The boundary gives the constant function , which is not strictly increasing.

    Verification: . : strictly increasing. : constant, not strictly increasing. Confirmed.

    Question 2 · School Level Mathematics · 2022 MSQ
    A stick is fixed on the ground at an angle of 60 degrees as shown in Figure 1. The part of the stick which is above the ground—which is the part that is shown in Figure 1—has a length of 10 metres. At a certain time during the day, the sun is directly overhead at this location and its rays strike the ground at an angle of 90 degrees. This is shown in Figure 2. At a certain later time the sun’s rays strike the ground at an angle of 60 degrees as shown in Figure 3. While Figures 2 and 3 show only the sun’s rays for the sake of clarity, the stick is present at this location at times and .
    Stick60°GroundFigure 1Sunrays90°GroundFigure 2Sunrays60°GroundFigure 3
    What are the lengths of the shadows of the stick at times and , respectively?
    1. A.

      metres and metres

    2. B.

      metres and metres

    3. C.

      metres and metres

    4. D.

      metres and metres

    Correct Answer:

    ["C"]

    Step-by-Step Solution

    Key idea: This is a trigonometric projection question, recognisable because it involves finding shadow lengths cast by a tilted object under varying sun angles.

    Step 1: Resolve the stick's position into coordinates. Let the base of the stick be at the origin . The stick has length m and is tilted at to the ground.

    Step 2: The top of the stick has horizontal coordinate m, and vertical coordinate m.

    Step 3: At time , the sun is directly overhead (). The rays are vertical, so the shadow is simply the horizontal projection of the stick. Shadow length = m.

    Step 4: At time , the sun's rays strike the ground at . The ray passing through the top of the stick forms a right triangle with the ground. The additional horizontal distance from the top's vertical projection to the shadow tip is .

    Step 5: Calculate this additional distance: m.

    Step 6: Since the stick leans in the direction the shadow is cast, the total shadow length is the sum of the horizontal projection and the additional distance: m.

    Answer: 5 metres and 10 metres (Option C).

    Question 3 · School Level Mathematics SUB

    Let . The tangent line to the graph of at intersects the graph at exactly one other point. What is the x-coordinate of this other point?

    Correct Answer:

    4

    Step-by-Step Solution

    Key idea: The intersection of a curve and its tangent line creates a polynomial equation where the point of tangency is a repeated root. We can use Vieta's formulas (sum of roots) to find the other intersection point without fully expanding the line equation.

    Step 1: Let the tangent line be . The x-coordinates of the intersections are the roots of .

    Step 2: Write the difference polynomial: .

    Step 3: Since the line is tangent to the curve at , is a root of with multiplicity at least 2. Let the roots be . We know and .

    Step 4: By Vieta's formulas, the sum of the roots of a cubic is .

    Here, the sum of the roots is .

    Step 5: Substitute the known roots: .

    Step 6: The other intersection point has an x-coordinate of 4.

    Answer: 4

    Question 4 · Probability Theory · 2022 SUB
    Common Description: Description for the next four questions:
    Dasholytics Inc runs an online analytics dashboard. The company employs three machines—Server 1, Server 2, and Server 3—to serve the data for the dashboard. At any point in time one of these three machines has the job of serving the data, and the other two are kept in standby mode. Dasholytics uses a server scheduler (software) that decides which of the three machines should serve the data at any given point of time. The scheduler switches between data servers without disrupting the data feed to the dashboard.
    The machine which is serving the data sometimes fails to do so; in this case an alert is sent out to the Dasholytics team and they investigate and fix the problem. The time for which a machine fails to serve data is accounted as service outage caused by that machine. For technical reasons the server scheduler is deactivated when there is such an outage: the outage gets over only when the issue with the server is fixed and it is put back online.
    The figures below describe the server usage and outage statistics as compiled over the last one year (365 days). Please use this information to answer the questions that follow.
    Server 1 Server 2 Server 3 0 1 2 3 4 5 Outage Percentage (%) Fig. (a) Server 1: 40% Server 3: 30% Server 2: 30% Fig. (b)
    Figure 1: Figure (a) shows the total service outage caused by each server, as a percentage of the total time that it served data. Figure (b) shows the total time that each server served data, as a percentage of the total duration over which this information was collected. An alert that a service outage has been caused by one of the three servers was sent out to the Dasholytics team. What is the probability that this outage was caused by Server 1?
    Correct Answer:

    0.14

    Step-by-Step Solution

    Insight: Given that an outage occurred, we need the posterior probability that Server 1 caused it, which is a direct application of Bayes' theorem.

    Exam route: P(S1|O) = P(O|S1)P(S1) / P(O) = 0.004 / 0.028 = 1/7 ≈ 0.14.

    Learning route:

    1. We need P(Server 1 | Outage).
    2. By Bayes' theorem, P(S1|O) = [P(O|S1) * P(S1)] / P(O).
    3. The numerator is the joint probability calculated in P2: 0.004.
    4. The denominator is the total outage probability calculated in P4/P1: 0.028.
    5. P(S1|O) = 0.004 / 0.028 = 4/28 = 1/7 ≈ 0.1428...
    6. Rounded to 2 decimal places, this is "0.14".

    Wrong path: Answering 0.40 (the prior probability of Server 1) commits the base rate fallacy, ignoring the new evidence (the outage).

    Question 5 · Probability Theory · 2026 SUB

    Common Description:

    Question (6) and (7) are based on the following information

    A list is an arrangement of natural numbers in a random order, with all orderings equally likely. We say that a position is a new maximum if for all . For example, in the list

    positions 1,3,5 are new maxima. Note that position 1 is always a new maximum. Now answer the two questions below based on this information.

    What is the expected number of new maxima in a list?

    Correct Answer:

    none

    Step-by-Step Solution

    Insight: This is an expected value of a sum of indicators question. The total number of records is the sum of indicator variables , and linearity of expectation gives the answer directly without needing independence.

    Exam route:

    1. Define .
    2. Write .
    3. Apply linearity of expectation: .
    4. Substitute to get .

    Learning route:

    Step 1. For each position , define the indicator random variable if for all , and otherwise.

    Step 2. The total number of new maxima is .

    Step 3. By linearity of expectation, .

    Step 4. From the single-position result, .

    Step 5. Therefore, , the -th harmonic number.

    Common trap: Attempting to compute the full distribution of using Stirling numbers, or trying to evaluate covariances because the indicators seem dependent. Linearity of expectation bypasses all dependence concerns.

    Verification: For , . Enumerating all 6 permutations of : record counts are 3, 2, 2, 2, 1, 1, averaging to . Matches.

    Question 6 · Probability Theory · 2022 SUB
    Consider the following code, in which is an integer array of length indexed from 0, and is an integer.
    function foo(A,x,n) {
        found = False;

        while(found != True) {
            i = randInt(0,n);

            if (A[i] == x) {
                found = True;
            }
        }

        return(i);
    }
    Here, randInt(0,n) returns an integer picked uniformly at random from the range .
    All integers present in array are distinct, and integer is present in array . Suppose we make the call foo(). What is the expected number of times that the call randInt(0, n) is made from within this call to foo()?
    Correct Answer:

    10.00

    Step-by-Step Solution

    Insight: The algorithm performs independent uniform random sampling with replacement until the target is found, which perfectly matches the Geometric distribution.

    Exam route: Identify the success probability per trial. The expected number of trials for a geometric distribution is simply the reciprocal, .

    Learning route:

    Step 1: The array has length 10 and contains distinct integers. The target is present exactly once.

    Step 2: The function randInt(0,10) returns an integer uniformly at random from the set .

    Step 3: The probability of selecting the correct index in any single call is .

    Step 4: The while loop repeats until the correct index is found. Because randInt is called fresh each time, each call is an independent trial.

    Step 5: The number of trials until the first success follows a Geometric distribution with success probability .

    Step 6: The expected value of a Geometric distribution (counting the successful trial) is .

    Step 7: Therefore, the expected number of calls to randInt is .

    Wrong path: A student might incorrectly assume the algorithm samples without replacement (like a standard deterministic linear search), leading them to believe the expected number of calls is . This is a conceptual error, as randInt is called independently each time, meaning sampling is strictly with replacement.

    Generalization: When an algorithm repeatedly samples uniformly at random with replacement until a specific condition is met, the expected number of trials is simply the reciprocal of the probability of success in a single trial.

    Verification: If the array had length 2, the probability of guessing correctly is . The expected number of guesses is . This matches our formula.

    Answer: 10.00

    Question 7 · Discrete Mathematics · 2026 SUB

    How many binary strings of length 8 contain exactly three 1s such that no two 1s are adjacent.

    Correct Answer:

    none

    Step-by-Step Solution

    Insight: The phrase "no two 1s are adjacent" is the signature trigger for the gap method — place all 0s first, then choose gaps to insert the 1s.

    Exam route: , . Zeros . Gaps . Answer .

    Learning route:

    This is a non-adjacent selection problem expressed in binary-string language. The constraint "no two 1s are adjacent" means there must be at least one 0 between every pair of 1s. The gap method handles exactly this type of spacing restriction.

    Step 1 — Identify the parameters. The string has length and must contain exactly ones. The remaining positions are zeros.

    Step 2 — Lay down the five 0s in a row and identify every available gap. A gap exists before the first 0, between each consecutive pair of 0s, and after the last 0:

    The number of gaps is .

    Step 3 — Choose of these 6 gaps and place exactly one 1 into each chosen gap. Since every pair of gaps is separated by at least one 0, no two 1s can ever end up adjacent. This one-to-one correspondence between gap-choices and valid strings guarantees the count is exact.

    Step 4 — Compute the binomial coefficient:

    .

    Tempting wrong path: A student might ignore the adjacency constraint entirely and compute . This counts all ways to place three 1s in eight positions, including those where 1s are adjacent. The adjacency constraint eliminates 36 of these arrangements, leaving only 20 valid strings.

    Verification: We can verify by listing a few valid strings: 10101000, 01010100, 10010100. All have exactly three 1s with no two adjacent. The formula is correct.

    Question 8 · Discrete Mathematics · 2023 SUB
    A domino is a sheet of paper with one number from printed on each half. For example, a domino has 4 printed on both halves. A domino has 0 printed on one half and 4 on the other half. The order is not important, so a domino is the same as a domino.
    A complete set of dominos is a set of dominos containing exactly one copy of each different domino.
    (a) How many dominos are there in a complete set of dominos?
    (b) In how many ways can you select 2 dominos from a complete set so that at least one of the dominos has a 0 on it and at least one of the dominos has a 9 on it.
    Correct Answer:

    none

    Step-by-Step Solution

    Insight: Part (a) is the standard unordered-pairs-with-repetition model; part (b) is a collective-constraint selection cleanly solved by partitioning the dominos into a feature table or by complementary counting.

    Exam route:

    (a) symbols, unordered with repetition allowed: .

    (b) Partition into 4 cells: (0 only, size 9), (9 only, size 9), (both, size 1), (neither, size 36).

    Valid pairs: paired with any other domino () plus one from and one from (). Total = .

    Learning route:

    This is a two-phase domino question, recognisable because the problem explicitly defines dominos as unordered pairs with doubles allowed, then asks a selection question with a collective "at least one ... and at least one ..." constraint across two chosen dominos.

    Phase 1 — Counting the complete set (part a).

    The trigger words are "order is not important" and the explicit mention of doubles like . This means we need the unordered-pairs-with-repetition model from the Pair Model Checklist:

    Here symbols , so:

    Verification by splitting cases: doubles ( through ) plus non-doubles gives . Confirmed.

    Phase 2 — Selecting 2 dominos with a collective constraint (part b).

    The trigger is "at least one domino has a 0 and at least one has a 9" applied to a pair of dominos. This is a collective constraint across the pair, not on each domino individually.

    Partition the 55 dominos by whether they contain 0 and whether they contain 9:

    • : contains 0 but not 9 → → size .
    • : contains 9 but not 0 → → size .
    • : contains both 0 and 9 → → size .
    • : contains neither → dominos from → .

    Check: . ✓

    A valid pair of 2 dominos must collectively have at least one 0 and at least one 9. The only ways this happens:

    1. One domino is from (it alone supplies both 0 and 9), paired with any of the remaining dominos. This gives pairs.
    2. One domino is from (supplies the 0) and the other is from (supplies the 9). This gives pairs.

    No other combination works: lacks 9, lacks 0, lacks 9, lacks 0, lacks both.

    Total valid pairs = .

    Verification by complementary counting:

    Total pairs of 2 from 55: .

    Pairs with no 0: choose 2 from dominos without 0 (formed from , size 45) → .

    Pairs with no 9: choose 2 from dominos without 9 (formed from , size 45) → .

    Pairs with neither 0 nor 9 (double-counted above): choose 2 from (size 36) → .

    By inclusion–exclusion, invalid = .

    Valid = . ✓

    Final answers: (a) , (b) .

    Question 9 · Discrete Mathematics MSQ

    From a group of 10 people including persons , , and , a committee of 5 is to be formed such that person must serve on the committee, and persons and cannot both serve on the committee. From the committee, a chairperson is to be chosen. The number of ways to form the committee and choose the chairperson is

    1. A.

      480

    2. B.

      525

    3. C.

      560

    4. D.

      600

    Correct Answer:

    B

    Step-by-Step Solution

    Key idea: this is a multi-constraint committee question with a mandatory inclusion ( must serve) and a conditional exclusion ( and cannot both serve). Since must be on the committee, fix first, then choose the remaining 4 members from the other 9 people, subject to the - constraint. Finally, multiply by the number of chairperson choices.

    Step 1: is fixed on the committee. We need to choose 4 more members from the remaining 9 people (including and ), such that and are not both on the committee.

    Step 2: Use the complement method. Count total ways to choose 4 from 9, then subtract the invalid ways (both and are chosen).

    Total ways to choose 4 from 9: .

    Invalid ways (both and are chosen): and are fixed, so we need to choose 2 more from the remaining 7 people: .

    Step 3: Subtract to get valid committees.

    Valid committees = .

    Step 4: Choose a chairperson from the 5 committee members.

    Chairperson choices = .

    Step 5: Multiply.

    Total ways = .

    Alternative method (casework):

    • Case 1: is on the committee, is not. and are fixed. Choose 3 more from the 7 people (excluding ): .
    • Case 2: is on the committee, is not. and are fixed. Choose 3 more from the 7 people (excluding ): .
    • Case 3: Neither nor is on the committee. is fixed. Choose 4 more from the 7 people (excluding and ): .

    Total committees = .

    Total ways = .

    Common trap: students often forget to fix first and use instead of , or they forget to multiply by 5 for the chairperson at the end.

    Answer: 525

    Question 10 · Programming · 2024 SUB

    Common Description:

    Questions 4 and 5 are based on the following description.

    The following question appeared in a quiz:

    “Write the code for a function SecondBest() that takes an array and a positive integer as arguments. The elements of are all integers, and is the number of elements in . The call SecondBest() should return the second largest element in . If has no second largest element, then the function should return the special value None.”

    A student submitted the code below as the answer to this question. In the code the array is indexed from 0.

    function SecondBest(A, n) {

    if n == 1 {

    return(None);

    }

    first = A[0];

    second = A[1];

    for i from 2 to (n-1) {

    if (A[i] >= first) and (A[i] >= second) {

    second = first;

    first = A[i];

    } else {

    if A[i] >= second {

    second = A[i];

    }

    }

    }

    if first != second {

    return(second);

    } else {

    return(None);

    }

    }

    This answer turned out to be wrong; this function gives the correct answer for some valid inputs, and wrong answers for other valid inputs. Answer the next two questions about this function.

    Give one example of an input array with exactly 3 elements for which the call SecondBest(, 3) returns a wrong answer. What is this wrong answer? What is the correct answer?

    Correct Answer:

    none

    Step-by-Step Solution

    Insight: This is an algorithm tracing and counterexample construction question, recognizable because it asks for a specific input that causes a flawed function to return a wrong answer.

    Exam route: Test . Initialization sets first = 10, second = 10. Loop : . Condition (5 >= 10) and (5 >= 10) is False. Else branch: 5 >= 10 is False. Loop ends. Final check 10 != 10 is False, returning None. The correct second largest is 5.

    Learning route:

    Step 1: Identify the pattern. The function initializes first and second to and . If these are identical maximums, the final check first != second will fail.

    Step 2: Construct .

    Step 3: Initialize first = 10, second = 10.

    Step 4: Loop : . Check (5 >= 10) and (5 >= 10) False.

    Step 5: Else branch: check 5 >= 10 False. second remains 10.

    Step 6: End loop. first = 10, second = 10.

    Step 7: Final check first != second 10 != 10 is False. Returns None.

    Step 8: The distinct elements are 10 and 5. The correct second largest is 5.

    Wrong path: A student might assume the algorithm correctly updates second to 5, producing the answer 5. This breaks at Step 5, where the condition 5 >= 10 is strictly False, so second is never updated.

    Generalization: When tracing flawed code, execute it exactly as written without assuming it implements the intended logic. Initialization with the first two elements creates a duplicate hazard if they are equal.

    Question 11 · Programming · 2025 SUB
    Common Description: Questions 10 and 11 are based on the following description.
    The following question appeared in a quiz:
    “Write the pseudocode for a function Closest() that takes an array , a positive integer , and an integer as arguments. The elements of are all integers less than , and is the number of elements in . The call Closest() should return an integer such that: (i) , (ii) is present in , and (iii) there is no in where holds. If has no such element , then the function should return the special value None.”
    A student submitted the code below as the answer to this question. In the code the array is indexed from 0, and MAXINT = . The call abs() returns the absolute value of integer .
    function Closest(A, n, x) { minVal = MAXINT; for i from 0 to (n-1) { absDiff = abs(x - A[i]); if (absDiff < minVal) { minVal = absDiff; y = A[i]; } } if (minVal != MAXINT) { return(y); } else { return(None); } }
    This answer turned out to be wrong; this function gives the correct answer for some valid inputs, and wrong answers for other valid inputs. Answer the next two questions about this function. What do the following function calls return?
    (a) Closest([-10,2,10], 3, 8)
    (b) Closest([0,-5,4], 3, 7)
    Correct Answer:

    none

    Step-by-Step Solution

    Insight: This is an algorithm tracing question for a closest value search, recognizable because it asks for the return value of specific function calls. The method applies here because we must track minVal and y by computing absolute differences step-by-step.

    Exam route: For (a) , : diff 18, . diff 6, . diff 2, . Returns 10. For (b) , : diff 7, . diff 12 (no update). diff 3, . Returns 4.

    Learning route:

    Step 1: This is an algorithm tracing question. We apply the linear scan method, computing absolute differences and updating trackers strictly on <.

    Step 2: Trace (a) Closest([-10, 2, 10], 3, 8).

    • Init: minVal = MAXINT.
    • : . absDiff = . minVal = 18, .
    • : . absDiff = . minVal = 6, .
    • : . absDiff = . minVal = 2, .
    • End loop. Returns .

    Step 3: Trace (b) Closest([0, -5, 4], 3, 7).

    • Init: minVal = MAXINT.
    • : . absDiff = . minVal = 7, .
    • : . absDiff = . is False.
    • : . absDiff = . minVal = 3, .
    • End loop. Returns .

    Wrong path: A student might miscalculate the absolute difference, e.g., computing as instead of , or as instead of . This leads to incorrect minVal updates.

    Generalization: Absolute difference is always non-negative. Careful arithmetic is required when negative numbers are involved in the array.

    Question 12 · Programming MSQ

    Match the flawed post-loop check of a SecondBest algorithm in Column P with its specific behavior when executed on the provided test array in Column Q. Which of the following matchings is completely correct?

    Column P (Flawed Post-Loop Check)

    P1: if n == 1: return NULL

    P2: if A[0] == A[n-1]: return NULL

    P3: if second_largest == -\infty: return 0

    P4: if second_largest == -\infty: return n

    Column Q (Behavior on Specific Test Array)

    Q1: Fails to return NULL for , because the length condition is not met.

    Q2: Incorrectly returns NULL for , due to a structural boundary check mismatch.

    Q3: Incorrectly returns for , due to a value-domain mismatch.

    Q4: Incorrectly returns for , due to a unit mismatch (returning length instead of NULL).

    1. A.

      P1-Q1, P2-Q2, P3-Q3, P4-Q4

    2. B.

      P1-Q2, P2-Q1, P3-Q4, P4-Q3

    3. C.

      P1-Q3, P2-Q4, P3-Q1, P4-Q2

    4. D.

      P1-Q4, P2-Q3, P3-Q2, P4-Q1

    Correct Answer:

    A

    Step-by-Step Solution

    Key idea: Each flawed post-loop check uses a condition that either mismatches the semantic requirement of "no second largest" or fails to trigger on specific edge cases.

    Step 1: Analyze P1. The condition n == 1 only catches arrays of length 1. On , , so the condition is False. It fails to return NULL and incorrectly proceeds to return the sentinel . This matches Q1.

    Step 2: Analyze P2. On , and . The condition A[0] == A[n-1] is True, so it returns NULL. However, the array has a valid second largest element (3). This is a structural check that incorrectly triggers. This matches Q2.

    Step 3: Analyze P3. On , the algorithm correctly leaves second_largest as . The condition -\infty == -\infty is True, so it returns . Returning is a value-domain mismatch, as is not the designated NULL indicator. This matches Q3.

    Step 4: Analyze P4. On , second_largest is . The condition is True, so it returns , which is . This is a unit mismatch, returning the array length instead of the required NULL indicator. This matches Q4.

    Answer: The correct matching is P1-Q1, P2-Q2, P3-Q3, P4-Q4, which corresponds to Option A.

    More CMI Data Science tests