Data Structures in Computer Science: Definition and Examples
Navigating the endless amounts of data online—from YouTube videos of cats to resources for filing your taxes—is not only an imperative skill for internet users, but also a career path many are choosing to pursue.
Data science is an incredibly rich field of study. Whether you’re interested in going to school to study data science or wanting to learn how the online world we all inhabit works behind the scenes, we’ve got your guide to the workings and real-world applications of data structures.
How Data Structures Work
Data structures are the organizational tools data scientists use to update, manage and index internet services efficiently. Data structures are also used as the basis for many algorithms, due to the way they can filter and sort large quantities of data. There are three main parts to a data structure that make it work:
The Memory Address: The fixed raw data element of any desired feature or function.
The Pointer: A reference tool that represents the location of a memory address.
The Procedure: A written code that manipulates or creates different functions inside the structure, either automatically or manually.
The pointer, the memory address and the procedures of a data structure are vitally important, as the use of them, or the way that they are represented in any given database or website, determines the different types of data structures a database can fall into.
Types of Data Structures
How the above metrics are applied to data will determine what type of data structure any given database is using. There are several types of data structures, which include:
Arrays are a more basic data structure. They are defined by any number of the same type of raw data element being present in a specific order. Arrays can be fixed-length or resizable—permitting that the data elements remain the same—and use an integer index as a pointer, and a mathematical formula procedure to compute specified data. Array data structures are great for accessing randomly generated data.
Linked list structures are defined by a linear arrangement of raw data elements of any type, called nodes. Each node has a specific data value, and always points to the next node in the linear arrangement. Linked list data structures are great for efficiently inserting or removing individual data elements without having to restructure the rest of the list.
Stack data structures are categorized by the data elements following a specific procedure in perpetuity. Stack procedure generally follows these steps:
Push: Adds new items to the stack.
Pop: Removes items from the stack.
Peek (or top): Returns the top element of the stack.
Isempty: Returns true when the stack is empty, otherwise returns false.
You can use stacks in tandem with a linked list or array data structure by substituting a stack for the procedure.
Tree graphs are a hierarchical data structure for the organization of larger or more complex abstract data types (ADT). Tree data structures are organized by three elements:
The root value is the beginning, or the root, of all the other raw data elements in the structure, and the cornerstone the rest of the data relates to. The parent nodes are larger, less specific data elements that smaller or more specific data can fall under as child nodes. There are several types of tree data structures, including:
Binary Trees: Where each parent node has exactly zero or two children.
Binary Search Trees: Where the left child value of a parent node is less than or equal to the parent value and the right child value is greater than or equal to the parent value.
N-ary Trees: Where the maximum number of children a parent node can have is zero or N. For example, a 3-ary tree has no more than three children nodes.
A graph data structure consists of nodes—also called vertices in some cases—and edges—also called lines or arcs. Due to the edges, which can connect any two nodes, graphs are a nonlinear data structure. There is a finite set of nodes in a graph, which are often used to represent data networks.
Examples of Data Structures
In the abstract, data structures can seem complicated and specialized. But you probably encounter hundreds of data structures each day without knowing it. Common examples of data structures include:
Playlists are an easy example of a real-world linked-list data structure—more specifically, a double-linked list. Whether they’re fixed playlists, like those found on music streaming platforms, or algorithmically generated playlists, like those produced by autoplay functions on video streaming platforms, playlists follow a linear progression. In the case of double-linked lists, there’s a pointer to the previous and the next node, which allows repetition without a manual restart.
Hierarchical data structures, like trees, and networking data structures, like graphs, are used when facilitating governance all the time. From local city planners, who may use graph data structures to organize their online maps or local directories, to the national level, like organizing census data, which—due to the amount and nature of the data—demands a hierarchical structure.
Search engines require a high level of organization, so it wouldn’t be unusual to find a few data structures in place across different search engines. However, the most commonly employed data structure across search engines is the array. Search engines will store related web pages in an array structure to produce a wide realm of related results whenever you search.
The internet has become integral to our everyday lives. Understanding different data structures can make your life easier not only as a student in a data science program, but as an informed internet denizen.