GenAI Exam Prep
Home Mock Exam
โ˜… FINAL MOCK EXAM

Full Mock Exam

A full-length practice exam covering all 20 lectures โ€” 40 MCQs (auto-graded) and 8 coding questions. Simulate the real test, then check every solution.

40 MCQs + 8 coding โฑ Suggested 75 min Target: 85%+
๐Ÿ’ก How to take this exam Answer all 40 MCQs by clicking an option, then attempt the coding questions on paper. Press Submit Exam to auto-grade the MCQs and reveal every solution. Use Reset to retake it. For a realistic run, time yourself to 75 minutes and do not peek at solutions first.
Score: — / 40
A Section A โ€” Multiple Choice (40 questions)

One mark each. Choose the single best answer.

MCQQ1L1

In machine learning, the computer's job during training is to produce the:

  • A Training data
  • B Rules / model, learned from data
  • C Hard-coded if-else logic
  • D The user interface
Answer: B

Traditional programming: human writes rules. ML: machine discovers the rules (the model) from data + answers.

MCQQ2L1

Grouping customers into segments with no predefined labels is:

  • A Classification
  • B Regression
  • C Clustering (unsupervised)
  • D Reinforcement learning
Answer: C

No labels + forming natural groups = clustering, an unsupervised task.

MCQQ3L2

For a skewed income column containing outliers, the safest way to fill missing values is:

  • A Mean imputation
  • B Median imputation
  • C Mode imputation
  • D Filling with zero
Answer: B

The median ignores extreme values, so it is robust for skewed data with outliers. The mean gets dragged by outliers.

MCQQ4L2

The colour column (Red, Green, Blue) should be converted to numbers using:

  • A Label Encoding
  • B One-Hot Encoding
  • C Min-Max scaling
  • D Z-score standardization
Answer: B

Colour is nominal (no order). One-hot encoding avoids inventing a fake ranking, unlike label encoding.

MCQQ5L2

With Q1 = 30 and Q3 = 70, the IQR upper bound for outlier detection is:

  • A 100
  • B 130
  • C 110
  • D 90
Answer: B

IQR = 70 โˆ’ 30 = 40. Upper bound = Q3 + 1.5ร—IQR = 70 + 60 = 130.

MCQQ6L3

Ordinary Least Squares finds the line that minimises:

  • A The sum of raw errors
  • B The sum of squared errors
  • C The number of data points
  • D The slope value
Answer: B

OLS squares errors so positive and negative residuals do not cancel, then minimises their sum.

MCQQ7L3

"Error variance must stay constant across all values of x" is the assumption of:

  • A Linearity
  • B Homoscedasticity
  • C No multicollinearity
  • D Normality of errors
Answer: B

Homoscedasticity = constant error variance. If errors fan out, it is violated (heteroscedasticity).

MCQQ8L4

The sigmoid function ฯƒ(0) equals:

  • A 0
  • B 1
  • C 0.5
  • D Infinity
Answer: C

ฯƒ(0) = 1/(1+eโฐ) = 1/2 = 0.5 โ€” the point of maximum uncertainty.

MCQQ9L4

Logistic Regression is fundamentally used for:

  • A Predicting continuous numbers
  • B Classification (predicting categories/probabilities)
  • C Clustering
  • D Dimensionality reduction
Answer: B

Despite its name, Logistic Regression is a classification algorithm โ€” it predicts the probability of a class.

MCQQ10L5

A confusion matrix gives TP=30, FP=10, FN=10, TN=50. The precision is:

  • A 0.60
  • B 0.75
  • C 0.50
  • D 0.90
Answer: B

Precision = TP/(TP+FP) = 30/(30+10) = 30/40 = 0.75.

MCQQ11L5

A model with 99% training accuracy and 62% test accuracy is suffering from:

  • A High bias (underfitting)
  • B High variance (overfitting)
  • C Perfect generalisation
  • D Data leakage only
Answer: B

A large train-test gap is the signature of overfitting / high variance โ€” the model memorised noise.

MCQQ12L5

For cancer screening, where missing a sick patient is dangerous, the priority metric is:

  • A Precision
  • B Recall
  • C Accuracy
  • D RMSE
Answer: B

Recall = TP/(TP+FN) minimises false negatives โ€” critical when a missed positive case is costly.

MCQQ13L6

A decision-tree node with 4 "Yes" and 4 "No" samples has a Gini index of:

  • A 0
  • B 0.5
  • C 1.0
  • D 0.25
