wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

MidtermExam-DSA-MakScie

Total questions: 100

Worksheet time: 2hrs 40mins

Name
Class
Date
1.

Which of the following is a mutable data type in Python?

a)

tuple

b)

string

c)

list

d)

frozenset

2.

What is the output of print(2 ** 3 ** 2)?

a)

64

b)

512

c)

16

d)

81

3.

Which of the following is not a valid Python identifier?

a)

my_var

b)

_data123

c)

2value

d)

value_2

4.

What does the is operator compare?

a)

Values of two objects

b)

Types of two objects

c)

Memory addresses (object identity)

d)

Length of objects

5.

Which of the following will raise an error?

a)

int("123")

b)

int("12.3")

c)

float("12.3")

d)

str(123)

6.

What will bool([]) return?

a)

True

b)

False

c)

Error

d)

None

7.

Which function returns the number of items in an iterable?

a)

count()

b)

len()

c)

size()

d)

num()

8.

Which of the following data types is immutable?

a)

list

b)

dictionary

c)

string

d)

set

9.

What is the default return value of a Python function without return statement?

a)

0

b)

None

c)

False

d)

""

10.

What is the output of print(type(lambda x: x))?

a)

b)

c)

d)

11.

Which of the following is not a Python loop construct?

a)

for

b)

do…while

c)

while

d)

nested for

12.

The pass statement is used to:

a)

Terminate a loop

b)

Skip iteration

c)

Define a placeholder with no action

d)

Raise an error

13.

Which of the following is used to handle exceptions?

a)

try-except

b)

do-catch

c)

check-except

d)

try-catch

14.

What will print(3 < 2 < 1) output?

a)

True

b)

False

c)

Error

d)

None

15.

What does dir() function return?

a)

Only user-defined variables

b)

List of methods and attributes

c)

Object type

d)

Object memory ID

16.

Which of these functions converts object into a string form?

a)

str()

b)

repr()

c)

Both A and B

d)

tostring()

17.

Which of the following collections has unique elements?

a)

list

b)

tuple

c)

set

d)

string

18.

Which Python keyword creates an anonymous block of code?

a)

block

b)

def

c)

lambda

d)

anon

19.

Which of these is NOT an abstract data type (ADT)?

a)

List

b)

Graph

c)

Dictionary

d)

Compiler

20.

Which operation is fastest in arrays compared to linked lists?

a)

Random access

b)

Deletion

c)

Insertion

d)

Traversal

21.

Which of these best describes "dynamic memory allocation"?

a)

Memory size is fixed at compile time

b)

Memory is allocated at runtime

c)

Memory cannot be freed

d)

Memory size is infinite

22.

What is the degree of a node in a tree?

a)

Number of children

b)

Number of parents

c)

Number of siblings

d)

Level number

23.

In a graph, if every edge has a direction, it is called:

a)

Undirected graph

b)

Directed graph

c)

Weighted graph

d)

Rooted graph

24.

Which of the following is a hierarchical data structure?

a)

Stack

b)

Queue

c)

Binary tree

d)

Array

25.

Which application typically uses a stack?

a)

Breadth-first search

b)

Expression evaluation

c)

Print queue

d)

Call center request handling

26.

A binary tree of height h can have at most:

a)

h nodes

b)

2^h nodes

c)

2^(h+1) - 1 nodes

d)

h^2 nodes

27.

Which of the following denotes constant time complexity?

a)

O(1)

b)

O(n)

c)

O(log n)

d)

O(n^2)

28.

What is the time complexity of accessing an element in an array by index?

a)

O(1)

b)

O(n)

c)

O(log n)

d)

O(n log n)

29.

Time complexity of linear search in worst case is:

a)

O(1)

b)

O(log n)

c)

O(n)

d)

O(n^2)

30.

Best-case complexity of binary search is:

a)

O(n)

b)

O(log n)

c)

O(1)

d)

O(n log n)

31.

Which algorithm has O(n log n) time complexity?

a)

Bubble sort

b)

Merge sort

c)

Linear search

d)

Selection sort

32.

Worst-case complexity of quicksort is:

a)

O(n log n)

b)

O(n^2)

c)

O(n)

d)

O(1)

33.

Which complexity class grows faster?

a)

O(n)

b)

O(log n)

c)

O(2^n)

d)

O(n log n)

34.

Which operation on stack has O(1) complexity?

a)

Traversal

b)

Push

c)

Search

d)

Sort

35.

Time complexity of inserting at the beginning of a linked list is:

a)

O(1)

b)

