Pakistan's best MCQs practice hub — FPSC · PPSC · CSS · NTS · Other Exams
Login
Programming, Databases & AI

Programming, Databases & AI MCQs With Answers

Programming and databases are the heart of computer science, and AI is now joining them in exam papers. These programming, database and AI MCQs cover algorithms, variables, loops, functions and recursion, high-level and low-level languages such as Python, C++, FORTRAN and assembly, HTML, CSS and JavaScript, compilers, assemblers and linkers, object-oriented programming and polymorphism, stacks, binary search, sorting and time complexity, SQL, primary keys, joins, normal forms and ACID properties, MySQL and MongoDB, SDLC models such as Agile and Spiral, version control with Git, and AI, neural networks, transformers and large language models. They help lecturer, IT and NTS candidates.

Take a scored quiz instead →

In Relational Database Management Systems (RDBMS), what property ensures that all operations within a database transaction either complete successfully or roll back completely?

AAtomicity
BConsistency
CIsolation
DDurability
Explanation

Atomicity (the 'A' in ACID) guarantees an 'all-or-nothing' execution model. If any operation within a transaction fails, the entire transaction is aborted and rolled back to preserve database integrity.

Submitted by: mcqstutor Team

Which SQL command is used to remove a table structure and all of its records permanently from a database schema?

ADELETE
BTRUNCATE
CDROP
DREMOVE
Explanation

DROP TABLE deletes both the table structure and its data permanently (DDL command). TRUNCATE removes all rows while keeping the structure intact, and DELETE removes selected rows (DML command).

Submitted by: mcqstutor Team

Which Normal Form eliminates partial dependency by ensuring that all non-key attributes are fully functionally dependent on the entire primary key?

AFirst Normal Form (1NF)
BSecond Normal Form (2NF)
CThird Normal Form (3NF)
DBoyce-Codd Normal Form (BCNF)
Explanation

2NF requires the table to be in 1NF and have no partial dependencies (non-prime attributes depending on only part of a composite primary key). 3NF eliminates transitive dependencies.

Submitted by: mcqstutor Team

Which type of database JOIN returns all records from the left table and matching records from the right table, filling with NULL where no match exists?

AINNER JOIN
BRIGHT JOIN
CLEFT OUTER JOIN
DFULL OUTER JOIN
Explanation

A LEFT JOIN (or LEFT OUTER JOIN) fetches every record from the left table. If a row has no corresponding match in the right table, SQL returns NULL for all right-table columns.

Submitted by: mcqstutor Team

Which linear data structure operates strictly on a Last-In, First-Out (LIFO) access mechanism?

AQueue
BLinked List
CStack
DBinary Tree
Explanation

A Stack works on LIFO (Last-In, First-Out), where push and pop operations happen at the top element. A Queue operates on FIFO (First-In, First-Out).

Submitted by: mcqstutor Team

What is the worst-case time complexity of the standard QuickSort algorithm when selecting a poor pivot element on an already sorted array?

AO(n log n)
BO(n)
CO(n²)
DO(log n)
Explanation

QuickSort uses Divide and Conquer. While its average time complexity is O(n log n), choosing an extreme element (smallest or largest) as pivot on a sorted array results in worst-case time complexity of O(n²).

Submitted by: mcqstutor Team

In Object-Oriented Programming (OOP), what term describes the ability of a single interface or method name to take multiple forms based on the object context?

AEncapsulation
BInheritance
CPolymorphism
DAbstraction
Explanation

Polymorphism ('many forms') allows methods to behave differently based on the calling object (e.g., via Method Overloading or Method Overriding). Encapsulation hides internal data, while Abstraction hides implementation complexity.

Submitted by: mcqstutor Team

Which search algorithm requires data to be sorted beforehand and repeatedly divides the search interval in half?

ALinear Search
BBinary Search
CDepth-First Search (DFS)
DBreadth-First Search (BFS)
Explanation

Binary Search requires a pre-sorted array. It compares the target value to the middle element, cutting the search domain in half with each iteration, achieving an efficient time complexity of O(log n).

Submitted by: mcqstutor Team

Which programming language paradigm uses mathematical functions and avoids changing state or mutable data?

AImperative Programming
BFunctional Programming
CProcedural Programming
DObject-Oriented Programming
Explanation

Functional Programming (e.g., Haskell, Lisp) treats computation as the evaluation of pure mathematical functions, avoiding side effects and mutable state, unlike Imperative or Object-Oriented styles.

Submitted by: mcqstutor Team

Which software development methodology emphasizes iterative delivery, customer collaboration, cross-functional self-organizing teams, and flexibility to changing requirements?

AWaterfall Model
BSpiral Model
CAgile Methodology
DV-Model
Explanation

