44 total
By the end of this subtopic, you should be able to:
An abstract data type, or ADT, is a way of thinking about data by focusing on two things:
This means an ADT is not just a list of values. It also includes the allowed actions, such as adding an item, removing an item, or looking at an item.
For example, a stack is an ADT. It stores data, but it also has special operations such as push and pop. A queue is another ADT, with operations such as enqueue and dequeue. A linked list is also an ADT because it stores data in linked nodes and allows items to be added or removed by changing pointers.
The word abstract means we are mostly interested in what the structure does, not all the low-level details of how it is built. In this topic, though, you also need to understand a simple way these ADTs can be implemented using arrays.
The syllabus names three important ADTs:
Each one stores data in a different way. Because they work differently, they are useful in different situations. A student needs to know both the structure and the reason for using it.
A stack is a linear structure where the last item added is the first item removed. This is called LIFO, which stands for Last In, First Out.
A good everyday example is a pile of trays or plates. You add a new plate to the top. When you remove a plate, you also take it from the top. You do not usually take one from the middle or bottom.
A stack has these important features:
The common operations are:
Imagine the stack currently contains:
Top -> C B A
Here, C was added last, so C will be removed first.
If you push D, the stack becomes:
Top -> D C B A
If you then pop, D is removed, and C becomes the top again.
The syllabus says you should be able to add, edit and delete data. In a stack:
In practice, a stack mainly allows direct work at the top. So if you want to change an item lower down, it is less convenient than using some other structure. That is one reason a stack is best when you mainly need to work with the most recent item.
A stack is useful when data must be handled in reverse order of arrival.
Examples of suitable situations include:
A stack should be chosen when the newest item needs to be removed before older items.
Sign in to view full notes