Data Structures and Algorithms 2024
Data Structures and Algorithms 2024
(a): Abstract Data Types (ADTs) are theoretical models that define a set of operations without
specifying the implementation details. Examples include:
1. Stack: A data structure that follows the Last-In-First-Out (LIFO) principle. It supports
operations like push (add element), pop (remove element), and peek (view the top
element).
2. Queue: A data structure that follows the First-In-First-Out (FIFO) principle. It supports
operations like enqueue (add element), dequeue (remove element), and peek (view the
front element).
3. Binary Tree: A hierarchical data structure composed of nodes, each containing a value
and two references to other nodes (left child and right child).
(b): Most data structures are accompanied by algorithms tailored to manipulate the data they
store efficiently. For instance:
1. Searching Algorithms: Binary search for sorted arrays, linear search for unsorted arrays.
2. Sorting Algorithms: Quick sort, merge sort, bubble sort.
3. Traversal Algorithms: Depth-First Search (DFS) for trees and graphs, Breadth-First Search
(BFS) for graphs.
(e): Discuss last-in-first-out (LIFO) as used in a stack data structure with the aid of a diagram. [7
marks]:
LIFO principle means that the last element added to the stack is the first one to be removed.
This behavior can be illustrated with a diagram showing elements stacked vertically, with the
most recently added element at the top. Operations like push (adding an element) and pop
(removing an element) follow this principle, ensuring consistent ordering.
References
1. Goodrich, Michael T., et al. "Data Structures and Algorithms in Java." John Wiley &
Sons, 2020.
2. Cormen, Thomas H., et al. "Introduction to Algorithms." MIT Press, 2009.
3. Weiss, Mark Allen. "Data Structures and Algorithm Analysis in Java." Pearson
Education, 2014.
4. Sedgewick, Robert, and Kevin Wayne. "Algorithms." Addison-Wesley, 2011.
5. Carrano, Frank M., and Timothy Henry. "Data Abstraction & Problem Solving with C++:
Walls and Mirrors." Pearson, 2016.