SWE Fundamentals Part 1 Flashcards
What is Big-O notation used for?
To describe the time and space complexity of an algorithm in terms of input size.
What is the time complexity of accessing an array element?
O(1)
What is the time complexity of searching in a hash table?
Average O(1), Worst O(n)
What is the time complexity of binary search?
O(log n)
What data structure is best for LIFO operations?
Stack
What data structure is best for FIFO operations?
Queue
What is the difference between a linked list and an array?
Linked lists are dynamic in size and better at insertions/deletions; arrays are faster for random access.
When would you use a hash map?
When you need fast key-value lookups.
What is recursion?
A function that calls itself to solve a smaller version of the problem.
What is a base case in recursion?
The condition under which the recursive calls stop.
What is the difference between DFS and BFS?
DFS explores depth before backtracking, BFS explores neighbors level by level.
When should you use BFS over DFS?
When looking for the shortest path in an unweighted graph.
What is dynamic programming?
An optimization technique for solving problems by storing and reusing subproblem results.
What are the two main techniques in dynamic programming?
Memoization (top-down) and tabulation (bottom-up)
What is a greedy algorithm?
An algorithm that chooses the best option at each step hoping to find a global optimum.
What is a heap used for?
Efficiently getting the min or max element, often in priority queues.
What is a graph?
A set of nodes (vertices) connected by edges.
How is a graph represented in code?
Adjacency list or adjacency matrix
What is selection sort’s time complexity?
O(n²) for all cases
Why is bubble sort inefficient?
It makes many unnecessary swaps, leading to O(n²) performance.
What is merge sort’s time complexity?
O(n log n)
What is quicksort’s average and worst-case time complexity?
Average O(n log n), Worst O(n²)
What is the stack used for in recursion?
To store function calls and local variables.