DEV Community

Agikonyo
Agikonyo

Posted on

Introduction to Data Structures and Algorithms with Modern JavaScript

In this article we will tackle the following:
i. What are data structures and Types of Data Structures?
ii. What is an Algorithm?

Data Structures
Data structures allow you to manage data. They help us to store and organize the data primitives, so that they can be efficiently accessed and used in algorithms.
a. Arrays
Arrays are ordered list of sequences of primitive data types, that are a special variable, which can hold more than one value. There are two object-oriented implementations of array-like objects: queue and stacks. In Array data duplicates are allowed, Size is adjusted dynamically, elements are accessed via index and are iterable (therefore, you can use the for loop)

b. Hashtable / map
A hash table is a dictionary-like data structure, where keys are paired with values. Maps are great for rapid retrieval and modification of data since they store data for easy access. Maps have become nearly ubiquitous. They are Ordered key value with pairs of data, and one can access data via keys. Maps are iterable and keys can be anything (we can use reference values)
c. Objects
In objects we group data into one. The keys that are used in objects have to be numbers or strings. Keys are important because they’re unique while values are not .Objects have contracts that can store data .Objects can contain methods and functionalities and are not iterable

d. Sets
Sets are unordered list of data, that doesn’t allow duplicates. In sets Insertion order is not stored, We access and extract data via method, iterable is allowed one ( can use the for loop)

e. Stacks
A stack is an ordered list which follows LIFO (last in first out) algorithm. You can access the elements of a stack from only a single end.

Algorithms
An algorithm is a sequence of steps to solve a well-defined problem. A set of rules that precisely define a sequence of operations. We have different types of algorithms as stated below;
i. Binary Search
This is a divide and conquer algorithm, that divides the array in half every time it checks whether an element of the array is the one, we're looking for.
ii. Big O notation
This is a way of representing the general growth in the computational hardness of a task as you increase the data set. We have 5 types of Big O notation as stated below
• O(1)
• O(n)
• O(n^2)
• O(log n)
• O(n!)

iii. Imperative code
This is when you tell your program every single step to achieve a specific outcome as per your expected output.
iv. Recursion
This is a programming technique using function or algorithm that calls itself one or more times until a specified condition is met at which time the rest of each repetition is processed from the last one called to the first. Recursion involves solving problems by breaking things down into simpler/smaller versions of themselves
v. Tail recursion
This is when, instead of doing an invocation of the recursive function as the return statement, it does a jump and reuses the same context of the prior recursive called.

Top comments (0)