COM212
COM212
2
Array Data An array is a data structure that stores a collection of
Structure elements in sequential memory locations one after the other.
Characteristics of an Array.
Each element in an array can be efficiently accessed using its index, which
represents its position within the array.
This direct access property makes arrays highly efficient for several
operations, such as indexing, iterating, and modifying elements.
Array element 15 can be accessed via its Application Areas of Arrays.
index
2
Applications of Arrays.
• Used in implementing mathematical data structures such as matrices and tensors. These structures are
pivotal in fields like linear algebra, numerical analysis, and machine learning. For instance, matrices, which are
two-dimensional arrays, enable operations such as matrix multiplication, determinant calculation, and matrix
inversion, fundamental in solving systems of linear equations and transformations in graphics
Array element 13 can be
accessed
• Used using
in Gameits index
development.
2 Arrays are used to represent 2D or 3D game boards, such as in chess, tic-tac-toe, or
grid-based games like Minesweeper or Tetris.
Application Areas of
Arrays.
• Used in Computer Graphics. In computer graphics, arrays are employed to represent images, where each element in the
array corresponds to a pixel’s color value. For example, a grayscale image can be stored in a two-dimensional array where
each element holds an intensity value. For colored images, three-dimensional arrays are used to store the red, green, and
blue (RGB) components of each pixel
• Used in Text processing and manipulation. Strings, which are essentially sequences of characters, can be viewed as
arrays of characters. Various operations such as searching, sorting, and pattern matching (e.g., the Knuth-Morris-Pratt
algorithm) utilize arrays for efficient implementation.
• Used in Sorting algorithms. Sorting algorithms including quicksort and merge sort, utilize arrays as the underlying data
structure for their operations. The efficiency of these algorithms, driven by the array’s random-access capability.
4
A linked list is a linear data structure consisting of a series of
Linked List Data
connected nodes, where each node contains:
Structure 1. Data: The value or information stored in the node.
2. Pointer (or Reference): A reference (or link) to the next
node in the sequence.
Linked lists back and forth nature provides versatile and powerful structures adaptable to a myriad of applications:
• Music Playlists: Enables sequential navigation with "next" and "previous" functionality.
5
Applications of Linked
lists.
• Used in File Systems:
Linked lists manage directories and file storage, allowing files to be stored in non-contiguous
memory locations. Each file block points to the next, enabling flexible storage management.
6
Stack Data A stack is a linear data structure that adheres to the Last In, First Out
Structure (LIFO) principle. In a stack, the element added last is the one to be removed
first. This characteristic makes stacks useful when data needs to be stored
and retrieved in reverse order from which it was added.
• Undo Mechanisms: Many applications, such as text editors, implement undo mechanisms by maintaining
actions in a stack. When an operation is performed, it is pushed onto the undo stack. To undo an operation, it is
popped from the stack, and an opposite action is executed (which might be pushed onto a redo stack).
• Depth-First Search (DFS): In graph traversal algorithms, such as Depth-First Search, stacks are
utilized to explore nodes in a depth-ward motion. Each time a new node is visited, it is pushed onto the
stack; backtracking occurs when a node has no unvisited adjacent nodes, achieved by popping the
stack.
Applications of Stacks.
• Recursive Function Calls:
Programming languages use a call stack to manage function calls. When a function is called,
its data (like local variables) is pushed onto the stack, and when the function finishes, the data
is popped off.
• Memory Management
Stacks are utilized for managing memory during program execution:
• Allocation of Function Calls: Allocating and deallocating memory for function
parameters, return addresses, and local variables.
8
QUEUE Data A queue is a linear data structure that follows a specific order for element
operations, known as First-In First-Out (FIFO). In a queue, the first element
Structure
added to the structure will be the first one to be removed.
• Task Scheduling: Queues are extensively used in operating systems for task scheduling. In a multitasking
environment, where numerous processes compete for CPU time, a queue can manage these processes efficiently.
• Print Spooling: In a networked environment with multiple print requests, queues manage print job spooling.
Each print job is placed in a queue and processed sequentially, ensuring that print commands are executed in the
order they were received.
Applications of Queues.
• Breadth-First Search (BFS) in Graphs: Queues facilitate the BFS algorithm in graph traversal, ensuring
exploration starts from the given node and moves level by level.
• Customer Service Systems: Customer service departments utilize queues to manage incoming customer
requests, be it in a call center or a service desk. Each customer is attended to in the order they arrived, which
is crucial for fairness and efficiency.
• Traffic Management: Queues are utilized in traffic management systems, especially at traffic signals. Vehicles
queue up at red lights and are allowed to pass sequentially when the light turns green, ensuring orderly traffic flow.
10
Tree Data Structure A tree is a hierarchical data structure that simulates a hierarchical tree
structure with a root value and subtrees of children, represented as a set of
linked nodes.
Applications of Trees.
• Network Routing: Trees are essential in network routing algorithms. Spanning trees, for example, are
utilized in network topology management to prevent loops.
• File Systems: Modern file systems often leverage tree structures for efficient file storage and retrieval.
Examples include the ext4 file system in Linux,
Applications of Trees.
• Database indexing: Binary search trees are used for searching and organizing data efficiently.
B-trees are commonly used in databases to enable efficient range queries and index management.
• Data Compression: Trees, specifically Huffman trees, are instrumental in data compression algorithms. Huffman
encoding uses a binary tree to assign variable-length codes to input characters, based on their frequencies. Characters
that occur more frequently are given shorter codes, which helps in reducing the overall size of the data.
12
Heap Data Heaps are a specialized tree-based data structure that satisfies the heap
Structure property.
A heap can be of two types:
A min-heap: for any given node i, the value of i is less than or equal to
the values of its children.
A max-heap: the value of i is greater than or equal to the values of its
children.
Applications of Heaps.
• Priority Queues: Heaps are the most efficient way to implement priority queues, where
elements with the highest or lowest priority are processed first.
• Max-Heap: Supports extracting the highest priority element efficiently.
• Min-Heap: Supports extracting the lowest priority element efficiently.
• Heap Sort: Heaps are used in the heap sort algorithm, which organizes data in
ascending or descending order efficiently.
Applications of Heaps.
• Resource Allocation and Load Balancing: Heaps help manage resources efficiently in
systems requiring dynamic allocation. Applications:
• Distributing tasks among multiple processors or servers.
• Managing virtual memory allocation in operating systems.
• Used in compression algorithms: A min-heap is used to create a Huffman tree, which generates
optimal prefix codes for data compression.
• Social media and e-commerce platforms use heaps to rank search results or posts by relevance
(priority ranking).
14
Graph Data A graph G is an abstract data structure that consists of a set of vertices V (or
Structure nodes) and a set of edges E connecting pairs of vertices.
Applications of Graphs.
• Social Networks: In social networks, graphs are employed to represent users as vertices, with edges
denoting relationships between them.
• Utilities and Resource Management: Utility networks, such as electrical grids and water distribution
systems, capitalize on graph theory. Here, vertices represent substations or nodes, while edges correspond to
transmission lines or pipes.
16