Answer: B

Gini = 1 โˆ’ (0.5ยฒ + 0.5ยฒ) = 1 โˆ’ 0.5 = 0.5 โ€” maximum impurity for a binary node.

MCQQ14L6

A decision tree chooses its splits to maximise:

  • A Node impurity
  • B Purity of the resulting child nodes (Information Gain)
  • C The number of leaves
  • D The tree depth
Answer: B

The tree greedily picks the split that most reduces impurity โ€” i.e. the highest Information Gain / lowest weighted Gini.

MCQQ15L7

A single-layer perceptron cannot solve the XOR problem because XOR is:

  • A Too large a dataset
  • B Not linearly separable
  • C A regression problem
  • D Missing a bias term
Answer: B

A single perceptron is a linear classifier; no single line separates XOR's classes. Hidden layers are needed.

MCQQ16L7

Backpropagation computes weight gradients using:

  • A Bayes' theorem
  • B The chain rule of calculus
  • C The Pythagorean theorem
  • D Linear regression
Answer: B

Backpropagation applies the chain rule layer-by-layer, from output to input, to find each weight's gradient.

MCQQ17L8

For the output layer of a 10-class classifier, the correct activation is:

  • A ReLU
  • B Sigmoid
  • C Softmax
  • D Linear
Answer: C

Softmax outputs probabilities across all classes that sum to 1 โ€” ideal for multi-class output.

MCQQ18L8

What gives an RNN the ability to handle sequential data?

  • A It has more parameters
  • B A hidden state that carries information across time steps
  • C It uses softmax in every layer
  • D It never uses activation functions
Answer: B

The hidden state is the RNN's memory โ€” it passes context from earlier steps forward.

MCQQ19L9

Which technique reduces a word to its dictionary root, always producing a real word?

  • A Stemming
  • B Lemmatization
  • C Padding
  • D Tokenization
Answer: B

Lemmatization uses a dictionary ("studies" โ†’ "study"). Stemming crudely chops endings and can produce non-words.

MCQQ20L9

Compared with one-hot encoding, word embeddings are:

  • A Larger and sparser
  • B Dense and capture semantic meaning
  • C Unable to be learned
  • D Only usable for numbers
Answer: B

Embeddings are compact, dense vectors where similar words sit close together โ€” one-hot vectors are huge, sparse and "dumb".

MCQQ21L10

In the self-attention formula, the Query (Q) vector represents:

  • A "What I'm looking for"
  • B "What I offer"
  • C "The actual information"
  • D The loss value
Answer: A

Query = what I need; Key = what I offer; Value = the actual information passed along.

MCQQ22L10

An LLM confidently producing made-up facts is called:

  • A Overfitting
  • B Hallucination
  • C Tokenization
  • D Backpropagation
Answer: B

A hallucination is a fluent but factually false output โ€” the model predicts what sounds right, not what is right.

MCQQ23L10

Why does a Transformer need Positional Encoding?

  • A To speed up the GPU
  • B Because it processes all words at once and would otherwise lose word order
  • C To remove stop words
  • D To compress the model
Answer: B

Parallel processing means no built-in order; positional encoding tags each word with its position.

MCQQ24L11

Image generators like Stable Diffusion are based on:

  • A Decision trees
  • B Diffusion models (noise refined step-by-step)
  • C Logistic regression
  • D K-means clustering
Answer: B

Diffusion models start from random noise and iteratively denoise it into an image guided by the prompt.

MCQQ25L11

Which is a generative model?

  • A Random Forest
  • B Support Vector Machine
  • C GPT
  • D Logistic Regression
Answer: C

GPT generates new content (generative). Random Forest, SVM and Logistic Regression are discriminative classifiers.

MCQQ26L12

The HTTP status code 429 from an AI API means:

  • A Authentication failed
  • B Too Many Requests (rate limit exceeded)
  • C Success
  • D Server not found
Answer: B

429 = Too Many Requests. Handle it with exponential backoff. 401 = auth issue, 403 = access restricted.

MCQQ27L12

An API key should be stored:

  • A Hard-coded in frontend JavaScript
  • B In environment variables / a secrets manager, used by the backend
  • C In a public GitHub repo
  • D Printed in the app's UI
Answer: B

Keys belong in env vars / secrets managers, used server-side only โ€” never exposed in frontend or public code.

MCQQ28L13

