Nepedia
Back to Discover
Advanced Reader
💻

Data structure

technology Maturity 11-13 Next article →

A data structure is a specialized format for organizing and storing data values. It is more than just a list of information. It defines the relationships between data values and the specific operations that can be applied to them. In computer science, these structures act as an algebraic structure about data. They serve as the essential foundation for abstract data types (ADT). While an ADT defines the logical form of a data type, the data structure provides its physical implementation. Efficient data structures are vital for designing efficient algorithms. They allow computers to manage massive amounts of information, such as large databases or internet indexing services.

Python 3. The standard type hierarchy-en
Python 3. The standard type hierarchy-en

To understand how they work, we must look at how they interact with computer memory. Computers use a pointer to fetch and store data at specific locations. A pointer is a bit string that represents a memory address. This address can be stored in memory and manipulated by a program. Data structures generally fall into two implementation categories based on these pointers. Array and record structures use arithmetic operations to compute the addresses of data items. In contrast, linked data structures store the addresses of data items directly within the structure itself. This distinction has massive implications for how well an algorithm can scale. For example, contiguous memory allocation in arrays allows for very rapid access and modification.

Hash table 3 1 1 0 1 0 0 SP
Hash table 3 1 1 0 1 0 0 SP

There are many distinct types of data structures, each suited to different tasks. An array is a collection of elements in a specific order. Elements are usually of the same type and are accessed using an integer index. A linked list is a linear collection of nodes. Each node contains a value and a pointer to the next node. While arrays allow for fast random access, linked lists allow for efficient insertion and removal of values. Records, also called tuples or structs, are aggregate structures. They contain a fixed number of values indexed by names, which are called fields.

Hash table 3 1 1 0 1 0 0 SP
Hash table 3 1 1 0 1 0 0 SP

Other structures are designed for specialized logic and speed. Hash tables, or hash maps, provide fast retrieval of values using keys. They use a hashing function to map keys to indexes in an array. This allows for constant-time access in most average cases. However, they must sometimes handle hash collisions using techniques like chaining or open addressing. Graphs represent relationships between entities using nodes, called vertices, and connections, called edges. Graphs can be directed or undirected, and they may contain cycles. Trees provide a hierarchical organization. A tree starts with a root node, and all other nodes form subtrees. A special type of tree called a trie, or prefix tree, is used for string retrieval. This is how autocomplete and spell-checking functions work.

Hash table 3 1 1 0 1 0 0 SP
Hash table 3 1 1 0 1 0 0 SP

Abstract data types can be implemented using different physical structures. For instance, stacks and queues are common abstract data types. A stack follows the Last In, First Out (LIFO) principle. It uses two main operations: push to add an element to the top, and pop to remove it. A queue follows the First In, First Out (FIFO) principle. It uses enqueue to add an item to the rear and dequeue to remove it from the front. Both stacks and queues can be built using either arrays or linked lists. This shows how the physical implementation changes the way the logical type behaves.

Hash table 3 1 1 0 1 0 0 SP
Hash table 3 1 1 0 1 0 0 SP

The history of programming languages shows how support for these structures has evolved. Low-level assembly languages and languages like BCPL often lack built-in support for data structures. However, many high-level languages include special syntax for them. The C language supports structs and vectors, which are one-dimensional arrays. Pascal supports records. Most modern languages provide standard libraries so programmers do not have to rewrite them. Examples include the C++ Standard Template Library and the Java Collections Framework. These libraries allow for modular programming. In object-oriented languages like Java or C++, classes are used to create opaque data types. This allows a programmer to hide the complex implementation details from the user.

Python 3. The standard type hierarchy-en
Python 3. The standard type hierarchy-en

Data structures connect deeply to many different fields of computing. They are used in relational databases through B-tree indices for data retrieval. In compiler implementations, hash tables are used to look up identifiers. Some structures even have concurrent versions. These allow multiple computing threads to access a single instance of the data structure at the same time. Whether it is a simple array or a complex B-tree, the choice of structure dictates the performance of the entire system. By choosing the right organization, developers can ensure that software remains fast and scalable as data grows.

762 words

Where will your curiosity go next?

Keep exploring at your chosen reading level.

🖼️ Images & Media (2)
File:Hash table 3 1 1 0 1 0 0 SP.svg
Hash table 3 1 1 0 1 0 0 SP.svg
File:Python 3. The standard type hierarchy-en.svg
Python 3. The standard type hierarchy-en.svg
More to explore

What is Nepedia?

A free, ad-free encyclopedia for children. Every article is written at five reading levels, so the same page works for a five-year-old and a fifteen-year-old — use the level switcher above to see this one change. No account needed to read.