Algorithms, Part 1 Course from Princeton — Stack, Queue, and Week 2 Assignment Deques and Randomized Queues

Introduction
Algorithms, Part 1 is a solid course for IT or software engineers to learn algorithms which are provided by Princeton. Of course, we still have to take time to clarify the concepts after completing the class.
Stack and queue are fundamental data structure for storing data in the practice. In this article, we will focus on APIs and different ways for implementations.
About this Series
This series aims to wrap up contents of Algorithms, Part 1.
- week 1: Union-find and Week 1 assignment Percolation
- week 2: this article
- week 3: Sorting and Week 3 assignment Collinear Points
- week 4: Binary Tree, Binary Heaps, and Week 4 Assignment 8 puzzle
- week 5: Hash table and Week 5 Assignment KD-Tree
Agenda
It includes the following topics in this article.
- Separate interface and implementation
- Introduction to Stack
- Stack implementation in Linked-list
- Stack implementation in Array (Resizing array)
- Introduction to Queue
- Queue implementation in Linked-list
- Queue implementation in Array (Resizing array)
- Priority queue implementation in Array
- Week 2 Programming Assignment: Deques and Randomized Queues
1. Separate interface and implementation
What we want to do is to completely separate the details of the implementation from the client
e.g., stack, queue, bag, priority queue, symbol table, union-find, etc.
Roles
client: program using operations defined in an interfaceimplementation: actual code implementing operationsinterface: the description of data type, basic operations
Benefits
Clienthas manyimplementationfrom which to choose but the client code should only perform the basic operations- Many clients can re-use the same
implementation
2. Introduction to Stack
Last in First out (LIFO): remove and return the item most recently added
APIs
APIs we have to implement for the stack.









