DEV Community

WashieMugo
WashieMugo

Posted on

Quick beginner Intro to Data Structures & Algorithm

Data structure:

A data structure basically refers to a format of organizing, processing, storing and retrieving data.
We can perceive a data structure as a shelf and the mode/method you place your books is the 'data structure'.

examples of data structures include:
Linear Data Structures:

  • Arrays
  • Stacks
  • Linked Lists
  • Queues

non-linear data Structures:

  • Trees
  • Graphs
  • Map

NB: Some data structures such as Hash-tables can be implemented linearly or non-linearly

Algorithm:

An algorithm refers to a set of instructions to a computer system defining how to procedurally solve a problem.
You can take an algorithm as a recipe. for attaining the end meal/product correctly one has to get the ingredients (inputs) correctly and the steps (flow / procedure) right, otherwise the meal will taste different (invalid output / semantically incorrect )or fail all the same.

Determining a good algorithm

A good algorithm should have the following key features :

  • Input : an algorithm should have 0 or more inputs
  • Output : an algorithm needs to produce an output after computation
  • Definiteness : each step of the algorithm should be well defined
  • Finiteness : the algorithm needs to terminate after a given number of steps (it shouldn't run forever)
  • Correctness : an algorithm should provide the correct output given a certain set of inputs.

Effectiveness of an algorithm

the effectiveness of an algorithm can be determined by calculating it's time and space complexities.
time complexity entails calculating the amount of time it takes to run an algorithm. the rule of thumb is that an effective algorithm should take the shortest time possible given a set of inputs.
Space Complexity on the other hand calculates the amount of memory an algorithm requires to run given a certain set of inputs. the rule of thumb here is that an algorithm should use the minimum amount of memory space possible.

Top comments (0)