Skip to content

Instantly share code, notes, and snippets.

@bushidocodes
Last active November 2, 2016 01:54
Show Gist options
  • Save bushidocodes/d7f6091c09245bf8dad09d1dd4185fb8 to your computer and use it in GitHub Desktop.
Save bushidocodes/d7f6091c09245bf8dad09d1dd4185fb8 to your computer and use it in GitHub Desktop.

Some Abstract Data Types

Set - List, Linked Tree, Trie, Hash Table List Stack Queue Map (Associative Array / Dictionary / etc.) Graph Tree

Array

An array is typically a contiguous set of addresses in memory, where the elements of the array are next to each other in memory. In JavaScript, arrays are actually objects under the hood, so they do not need to be predefined as having a certain number of elements, like some other language

Stack

A stack in computer science is like a stack of books. One can add a book to the top of the stack or take a book off the top of the stack, but one cannot take or place any book underneath other books. This is a “Last In, First out” (LIFO) type system. Typically, the act of adding an item to the top of the stack is described as “pushing” that item and the act of removing an item from the top of the stack is “poping” that item.

Queue

A queue in computer science is like a line for the midnight showing of a movie. People get in line according to the order that they arrive, and people enter the movie from the front of the line. One can only join the line at the back of the time. This is a “First In, First Out” (FIFO) system, and the act of joining the back of the queue is called “enqueuing” and the act of leaving the queue to do whatever you’re waiting for is called “dequeuing.”

Set

In Computer Science, a set is an unordered collection of unique values.

Linked Lists

In Computer Science, a list is an ordered collection of values, where a value may occur more than once.

A Linked List is a sequence of nodes that contains information and a reference to the next node.

{self:{name: “Sean McBride”, age: 30}, next: “Erica McBride”};
{self:{name: “Erica McBride”, age: 31}, next: “Maria Regina Riegger”};
{self:{name: “Maria Regina Riegger”, age: 31}, next: null};

Or, this is an array of objects:

Function LinkedList () {
var LinkedList = {
  var head = 0, //this points to the first element.
  var myLinkedList = [
    {self:{name: “Sean McBride”, age: 30}, next: 1},
    {self:{name: “Erica McBride”, age: 31}, next: 2},
    {self:{name: “Maria Regina Riegger”, age: 31}, next: null}
  ]
}

In a uni-directional implementation: The "head" is the pointer to the first item in the list. The "tail" is the last item in the list: an element without a pointer.

In a bi-directional implementatio, the "head" is a pointer to the first element and the "tail" is a pointer to the last element and each element points to the previous or subsequent element.

In this sort of implementation, the next attribute can be altered to change the order without having to shift the numbered indices of each element inside of the array.

Elements can be placed at any intermediate point in a LinkedList by modifying the next attribute of the previous element and pointing the next attribute of the new element to what the previous element had hitherto been pointing to A.next = C instantiate B A.next=B B.next=C Deleting B simple involves setting A.next back to C. B may persist without reference or it can somehow be garbage collected.

Binary Search Tree / Binary Sorted Tree

There is a root node with a binary value. New values are added to the tree. If the new value is less than the parent node, it progresses to the node at the left branch. If the new value is more than the parent node, then it progresses to the node at the right branch. It keeps doing this recursively until it reaches the bottom of the three, where it is appended as a new node. What if it finds a match on the tree?

JavaScript Primitive Data Types

  • Undefined - default for unassigned vars / nonexistance props
  • Null
  • Boolean
  • String - UTF-16
  • Number - 64 bit Double Float IEEE
  • Symbol - New ES6 Thing. Unique Token???

Dictionary

  • AKA Associative Array

Most JavaScript engines implement the Object standards via structs, but switch to hash tables is the Object exceeds a certain number of keys.

Tree ADT Nodes contain values There is a primary root node Children are recursive subtrees The final nodes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment