2. Agenda
• Overview the concept of Abstract Data Types (ADT)
• Operations on Lists
• Stack and how to use it in recursions
• Queue and how to use it in operating systems and algorithm design
Sains Data - UNS 2
3. Abstract Data Types (ADTs)
• ADT is a collection of objects with their set of operations.
• ADTs consists of lists, sets, and graphs, and their respective operations just
as integers, reals, and booleans.
• So, the set of ADTs, typically have such operations such as add, remove,
and contains.
• Using Java, we can implement ADTs to perform an operation on the ADT.
• The three data structures (Lists, Stacks, and Queues) are the typical/usual
example of ADTs.
• We can use those ADTs in several ways. But once we use the ADTs correctly,
we don’t need to how to implement them (ADTs).
Sains Data - UNS 3
4. The List
• The basic form of a list is 𝐴0, 𝐴1, 𝐴2, … , 𝐴𝑁−1 with the size of this list
is N.
• If 𝑵 = 𝟎, we call this list as an empty list.
• For simplifications, we will assume that the elements of lists are in
integers. Although, complex elements are allowed.
• Here, we will discuss two types of lists, which are:
• Simple Implementation of Lists: Array and Linked Lists
• Lists in Java Collection API
• ArrayList implementation
Sains Data - UNS 4
5. Simple Linked Lists
• To prevent linear cost of insertion and deletion, we need to save
lists next to each other.
• Linked lists have a series of nodes.
• Each of those nodes contains the element and a link to a node
from the next successor.
Sains Data - UNS 5
General concepts of linked list -- Picture taken from (Weiss, 2012)
Head
Predeces
sor of X
Node
X
Successo
r of X
tail
6. Simple Linked Lists: remove and insert
methods
• The remove method can be executed in one next reference change.
• Next, the insert method needs a new node from the system by using a
new call and then executing two reference maneuvers.
Sains Data - UNS 6
7. Lists in the Java Collections API
• Collection interface:
• Resides in package java.util.
• Iterators:
• Any collection implements Iteratable, must have a method with a name of
iterator that returns an object of type Iterator.
• There are tow popular implementation of List ADT:
• ArrayList: growable array implementation with constant get and set time. But,
very expensive to insert or remove an item.
• LinkedList: double List Implementation of the List ADT.
Sains Data - UNS 7
8. Operations of ArrayList and LinkedList
• To create/destroy a list
• To expand/shrink the list
• Read/write operations
• Changing the existing node
• Get the current position in the list
• Get the status of the list
Sains Data - UNS 8
9. Stack
• A stack is a list with the restriction that insertions and deletions can
be performed in only one position, such as the end of the list, top.
• There are 2 operations on a stack, which are push (to insert) and pop
(delete the most recent element).
• Stacks sometimes are known as LIFO (last in, first out).
Sains Data - UNS 9
10. Operations of Stacks
• Stack_empty(S): Check if the stack is empty return true
• Stack_full(S): Check if the stack is full return true
• Push(S, e): save item e into S whenever a place is still available
• Pop(S): get the last item stored in S (this item is considered as the last
item/element/top element) if S is not empty.
Sains Data - UNS 10
11. Queue
• Queues are list, where insertion is done at one end, and deletion is
performed at the other end.
Sains Data - UNS 11
12. References:
• Mark Allen Weiss, 2012, Data Structures and Algorithm Analysis in
Java, 3rd edition.
• GeeksforGeeks
Sains Data - UNS 12