Skip to content

A space for me to learn and fiddle around with different data structures and algorithms.

License

Notifications You must be signed in to change notification settings

MarvelProgramming/Data-Structures-And-Algorithms

Repository files navigation

Data-Structures-And-Algorithms

Marvel Johnson
LinkedIn | GitHub


Tests

Description:

A space for me to learn and fiddle around with different data structures and algorithms.

I'm using Jest for the unit tests, which can be ran using the npm test command.


Data Structures:


Algorithms:



A tree-like structure where the root is on top (R), branches are the 'edges' or 'nodes' that have children (B), and leaves are the 'nodes' that have no children (L).


The examples below were created with the stringify function built into the BinaryTree class (with the exception of the first example).

Visual Example 1
___R___
_B___B_
L_L_L_L
Visual Example 2
_______5_______
___0_______7___
_X___2___X___X_
X_X_X_4_X_X_X_X
Visual Example 3
_______________________________5_______________________________
_______________1_______________________________5_______________
_______X_______________4_______________X_______________6_______
___X_______X_______X_______X_______X_______X_______X_______7___
_X___X___X___X___X___X___X___X___X___X___X___X___X___X___X___9_
X_X_X_X_X_X_X_X_X_X_X_X_X_X_X_X_X_X_X_X_X_X_X_X_X_X_X_X_X_X_8_X

I've implemented a number of functions that allow a binary tree to be manipulated:

The constructor takes one argument that defines what value the root node will have. This is important, because the placement of insertions depends upon whether the input value is greater than or less than the value of the root node.

const tree = new BinaryTree(value);

Convenience getters for accessing properties on the root node.

tree.value;
tree.left;
tree.right;

Performs a recursive dive into the tree, choosing a direction based on the delta between the input value and the current node's value.

tree.insert(value);

Performs a recursive search for the input value, and removes it if it's found.

tree.delete(value);

Recursively swaps the left and right properties of each node in the tree, starting from the root.

tree.reverse();

Returns a formatted string representation of the binary tree.

tree.stringify();

Resources


A unidirectional chain of nodes where each node contains a value and a pointer to the next node.

The examples below were created with the stringify function built into the SinglyLinkedList class.

Visual Example 1
1
Visual Example 2
1 -> 2 -> -44 -> 12
Visual Example 3
852 -> 22 -> -50 -> -10 -> 73 -> 13 -> 98 -> 9

The SinglyLinkedList has a parameterless constructor

const singlyLinkedList = new SinglyLinkedList();

The add function allows you to append nodes to the end of the chain, replacing the tail with the newly created node

singlyLinkedList.add(value);

The removeAt function accepts an input that represents the index belonging to the node you'd like to delete

singlyLinkedList.removeAt(index);

You may use the getAt function to retrieve a node at a given index

singlyLinkedList.getAt(index);

The reverse function will flip the pointer for each node in the chain with a time and space complexity of O(n) and O(1) respectively

singlyLinkedList.reverse();

You can produce a string representation of the SinglyLinkedList with the stringify method (check the visual examples above for what to expect as an output)

singlyLinkedList.stringify();

Resources


-Coming Soon-


Resources


-Coming Soon-


Resources


-Coming Soon-


Resources




-Coming Soon-


Resources


-Coming Soon-


Resources


-Coming Soon-


Resources


-Coming Soon-


Resources

Wikipedia: https://en.wikipedia.org/wiki/Bucket_sort



-Coming Soon-


Resources


-Coming Soon-


Resources


-Coming Soon-


Resources

About

A space for me to learn and fiddle around with different data structures and algorithms.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published