NivaarExam PrepOfficial exam papers ↗

25-Comp-A4 Program Design and Data Structures · December 2014

Question 2 of 9: Programming — Cost and Reliability of Every Subsystem Combination

Nivaar worked solution (AI-drafted; not reviewed by a licensed engineer)

Notes on this paper

Paper format. 98-Comp-A4 Program Design and Data Structures, December 2014 — 3 hours, closed book, no calculator permitted. Nine questions, each of equal weight (20 marks); candidates answer any six, so a complete paper is 120 marks. Pseudocode or any high-level language is accepted, and the examiner's note states explicitly that marking emphasises the operation of the program, not syntactic details. All nine questions are answered below, because the whole set is the more useful revision resource. Answers are given in C or C++ as the question dictates; each is compilable as written, but a clear, correctly reasoned pseudocode answer would earn the same marks.

Reference texts for this subject.

  • Cormen, Leiserson, Rivest & Stein, Introduction to Algorithms, 4th ed. — tree traversals (ch. 12), partitioning (ch. 7), asymptotic analysis (ch. 3).
  • Weiss, Data Structures and Algorithm Analysis in C, 2nd ed. — linked lists (ch. 3), binary search trees (ch. 4).
  • Deitel & Deitel, C++ How to Program, 10th ed. — class design and operator overloading (ch. 9–10), file streams (ch. 14).
  • Kernighan & Ritchie, The C Programming Language, 2nd ed. — character I/O idioms (ch. 1, 7), pointers and structures (ch. 5–6).
  • Stroustrup, The C++ Programming Language, 4th ed. — value semantics and const-correctness (ch. 16–18).

The Computer Engineering citation list is built around architecture and networking texts (Patterson & Hennessy, Tanenbaum, Mano); this subject is programming and data structures, so the works above are cited instead.

Question 2: Programming — Cost and Reliability of Every Subsystem Combination (20 marks)

Question text not reproduced: the examination questions are © Engineers and Geoscientists BC. Open the official past paper (linked at the top of this page) to read the question, then follow the worked solution below.

Given. Four subsystems in series, each available in two variants, with the manufacturing cost and mean time between failure of every variant, and the series MTBF relation quoted in the question.

Subsystem options
SubsystemVariantMTBF (years)Cost
brakesdisc4$15.00
drum5$25.00
enginewankle3$1,067.00
conventional6$1,850.00
suspensionair9$430.00
oil7$320.00
electricalcomputer2$130.00
standard4$40.00

Find. A program that enumerates every whole car and reports three winners: the cheapest, the one with the longest MTBF, and the one with the lowest cost per failure-free year.

brakesdisc 4 yr / 15.00drum 5 yr / 25.00enginewankle 3 yr / 1067conv. 6 yr / 1850suspensionair 9 yr / 430oil 7 yr / 320electricalcomputer 2 yr / 130standard 4 yr / 40any one subsystem failing stops the whole system → failure rates add
Reliability block diagram. The four subsystems sit in series — the question states that the failure of any subsystem dooms the whole car — so their failure rates (reciprocal MTBFs) add. Costs are in dollars, MTBF in years.