Agile Software Development delivers functional software in short sprints (1–4 weeks), adapting swiftly to changing user needs. Waterfall is linear and sequential, making mid-course adjustments difficult.

Submitted by: mcqstutor Team

Which SDLC model incorporates explicit risk assessment and management at every iterative phase of development?

AWaterfall Model
BSpiral Model
CRAD Model
DPrototyping Model
Explanation

The Spiral Model (proposed by Barry Boehm) combines iterative development with systematic risk analysis across four quadrants: Planning, Risk Analysis, Engineering, and Evaluation.

Submitted by: mcqstutor Team

Which markup language is the standard language for creating web pages and defining their structure?

AHTML
BCSS
CJavaScript
DPHP
Explanation

HTML (HyperText Markup Language) structures web content. CSS controls layout and styling, JavaScript enables dynamic client-side scripting, and PHP executes server-side logic.

Submitted by: mcqstutor Team

Which field of Artificial Intelligence enables machines to process, interpret, and understand human text and spoken language?

AComputer Vision
BNatural Language Processing (NLP)
CRobotics Process Automation (RPA)
DExpert Systems
Explanation

Natural Language Processing (NLP) combines computational linguistics with machine learning to enable computers to understand, parse, and generate human language.

Submitted by: mcqstutor Team

What is the primary function of an Assembler in computer programming?

ATranslates High-Level Language source code into Machine Code line by line
BTranslates Assembly Language mnemonic code into Machine Code (Binary)
CLinks object files together to create an executable binary file
DExecutes high-level code directly without compilation
Explanation

An Assembler translates symbolic Assembly Language (mnemonics like MOV, ADD) into raw machine code (0s and 1s). Compilers translate entire high-level programs at once, while Interpreters translate line by line.

Submitted by: mcqstutor Team

Which type of software maintenance is performed to modify a software system to adapt to changes in its surrounding environment (e.g., new OS version)?

ACorrective Maintenance
BAdaptive Maintenance
CPerfective Maintenance
DPreventive Maintenance
Explanation

Adaptive Maintenance alters software to stay compatible with changing external environments (OS, hardware, regulations). Corrective fixes bugs, Perfective adds new features, and Preventive refactors code to avoid future failures.

Submitted by: mcqstutor Team

What term refers to the process of converting human-readable source code into an intermediate bytecode format executed by a virtual machine (e.g., Java JVM)?

AInterpretation
BBytecode Compilation
CLinking
DAssembly
Explanation

Java compiles source code (.java) into platform-independent Bytecode (.class), which is then interpreted or JIT-compiled by the Java Virtual Machine (JVM) on target platforms.

Submitted by: mcqstutor Team

Which system software component translates a high-level source code file into object code modules prior to linking?

ALinker
BCompiler
CLoader
DDebugger
Explanation

A Compiler translates entire high-level source code into machine code/object code. The Linker then combines object modules with external libraries to generate an executable binary file (.exe).

Submitted by: mcqstutor Team

Which traversal algorithm visits a Binary Search Tree (BST) nodes in strict ascending sorted key order?

APre-order Traversal
BIn-order Traversal
CPost-order Traversal
DLevel-order Traversal
Explanation

In-order Traversal (Left subtree -> Root node -> Right subtree) visits nodes of a Binary Search Tree in sorted ascending order. Pre-order is used for cloning, and Post-order for node deletion.

Submitted by: mcqstutor Team

In artificial neural networks, which function is applied to the weighted sum of inputs at a neuron to introduce non-linearity into the network model?

ACost Function
BActivation Function
CGradient Descent
DLoss Function
Explanation

Activation Functions (such as ReLU, Sigmoid, or Tanh) introduce non-linear mapping into neural networks, enabling them to learn complex non-linear patterns in data.

Submitted by: mcqstutor Team

Which programming language, created by Guido van Rossum in 1991, is widely used in Data Science and AI?

AJava
BPython
CRuby
DC++
Explanation

Python is a high-level, interpreted programming language created by Dutch developer Guido van Rossum and released in 1991. Renowned for its simple syntax and extensive libraries (NumPy, Pandas, PyTorch), it is the leading language for Data Science, Machine Learning, and Artificial Intelligence.

Submitted by: mcqstutor Team

What does SQL stand for in database management systems?

AStructured Query Language
BSystem Query Language
CStandard Question Language
DSequential Query Logic
Explanation

SQL stands for Structured Query Language. Developed by IBM in the 1970s, SQL is the standardized programming language used to create, query, update, manage, and manipulate data stored in Relational Database Management Systems (RDBMS) like MySQL, PostgreSQL, and Oracle.

Submitted by: mcqstutor Team

In relational databases, what is a column that uniquely identifies each row/record in a table called?

APrimary Key
BUnique Index
CCandidate Key
DForeign Key
Explanation

