NEW
Font size
WorksheetsQuiz1-DSA-FCPC
Total questions: 50
Worksheet time: 50mins
Big O notation is used to describe:
The exact runtime of an algorithm
The growth rate of an algorithm as input size increases
The memory size of a program
The programming language speed
Which of the following represents the fastest time complexity?
O(1)
O(log n)
O(n)
O(n²)
If an algorithm takes the same amount of time regardless of input size, its time complexity is:
O(n)
O(n²)
O(1)
O(log n)
Which of the following is better in terms of efficiency for large input sizes?
O(n²)
O(log n)
O(2ⁿ)
O(n³)
The time complexity of inserting an element at the end of an array is usually:
O(1)
O(n)
O(n²)
O(log n)
The Big O of binary search is:
O(1)
O(n)
O(log n)
O(n²)
The nested loop below has what time complexity? for i in range(n): for j in range(n): print(i, j)
O(n)
O(n²)
O(log n)
O(n log n)
Which one is not a valid Big O notation?
O(n³)
O(1)
O(5n + 10)
O(n + log n)
If an algorithm has time complexity O(n), doubling the input size will roughly:
Double the work
Square the work
Halve the work
Not change the work
The Big O of a constant-time algorithm is:
O(1)
O(n)
O(n²)
O(log n)
For the loop: for i in range(n): print(i) The time complexity is:
O(n)
O(n²)
O(1)
O(log n)
Big O ignores:
Input size
Growth rate
Constant factors
Worst-case scenarios
A string is usually defined as:
A sequence of numbers
A sequence of characters
A sequence of arrays
A sequence of lists
In most programming languages, strings are:
Mutable
Immutable
Lists
Arrays of integers
What is the index of the first character in a string?
0
1
-1
Depends on the language
The operation of joining two strings together is called:
Slicing
Concatenation
Traversal
Substring
What will be the length of string "Hello"?
4
5
6
0
Which function is used to find the length of a string in Python?
size()
len()
length()
count()
Accessing s[-1] in Python string s gives:
First character
Last character
Error
Middle character
The time complexity of finding the length of a string is:
O(1)
O(n)
O(log n)
O(n²)
Which of the following is a substring of "computer"?
com
put
ter
All of the above
Which operator is used to check if a substring exists in a string in Python?
=
==
in
contains
Reversing a string in Python can be done by:
s.reverse()
reverse(s)
s[::-1]
s[-1:0]
Which string is considered empty?
" "
""
None
Zero
The process of removing leading and trailing spaces in a string is called:
Trimming
Cutting
Splitting
Stripping
In "banana".count("a"), the output is:
1
2
3
4
Which method changes all letters to uppercase in Python?
str.upper()
str.capitalize()
str.big()
str.uppercase()
What is the result of "hello" + "world"?
"hello world"
"helloworld"
"hello+world"
Error
A list is best described as:
A collection of numbers only
An ordered collection of elements
A single character
An
What will be the output of the following code?
sentence = "Python is fun"
result = " ".join([word[::-1] for word in sentence.split()]) print(result)
Python is fun
nohtyP si nuf
nuf si nohtyP
['nohtyP', 'si', 'nuf']
What does the following code print?
words = ["cat", "elephant", "dog", "lion", "ant"]
result = [w for w in words if len(w) > 3]
print(result)
['cat', 'dog', 'ant']
['elephant', 'lion']
['elephant']
['lion', 'dog']
What will be the output of the code?
text = "Intermediate Python"
vowels = "aeiouAEIOU" result = "".join([ch for ch in text if ch not in vowels])
print(result)
Intrmdt Pythn
Intermediate Python
ntrmdt Pythn
Intmdt Pyth
What does the following code print?
s = "banana"
result = [f"{ch}:{s.count(ch)}" for ch in set(s)]
print(result)
['b:1', 'a:3', 'n:2']
['banana']
['a:6', 'n:6']
['1:b', '3:a', '2:n']
What will be the result?
data = [["Py", "thon"], ["is"], ["cool"]]
result = "".join([part for sub in data for part in sub])
print(result)
Pythoniscool
['Py', 'thon', 'is', 'cool']
Py thon is cool
Pyisthoncool
What is the output of the following code?
s = "My phone number is 12345 and zip is 67890"
result = [num for num in s.split() if num.isdigit()]
print(result)
['My', 'phone']
[12345, 67890]
['12345', '67890']
['number', 'zip']
What will be printed?
s1 = "python"
s2 = "notebook"
result = list(set(s1) & set(s2))
print(result)
['p', 'y']
['o', 'n', 't']
['n', 'o']
['python', 'notebook']
What does the code output?
words = ["apple", "banana", "cherry"]
result = ", ".join(words[:-1]) + " and " + words[-1]
print(result)
apple banana cherry
apple, banana, cherry
apple, banana and cherry
apple and banana and cherry
What will be the result? words = ["Apple", "Banana", "apple", "Cherry", "banana"]
result = list({w.lower(): w for w in words}.values())
print(result)
['Apple', 'Banana', 'Cherry']
['apple', 'banana', 'cherry']
['apple', 'Cherry']
['Banana', 'Apple', 'Cherry']
What will this code print?
name = "Python"
print(name[0])
P
n
o
Py
What will this code print?
numbers = [1, 2, 3]
numbers.append(4)
print(numbers)
[1, 2, 3]
[4, 1, 2, 3]
[1, 2, 3, 4]
Error
What does this code print?
text = "hello world"
print("world" in text)
True
False
"world"
Error
What is the result of the following code?
letters = ["a", "b", "c", "d"]
print(letters[0:2])
['a', 'b']
['b', 'c']
['a', 'b', 'c']
['c', 'd']
What will this code output?
nums = [10, 20, 30]
nums[1] = 99
print(nums)
[10, 20, 30]
[99, 20, 30]
[10, 99, 30]
Error
What is the result of the following code?
nums = [1, 2, 3, 4, 5]
print(nums[::2])
[1, 2, 3]
[2, 4]
[1, 3, 5]
[5, 4, 3, 2, 1]
What does this code print?
nums = [10, 20, 30]
nums.pop()
print(nums)
[10, 20, 30]
[10, 20]
[20, 30]
[30]
What will be the result?
text = "hello"
print(list(text))
['h', 'e', 'l', 'l', 'o']
['hello']
h e l l o
Error
What will this code print?
text = "Data Science"
print(text[::-1])
Data Science
ecneicS ataD
ecneicSataD
Error
What is the output?
nums = [2, 4, 6, 8]
result = [n/2 for n in nums]
print(result)
[1, 2, 3, 4]
[2, 4, 6, 8]
[1.0, 2.0, 3.0, 4.0]
[1.2, 2.4, 3.6, 4.8]
What is the result of this code?
nums = [1, 2, 3, 4, 5]
print(nums[::3])
[1, 4]
[1, 2, 3]
[3, 5]
[2, 5]
What will this code print?
text = "programming"
print(text.replace("g", "G"))
proGramminG
ProGramminG
programming
proGrammin
