Explore topic-wise MCQs in Python.

This section includes 114 Mcqs, each offering curated multiple-choice questions to sharpen your Python knowledge and support exam preparation. Choose a topic below to get started.

1.

What’s wrong with this code which returns xor of two nodes address ?

A. nothing wrong. everything is fine
B. type casting at return is missing
C. parameters are wrong
D. total logic is wrong
Answer» C. parameters are wrong
2.

How would you delete a node in the singly linked list? The position to be deleted is given.

A. a
B. b
C. c
D. d
Answer» B. b
3.

Which of the following piece of code has the functionality of counting the number of elements in the list?

A. a
B. b
C. c
D. d
Answer» B. b
4.

How do you insert an element at the beginning of the list?

A. a
B. b
C. c
D. d
Answer» B. b
5.

What is the functionality of the following piece of code? Select the most appropriate

A. Print success if a particular element is not found
B. Print fail if a particular element is not found
C. Print success if a particular element is equal to 1
D. Print fail if the list is empty
Answer» C. Print success if a particular element is equal to 1
6.

How do you count the number of elements in the circular linked list?

A. a
B. b
C. c
D. d
Answer» B. b
7.

What is the output of following function for start pointing to first node of following linked list?

A. 1 4 6 6 4 1
B. 1 3 5 1 3 5
C. 1 2 3 5
D. 1 3 5 5 3 1
Answer» E.
8.

What does the following function do for a given Linked List with first node as head?

A. Prints all nodes of linked lists
B. Prints all nodes of linked list in reverse order
C. Prints alternate nodes of Linked List
D. Prints alternate nodes in reverse order
Answer» C. Prints alternate nodes of Linked List
9.

The following function reverse() is supposed to reverse a singly linked list. There is one line missing at the end of the function.What should be added in place of “/*ADD A STATEMENT HERE*/”, so that the function correctly reverses a linked list.

A. *head_ref = prev;
B. *head_ref = current;
C. *head_ref = next;
D. *head_ref = NULL;
Answer» B. *head_ref = current;
10.

The following C function takes a single-linked list of integers as a parameter and rearranges the elements of the list.The function is called with the list containing the integers 1, 2, 3, 4, 5, 6, 7 in the given order. What will be the contents of the list after the function completes execution?

A. 1, 2, 3, 4, 5, 6, 7
B. 2, 1, 4, 3, 6, 5, 7
C. 1, 3, 2, 5, 4, 7, 6
D. 2, 3, 4, 5, 6, 7, 1
Answer» C. 1, 3, 2, 5, 4, 7, 6
11.

The following C function takes a simply-linked list as input argument.It modifies the list by moving the last element to the front of the list and returns the modified list. Some part of the code is left blank.Choose the correct alternative to replace the blank line.

A. q = NULL; p->next = head; head = p;
B. q->next = NULL; head = p; p->next = head;
C. head = p; p->next = q; q->next = NULL;
D. q->next = NULL; p->next = head; head = p;
Answer» E.
12.

What is the functionality of the following code?

A. Inserting a node at the beginning of the list
B. Deleting a node at the beginning of the list
C. Inserting a node at the end of the list
D. Deleting a node at the end of the list
Answer» D. Deleting a node at the end of the list
13.

Which of the following performs deletion of the last element in the list? Given below is the Node class.

A. a
B. b
C. c
D. d
Answer» B. b
14.

Choose the code snippet which inserts a node to the head of the list?

A. a
B. b
C. c
D. d
Answer» B. b
15.

What is the functionality of the following code? Choose the most appropriate answer.

A. Return data from the end of the list
B. Returns the data and deletes the node at the end of the list
C. Returns the data from the beginning of the list
D. Returns the data and deletes the node from the beginning of the list
Answer» C. Returns the data from the beginning of the list
16.

Consider the following definition in c programming language.Which of the following c code is used to create new node?

A. ptr = (NODE*)malloc(sizeof(NODE));
B. ptr = (NODE*)malloc(NODE);
C. ptr = (NODE*)malloc(sizeof(NODE*));
D. ptr = (NODE)malloc(sizeof(NODE));
Answer» B. ptr = (NODE*)malloc(NODE);
17.

Are the below statements true about skiplists?In a sorted set of elements skip lists can implement the below operations i.given a element find closest element to the given value in the sorted set in O(logn) ii.find the number of elements in the set whose values fall a given range in O(logn)

A. True
B. False
C. May be
D. Can't say
Answer» B. False
18.

Given the Node class implementation, select one of the following that correctly inserts a node at the tail of the list.

A. a
B. b
C. c
D. d
Answer» B. b
19.

Standard approach for implementation of a list is/are of

A. 1 type
B. 2 types
C. 3 types
D. 4 types
Answer» C. 3 types
20.

Important concept related to lists is of

A. Location
B. Position
C. Arrays
D. Pointers
Answer» C. Arrays
21.

The worst case time required to search a given element in a sorted linked list of length n is

A. O(1)
B. O(n)
C. O(log2 n)
D. O(n log2 n)
Answer» C. O(log2 n)
22.

Beginnning of any list is called its

A. Pointer
B. Head
C. Initializer
D. Automator
Answer» C. Initializer
23.

Assume there is a free list which contains nodes and is filled with a value if it is already assigned and the value will be the size of requested block else will be 0. The below code represents what ?

A. code for first fit
B. code for best fit
C. code for worst fit
D. none of the mentioned
Answer» B. code for best fit
24.

Which of the following piece of code removes the node from a given position?

