wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Quiz1-DSA-FCPC

Total questions: 50

Worksheet time: 50mins

Name
Class
Date
1.

Big O notation is used to describe:

a)

The exact runtime of an algorithm

b)

The growth rate of an algorithm as input size increases

c)

The memory size of a program

d)

The programming language speed

2.

Which of the following represents the fastest time complexity?

a)

O(1)

b)

O(log n)

c)

O(n)

d)

O(n²)

3.

If an algorithm takes the same amount of time regardless of input size, its time complexity is:

a)

O(n)

b)

O(n²)

c)

O(1)

d)

O(log n)

4.

Which of the following is better in terms of efficiency for large input sizes?

a)

O(n²)

b)

O(log n)

c)

O(2ⁿ)

d)

O(n³)

5.

The time complexity of inserting an element at the end of an array is usually:

a)

O(1)

b)

O(n)

c)

O(n²)

d)

O(log n)

6.

The Big O of binary search is:

a)

O(1)

b)

O(n)

c)

O(log n)

d)

O(n²)

7.

The nested loop below has what time complexity? for i in range(n): for j in range(n): print(i, j)

a)

O(n)

b)

O(n²)

c)

O(log n)

d)

O(n log n)

8.

Which one is not a valid Big O notation?

a)

O(n³)

b)

O(1)

c)

O(5n + 10)

d)

O(n + log n)

9.

If an algorithm has time complexity O(n), doubling the input size will roughly:

a)

Double the work

b)

Square the work

c)

Halve the work

d)

Not change the work

10.

The Big O of a constant-time algorithm is:

a)

O(1)

b)

O(n)

c)

O(n²)

d)

O(log n)

11.

For the loop: for i in range(n): print(i) The time complexity is:

a)

O(n)

b)

O(n²)

c)

O(1)

d)

O(log n)

12.

Big O ignores:

a)

Input size

b)

Growth rate

c)

Constant factors

d)

Worst-case scenarios

13.

A string is usually defined as:

a)

A sequence of numbers

b)

A sequence of characters

c)

A sequence of arrays

d)

A sequence of lists

14.

In most programming languages, strings are:

a)

Mutable

b)

Immutable

c)

Lists

d)

Arrays of integers

15.

What is the index of the first character in a string?

a)

0

b)

1

c)

-1

d)

Depends on the language

16.

The operation of joining two strings together is called:

a)

Slicing

b)

Concatenation

c)

Traversal

d)

Substring

17.

What will be the length of string "Hello"?

a)

4

b)

5

c)

6

d)

0

18.

Which function is used to find the length of a string in Python?

a)

size()

b)

len()

c)

length()

d)

count()

19.

Accessing s[-1] in Python string s gives:

a)

First character

b)

Last character

c)

Error

d)

Middle character

20.

The time complexity of finding the length of a string is:

a)

O(1)

b)

O(n)

c)

O(log n)

d)

O(n²)

21.

Which of the following is a substring of "computer"?

a)

com

b)

put

c)

ter

d)

All of the above

22.

Which operator is used to check if a substring exists in a string in Python?

a)

=

b)

==

c)

in

d)

contains

23.

Reversing a string in Python can be done by:

a)

s.reverse()

b)

reverse(s)

c)

s[::-1]

d)

s[-1:0]

24.

Which string is considered empty?

a)

" "

b)

""

c)

None

d)

Zero

25.

The process of removing leading and trailing spaces in a string is called:

a)

Trimming

b)

Cutting

c)

Splitting

d)

Stripping

26.

In "banana".count("a"), the output is:

a)

1

b)

2

c)

3

d)

4

27.

Which method changes all letters to uppercase in Python?

a)

str.upper()

b)

str.capitalize()

c)

str.big()

d)

str.uppercase()

28.

What is the result of "hello" + "world"?

a)

"hello world"

b)

"helloworld"

c)

"hello+world"

d)

Error

29.

A list is best described as:

a)

A collection of numbers only

b)

An ordered collection of elements

c)

A single character

d)

An

30.

What will be the output of the following code?

sentence = "Python is fun"

result = " ".join([word[::-1] for word in sentence.split()]) print(result)

a)

Python is fun

b)

nohtyP si nuf

c)

nuf si nohtyP

d)

['nohtyP', 'si', 'nuf']

31.

What does the following code print?