O(log n)

c)

O(n)

d)

O(n^2)

36.

Time complexity of enqueue operation in a queue is:

a)

O(1)

b)

O(n)

c)

O(log n)

d)

O(n log n)

37.

Which of these is the fastest growth?

a)

O(n)

b)

O(n^2)

c)

O(2^n)

d)

O(n log n)

38.

Which complexity is desirable for efficient algorithms?

a)

O(n^2)

b)

O(n^3)

c)

O(1)

d)

O(2^n)

39.

The Big O of traversing all elements in a linked list is:

a)

O(1)

b)

O(n)

c)

O(log n)

d)

O(n log n)

40.

Which has a better complexity: O(n log n) vs O(n^2)?

a)

O(n^2)

b)

O(n log n)

c)

Both equal

d)

Cannot determine

41.

Which of the following creates a list in Python?

a)

list = {}

b)

list = []

c)

list = ()

d)

list = set()

42.

Which function adds an element at the end of a list?

a)

append()

b)

insert()

c)

extend()

d)

add()

43.

Which function adds an element at the end of a list?

a)

append()

b)

insert()

c)

extend()

d)

add()

44.

What will print([1,2,3] * 2) output?

a)

[1,2,3,1,2,3]

b)

[2,4,6]

c)

[1,2,3,2]

d)

Error

45.

Which method removes the last element from a list?

a)

remove()

b)

delete()

c)

pop()

d)

discard()

46.

What is the result of len([[],[1],[1,2]])?

a)

2

b)

3

c)

4

d)

5

47.

Which of the following creates a shallow copy of a list?

a)

list1 = list2

b)

list1 = list2.copy()

c)

list1 = copy.deepcopy(list2)

d)

list1 = (list2)

48.

What does list(range(3)) return?

a)

[0,1,2]

b)

[1,2,3]

c)

[0,1,2,3]

d)

Error

49.

Which method extends a list with another iterable?

a)

append()

b)

insert()

c)

extend()

d)

merge()

50.

What will sum([1,2,3,4]) return?

a)

10

b)

24

c)

1234

d)

[10]

51.

Which method sorts a list in place?

a)

sorted()

b)

sort()

c)

order()

d)

arrange()

52.

What will min([3,5,2,7]) output?

a)

7

b)

2

c)

3

d)

5

53.

Which indexing returns the last item of a list?

a)

list[-1]

b)

list[last]

c)

list[len(list)]

d)

list[]

54.

What is the output of len([1, [2, 3]])?

a)

2

b)

3

c)

4

d)

Error

55.

What will list("Python") return?

a)

['Python']

b)

['P','y','t','h','o','n']

c)

('P','y','t','h','o','n')

d)

Error

56.

Which method removes element by value?

a)

pop()

b)

remove()

c)

discard()

d)

delete()

57.

Which method converts string to lowercase?

a)

tolower()

b)

lower()

c)

casefold()

d)

Both B and C

58.

Strings in Python are:

a)

Mutable

b)

Immutable

c)

Fixed length

d)

None

59.

What will "hello".capitalize() return?

a)

hello

b)

HELLO

c)

Hello

d)

Error

60.

Which operator concatenates strings?

a)

*

b)

+

c)

&

d)

concat()

61.

What will "python".find("t") return?

a)

1

b)

2

c)

3

d)

-1

62.

Which method removes whitespace from both ends?

a)

strip()

b)

trim()

c)

ltrim()

d)

clean()

63.

What will "abc" * 3 output?

a)

abcabcabc

b)

abc3

c)

['abc','abc','abc']

d)

Error

64.

"Python".startswith("Py") returns:

a)

True

b)

False

c)

None

d)

Error

65.

Which method splits a string into a list?

a)

partition()

b)

split()

c)

slice()

d)

break()

66.

What will "".join(['a','b','c']) return?

a)

['a','b','c']

b)

abc

c)

a b c

d)

Error

67.

In a singly linked list, each node contains:

a)

Data only

b)

Data + two pointers

c)

Data + one pointer

d)

Pointer only

68.

Time complexity of traversing a singly linked list is:

a)

O(1)

b)

O(n)

c)

O(log n)

d)

O(n log n)

69.

Inserting a node at the beginning of a singly linked list is:

a)

O(1)

b)

O(n)

c)

O(log n)

d)

O(n^2)

70.

Which pointer in singly linked list is NULL at the end?

a)

head

b)

tail

c)

next of last node

d)

data of last node

71.

Which of the following is disadvantage of singly linked list?

a)

Requires more memory