Approach. Enumerate all $2^4$ combinations with four nested loops; for each, add the four costs and the four failure rates, invert the rate sum to get the system MTBF, and track three running minima/maxima in the same pass.

  1. Recognise the structure as a series system. The question states the failure of any subsystem dooms the entire car, which is the definition of a series reliability configuration. Under the constant-hazard model this makes failure rates, not lifetimes, additive: $$\lambda_{total} = \sum_{i}\lambda_{i} = \sum_{i}\frac{1}{MTBF_{i}}$$ so the system MTBF is the harmonic-style combination the question supplies. The practical consequence is worth stating: the system is always less reliable than its worst subsystem.
  2. Count the design space. Four subsystems, two variants each, independently chosen, gives $$N = 2 \times 2 \times 2 \times 2 = 2^{4} = 16$$ whole cars — small enough that exhaustive enumeration is not merely acceptable but the correct engineering answer. No search heuristic is warranted at this size, and enumeration cannot miss the optimum.
  3. Define the three figures of merit. For a car choosing variant $v_i$ of subsystem $i$, $$C = \sum_{i} c_{i,v_i}, \qquad MTBF = \left(\sum_{i}\frac{1}{m_{i,v_i}}\right)^{-1}, \qquad R = \frac{C}{MTBF}$$ The third, $R$, is the cost per failure-free year, and note that it equals $C \times \sum_i 1/m_i$ — computing it that way avoids a needless division and any risk of dividing by zero.
  4. Enumerate with nested loops and keep three running winners. One pass suffices for all three questions; there is no need to store the sixteen rows.
    #include <stdio.h>
    
    #define NSUB 4      /* brakes, engine, suspension, electrical */
    #define NOPT 2      /* two choices per subsystem */
    
    int main(void)
    {
        const char *name[NSUB][NOPT] = {
            {"disc",     "drum"},
            {"wankle",   "conventional"},
            {"air",      "oil"},
            {"computer", "standard"}
        };
        const double mtbf[NSUB][NOPT] = {{4, 5}, {3, 6}, {9, 7}, {2, 4}};
        const double cost[NSUB][NOPT] = {{  15.00,   25.00},
                                         {1067.00, 1850.00},
                                         { 430.00,  320.00},
                                         { 130.00,   40.00}};
    
        int b, e, s, l;
        int cheapAt[NSUB], longAt[NSUB], bestAt[NSUB];
        double cheapC = -1.0, longM = -1.0, bestR = -1.0;
    
        /* Nested loops, as the hint directs: 2 x 2 x 2 x 2 = 16 whole cars. */
        for (b = 0; b < NOPT; b++)
          for (e = 0; e < NOPT; e++)
            for (s = 0; s < NOPT; s++)
              for (l = 0; l < NOPT; l++) {
                  int pick[NSUB]; int k;
                  double c, inv, m, perYear;
    
                  pick[0] = b; pick[1] = e; pick[2] = s; pick[3] = l;
    
                  c = inv = 0.0;
                  for (k = 0; k < NSUB; k++) {
                      c   += cost[k][pick[k]];
                      inv += 1.0 / mtbf[k][pick[k]];   /* failure rates add */
                  }
                  m       = 1.0 / inv;                 /* system MTBF, years  */
                  perYear = c * inv;                   /* = c / m             */
    
                  printf("%-10s %-13s %-4s %-9s  %8.2f %7.4f %9.2f\n",
                         name[0][b], name[1][e], name[2][s], name[3][l],
                         c, m, perYear);
    
                  if (cheapC < 0.0 || c       < cheapC) { cheapC = c;       for (k=0;k<NSUB;k++) cheapAt[k]=pick[k]; }
                  if (longM  < 0.0 || m       > longM ) { longM  = m;       for (k=0;k<NSUB;k++) longAt [k]=pick[k]; }
                  if (bestR  < 0.0 || perYear < bestR ) { bestR  = perYear; for (k=0;k<NSUB;k++) bestAt [k]=pick[k]; }
              }
    
        putchar('\n');
        printf("cheapest        : %8.2f\n", cheapC);
        printf("longest MTBF    : %8.4f years\n", longM);
        printf("best value      : %8.2f per failure-free year\n", bestR);
        return 0;
    }
  5. Read off the cheapest car. Taking the cheaper variant of every subsystem independently — disc brakes, wankle engine, oil suspension, standard electrical — gives $$C = 15.00 + 1067.00 + 320.00 + 40.00$$ $$\boxed{C_{\min} = 1442.00\ \text{dollars}}$$ with a system MTBF of 1.0244 years. Cost is a plain sum, so choosing each subsystem's cheaper variant independently is guaranteed optimal.
  6. Read off the most reliable car. Reliability is likewise separable — the rate sum is minimised by taking the largest MTBF in every subsystem — giving drum brakes, conventional engine, air suspension and standard electrical: $$\frac{1}{MTBF} = \frac{1}{5}+\frac{1}{6}+\frac{1}{9}+\frac{1}{4} = \frac{36+30+20+45}{180} = \frac{131}{180}$$ $$\boxed{MTBF_{\max} = \frac{180}{131} = 1.3740\ \text{years}}$$ at a cost of $2,345.00. Note that the standard electrical unit is chosen here even though reliability is the only criterion: at 4 years against the computer unit's 2, it is both cheaper and more reliable, so the computer variant is dominated outright.
  7. Read off the best value, which is neither of the above. The ratio $R$ is not separable — it couples cost and reliability — so it must genuinely be searched. The winner is drum brakes, wankle engine, oil suspension, standard electrical: $$R = \frac{1452.00}{1.0797}$$ $$\boxed{R_{\min} = 1344.83\ \text{dollars per failure-free year}}$$ For $10.00 more than the cheapest car, the drum brakes buy enough extra life to beat it on value ($1,407.67 per year), while the most reliable car is far off the pace at $1,706.64 per year. That the three questions have three different answers is the whole point of the exercise.
All sixteen combinations (cost in dollars, MTBF in years)
BrakesEngineSuspensionElectrical CostMTBFCost per failure-free year
discwankleaircomputer1,642.000.83721,961.28
discwankleairstandard1,552.001.05881,465.78
discwankleoilcomputer1,532.000.81551,878.52
discwankleoilstandard1,442.001.02441,407.67
discconventionalaircomputer2,425.000.97302,492.36
discconventionalairstandard2,335.001.28571,816.11
discconventionaloilcomputer2,315.000.94382,452.80
discconventionaloilstandard2,225.001.23531,801.19
drumwankleaircomputer1,652.000.87381,890.62
drumwankleairstandard1,562.001.11801,397.12
drumwankleoilcomputer1,542.000.85021,813.69
drumwankleoilstandard1,452.001.07971,344.83
drumconventionalaircomputer2,435.001.02272,380.89
drumconventionalairstandard2,345.001.37401,706.64
drumconventionaloilcomputer2,325.000.99062,347.14
drumconventionaloilstandard2,235.001.31661,697.54
Question 2 — results
Question askedWinning systemCostMTBF (years)Cost per failure-free year
1. Cheapestdisc / wankle / oil / standard$1,442.001.0244$1,407.67
2. Longest MTBFdrum / conventional / air / standard$2,345.001.3740$1,706.64
3. Lowest cost per failure-free yeardrum / wankle / oil / standard$1,452.001.0797$1,344.83
Combinations enumerated16