DEV Community

Cover image for Data Structures 101: Introduction to Data Structures and Algorithms.
GerryJ
GerryJ

Posted on

Data Structures 101: Introduction to Data Structures and Algorithms.

Difference between Data Structures and Algorithms?
An algorithm is "a finite sequence of instructions, each of which has a clear meaning and can be completed with a finite amount of effort in a finite amount of time_" for a specific activity. Simply put, an algorithm defines a collection of instructions that must be followed in a certain order to get the intended result. Algorithms are often written without regard to the underlying programming languages; that is, an algorithm can be written in more than one computer language.
The capacity of computer scientists to create an effective algorithm is dependent on their ability to arrange data properly. As a result, data structures are systemic methods of structuring data for certain operations. To note, no single data structure works well for all purposes, therefore, it is important to learn the strengths and limitations of several of them.

Data structures can be categorized into;

  • Linear Data Structure
  • Non-linear Data Structure

Image description

Linear Data Structure

If the elements of a data structure combine to generate a certain order, it is said to be linear. A linear relationship between all the pieces represented by a linear memory location is one technique of describing such linear structure inside memory. A good example of such are Arrays.
The second method uses the idea of pointers or links to create a linear relationship between all of the objects displayed, e.g, Linked lists.
Arrays, Queues, Stacks, and Linked Lists are all instances of linear data structures.

Non-Linear Data Structure

This structure is mostly used to describe data that has a hierarchical relationship between the various parts.

The following are some examples of non-linear data structures;

  • Graphs
  • Trees

Characteristics of an Algorithm

  • Unambiguous − Each of its steps and their inputs/outputs should be clear and must lead to only one meaning.

  • Input− Have 0 or more well-defined inputs.

  • Output − Have 1 or more well-defined outputs, and should match the desired output.

  • Finite− Must terminate after a finite number of steps.

  • Feasibility− Should be feasible with the available resources.

  • Independent− An algorithm should have step-by-step directions, which should be independent of any programming code.

Efficiency of an algorithm

The efficiency of an algorithm can be determined by two main factors; time and space

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

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 (2)

Collapse
 
aravindhnirmal profile image
aravindhnirmal

sweet! can u recommand some youtube channel for ds?

Collapse
 
mneme profile image
Alex T

short and sweet. can share on examples of when to use linear and non-linear data structure? I know social media platform will be on non-linear