DEV Community

Cover image for JAVASCRIPT 102: INTRODUCTION TO DATA STRUCTURES AND ALGORITHMS WITH MODERN JAVASCRIPT
Abdulmuizz98
Abdulmuizz98

Posted on

JAVASCRIPT 102: INTRODUCTION TO DATA STRUCTURES AND ALGORITHMS WITH MODERN JAVASCRIPT

JAVASCRIPT 102: INTRODUCTION TO DATA STRUCTURES AND ALGORITHMS WITH MODERN JAVASCRIPT

One thing that can be considered almost a given in most interviews is the test of a candidate's appreciation of data structures and algorithms. A good knowledge of what data structure to use in specific problems is what separates elite developers from the rest.

Congrats, on taking your first steps to that elite class.

ALGORITHMS

Oxford dictionary defines an algorithm as a process or set of rules to be followed in calculations or other problem-solving operations, especially by a computer. An algorithm can be seen as a set of structured statements or instructions that dictate the steps to solving a particular problem.

When faced with a problem, a structured way to go about the algorithm is to use a flow-chart (a diagrammatic representation of the steps involved) or a pseudo-code (a statement of the steps in a near-native language).

Some common algorithms you can practice for interviews include:

Fizz Buzz

Given a number as an input, print out every integer from 1 to that number. However, when the integer is divisible by 2, print out "Fizz"; when it's divisible by 3, print out "Buzz"; when it's divisible by both 2 and 3, print out "Fizz Buzz".
Reverse String
Required to reverse the order of characters in an input string.

Palindrome

A palindrome is a word or phrase that reads the same backward as forward. Write a function that checks for this.

DATA STRUCTURES

Now data structures.

There are a number of data structures that are indispensable to developers when coming up with algorithms or writing solutions to problems. These structures help them attain efficiency without compromising on performance.

I'd be introducing you to some of the basic ones. Here you go.

Array

An array is an ordered data structure with elements separated by a comma while encapsulated within square brackets. For example,

    var List = ["boy", "girl", "woman"]
Enter fullscreen mode Exit fullscreen mode

Queues

The queue works conversely to a Stack. The difference is laden in the fact that Queue uses the FIFO principle (First In First Out). Take for instance, when you queue for a bus, the first in the queue will always board first. Queue has the following methods; enqueue, dequeue, front, isEmpty, size.

Stack

In stacks, the last item to get in the structure is the one that gets pulled first. This is called LIFO just like when you stack CDs on a pile, you can only remove the last stacked CD first.
.Stack has the following methods push, pop, peek, and length.

Linked list.

A linked list is a data structure that imitates a kind of chain linking structure. The first node in the structure is called the head and it holds a pointer that connects to the next and the cycle continues till the last node is called the tail.

Top comments (0)