A stack follows the Last-In-First-Out (LIFO) principle.
題目(共 24 題)
In a binary search tree, the left child of any node must be greater than its parent node.
A queue can be efficiently implemented using two stacks.
The time complexity of accessing an element in a hash table is always \(O(1)\) in the worst case.
A complete binary tree with n nodes has a height of \(O(\log n)\).
In a doubly linked list, each node contains pointers to both the next and previous nodes.
A circular queue eliminates the problem of wasted space that occurs in a linear queue.
Depth-first search (DFS) always finds the shortest path between two nodes in a graph.
The maximum number of nodes in a binary tree of height \(h\) is \(2^{h+1}-1\).
An AVL tree is a self-balancing binary search tree where the height difference between left and right subtrees of any node is at most 1.
What is the time complexity of inserting an element at the beginning of a singly linked list?
a) \(O(1)\) b) \(O(n)\) c) \(O(\log n)\) d) \(O(n^2)\)
Which data structure is most suitable for implementing a browser's back button functionality?
a) Queue b) Stack c) Binary Tree d) Hash Table
In a max heap, where is the largest element located?
a) At a leaf node b) At the root node c) At the rightmost node d) At the deepest level
In a B-tree of order m, what is the maximum number of children a non-root internal node can have?
a) \(m-1\) b) \(m\) c) \(m+1\) d) \(2m\)
What is the worst-case time complexity of Dijkstra's algorithm for finding the shortest path in a graph with V vertices and E edges when implemented with a binary min-heap?
a) \(O(V)\) b) \(O(V+E)\) c) \(O((V+E)\log V)\) d) \(O(V^2)\)
The evaluation of the prefix expression: / + * − * 5 3 7 2 10 + 4 2.
Given a binary search tree with root 45, and the following nodes: 25, 65, 15, 35, 55, 75, 10, 20. Insert 18, 30, 50, 70 (in this order) into the binary search tree. What is the pre-order traversal?
Let \(T(n)=3T\!\left(\frac n3\right)+n,\ T(1)=2\), then \(T(n)=O(b)\). What is b?
In a hash table with 20 slots using linear probing, what is the worst-case number of comparisons needed to search for an element that is NOT in the table when the load factor is 0.75?
Order the following functions by their growth rate from slowest to fastest: \(2^{\sqrt n},\ n^{1.5},\ \log(n!),\ \dfrac{n^2}{\log n},\ n\log^2n,\ 3^n,\ n^{\log n}\).
Consider a CPU task scheduler where processes are prioritized based on urgency:
Priority 1: Critical system tasks (highest priority)
Priority 2: Real-time applications
Priority 3: User applications
Priority 4: Background tasks (lowest priority)
Given the following task arrivals:
| Task A | Task B | Task C | Task D | Task E | Task F | Task G |
|---|---|---|---|---|---|---|
| 3 | 1 | 4 | 2 | 1 | 3 | 2 |
(a) Show the min-heap after all tasks have been added (lower priority number = higher urgency). (5 分)
(b) If 3 tasks are executed (removed from queue), show the order they are executed and the heap after each removal. (5 分)
Consider the following undirected graph:
Vertices: A, B, C, D, E, F
Edges: (A,B), (A,C), (B,D), (C,D), (C,E), (D,E), (D,F), (E,F)
(a) Draw the adjacency matrix representation of this graph. (5 分)
(b) Starting from vertex A, show the order of vertices visited using Breadth-First Search (BFS). Assume that when multiple vertices are available, they are visited in alphabetical order. (5 分)
Consider a hash table of size 11 using the hash function \(h(k)=k\%11\). Use linear probing to resolve collisions. Insert the following keys in order: 23, 45, 12, 67, 34, 78, 56, 89, 31.
(a) Show the final state of the hash table after all insertions. (5 分)
(b) How many collisions occurred during the insertion process? (5 分)
Given the following C++ function, what will this function return for abc##d. Explain your reasoning.
string processString(string input) {
stack<char> S;
string result = "";
for(char c : input) {
if(c == '#') { if(!S.empty()) S.pop(); }
else { S.push(c); }
}
while(!S.empty()) { result = S.top() + result; S.pop(); }
return result;
}