Adding the phrase "Let's think step by step" to a prompt is an example of:

  • A Zero-shot prompting
  • B Role prompting
  • C Chain-of-Thought prompting
  • D Prompt injection
Answer: C

That magic phrase triggers Chain-of-Thought โ€” step-by-step reasoning that boosts accuracy on logic/maths.

MCQQ29L13

For deterministic, precise code generation, the temperature should be:

  • A Low (near 0)
  • B High (near 1)
  • C Negative
  • D Exactly 100
Answer: A

Low temperature โ†’ precise, reproducible output (coding, maths). High temperature โ†’ creative, varied output.

MCQQ30L14

To give a chatbot access to constantly-changing company data, the best approach is:

  • A Fine-tuning
  • B RAG (retrieval)
  • C Raising the temperature
  • D Removing the system prompt
Answer: B

RAG can be updated instantly by editing the database; fine-tuning needs slow retraining for new data.

MCQQ31L14

LoRA makes fine-tuning efficient by:

  • A Updating every parameter of the model
  • B Freezing the base model and training only a small adapter
  • C Deleting the training data
  • D Skipping training entirely
Answer: B

LoRA (a PEFT method) trains only ~1% of parameters in an adapter layer โ€” fast, cheap, modular.

MCQQ32L15

A chatbot appears to remember earlier turns because the application:

  • A Retrains the model after each message
  • B Re-sends the full conversation history with every request
  • C Stores messages inside the model's weights
  • D Uses a higher temperature
Answer: B

LLMs are stateless; "memory" is the app passing the whole message history each time.

MCQQ33L15

Keeping only the last N conversation turns to bound token cost is called:

  • A Full-history memory
  • B Windowed (buffer) memory
  • C Fine-tuning
  • D Tokenization
Answer: B

Window/buffer memory keeps a sliding window of recent turns โ€” cheap and bounded.

MCQQ34L16

The correct order of the RAG pipeline is:

  • A Retrieve โ†’ Augment โ†’ Generate
  • B Generate โ†’ Retrieve โ†’ Augment
  • C Augment โ†’ Generate โ†’ Retrieve
  • D Train โ†’ Test โ†’ Deploy
Answer: A

Retrieve relevant docs, augment the prompt with them, then generate the grounded answer.

MCQQ35L16

Which of these is a vector database used in RAG?

  • A MySQL
  • B MongoDB
  • C FAISS
  • D SQLite
Answer: C

FAISS (and Chroma, Pinecone, Weaviate) store embeddings and do fast similarity search.

MCQQ36L17

Gradio's core philosophy is to:

  • A Build complete multi-page applications
  • B Wrap a single Python function into a web UI
  • C Manage cloud servers
  • D Replace Python with JavaScript
Answer: B

Gradio is function-first โ€” give it a function plus input/output types and it builds the UI. Streamlit builds full apps.

MCQQ37L18

In the "digital intern" model of an agent, Tools play the role of the:

  • A Brain
  • B Hands
  • C Instructions
  • D Memory
Answer: B

Brain = LLM, Hands = Tools, Instructions = Prompts. Tools let the agent act on the world.

MCQQ38L18

Which Ollama command only downloads a model without starting a chat?

  • A ollama pull
  • B ollama run
  • C ollama list
  • D ollama rm
Answer: A

ollama pull downloads only; ollama run downloads (if needed) AND starts the chat.

MCQQ39L19

The ReAct framework follows the cycle:

  • A Retrieve โ†’ Augment โ†’ Generate
  • B Think โ†’ Act โ†’ Observe
  • C Encode โ†’ Decode โ†’ Output
  • D Train โ†’ Validate โ†’ Test
Answer: B

ReAct = Reason + Act: Think, Act, Observe, then think again โ€” enabling self-correction.

MCQQ40L20

In n8n, the node that starts a workflow at a scheduled time is the:

  • A IF node
  • B HTTP Request node
  • C Schedule Trigger
  • D Gmail node
Answer: C

A Schedule Trigger fires the workflow at set times โ€” the n8n equivalent of a cron job.

B Section B โ€” Coding Questions (8 questions)

Write the code on paper, then press Show Solution (or Submit Exam) to compare. These are not auto-graded.

CodingC1L2 ยท Preprocessing

Given a DataFrame df, write code to: fill missing values in Age with the median, and one-hot encode the nominal column City.

Solution
Python
import pandas as pd

# Median imputation for Age
df['Age'] = df['Age'].fillna(df['Age'].median())

