DEV Community

Moreen Isaac
Moreen Isaac

Posted on

INTRODUCTION TO DATA STRUCTURES AND ALGORITHMS

With the rise of technology use ,data structures and Algorithms is a big requirement for all software engineers.
So what is Data structures and algorithms and why are they important for all software engineers?

Data Structures is a particular way of organizing data in a computer so that it can be accessed and used effectively. Just like in real life,we choose different storing assets like containers depending on what we want to store and how we want to access them.
 
Data structures are divided into 2 two types, Linear and non-liner data and we get to choose what data structure to use with regards to what we what it to achieve.
Liner data structures are further listed to Array,Stack ,queue and linked lists.
Array is a container which can hold a fix number of items and these items should be of the same type. Most of the data structures make use of arrays to implement their algorithms. Following are the important terms to understand the concept of Array.

  1. Element − Each item stored in an array is called an element.
  2. Index − Each location of an element in an array has a numerical index, which is used to identify the element and they start at 0.

Following are the basic operations supported by an array.

  1. Traverse − print all the array elements one by one.
  2. Insertion − Adds an element at the given index.
  3. Deletion − Deletes an element at the given index.
  4. Search − Searches an element using the given index or by the value.
  5. Update − Updates an element at the given index

EXAMPLE
Given an array of integers, find the sum of its elements.
In this scenario we are going to 1st add all the elements till we reach the end of the array the display the final answer as Sum.

function simpleArraySum(ar) {
    // Write your code here
    let n = ar.length;
    let sum = 0;
 for(let i = 0; i < n; i++){
     sum = sum + ar[i]
; }
return sum
;} 
Enter fullscreen mode Exit fullscreen mode

Top comments (0)