A Primary Key is a database column (or set of columns) that uniquely identifies each individual record/row in a relational database table. Primary key values must be completely unique and cannot contain NULL values.

Submitted by: mcqstutor Team

What generative AI architecture introduced by Google researchers in 2017 forms the foundation of modern LLMs like ChatGPT and Gemini?

ATransformer Architecture
BConvolutional Neural Network (CNN)
CGenerative Adversarial Network (GAN)
DRecurrent Neural Network (RNN)
Explanation

The Transformer architecture was introduced in the seminal 2017 paper 'Attention Is All You Need' by Google researchers. Utilizing self-attention mechanisms, Transformers process sequential data in parallel, serving as the core foundation for modern Large Language Models (LLMs) like GPT-4, Claude, and Gemini.

Submitted by: mcqstutor Team

What does LLM stand for in modern Artificial Intelligence applications?

ALarge Language Model
BLayered Learning Matrix
CLogical Learning Machine
DLinear Language Model
Explanation

LLM stands for Large Language Model. It refers to advanced deep-learning artificial intelligence models trained on massive text datasets (containing hundreds of billions of parameters) to understand, generate, translate, and synthesize human language.

Submitted by: mcqstutor Team

What is the process of finding and fixing errors in a computer program called?

ACompiling
BFormatting
CInstalling
DDebugging
Explanation

- Debugging means finding and fixing errors in code.
- It is an important part of software development.
- Programmers use special tools to help find errors.

Submitted by: mcqstutor Team

What is a set of step-by-step instructions used to solve a problem called?

ADatabase
BCompiler
CVariable
DAlgorithm
Explanation

- An algorithm is a set of steps to solve a problem.
- It forms the logic behind computer programs.
- A good algorithm gives a correct result in a set number of steps.

Submitted by: mcqstutor Team

What is a named storage location in a program that can hold changing data called?

AFunction
BLoop
CCompiler
DVariable
Explanation

- A variable stores data that can change while a program runs.
- It has a name and usually a specific data type.
- Examples include storing a number or a piece of text.

Submitted by: mcqstutor Team

What is a reusable block of code that performs a specific task called?

AVariable
BLoop
CArray
DFunction
Explanation

- A function is a reusable block of code for a specific task.
- It can be called multiple times in a program.
- Functions make programs more organized and easier to read.

Submitted by: mcqstutor Team

What is a programming structure that repeats a block of code multiple times called?

AFunction
BVariable
CArray
DLoop
Explanation

- A loop repeats a block of code multiple times.
- Common types include for loops and while loops.
- Loops help avoid writing the same code repeatedly.

Submitted by: mcqstutor Team

Which programming language is widely known for its simple, easy-to-read syntax for beginners?

AC++
BSQL
CHTML
DPython
Explanation

- Python is known for its simple, readable syntax.
- It is commonly used for beginners learning to code.
- Python is also widely used in data analysis and AI.

Submitted by: mcqstutor Team

Which language is used to control the colors, fonts, and layout of a webpage?

ACSS
BHTML
CSQL
DJava
Explanation

- CSS controls the visual style of a webpage.
- It handles colors, fonts, and layout.
- CSS works together with HTML.

Submitted by: mcqstutor Team

Which language is commonly used to add interactive features to a webpage?

AJavaScript
BCSS
CSQL
DC
Explanation

- JavaScript adds interactivity to webpages.
- It runs directly inside most web browsers.
- HTML, CSS, and JavaScript are the three core web technologies.

Submitted by: mcqstutor Team

Which term describes a single row of data within a database table?

AField
BRecord
CQuery
DIndex
Explanation

- A record is a single row of data in a database table.
- It represents one complete entry, like one customer.
- A record is made up of several fields.

Submitted by: mcqstutor Team

What is the technology that lets machines perform tasks that normally need human intelligence called?

AArtificial Intelligence
BCloud Computing
CVirtual Reality
DWeb Hosting
Explanation

- Artificial Intelligence lets machines perform human-like tasks.
- It is used in voice assistants and recommendations.
- AI includes areas like machine learning.

Submitted by: mcqstutor Team

What is a computer program designed to simulate a conversation with a user called?

ASearch engine
BChatbot
CWeb browser
DFirewall
Explanation

- A chatbot simulates a conversation with a user.
- It is often used for customer service.
- Some chatbots use artificial intelligence to respond.

Submitted by: mcqstutor Team

Which language is ‘Low-level’?

AJava
BPython
CC++
DAssembly language
Explanation

• Low-level languages are closer to machine code and hardware architecture.
• Assembly language uses mnemonics corresponding to machine instructions.
• High-level languages are more readable and abstracted from hardware.

Submitted by: mcqstutor Team

Which of these is a ‘Database’ management system?

AVLC Player
BMySQL
CNotepad
DPaint
Explanation

