Data Structures 101: Introduction to Data Structures and Algorithms.

Data structures are the mental framework we use when solving problems. They're a fundamental part of computer science and typically the first topic in any introductory programming class. If you haven't had a chance to learn what they are, or how they work, this article will help get your feet wet on data structures and algorithms.

What is a Data Structure

A data structure is a collection of data that can be manipulated in some meaningful way. In programming, it's used to store, retrieve and search for data. These days, data structures are ubiquitous. It's hard to imagine a program without them.

What are Data Types

Data types are the various kinds of data a language can represent.

For example, in Python the following are data types:

int = integer (whole numbers)

float = floating-point number (decimal numbers)

str = a string of characters

Types of Data Structures

Data structures are divided into two depending on whether they are established by a programming language(primitive) or a user(non-primitive).
Further, the non-primitive data structure is divided based on how they are organized in memory.

All data types are Data Structures

Linear DataStructure - organized sequentially in memory and examples include arrays, stacks, queues and linked lists.

Non-Linear Data Structure - organized in a hierarchical fashion where elements are interconnected and assume a parent-child model and examples include graphs, trees and tries.

What is an Algorithm

In programming, algorithms are the basic building blocks of programs. They're what make programs do what they do.

An algorithm is a "step-by-step" procedure for solving a problem. An example of an algorithm might be how to best solve a quadratic equation.

Algorithms ought to possess:

  1. Correctness: The algorithm should always produce the correct result in a finite amount of time, regardless of what data it's given.
  2. Efficiency: An algorithm should run as fast as possible (within reason) regardless of the size of its input, and never take longer than necessary to complete a task.
  3. Simplicity: An algorithm should be easy to understand and implement correctly.

The efficacy of an algorithm is often judged based on time & space complexity.

When should I use Data Structures?

  1. Sorting algorithms and data structures that help you sort your data (e.g., arrays)
  2. Searching and finding algorithms and data structures that help you find specific values (e.g., hash tables, maps)
  3. Displaying or manipulating data structures to explore the structure or order of the data (e.g., trees, graphs, lists)
  4. Serializing or storing data structures for later use (e.g., heaps, stacks)
  5. Subsetting data from a collection of data structures (e.g., trees)
  6. Combining two or more data structures to produce a new one (e.g., trees and lists)