Data Structures 101: Introduction to Data Structures and Algorithms

DS - Data Structure

ยท

3 min read

Algorithms are collections of steps to solve a particular problem.

Data structures are named locations used to store and organize data. It's a way of arranging data on a computer so that it can be accessed and updated efficiently.

Depending on the requirement and project, it is important to choose the right data structure for your project. For example, if data is to be stored sequentially in memory, then an Array would be a good fit.

Learning data structures and algorithms allow us to write efficient and optimized computer programs.

What are the Types of Data Structures we have?

  1. Linear DS

  2. Non-Linear DS.

Linear DS

In a linear data structure, elements are arranged in sequence one after the other. This makes the implementation of elements easy. However, when the complexity of the program increases, this data structure might not be the best choice because of operational complexities.

Examples of Linear DS

  • Arrays: In an Array, elements in memory are arranged in continuous memory. All the elements of an array are of the same type, and the type of elements that can be stored in the form of arrays is determined by the programming language.

https___bucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com_public_images_6ddcfa23-d872-4b90-8243-daa926803a74_501x146.png

  • Stacks: Stacks are stored in the LIFO principle (Last In, First Out). i.e the last element stored in a stack will be removed first. Just like a pile of plates. You can place one plate on top of the pile, where the last plate kept on the pile will be removed first.

Lifo_stack.png

  • Queue: Unlike a Stack, the queue works in with the FIFO principle (First In, First Out) where the first element stored in the queue will be removed first. Similar to a queue of people at a ticket stand where the first person in the queue gets his/her ticket first.

queue.png

  • Linked List: In a linked list, data elements are connected through a series of nodes, with each node containing the data item and a memory address linking to the next node.

https___bucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com_public_images_af4b20ca-317e-40eb-8dc2-17d783b86d59_399x200.png

Non-Linear DS

Unlike linear data structures, elements in non-linear are not stored sequentially. Instead, they are arranged in a hierarchical manner where one element is connected to one or more elements, like a family tree or a cooperate ladder. Non-linear data structures are further divided into graphs and tree-based data structures.

https___bucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com_public_images_5ad96d22-e3c6-4689-9091-65ef6be540fc_644x415.webp

Examples of Non-Linear DS

  • Graph DS: In the graph data structure, each node is called a vertex and each vertex is connected to other vertices through edges.
  • Trees DS: Similar to a graph, a tree is also a collection of vertices and edges. However, in trees, there can only be one edge between two vertices.

Common Tree-Based Data Structure

  • Binary Tree

  • Binary Search Tree

  • AVL Tree

  • B-Tree

  • B+ Tree

  • Red-Black Tree

Why Data Structures?

Knowledge of data structures provides a better way of organizing, maintaining, and storing data efficiently and this helps you write memory and time-efficient code.

Other really good resources you should check out are:

Gracias

Hey was this helpful? Please do leave a comment and a like below so others can find this post ๐Ÿ™‚.

Originally posted on my newsletter: Michael Ibinola

You can also find me: My Twitter & Github

ย