words = ["cat", "elephant", "dog", "lion", "ant"]

result = [w for w in words if len(w) > 3]

print(result)

a)

['cat', 'dog', 'ant']

b)

['elephant', 'lion']

c)

['elephant']

d)

['lion', 'dog']

32.

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)

a)

Intrmdt Pythn

b)

Intermediate Python

c)

ntrmdt Pythn

d)

Intmdt Pyth

33.

What does the following code print?

s = "banana"

result = [f"{ch}:{s.count(ch)}" for ch in set(s)]

print(result)

a)

['b:1', 'a:3', 'n:2']

b)

['banana']

c)

['a:6', 'n:6']

d)

['1:b', '3:a', '2:n']

34.

What will be the result?

data = [["Py", "thon"], ["is"], ["cool"]]

result = "".join([part for sub in data for part in sub])

print(result)

a)

Pythoniscool

b)

['Py', 'thon', 'is', 'cool']

c)

Py thon is cool

d)

Pyisthoncool

35.

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)

a)

['My', 'phone']

b)

[12345, 67890]

c)

['12345', '67890']

d)

['number', 'zip']

36.

What will be printed?

s1 = "python"

s2 = "notebook"

result = list(set(s1) & set(s2))

print(result)

a)

['p', 'y']

b)

['o', 'n', 't']

c)

['n', 'o']

d)

['python', 'notebook']

37.

What does the code output?

words = ["apple", "banana", "cherry"]

result = ", ".join(words[:-1]) + " and " + words[-1]

print(result)

a)

apple banana cherry

b)

apple, banana, cherry

c)

apple, banana and cherry

d)

apple and banana and cherry

38.

What will be the result? words = ["Apple", "Banana", "apple", "Cherry", "banana"]

result = list({w.lower(): w for w in words}.values())

print(result)

a)

['Apple', 'Banana', 'Cherry']

b)

['apple', 'banana', 'cherry']

c)

['apple', 'Cherry']

d)

['Banana', 'Apple', 'Cherry']

39.

What will this code print?

name = "Python"

print(name[0])

a)

P

b)

n

c)

o

d)

Py

40.

What will this code print?

numbers = [1, 2, 3]

numbers.append(4)

print(numbers)

a)

[1, 2, 3]

b)

[4, 1, 2, 3]

c)

[1, 2, 3, 4]

d)

Error

41.

What does this code print?

text = "hello world"

print("world" in text)

a)

True

b)

False

c)

"world"

d)

Error

42.

What is the result of the following code?

letters = ["a", "b", "c", "d"]

print(letters[0:2])

a)

['a', 'b']

b)

['b', 'c']

c)

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

d)

['c', 'd']

43.

What will this code output?

nums = [10, 20, 30]

nums[1] = 99

print(nums)

a)

[10, 20, 30]

b)

[99, 20, 30]

c)

[10, 99, 30]

d)

Error

44.

What is the result of the following code?

nums = [1, 2, 3, 4, 5]

print(nums[::2])

a)

[1, 2, 3]

b)

[2, 4]

c)

[1, 3, 5]

d)

[5, 4, 3, 2, 1]

45.

What does this code print?

nums = [10, 20, 30]

nums.pop()

print(nums)

a)

[10, 20, 30]

b)

[10, 20]

c)

[20, 30]

d)

[30]

46.

What will be the result?

text = "hello"

print(list(text))

a)

['h', 'e', 'l', 'l', 'o']

b)

['hello']

c)

h e l l o

d)

Error

47.

What will this code print?

text = "Data Science"

print(text[::-1])

a)

Data Science

b)

ecneicS ataD

c)

ecneicSataD

d)

Error

48.

What is the output?

nums = [2, 4, 6, 8]

result = [n/2 for n in nums]

print(result)

a)

[1, 2, 3, 4]

b)

[2, 4, 6, 8]

c)

[1.0, 2.0, 3.0, 4.0]

d)

[1.2, 2.4, 3.6, 4.8]

49.

What is the result of this code?

nums = [1, 2, 3, 4, 5]

print(nums[::3])

a)

[1, 4]

b)

[1, 2, 3]

c)

[3, 5]

d)

[2, 5]

50.

What will this code print?

text = "programming"

print(text.replace("g", "G"))

a)

proGramminG

b)

ProGramminG

c)

programming

d)

proGrammin