Basic Knowledge Flashcards
Basic Programming questions that are asked (23 cards)
How do you test for nulls in an array in a language of your choice?
To test for None
values in a Python array:
```python
arr = [1, None, 3, None, 5]
has_none = any(x is None for x in arr)
print(has_none) # True
~~~
Summary: Use any(x is None for x in array)
to check for None
values in Python.
What is the space complexity for Quicksort?
Space Complexity of Quicksort:
- Best/Average Case: ( O(\log n) ) due to recursive stack usage.
- Worst Case: ( O(n) ) when the pivot selection is poor (e.g., sorted arrays without optimization).
What is a collision in hashing?
Collision in Hashing:
A collision occurs when two different inputs produce the same hash value, causing both to map to the same index in a hash table.
What is Unit Testing?
Unit Testing: Test individual functions or components.
What is integration testing?
Integration Testing: Test combined modules to ensure proper interaction.
What is system testing?
System Testing: Validate the complete system’s functionality.
What is acceptance testing?
Acceptance Testing: Ensure the code meets user requirements
Name all of the possibilities for Big O notation
“Calm Lions Need Lots of Nap Snacks”
C = Constant (O(1))
L = Logarithmic (O(log n))
N = Linear (O(n))
L = Linearithmic (O(n log n))
N = Quadratic (O(n²))
S = Super-exponential (O(2ⁿ))
Explain logarithmic time:
O(log n)
Halves the input with each step, which drastically reduces work.
Explain Linear Time:
O(n)
Time grows directly with the size of the input.
Explain Linearithmic Time:
O(nLogn)
Divides and conquers, like O(log n), but repeats the divide step for each input.
Explain Quadratic Time:
O(n²)
Time grows proportionally to the square of the input size (nested loops).
Explain Exponential Time:
O(2ⁿ)
Time doubles with each additional input.
What is a list
An ordered, mutable collection of items, supporting different data types and duplicates.
What is a Tuple
An ordered, immutable collection of items. Often used when data should not be changed.
What is a Set
An unordered collection of unique elements, useful for removing duplicates.
What is a dictionary
An unordered collection of key-value pairs for fast lookups.
What is an Array
Similar to lists but optimized for storing large amounts of numeric data with fixed type.
What is a Stack?
A Last-In-First-Out (LIFO) data structure. You can implement stacks using lists or deque.
What is a Queue?
A First-In-First-Out (FIFO) data structure. Use queue.Queue or deque for queue-based operations.
What is a Heap?
A binary heap (priority queue) where the smallest element is always at the top.
What is a Binary Tree?
A hierarchical data structure where nodes are connected by edges. The root node is the top, and each node has children.
What is a Deque
A double-ended queue for adding/removing items efficiently from both ends.