Constructor:
- initializes a new node with given value
Parameters:
value
: the value to be stored in node
Properties:
next
: a reference to the next nodevalue
: value stored in node
Constructor:
- initializes an empty stack object with a
length
of 0 andhead
set toundefined
Properties:
length
: number of nodeshead
: top node of a stack
Methods:
pop
: remove top node and returns nodevalue
push
: creates a new node with a givenvalue
and insert a node in a top of stackpeek
: returns a top nodevalue
Contructor:
- initializes a new node with a given value
Properties:
next
: reference to the next nodeprev
: reference to the previous nodevalue
: value of the node
Properties:
head
: first node of the queuetail
: last node of the queue
Methods:
enqueue
: creates a new node and add it to the end of the queue (tail
)dequeue
: removes a firs node (head
) and returns its valuepeek
: returns first node value (head
)
Constructor:
- initializes a new binary node with given
value
Parameters:
value
: the value to be stored in node
Properties:
left
: left child noderight
: right child nodevalue
: value stored in node
Constructor:
- initializes an empty binary tree with
root
set toundefined
and asize
to 0
Properties:
root
: root node of the binary treesize
: number of nodes in tree
Methods:
insert
:insert(value: T): this
, creates a new node with a given value and insert to the tree as a last node (BFS), returns thisfind
: search for a value in binary tree (DFS), returns booleanpreOrder
: traverses the tree in pre-order (DFS) and applies a callback function on each node value, returns an array of nodes values or array of results of callback functioninOrder
: same aspreOrder
but in orderpostOrder
: same aspreOrder
but in post orderlevelOrder
: traverses the tree in level-order (BFS)
Contstructor:
- initializes an adjacency list as an empty Map object
Properties:
adjacencyList
: map to store grap structure
Methods:
addVertex
: adds a new vertex to the graphaddEdge
: adds a new edge between two vertices, if the vertices do not exists, they are added to the graphgetEdgeWeight
: returns the weight of the edge between two veticesdepthFirstSearch
: performs a DFS starting from a given vertexbreadthFirstSearch
: performs BFS starting from a given vertex.
Constructor:
- initialize a new node with a given value
Properties:
value
: node valuenext
: reference to the next node
Properties:
head
: first node of the listlength
: number of nodes in the list
Methods:
prepend
: creates a new node with a given value and insert it at the beginning of the listappend
: creates a new node with a given value and insert it at the endinsertAt
: creates a new node with a given value and insert it at a given indexremoveAt
: removes a node at a given indexremove
: removes a node with a given valuesearch
: search for a node with a given value, returnsboolean
validateIdx
: private method for a validating if a given index is not out of bounds
Constructor:
- initialize a new MinMaxStack object with a min and max properties sets to a new Stack objects, calls super()
Properties:
min
: stores a stuck object for storing current min value of the MinMaxStack objectmax
:stores a stuck object for storing current max value of the MinMaxStack object- all properties inherited from Stack class
Methods:
pop
: creates a new node with a given value and add it to the top of the stackpush
: removes a top node of the stack and returns its valuesetMinMaxOnPush
: private method using to adjust current min and max values in the stack after adding a new nodesetMinMaxOnPop
: private method using to adjust current min and max values in the stack after removing a nodegetMin
: returns a min valuegetMax
: returns a max value
Determines if a binary tree is a binary search tree. Returns boolean.
Parameters:
root
: root node of a binary tree
Finds the shortest path between two vertices in a graph using Breadth-First-Search. Returns path as an array or underfind
.
Parameters:
start
: start vertexend
: end vertexadjacencyList
: adjacency list representing the graph
Finds the shortest path between two vertices in a graph using Dijkstra's algorithm. Returns path as an array or underfind
.
start
: start vertexend
: end vertexadjacencyList
: adjacency list representing the graph
Detects if a linked list has a cycle, using fast and slow pointers. Returns boolean
.
Parameters:
head
: a head of a linked list