• MySQL is a popular open-source relational database management system (RDBMS).
• It uses Structured Query Language (SQL) for database operations.
• Other examples include PostgreSQL and Oracle Database.

Submitted by: mcqstutor Team

Which is a ‘High-level’ programming language?

APython
BMachine Code
CHexadecimal
DAssembly
Explanation

• High-level languages are designed for ease of use by humans.
• They use abstract concepts and require a compiler or interpreter.
• Python is highly popular for its readability and large ecosystem.

Submitted by: mcqstutor Team

What is a ‘Bug’ in a computer program?

AAn error in the code
BA software feature
CA network virus
DA hardware component
Explanation

• Bugs are defects that cause software to produce incorrect results or crash.
• The process of finding and fixing them is called 'debugging'.
• Complex systems are prone to bugs.

Submitted by: mcqstutor Team

What is the function of a ‘Compiler’s linker’?

ATranslates high-level code
BDetects syntax errors
COptimizes performance
DCombines object files into an executable
Explanation

• After compilation, source code is converted into object code.
• The linker joins these object files and library files into a final runnable program.
• It resolves external references.

Submitted by: mcqstutor Team

Which of these is a ‘Relational database’ model?

ALists
BFiles
CFolders
DTables
Explanation

• Relational databases store data in tables (rows and columns).
• They use foreign keys to relate data across tables.
• SQL is the standard language for relational databases.

Submitted by: mcqstutor Team

Which is a ‘High-level’ language for scientific computing?

AHexadecimal
BMachine code
CAssembly
DFORTRAN
Explanation

• FORTRAN (Formula Translation) was developed for scientific and engineering calculations.
• It is one of the oldest high-level languages.
• It remains used in specialized fields.

Submitted by: mcqstutor Team

What is a ‘Database’?

AAn organized collection of data
BA software program
CA type of monitor
DA network cable
Explanation

• Databases allow for efficient storage, retrieval, and updates of large data sets.
• They are managed by Database Management Systems (DBMS).
• Essential for modern software and business operations.

Submitted by: mcqstutor Team

What is ‘C++’?

AA network protocol
BAn operating system
CA high-level programming language
DA type of printer
Explanation

• C++ was created as an extension of the C language, adding classes (Object-Oriented Programming).
• It is known for its high performance and control over hardware.
• Commonly used for games, operating systems, and heavy applications.

Submitted by: mcqstutor Team

Which of these is used for ‘Version control’?

APaint
BExcel
CGit
DNotepad
Explanation

• Git tracks changes in code over time, allowing for collaboration.
• It allows developers to revert to previous versions if needed.
• Essential for team-based software engineering.

Submitted by: mcqstutor Team

Which file extension is used for ‘Python’ scripts?

A.js
B.txt
C.exe
D.py
Explanation

• .py is the standard extension for Python source files.
• It is an interpreted language.
• Python is popular for data science, AI, and automation.

Submitted by: mcqstutor Team

Which of these is a ‘Non-relational’ (NoSQL) database?

AOracle
BPostgreSQL
CMongoDB
DMySQL
Explanation

• NoSQL databases are designed for unstructured or semi-structured data.
• They offer flexibility and scalability compared to traditional relational models.
• Popular in big data applications.

Submitted by: mcqstutor Team

What is ‘Syntax’ in programming?

AThe style of the code
BThe logic of the program
CThe set of rules for writing code
DThe speed of the program
Explanation

• Syntax errors occur when code violates the language's grammar rules.
• The compiler/interpreter will reject syntactically incorrect code.
• It is the 'language' of the programming language.

Submitted by: mcqstutor Team

What is ‘Object-Oriented Programming’ (OOP)?

AScripting
BProgramming based on objects/classes
CProcedural programming
DMachine code
Explanation

• OOP focuses on bundling data and behavior into objects.
• Key concepts: encapsulation, inheritance, polymorphism.
• Major languages: Java, C++, Python, C#.

Submitted by: mcqstutor Team

Which of these is a ‘Database’ query language?

AHTML
BPython
CJava
DSQL
Explanation

• SQL (Structured Query Language) is the standard for accessing databases.
• Used for creating, reading, updating, and deleting data.
• Compatible with almost all relational database systems.

Submitted by: mcqstutor Team

What is ‘Recursion’ in programming?

AAn error
BA loop
CA function calling itself
DA data structure
Explanation

• Recursive functions solve problems by breaking them into smaller sub-problems.
• Must have a 'base case' to prevent infinite loops.
• Useful for tree and graph algorithms.

Submitted by: mcqstutor Team

What does ‘HTML’ stand for?

AHyperText Machine Language
BHighText Markup Language
CHyperlink Text Markup Language
DHyperText Markup Language
Explanation

• HTML is used to structure content on the web.
• Uses tags like

and

.
• Interpreted by web browsers.

Submitted by: mcqstutor Team