Important Mcqs Cs
Important Mcqs Cs
(b) IndexError
Reason (R): The finally block is designed for cleanup activities that must occur
regardless of error states.
7. Which block contains code that is executed only if no exception is raised in the try
block?
(b) else
(a) FileNotFoundError
10. What happens if an exception is raised and no matching except block is found?
11. The assert statement raises an exception when its expression evaluates to:
(b) False
12. Which clause can be used to catch any exception not caught by previous except
blocks?
(b) ValueError
20. The process of creating an exception object and handing it to the runtime system is
called:
Throwing exception
21. Which statement is used to test an expression and raise an AssertionError if it fails?
(c) assert
(c) SyntaxError
29. The code that is designed to execute when a specific exception is raised is called:
30. If an unhandled exception occurs and a finally block exists, what happens?
IndentationError
37. When a syntax error is found in a script file, how is it often indicated?
38. What does the call stack represent during exception handling?
43. Which keyword is used to define a block of code to test for errors?
(c) try
2. The special character that marks the end of a line in a text file is called:
[Link] will likely happen if you open a binary file (like an image) using a text editor like
Notepad?
4. The function used to open a file in Python is: (a) create() (b) access() (c) open() (d)
handle()
7. Which file mode opens a file for both reading and writing, and places the file object at
the beginning?
8. Which file mode opens a file for writing only, and overwrites the file if it already
exists?
9. If you open an existing file in append mode (a), where is the file object initially
positioned?
(a) Beginning of the file (b) Middle of the file (c) End of the file (d) At the last modified
byte
(c) Frees system resources and ensures data is saved (d) Changes the file mode
11. What is the primary advantage of using the with clause to open a file?
12. If you open a new file in write mode (w) and write data, then open the same file again
in write mode (w) and write new data, what happens to the first data?
(c) It is overwritten/lost
13. The write() method returns: (c) The number of characters written (d) None
14. Before writing numeric data to a text file using write(), it must be:
15. Which method is used to write multiple strings from an iterable (like a list) to a file?
(a) 10 lines (b) 10 words (c) 10 bytes/characters (d) The entire file if it's 10 bytes or less
18. If you call read() without any arguments, it will: (a) Read one line (b) Read one
character (c) Read the entire file content (d) Cause an error
20. To read all lines of a file into a list where each element is a line (including newline),
you use:
(d) readlines()
(a) Beginning of file (0) (b) Current position(1) (c) End of file (2)
24. The process of converting a Python object into a byte stream for storage is called:
(c) pickle
26. To write (dump) a Python object to a binary file, you open the file in mode:
27. To read (load) a Python object from a binary file, you use:
(c) [Link]()
28. When reading multiple objects from a binary file using [Link](), how is the end
of file typically handled?
29. Which attribute of a file object tells you if the file is closed?
(c) [Link]
30. If a file is opened in 'r' mode and the file does not exist, what happens?
31. What is the purpose of the flush() method mentioned in the context of writing files?
(b) To clear the internal buffer and write data to the file immediately
32. In a text file, contents are commonly separated by all of the following EXCEPT:
(a) Whitespace (b) Comma (,) (c) Tab (\t) (d) Semicolon (;)
34. Which method is used to find the size of the binary file in bytes in Program 2-8?
STACK
(c) Linear
(b) LIFO
4. The end of the stack from where elements are added or removed is called ________.
(c) TOP
(b) PUSH
(c) POP
(b) Underflow
(b) Overflow
(c) List
(c) append()
(b) pop()
12. The notation in which operators are written between operands is called ________.
(c) Infix
13. The notation in which operators are written before operands is called ________.
(d) Prefix
14. The notation in which operators are written after operands is called ________.
(c) Postfix
16. For conversion from infix to postfix, a stack is used to store ________.
(b) Operators
(a) Operators
(b) Stack
(a) Stack
(b) len()
(b) Is dynamic
34. The time complexity of PUSH and POP operations in a stack implemented using list
is ________.
(b) O(1)
37. In a stack, the element that is inserted first will be removed ________.
(b) Last
38. In a stack, the element that is inserted last will be removed ________.
(a) First
52. Assertion (A): Trying to POP from an empty stack causes underflow.
Reason (R): Underflow is a condition when stack is empty and we try to delete.
Reason (R): List provides append() and pop() methods which work at the same end.
QUEUE
(b) Head
(d) DEQUEUE
(b) Underflow
7. In Python, which list method is typically used to implement the enqueue operation?
(c) append(element)
8. In Python, which list method is typically used to implement the dequeue operation?
(b) pop(0)
11
9. Which data structure allows insertion and deletion from both ends?
(b) Queue
10. If insertion and deletion in a Deque are performed from the same end, it behaves like
a:
(b) Stack
11. If insertion and deletion in a Deque are performed from opposite ends, it behaves like
a:
(a) Queue
(c) insertFront
(c) Tail
18. What is the time complexity of the dequeue operation using pop(0) on a Python list of
size n?
(c) O(n)
20. In the algorithm to check for palindrome using a deque, characters are initially
inserted:
Reason (R): In a queue, insertion happens at the rear and deletion happens at the front.
Reason (R): A Stack requires insertion and deletion at the same end.
24. For the queue operations: enqueue(A), enqueue(B), dequeue(), enqueue(C), dequeue().
What is the sequence of elements removed?
12
(b) A, B
26. In Python, to read the last element of a list myDeque without removing it, you would
use:
d) [Link]()
29. Which method adds an element to the front of a deque in the provided Python
implementation?
31. What will be the output of peek() after: enqueue(10), enqueue(20), dequeue()?
(b) 20
34. When implementing a queue with a Python list, why might we not need an isFull()
function?
(b) Because Python lists are dynamic and don't have a fixed size
35. For a deque containing elements [1, 2, 3] (Front=1, Rear=3), what does getRear()
return?
(c) 3
37. If you use only insertRear and deletionFront operations on a deque, it functions as a:
(b) Queue
39. In the palindrome checking algorithm using a deque, when do you stop and declare
the string as a palindrome?
(b) When the deque becomes empty or has one character left
41. Elements 'P', 'Q', 'R' are enqueued in that order. After one dequeue, what is at the
front?
(b) Q
13
44. Which Python function, when used on a list-based queue, corresponds to the
deletionRear() operation on a deque?
(c) pop()
46. The append() method in a list always adds the element at the:
(c) End
52. Assertion (A): The enqueue operation in a queue is always performed at the Rear end.
Reason (R): The Rear end of a queue is also called the Tail.
53. Assertion (A): A Deque can function as both a Stack and a Queue.
Reason (R): A Deque allows insertion and deletion of elements at both its ends.
SORTING
1. What is sorting?
3. In Bubble Sort, each full iteration through the list is called a ______.
(b) pass
4. For a list of n elements, how many passes does Bubble Sort make in the worst case?
(b) n-1
14
5. In Bubble Sort, after each pass, the largest element moves to the ______.
(c) end
6. What is the time complexity of Bubble Sort, Selection Sort and Insertion Sort?
(c) O(n²)
(b) sorted
(b) n-1
10. In Selection Sort, the smallest element is swapped with the ______ element of the
unsorted list.
(c) leftmost
(a) O(1)
(a) O(n)
(b) O(n2)
20. Which sorting technique selects the smallest element and swaps it?
21. Which sorting technique inserts an element into its correct position by shifting?
27. In Selection Sort, after each pass, the size of the unsorted list ______.
(b) decreases
30. The number of swaps in Bubble Sort is ______ compared to Selection Sort.
(b) more
DATABASE CONCEPTS
5. When the same data maintained in different files do not match, it is called?
6. The difficulty in writing new application programs to retrieve data from multiple
isolated files of different formats is due to?
7. If the structure of a data file is changed, all application programs accessing it need to
be changed. This is known as?
11. Restrictions on the type of data that can be inserted into a table column are called?
12. Data about the data, such as schema and constraints stored by the DBMS, is called?
(b) Meta-data
13. The state or snapshot of the database with actual data at a particular time is called?
(c) Query
16. The underlying component used by a DBMS to create a database and handle queries
is the?
(c) Relation
(c) Cardinality
(b) Degree
17
(b) Cardinality
24. Which property of a relation states that each attribute must have a unique name?
25. Which property of a relation states that the sequence of tuples is immaterial?
26. The value used to represent unknown or non-applicable data in an attribute is?
(c) NULL
27. An attribute (or set) that can uniquely identify tuples in a relation is a?
29. The candidate keys not chosen as the primary key are called?
31. An attribute in one relation whose value is derived from the primary key of another
relation is a?
32. The relation that contains the foreign key is called the?
(c) Constraints
46. Which of the following best describes a Database Management System (DBMS)?
(c) Relation
50. Centralized storage in a DBMS can increase the risk of data loss from a single point
of failure. This is a limitation related to?
3. When the same data in different files do not match, it results in data data
inconsistency
4. The lack of links between related files in a file system leads to data isolation
5. If changing a file's structure requires changing all accessing programs, it exhibits data
dependency
9. Data about the data stored in the database catalog is called Metadata
10. The snapshot of a database with actual data at any time is a database Instance
13. The most commonly used data model is the Relational data model.
DATA COMMUNICATION
2. In data communication, the path through which the message travels is called:
19
(b) Hertz
(a) Simplex
7. In which communication mode can both devices send and receive data simultaneously?
(c) Full-duplex
(b) Packets
(c) Piconet
(b) Wi-Fi
(b) 2G
(b) HTTP
(b) Bandwidth
25. Which mobile generation supports interactive multimedia and high-speed Internet?
(c) 4G
21
(b) Nodes
27. Which protocol ensures flow control between sender and receiver?
(c) TCP
28. Which wireless technology is used for short-distance device connectivity like mouse
and keyboard?
(b) Bluetooth
(c) SMTP
(b) TCP
33. The outer conductor in coaxial cable is usually made of: (a) Copper mesh
34. Which protocol defines how two devices authenticate each other for a direct link?
(c) PPP
35. Which component of data communication is also called the transmission media?
(d) Channel
22
COMPUTER NETWORK
4. Which term refers to any device that can receive, create, store, or send data in a
network?
(b) Node
(c) Packets
6. The research project commissioned by the U.S. Department of Defence that led to the
development of the Internet was:
7. Who developed network messaging or Email and introduced the use of the '@' symbol?
(c) TCP/IP
9. The birth of the World Wide Web (WWW) is attributed to the development of HTML
and URL by:
10. A network that connects personal devices within an approximate range of 10 metres
is called a:
(d) PAN
11. Which type of network can be formed by connecting two smartphones via Bluetooth?
12. A network covering a single room, office floor, or university campus is typically a:
23
(b) LAN
13. Which set of rules decides how computers connect via cables in a LAN?
(c) Ethernet
(c) MAN
17. The largest Wide Area Network (WAN) that connects billions of devices globally is
the:
(c) Internet
18. A device used for conversion between analog signals and digital bits is called a:
(b) Modem
19. Which device acts as an interface between a computer and a wired network and has a
unique MAC address?
20. The unique hardware address associated with a Network Interface Card is the:
(d) RJ45
22. Which analog device regenerates weakened signals on a cable to extend transmission
distance?
(c) Repeater
23. A network device that broadcasts data received on any port to all other ports is a:
(c) Hub
24
25. Which device extracts the destination address from a data packet and forwards it
selectively to the intended device?
(c) Switch
26. A device that connects a local area network to the internet and can analyze/repackage
data is a:
(c) Router
27. The entry and exit point of a network, through which all data must pass, is the:
(c) Gateway
28. For simple home internet connectivity, the gateway is usually the:
(b) Topology
(d) Mesh
31. Which topology is known for being highly reliable because the failure of one node
does not break communication between others?
(d) Mesh
(c) Unidirectional
33. Which topology uses a single backbone cable shared by all nodes?
(c) Bus
37. A hierarchical topology with multiple branches, each containing basic topologies, is
called:
25
39. The first six hexadecimal digits of a MAC address represent the:
40. Which address can change if a node is moved from one network to another?
(d) IP Address
44. The collection of interlinked web pages and resources accessible over the Internet is
the:
46. The more secure version of the protocol used to retrieve web pages is:
(c) HTTPS
47. The process of converting a domain name to its corresponding IP address is called:
49. How many root DNS servers are there at the top level of the hierarchy?
(c) 13
50. The organization that maintains the list of DNS root servers is:
(c) IANA
26
SECURITY ASPECTS
(b) Worm
(b) Spyware
15. Which intrusion method floods the network to overwhelm detection systems?
(b) Eavesdropping
20. Which malware is named after a deceptive gift from Greek history?
(c) Trojan
21. What type of hacker hacks for fun or challenge without malicious intent?
(b) Keylogger
(c) HTTPS
(b) Sniffing
(b) Adware
(c) Signature-based
34. What should you look for in a URL when entering sensitive information?
(b) https://
36. Which hacker type is employed to find and fix security flaws?
38. Which network threat involves capturing traffic for later analysis?
(b) Snooping
(c) Ransomware
(c) Trojan
SQL
Char(10)
NOT NULL
5. Which statement permanently removes a table and all its data from the database?
DROP TABLE
INSERT INTO
8. When inserting data, text and date values should be enclosed in:
Single quotes(‘ ‘ )
WHERE
IS NULL
ROUND(N)
16. Which function returns the current system date and time?
NOW( )
18. Which relational algebra operation returns all possible combinations of rows from
two tables?
Cartesian product
1. ______ is the most popular query language used by major relational DBMS.
5. A column which can uniquely identify each row in a table is called a _______.
5. The _____statement is part of DML and is used to add new records to a table.