b)

Cannot traverse backward

c)

No random access

d)

All of the above

72.

Deleting the head node in singly linked list requires:

a)

O(1) time

b)

O(n) time

c)

O(log n) time

d)

O(n^2) time

73.

Searching for an element in a singly linked list takes:

a)

O(1)

b)

O(n)

c)

O(log n)

d)

O(n log n)

74.

What is stored in the last node of a singly linked list?

a)

First node's address

b)

NULL

c)

Random address

d)

Data only

75.

Which operation is expensive in singly linked list compared to array?

a)

Traversal

b)

Insertion at beginning

c)

Random access

d)

Deletion

76.

In a singly linked list, to delete a node we need access to:

a)

Head pointer only

b)

Node pointer only

c)

Previous node pointer

d)

Tail pointer only

77.

Which traversal is possible in singly linked list?

a)

Forward only

b)

Backward only

c)

Both forward and backward

d)

Random

78.

Which of these operations requires O(n) time in singly linked list?

a)

Insert at head

b)

Delete head

c)

Access nth node

d)

Traverse one step

79.

In a doubly linked list, each node contains:

a)

Data + one pointer

b)

Data + two pointers

c)

Data only

d)

Pointer only

80.

Which of the following supports traversal in both directions?

a)

Singly linked list

b)

Doubly linked list

c)

Circular linked list

d)

Array

81.

Extra memory in doubly linked list is used for:

a)

Tail pointer

b)

Next and Previous pointer

c)

Head pointer

d)

Data duplication

82.

Which operation is easier in doubly linked list compared to singly?

a)

Insertion at beginning

b)

Backward traversal

c)

Deletion of a node

d)

All of the above

83.

Deleting a node in doubly linked list requires:

a)

Updating only next pointer

b)

Updating only previous pointer

c)

Updating both next and previous pointers

d)

No update

84.

Time complexity of insertion at head in doubly linked list is:

a)

O(1)

b)

O(n)

c)

O(log n)

d)

O(n^2)

85.

Which pointer in doubly linked list points backward?

a)

prev

b)

next

c)

head

d)

tail

86.

What is the last node's next pointer in doubly linked list?

a)

Points to first node

b)

NULL

c)

Points to middle node

d)

Random value

87.

Which is disadvantage of doubly linked list?

a)

Requires extra memory

b)

Cannot traverse backward

c)

Random access is possible

d)

Deletion is complex

88.

Which operation is O(n) in doubly linked list?

a)

Insert at head

b)

Delete head

c)

Search for element

d)

Insert at tail

89.

Which linked list requires more memory per node?

a)

Singly

b)

Doubly

c)

Both equal

d)

None

90.

Which traversal is possible in doubly linked list?

a)

Forward only

b)

Backward only

c)

Both forward and backward

d)

None

91.

If a doubly linked list is empty, both head and tail pointers are:

a)

Pointing to NULL

b)

Pointing to each other

c)

Pointing to garbage

d)

Pointing to first node

92.

class Node:

def init(self, data):

self.data = data

self.next = None

n1 = Node(10)

print(n1.data, n1.next)

What will be the output?

(a)  

93.

What is printed?

n1 = Node(5)

n2 = Node(7)

n1.next = n2

print(n1.next.data)

(a)  

94.

What is the output?

head = Node(1)

head.next = Node(2)

head.next.next = Node(3)

temp = head

while temp:

print(temp.data, end=" ")

temp = temp.next

(a)  

95.

What is the new head value?

head = Node(20)

new_node = Node(10)

new_node.next = head

head = new_node

print(head.data)

(a)  

96.

What is printed?

head = Node(1)

head.next = Node(2)

head.next.next = Node(3)

new_node = Node(4)

temp = head

while temp.next:

temp = temp.next

temp.next = new_node

print(temp.next.data)

(a)  

97.

How many nodes are there?

head = Node(1)

head.next = Node(2)

head.next.next = Node(3)

count = 0

temp = head

while temp:

count += 1

temp = temp.next

print(count)

(a)  

98.

What remains as head?

head = Node(100)

head.next = Node(200)

head = head.next

print(head.data)

(a)  

99.

What is printed?

head = Node(1)

head.next = Node(2)

head.next.next = Node(3)

temp = head

while temp.next:

temp = temp.next

print(temp.data)

(a)  

100.

What is printed?

key = 5

head = Node(3)

head.next = Node(5)

head.next.next = Node(7)

temp = head

found = False

while temp:

if temp.data == key:

found = True

temp = temp.next

print(found)

(a)