Programming Fundamentals and Data Structures
What this domain tests
The HP JBT section on programming fundamentals checks whether you can trace code, reason about memory, and choose the right data structure for an operation. Expect questions on control flow, functions, arrays, strings, pointers and references, linked lists, stacks, queues, trees, hash tables, and Big-O.
Core rules
- Array indexing is zero-based; accessing
a[n]on an array of sizenis undefined behavior. - A singly linked list node stores data plus a
nextpointer; insertion at the head is O(1), search is O(n). - A stack is LIFO, a queue is FIFO; both can be built on arrays or linked lists.
- Binary search trees keep left < node < right for efficient search when balanced; unbalanced trees degrade to O(n).
- Hash tables average O(1) lookup but need collision handling, such as chaining or open addressing.
- Recursion needs a base case and progress toward it, or it overflows the call stack.
Worked example
Reverse a singly linked list iteratively. Keep three pointers: prev = null, curr = head, next = null. While curr != null: save next = curr.next; point curr.next = prev; move prev = curr; move curr = next. Return prev. Each node's link is flipped once, and saving next before overwriting prevents losing the rest of the list. Time O(n), space O(1).
Traps
Pass-by-value copies the reference for objects; reassigning the parameter does not change the caller's variable. Array parameters decay to pointers, so sizeof inside a function is the pointer size, not the array size. Off-by-one errors in loops and missing base cases are common. Do not confuse O(log n) balanced-tree search with O(n) search in an unbalanced tree.