Font size
WorksheetsMidtermExam-DSA-MakScie
Total questions: 100
Worksheet time: 2hrs 40mins
Which of the following is a mutable data type in Python?
tuple
string
list
frozenset
What is the output of print(2 ** 3 ** 2)?
64
512
16
81
Which of the following is not a valid Python identifier?
my_var
_data123
2value
value_2
What does the is operator compare?
Values of two objects
Types of two objects
Memory addresses (object identity)
Length of objects
Which of the following will raise an error?
int("123")
int("12.3")
float("12.3")
str(123)
What will bool([]) return?
True
False
Error
None
Which function returns the number of items in an iterable?
count()
len()
size()
num()
Which of the following data types is immutable?
list
dictionary
string
set
What is the default return value of a Python function without return statement?
0
None
False
""
What is the output of print(type(lambda x: x))?
Which of the following is not a Python loop construct?
for
do…while
while
nested for
The pass statement is used to:
Terminate a loop
Skip iteration
Define a placeholder with no action
Raise an error
Which of the following is used to handle exceptions?
try-except
do-catch
check-except
try-catch
What will print(3 < 2 < 1) output?
True
False
Error
None
What does dir() function return?
Only user-defined variables
List of methods and attributes
Object type
Object memory ID
Which of these functions converts object into a string form?
str()
repr()
Both A and B
tostring()
Which of the following collections has unique elements?
list
tuple
set
string
Which Python keyword creates an anonymous block of code?
block
def
lambda
anon
Which of these is NOT an abstract data type (ADT)?
List
Graph
Dictionary
Compiler
Which operation is fastest in arrays compared to linked lists?
Random access
Deletion
Insertion
Traversal
Which of these best describes "dynamic memory allocation"?
Memory size is fixed at compile time
Memory is allocated at runtime
Memory cannot be freed
Memory size is infinite
What is the degree of a node in a tree?
Number of children
Number of parents
Number of siblings
Level number
In a graph, if every edge has a direction, it is called:
Undirected graph
Directed graph
Weighted graph
Rooted graph
Which of the following is a hierarchical data structure?
Stack
Queue
Binary tree
Array
Which application typically uses a stack?
Breadth-first search
Expression evaluation
Print queue
Call center request handling
A binary tree of height h can have at most:
h nodes
2^h nodes
2^(h+1) - 1 nodes
h^2 nodes
Which of the following denotes constant time complexity?
O(1)
O(n)
O(log n)
O(n^2)
What is the time complexity of accessing an element in an array by index?
O(1)
O(n)
O(log n)
O(n log n)
Time complexity of linear search in worst case is:
O(1)
O(log n)
O(n)
O(n^2)
Best-case complexity of binary search is:
O(n)
O(log n)
O(1)
O(n log n)
Which algorithm has O(n log n) time complexity?
Bubble sort
Merge sort
Linear search
Selection sort
Worst-case complexity of quicksort is:
O(n log n)
O(n^2)
O(n)
O(1)
Which complexity class grows faster?
O(n)
O(log n)
O(2^n)
O(n log n)
Which operation on stack has O(1) complexity?
Traversal
Push
Search
Sort
Time complexity of inserting at the beginning of a linked list is:
O(1)
O(log n)
O(n)
O(n^2)
Time complexity of enqueue operation in a queue is:
O(1)
O(n)
O(log n)
O(n log n)
Which of these is the fastest growth?
O(n)
O(n^2)
O(2^n)
O(n log n)
Which complexity is desirable for efficient algorithms?
O(n^2)
O(n^3)
O(1)
O(2^n)
The Big O of traversing all elements in a linked list is:
O(1)
O(n)
O(log n)
O(n log n)
Which has a better complexity: O(n log n) vs O(n^2)?
O(n^2)
O(n log n)
Both equal
Cannot determine
Which of the following creates a list in Python?
list = {}
list = []
list = ()
list = set()
Which function adds an element at the end of a list?
append()
insert()
extend()
add()
Which function adds an element at the end of a list?
append()
insert()
extend()
add()
What will print([1,2,3] * 2) output?
[1,2,3,1,2,3]
[2,4,6]
[1,2,3,2]
Error
Which method removes the last element from a list?
remove()
delete()
pop()
discard()
What is the result of len([[],[1],[1,2]])?
2
3
4
5
Which of the following creates a shallow copy of a list?
list1 = list2
list1 = list2.copy()
list1 = copy.deepcopy(list2)
list1 = (list2)
What does list(range(3)) return?
[0,1,2]
[1,2,3]
[0,1,2,3]
Error
Which method extends a list with another iterable?
append()
insert()
extend()
merge()
What will sum([1,2,3,4]) return?
10
24
1234
[10]
Which method sorts a list in place?
sorted()
sort()
order()
arrange()
What will min([3,5,2,7]) output?
7
2
3
5
Which indexing returns the last item of a list?
list[-1]
list[last]
list[len(list)]
list[]
What is the output of len([1, [2, 3]])?
2
3
4
Error
What will list("Python") return?
['Python']
['P','y','t','h','o','n']
('P','y','t','h','o','n')
Error
Which method removes element by value?
pop()
remove()
discard()
delete()
Which method converts string to lowercase?
tolower()
lower()
casefold()
Both B and C
Strings in Python are:
Mutable
Immutable
Fixed length
None
What will "hello".capitalize() return?
hello
HELLO
Hello
Error
Which operator concatenates strings?
*
+
&
concat()
What will "python".find("t") return?
1
2
3
-1
Which method removes whitespace from both ends?
strip()
trim()
ltrim()
clean()
What will "abc" * 3 output?
abcabcabc
abc3
['abc','abc','abc']
Error
"Python".startswith("Py") returns:
True
False
None
Error
Which method splits a string into a list?
partition()
split()
slice()
break()
What will "".join(['a','b','c']) return?
['a','b','c']
abc
a b c
Error
In a singly linked list, each node contains:
Data only
Data + two pointers
Data + one pointer
Pointer only
Time complexity of traversing a singly linked list is:
O(1)
O(n)
O(log n)
O(n log n)
Inserting a node at the beginning of a singly linked list is:
O(1)
O(n)
O(log n)
O(n^2)
Which pointer in singly linked list is NULL at the end?
head
tail
next of last node
data of last node
Which of the following is disadvantage of singly linked list?
Requires more memory
Cannot traverse backward
No random access
All of the above
Deleting the head node in singly linked list requires:
O(1) time
O(n) time
O(log n) time
O(n^2) time
Searching for an element in a singly linked list takes:
O(1)
O(n)
O(log n)
O(n log n)
What is stored in the last node of a singly linked list?
First node's address
NULL
Random address
Data only
Which operation is expensive in singly linked list compared to array?
Traversal
Insertion at beginning
Random access
Deletion
In a singly linked list, to delete a node we need access to:
Head pointer only
Node pointer only
Previous node pointer
Tail pointer only
Which traversal is possible in singly linked list?
Forward only
Backward only
Both forward and backward
Random
Which of these operations requires O(n) time in singly linked list?
Insert at head
Delete head
Access nth node
Traverse one step
In a doubly linked list, each node contains:
Data + one pointer
Data + two pointers
Data only
Pointer only
Which of the following supports traversal in both directions?
Singly linked list
Doubly linked list
Circular linked list
Array
Extra memory in doubly linked list is used for:
Tail pointer
Next and Previous pointer
Head pointer
Data duplication
Which operation is easier in doubly linked list compared to singly?
Insertion at beginning
Backward traversal
Deletion of a node
All of the above
Deleting a node in doubly linked list requires:
Updating only next pointer
Updating only previous pointer
Updating both next and previous pointers
No update
Time complexity of insertion at head in doubly linked list is:
O(1)
O(n)
O(log n)
O(n^2)
Which pointer in doubly linked list points backward?
prev
next
head
tail
What is the last node's next pointer in doubly linked list?
Points to first node
NULL
Points to middle node
Random value
Which is disadvantage of doubly linked list?
Requires extra memory
Cannot traverse backward
Random access is possible
Deletion is complex
Which operation is O(n) in doubly linked list?
Insert at head
Delete head
Search for element
Insert at tail
Which linked list requires more memory per node?
Singly
Doubly
Both equal
None
Which traversal is possible in doubly linked list?
Forward only
Backward only
Both forward and backward
None
If a doubly linked list is empty, both head and tail pointers are:
Pointing to NULL
Pointing to each other
Pointing to garbage
Pointing to first node
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)
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)
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)
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)
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)