# One-hot encode the nominal City column
df = pd.get_dummies(df, columns=['City'], drop_first=True)
print(df.head())

drop_first=True avoids the dummy variable trap.

CodingC2L3 ยท Linear Regression

Train a Linear Regression model on X = [[1],[2],[3],[4]], y = [10,20,30,40] and predict for x = 7.

Solution
Python
from sklearn.linear_model import LinearRegression

X = [[1], [2], [3], [4]]
y = [10, 20, 30, 40]            # rule: y = 10x

model = LinearRegression()
model.fit(X, y)
print("Prediction for x=7:", model.predict([[7]]))
OutputPrediction for x=7: [70.]
CodingC3L5 ยท Evaluation

Given y_true and y_pred, write code to print the confusion matrix, precision, recall and F1 score.

Solution
Python
from sklearn.metrics import (confusion_matrix, precision_score,
                             recall_score, f1_score)

y_true = [1, 0, 1, 1, 0, 1]
y_pred = [1, 0, 0, 1, 0, 1]

print("Confusion matrix:\n", confusion_matrix(y_true, y_pred))
print("Precision:", precision_score(y_true, y_pred))
print("Recall   :", recall_score(y_true, y_pred))
print("F1 Score :", round(f1_score(y_true, y_pred), 3))
OutputConfusion matrix: [[2 0] [1 3]] Precision: 1.0 Recall : 0.75 F1 Score : 0.857
CodingC4L4/L7 ยท Sigmoid

Write a numpy sigmoid(z) function and use it to classify z = 1.5 (class 1 if output โ‰ฅ 0.5).

Solution
Python
import numpy as np

def sigmoid(z):
    return 1 / (1 + np.exp(-z))

p = sigmoid(1.5)
print("Probability:", round(p, 4))
print("Class:", 1 if p >= 0.5 else 0)
OutputProbability: 0.8176 Class: 1
CodingC5L8 ยท Neural Network

Build and compile a Keras MLP for a 3-class classification problem with input dimension 10 and one hidden layer of 16 ReLU neurons.

Solution
Python
from keras import models, layers
from keras.layers import Input

model = models.Sequential([
    Input(shape=(10,)),
    layers.Dense(16, activation='relu'),     # hidden layer
    layers.Dense(3,  activation='softmax')   # 3-class output
])

model.compile(optimizer='adam',
              loss='categorical_crossentropy',
              metrics=['accuracy'])

3 classes โ†’ 3 output neurons + softmax + categorical_crossentropy.

CodingC6L9 ยท NLP

Write code to lowercase a sentence, remove punctuation, and split it into tokens.

Solution
Python
import string

text = "Hello, NLP World! Let's tokenize THIS."

text = text.lower()
text = text.translate(str.maketrans('', '', string.punctuation))
tokens = text.split()

print(tokens)
Output['hello', 'nlp', 'world', 'lets', 'tokenize', 'this']
CodingC7L16 ยท RAG

Using Chroma, create a collection, add two documents, and query for the most relevant one.

Solution
Python
import chromadb

client = chromadb.Client()
collection = client.create_collection("docs")

collection.add(
    documents=["Our return policy lasts 30 days.",
               "The warehouse is in Mumbai."],
    ids=["d1", "d2"]
)

result = collection.query(
    query_texts=["How long do I have to return an item?"],
    n_results=1
)
print(result["documents"][0])
Output['Our return policy lasts 30 days.']

The query matched the return-policy document by meaning, not keywords.

CodingC8L18/L19 ยท Agents

Using LangChain, define a tool that adds two numbers and bind it to an LLM. Then build a minimal LangGraph State.

Solution
Python
from langchain_core.tools import tool
from typing import TypedDict, Annotated
from langgraph.graph.message import add_messages

# A tool: a function with a docstring
@tool
def add(a: int, b: int) -> int:
    """Add two numbers together."""
    return a + b

# Bind the tool to the LLM
llm_with_tools = llm.bind_tools([add])

# A minimal LangGraph state
class AgentState(TypedDict):
    messages: Annotated[list, add_messages]

The @tool decorator + docstring let the LLM know when to call add; the State stores the appended message history.

๐ŸŽฏ Finished? Press Submit Exam at the top to grade your 40 MCQs and reveal all solutions. Aim for 85%+ โ€” if you score lower, note which lectures the missed questions belong to (shown as the topic tag) and re-read those pages.