Data Structures Introduction
Tags: javascript, html, css, webdev
Published: 2021-02-11 06:10:36

---
title: Data Structures Introduction
published: true
description: 
tags: javascript, html, css, webdev
//cover_image: https://direct_url_to_image.jpg
---

                       -Which Data Structure is The Best?
                       -ES2015 Class Syntax Overview
                       -Data Structure: The Class Keyword
                       -Data Structure: Adding Instance Methods
                      
                     
  
                        
             


###Which Data Structure is The Best?
Data structures are collections of values, the relationships among them, and the functions or operations that can be applied to the data. Data structures excel at different things. Some are highly specialized, while others are more generally used. 

Visualized Data Structures

####Array

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/e5fwvhuwuptqzphxond1.png)

####Singly Linked List 
 ![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/zjcvtqzwjhx1jy05h5g1.png)

####Hash Table 

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/ww820m7x9cuwm0b6sdac.png)


####Tree 

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/anr5fmbcnq45qna5mzj3.png)

####Binary Search Tree 
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/43qx67syoph46215a1dj.png)


####Undirected Graph 

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/9e2hjh6crh7zsw5eq4cl.png)


####Directed Graph

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/g0x7xd5pywrncyjb6q5i.png)



All data structures store data, however the relationship between the data and the functionality between methods differ. 

###ES2015 Class Syntax Overview

What is a class? 
A class is a blueprint for creating objects with pre-defined properties and methods. 

####Class example 

```javascript 

class Student {
    constructor(firstName, lastName, year){
        this.firstName = firstName;
        this.lastName = lastName;
        this.grade = year;
    }
}

let firstStudent = new Student("Colt", "Steele",1);
let secondStudent = new Student("Blue", "Steele",2);

```
The method to create new objects must be called constructor. 
The class keyword creates a constant that can not be redefined. 




###Data Structure: Adding Instance Methods

```javascript 

class Student {
    constructor(firstName, lastName, year){
        this.firstName = firstName;
        this.lastName = lastName;
        this.grade = year;
        this.tardies = 0;
        this.scores = [];
    }
    fullName(){
        return `Your full name is ${this.firstName} ${this.lastName}`;
    }
    markLate(){
        this.tardies += 1;
        if(this.tardies >= 3) {
            return "YOU ARE EXPELLED!!!!"
        }
        return `${this.firstName} ${this.lastName} has been late ${this.tardies} times`;
    }
    addScore(score){
        this.scores.push(score);
        return this.scores
    }
    calculateAverage(){
        let sum = this.scores.reduce(function(a,b){return a+b;})
        return sum/this.scores.length;
    }  
}

let firstStudent = new Student("Colt", "Steele",1);
let secondStudent = new Student("Blue", "Steele",2);



```