To turn in your reading, “Reply” to the discussion by teaching something that you learned. Then review what one of your classmates learned, and leave a comment.
Some ideas for how you might want to teach:
A stack is a data structure that consists of Nodes. Each Node references the next Node in the stack, but does not reference its previous.
Common terminology for a stack is
Push - Nodes or items that are put into the stack are pushed
Pop - Nodes or items that are removed from the stack are popped. When you attempt to pop an empty stack an exception will be raised.
Top - This is the top of the stack.
Peek - When you Peek you will view the value of the Top Node in the stack. When you attempt to Peek an empty stack an exception will be raised.
IsEmpty - returns true when stack is empty otherwise returns false.
Stacks follow these concepts:
FILO
LIFO
Push O(1)
O(1) operation. This is because it takes the same amount of time no matter how many Nodes (n) you have in the stack.Pop O(1)
Popping a Node off a stack is the action of removing a Node from the Top. When conducting a pop, the Top Node will be re-assigned to the Node that lives below and the Top Node is returned to the user.
Typically, you would check isEmpty before conducting a pop.
Peek O(1)
When conducting a peek, you will only be inspecting the Top Node of the stack.
Typically, you would check isEmpty before conducting a peek.
IsEmpty O(1)
Here is the pseudocode for isEmpty
ALGORITHM isEmpty()
// INPUT <-- none
// OUTPUT <-- boolean
return top = NULL
A queue is a linear structure which follows a particular order in which the operations are performed. The order is First In First Out (FIFO).
A good example of a queue is any queue of consumers for a resource where the consumer that came first is served first.
Common terminology for a queue is
Enqueue - Nodes or items that are added to the queue.
Dequeue - Nodes or items that are removed from the queue. If called when the queue is empty an exception will be raised.
Front - This is the front/first Node of the queue.
Rear - This is the rear/last Node of the queue.
Peek - When you Peek you will view the value of the front Node in the queue. If called when the queue is empty an exception will be raised.
IsEmpty - returns true when queue is empty otherwise returns false.
Queues follow these concepts:
FIFO
LILO
Enqueue O(1)
enqueue action. This is done with an O(1) operation.Dequeue O(1)
dequeue action. This is done with an O(1) operation.Peek O(1)
When conducting a peek, you will only be inspecting the Front Node of the queue.
Typically, you would check isEmpty before conducting a peek.
IsEmpty O(1)
Here is the pseudocode for isEmpty
ALGORITHM isEmpty()
// INPUT <-- none
// OUTPUT <-- boolean
return front = NULL

and
