Welcome to my repository on data structures and algorithms! Here, you will find a collection of resources and implementations related to various data structures and algorithms in computer science using JavaScript.
An array is a linear data structure that stores a fixed-size sequence of elements of the same type. Each element can be accessed by its index, and the elements are stored in contiguous memory locations.
A linked list is a linear data structure that consists of a sequence of nodes, where each node contains a value and a reference to the next node in the list. Linked lists are dynamic in size and can be easily inserted or removed from the list.
A tree is a hierarchical data structure that consists of nodes organized into a parent-child relationship. The topmost node is called the root, and the nodes below it are called its children. Each node can have one or more children, and the nodes at the bottom level are called leaf nodes.
A graph is a data structure that consists of a set of vertices (nodes) and a set of edges that connect them. The edges can be directed or undirected, and the graph can be weighted or unweighted.
A heap is a complete binary tree that satisfies the heap property, which states that the value of each node must be greater than or equal to the values of its children (for a max heap) or less than or equal to the values of its children (for a min heap). Heaps are often used to implement priority queues.
A hash table is a data structure that stores key-value pairs in an array and uses a hash function to map the keys to the array indices. Hash tables are used for fast lookups, insertions, and deletions, and they have an average-case time complexity of O(1).
Sorting algorithms are used to arrange elements of a list in a specific order (ascending, descending, etc.).
Bubble sort is a simple sorting algorithm that repeatedly iterates through the list and swaps adjacent elements if they are in the wrong order
Insertion sort is a simple sorting algorithm that builds the final sorted list one item at a time by comparing the current item to the items already in the sorted list and inserting it in the correct position.
Merge sort is a divide and conquer algorithm that recursively divides the list into smaller lists until each list has only one element, and then merges the lists back together in a sorted order.
Quick sort is a divide and conquer algorithm that selects a pivot element from the list and partition the other elements into two lists based on whether they are less than or greater than the pivot. It then recursively sorts the two lists.
Searching algorithms are used to find an element in a list or a specific position in a list.
Linear search is a simple search algorithm that sequentially checks each element of the list until it finds the target element or determines that it is not present.
Binary search is an efficient search algorithm that works on sorted lists and uses a divide and conquer approach to find the target element. It repeatedly divides the list in half and compares the target element to the middle element until it is found or it is determined that it is not present.
Graph algorithms are algorithms that operate on graphs and are used to solve problems such as finding the shortest path between two nodes or determining the connected components of a graph.
Breadth first search (BFS) is an algorithm that traverses a graph by exploring all the nodes at the current depth level before moving on to the next depth level.
Depth first search (DFS) is an algorithm that traverses a graph by exploring as far as possible along each branch before backtracking.
Dijkstra's algorithm is an algorithm for finding the shortest paths between nodes in a graph with non-negative edge weights, used for problems such as routing and navigating a map.