# Q5(a) Genetic algorithm [10]

Subject: Intelligent Systems II

Exam: TEE

Reader: https://deep-learning-study-room.vercel.app/is2/#tee/mocks/paper-reexam-2026/q5a

Canonical: https://deep-learning-study-room.vercel.app/read/is2/tee/mocks/paper-reexam-2026--q5a/

100-mark timed practice using the actual Re-exam 2026 paper. Q1 compulsory; any four of Q2–Q7. Worked solutions are below the questions.

**Implement a GA to maximise 

$$
f(x)=2x^3-3x^2+8x
$$

 for x in [0,50]. Take 4-bit representations of 12, 20, 17, 13. Crossover after the second bit and mutate by flipping any one bit. Produce two offspring and comment on fitness.** [10 marks]

### Answer

**The printed data are inconsistent.** 20 and 17 do not fit into four bits, and covering 0–50 needs six bits. We use six-bit encoding to preserve the supplied parent values and the stated range.

#### Given

Printed parents: [12, 20, 17, 13]. Worked variant: [12, 20, 17, 13] with 6 bits. For the unspecified selection step, select the two highest-fitness candidates. For the unspecified mutation location, flip the last bit of each child. Crossover is after bit 2.

#### To find

Two valid children under the declared assumptions and their fitness.

#### Formula and why it applies

Encoding must respect the candidate range. Crossover swaps tails; mutation flips the chosen bit. Fitness is evaluated after mutation.



$$
f(x)=2x^3-3x^2+8x
$$



#### Solution

##### Step 1. Encode and evaluate the declared parent population

| x | Binary | Fitness substitution |
| --- | --- | --- |
| 12 | 001100 | 2(12³) − 3(12²) + 8(12) = 3120 |
| 20 | 010100 | 2(20³) − 3(20²) + 8(20) = 14960 |
| 17 | 010001 | 2(17³) − 3(17²) + 8(17) = 9095 |
| 13 | 001101 | 2(13³) − 3(13²) + 8(13) = 3991 |

##### Step 2. Select the two fittest under the stated assumption

[20, 17] with fitness [14960, 9095].

##### Step 3. Cut after bit 2 and exchange tails

| Parent 1 | Parent 2 | Child 1 | Child 2 |
| --- | --- | --- | --- |
| 01 | 0100 | 01 | 0001 | 010001 | 010100 |

##### Step 4. Flip the last bit of each child

| Before | After | Decoded x |
| --- | --- | --- |
| 010001 | 010000 | 16 |
| 010100 | 010101 | 21 |

##### Step 5. Evaluate both children

| x | Fitness calculation |
| --- | --- |
| 16 | 2(4096) − 3(256) + 8(16) = 7552 |
| 21 | 2(9261) − 3(441) + 8(21) = 17367 |

##### Step 6. Compare with the selected parents

Best parent score = 14960; best child score = 17367. Parent average = 12027.5; child average = 12459.5. Both the best score and the average score increased in this worked variant. An individual child can still be worse than a parent; GA does not guarantee improvement after every random operator.

**Final answer.** Under these declared repairs and operator choices, children are [16, 21] with fitness [7552, 17367]. These are not unique answers to the inconsistent and under-specified original question.

The printed wording about “two offspring” is not an explicit requirement for two complete generations. The M2 examples separately work two full generations because your class update asks for iteration 2.

## Evaluate the polynomial without skipping the powers

Calculate x²=x×x, then x³=x²×x. Multiply each by its coefficient and combine with the written signs. A bit-string repair in the worked answer is an explicitly stated response to inconsistent printed givens; it is not a new instruction in the original paper.

### x=12



$$
x^2=12\times12=144\qquad x^3=144\times12=1728
$$





$$
2x^3=3456\quad 3x^2=432\quad 8x=96
$$





$$
f(12)=3456-432+96=3120
$$



### x=20



$$
x^2=20\times20=400\qquad x^3=400\times20=8000
$$





$$
2x^3=16000\quad 3x^2=1200\quad 8x=160
$$





$$
f(20)=16000-1200+160=14960
$$



### x=17



$$
x^2=17\times17=289\qquad x^3=289\times17=4913
$$





$$
2x^3=9826\quad 3x^2=867\quad 8x=136
$$





$$
f(17)=9826-867+136=9095
$$



### x=13



$$
x^2=13\times13=169\qquad x^3=169\times13=2197
$$





$$
2x^3=4394\quad 3x^2=507\quad 8x=104
$$





$$
f(13)=4394-507+104=3991
$$



### x=16



$$
x^2=16\times16=256\qquad x^3=256\times16=4096
$$





$$
2x^3=8192\quad 3x^2=768\quad 8x=128
$$





$$
f(16)=8192-768+128=7552
$$



### x=21



$$
x^2=21\times21=441\qquad x^3=441\times21=9261
$$





$$
2x^3=18522\quad 3x^2=1323\quad 8x=168
$$





$$
f(21)=18522-1323+168=17367
$$


