Python
Basic Data Structures
Algorithms
Advanced Data Structures
Miscellaneous 🎉
100

Which function is used to display output?

print()

100

What data type is used for whole numbers?

int

100

What is the name of the Python function that can be used to sort a list of numbers from ascending order?

sorted()

100

What data structures can insert and delete elements from both ends in O(1) time?

Deques

100

What mode do you use when opening a file to write and read to it

open("file.txt","__")

r+ or w+

200

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

8

200

Which data type stores ordered and immutable values?

tuple

200

What is the name of the algorithm that divides a list in half until its target element is found?

Binary Search

200

What data structure is commonly used to implement priority queues?

Heaps

200

What is the output of the following code?

my_list = [1, 2, 3]

my_list += [4, 5]

my_list[1:3] = [6, 7]

my_list *= 2

print(my_list)

[1, 6, 7, 4, 5, 1, 6, 7, 4, 5]

300

What is the variable naming convention used?

snake_case

300

What is the time complexity of removing the first item in a list?

O(n)

300

What algorithm works by picking the smallest element in an unsorted list to place in a sorted list?

Selection sort

300

What is the difference between a stack and queue? 

A stack is LIFO (last in first out) while a queue is FIFO (first in first out)

300

What bitwise operator is used with bitmasks?

XOR (or left shift)

400

What operator is used to check if two variables share references?

is

400

What does type({}) return?

<class 'dict'>

400

What algorithm finds the shortest path in a weighted tree with different edge weights to calculate the minimum total weight?

Dijkstra’s algorithm

400

In a heap, what is the time complexity to insert a new element?

O(log n)

400

What input method do sweaty CCC writers use?

sys.stdin.readline

500

What keyword is used to make a function accept any number of arguments?

*args

500

What is the output of print(''.join(sorted(set('banana'))))?

abn

500

What is the worst case time complexity of the bubble sort algorithm?

O(n²)

500

How do you reverse a stack using recursion?

You recursively pop out the first element and inserting it at the bottom

500

What regex expression would you need to filter out all numbers in a string that are real numbers? (integers, decimals, commas, negative numbers,etc). Assume valid numbers have a comma separating every three digits.

re.findAll(r”\-?\d\d?\d?(,\d{3})*(.\d+)?”, num)