A. a
B. b
C. c
D. d
Answer» B. b
25.

How do you insert a node at the beginning of the list?

A. a
B. b
C. c
D. d
Answer» B. b
26.

Key design decision embodied in this ADT is support for concept of a

A. Partition
B. Parameter
C. Current position
D. Current element
Answer» D. Current element
27.

Consider the following doubly linked list: head-1-2-3-4-5-tailWhat will be the list after performing the given sequence of operations?

A. head-0-1-2-3-4-5-6-tail
B. head-1-2-3-4-5-6-tail
C. head-6-1-2-3-4-5-0-tail
D. head-0-1-2-3-4-5-tail
Answer» D. head-0-1-2-3-4-5-tail
28.

What is the functionality of the following piece of code?

A. Return the element at the tail of the list but do not remove it
B. Return the element at the tail of the list and remove it from the list
C. Return the last but one element from the list but do not remove it
D. Return the last but one element at the tail of the list and remove it from the list
Answer» C. Return the last but one element from the list but do not remove it
29.

In a linked list array, objects are referred to as

A. Instances
B. Attributes
C. Nodes
D. Entity
Answer» D. Entity
30.

A pointer that is used to keep last link of list is called

A. Head
B. Initiator
C. Tail
D. Terminator
Answer» D. Terminator
31.

How are free blocks linked together mostly and in what addressing order?

A. circular linked list and increasing addressing order
B. linked list and decreasing addressing order
C. linked list and in no addressing order
D. none of the mentioned
Answer» B. linked list and decreasing addressing order
32.

First link node of list is accessed from a pointer named

A. Tail
B. Head
C. Terminator
D. Initiator
Answer» C. Terminator
33.

Consider an implementation of unsorted singly linked list. Suppose it has its representation with a head pointer only.Given the representation, which of the following operation can be implemented in O(1) time?i) Insertion at the front of the linked listii) Insertion at the end of the linked listiii) Deletion of the front node of the linked listiv) Deletion of the last node of the linked list

A. I and II
B. I and III
C. I, II and III
D. I, II and IV
Answer» C. I, II and III
34.

Accessing free list very frequently for wide range of addresses can lead to

A. paging
B. segmentation fault
C. memory errors
D. cache problems
Answer» B. segmentation fault
35.

The time required to search an element in a linked list of length n is

A. O(1)
B. O(n)
C. 0 (n2)
D. O(log2 n)
Answer» C. 0 (n2)
36.

Which of the following statements are true ?i) practical application of XOR linked lists are in environments with limited space requirements, such as embedded devices.ii)xor lists are not suitable because most garbage collectors will fail to work properly with classes or structures that don’t contain literal pointersiii)in order to calculate the address of the next node you need to remember the address of the previous nodeiv)xor lists are much efficient than single, doubly linked lists and arrays

A. i, ii, iii, iv
B. i, ii, iii
C. i, ii
D. i
Answer» C. i, ii
37.

Number of elements stored in any list is called its

A. Positioning
B. Sequencing
C. Model
D. Length
Answer» E.
38.

End of any list is called its

A. Tail
B. Terminator
C. Aborter
D. Committer
Answer» B. Terminator
39.

A linked list is made up of a set of objects known as

A. Nodes
B. Arrays
C. Entities
D. Instances
Answer» B. Arrays
40.

If in a linked list address of first node is 1020 then what will be the address of node at 5th position ?

A. 1036
B. 1028
C. 1038
D. None of these
Answer» E.
41.

Definition of a list is to be

A. Finite
B. Inifinte
C. No-limit
D. Empty
Answer» B. Inifinte
42.

A linked list contains a list pointer variable _____that stores the address of the first node of the list.

A. Start
B.
C. Next
D. Empty list
Answer» B.
43.

A situation where the user tries to delete a node from an empty linked list is termed as___________.

A. Underflow
B. Overflow
C. Pointers
D. None of the above
Answer» B. Overflow
44.

While creating a linked list or inserting an element into a linked list, whenever a request for the new node arrives, the memory manager searches through the ------------for the block of desired size.

A. Free pool
B. Memory bank
C. Free storage list
D. None of the above
Answer» D. None of the above
45.

As memory is allocated dynamically to a linked list, a new node can be inserted anytime in the list. For this, the memory manager maintains a special linked list known as___________.

A. Free pool
B. Memory bank
C. Free storage list
D. All of the above
Answer» D. All of the above
46.

What does creating a node mean?

A. Defining its structure
B. Allocating memory to it
C. Initialization
D. All of the above
Answer» E.
47.

In doubly linked lists, traversal can be performed?

A. Only in forward direction
B. Only in reverse direction
C. In both directions
D. None of the above
Answer» D. None of the above
48.

A variation of linked list is circular linked list, in which the last node in the list points to first node of the list. One problem with this type of list is?

A. It waste memory space since the pointer head already points to the first node and thus the list node does not need to point to the first node.
B. It is not possible to add a node at the end of the list.
C. It is difficult to traverse the list as the pointer of the last node is now not NULL
D. All of above
Answer» D. All of above
49.

A variant of linked list in which last node of the list points to the first node of the list is?

A. Singly linked list
B. Doubly linked list
C. Circular linked list
D. Multiply linked list
Answer» D. Multiply linked list
50.

In a circular linked list

A. Components are all linked together in some sequential manner.
B. There is no beginning and no end.
C. Components are arranged hierarchically.
D. Forward and backward traversal within the list is permitted.
Answer» C. Components are arranged hierarchically.