comp 2503 midterm additional flashcards
1
Q
What is the process for drawing an object reference diagram for a linked list?
A
- Draw boxes for each node containing data, 2. Draw arrows for references between nodes, 3. Label reference variables (head/tail/current), 4. Show null references with ground symbol or ×
2
Q
How do you verify if parentheses match using a stack?
A
- Push opening parentheses onto stack, 2. For each closing parenthesis, pop stack and verify match, 3. Stack should be empty at end, 4. Return false if mismatch or stack not empty
3
Q
What are the steps to implement Binary Search?
A
- Find middle element, 2. Compare with target, 3. If target smaller, search left half, 4. If target larger, search right half, 5. Repeat until found or subarray empty
4
Q
What is the process for growing an array-based implementation when full?
A
- Create new array (typically 2x size), 2. Copy all elements to new array, 3. Update reference to new array, 4. Update capacity variables
5
Q
How do you maintain references when removing a node from middle of doubly-linked list?
A
- Update previous node’s next pointer to skip removed node, 2. Update next node’s previous pointer to skip removed node, 3. Clear removed node’s references, 4. Update size counter