DEV Community

Hussam Elmaghraby
Hussam Elmaghraby

Posted on • Edited on

Data Structures in Dart - #1 -Complexity

In this series of blogs, we will talk about the data structure in Dart.
So let's know what a data structure is.

Data structures

A data structure is a way to store and organize data in order to facilitate access and modification. Using the appropriate data structure or structures is an important part of algorithm design. No single data structure works well for all purposes, and so you should know the strengths.
and the limitations of several of them.

Firstly, before we dive into data structure, we need to know what _complexity _is.

Complexity refers to the amount of time, space, and other resources required to solve a problem or execute an algorithm.

Complexity is characterizing the efficiency of algorithms. Efficiency can be measured by

  1. Space Complexity -> Related to data structures and how information is stored

  2. Time Complexity -> Related to how fast the algorithm can process data and provide results

Time Complexities Cases:

Time Complexities Cases

  • Constant Time

    • It takes the same time regardless of the number of inputs. For example:

Constant Time Example 1

or

Constant Time Example 2

_Note : As input data increases, the amount of time the algorithm takes does not change. The Big O notation for constant time is O(1).

Constant Time

Note:
The Big O Notation is a metric for determining an algorithm's efficiency. Put simply, it gives an estimate of how long it takes your code to run on different sets of inputs. You can also see it as a way to measure how effectively your code scales as your input size increases.

Big O analysis

  • Linear Time

Linear Time Example

Linear Time

As you can see, as the amount of data increases, the running time increases by the same value.

The Big O notation for this type of complexity is o(n).

  • Quadratic Time

This type of algorithm takes time proportional to the square of the size of the inputs.

Quadratic Time Example

As you can see in the graph below, as the input size increases, the time it takes to run this code increases drastically.

Quadratic Time

The Big O notation for this type is O(n)^2.

Finally

At this point, you now know the concept of complexity and how to calculate the algorithm's efficiency.

In this article, I just talk about three types of complexity. If you want to know about the rest of the complexity types, you can find many resources on the internet.

I'm excited to see you in the next article.

See you soon!

Top comments (0)