Introduction to Data Structures in Python

Data Structures are an efficient and organized way of storage of data such that they can be accessed, modified, and manipulated easily. They are fundamental elements of a computer program that helps the program to run easily.

In computer science, Data Structures can be divided into two types:

  1. Linear DS
  2. Non-Linear DS

Linear Data Structures

Elements in a Linear Data Structure are stored sequentially with each element being connected to the one next to it, as well as to the one before it.

Computer memory is sequential too. That's why Linear Data Structures are easy to use. Besides, they have a single level which enables them to get traversed in a single go.

Examples of Linear Data Structures are:

  1. Arrays
  2. Linked Lists
  3. Stacks
  4. Queues
  5. Matrices

d12

Non-Linear Data Structures

In Non-Linear Data Structures no two elements are stored in sequential order. They are not connected in a particular pattern and can be traversed from any element or group of elements to any element or group of elements without following a sequence.

Non-Linear Data Structures are difficult to implement due to their non-singular level nature, and cannot be traversed in one go. It uses computer memory more efficiently too.

Examples of Non-Linear Data Structures are:

  1. Trees
  2. Heaps
  3. Hash Tables
  4. Graphs

b9120bbd-a3d1-47b0-994b-fec33a80a9c0

Python Specific Data Structures

Python pre-defined data structures are data structures that are adaptable, easy to use, and efficient in the Python environment. Also, pre-defined data structures can store different types of data in the same structure.

There are four types of such data structures:

  1. Lists
  2. Tuples
  3. Dictionaries
  4. Sets

Differences between Linear and Non-Linear Data Structures

Linear Data Structures Non-Linear Data Structures
Elements are ordered in a linear manner. Elements are ordered in a non-linear manner.
Each element is attached to the next as well as the previous element. Each element or group of elements is attached to any other element or group of elements.
Implementation is easy. Implementation is problematic.
Can be traversed in a single pass. Cannot be traversed in a single pass.
Memory not used efficiently. Memory used efficiently.
Used in software development. Used in AI, ML, and research.
Examples, array, lists, stacks, queues, and linked lists. Examples, trees, and graphs.
Time complexity increases with increases in size. Time complexity remains the same with an increase in size.
Has a single level. Has multiple levels.
0 results
Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions