Lecture 02 - Abstract Data Type, Arrays & Linked List
Lecture 02 - Abstract Data Type, Arrays & Linked List
CSE 4303
Data Structure
Asaduzzaman Herok
Lecturer | CSE | IUT
[email protected]
What is Abstract Data Type?
An abstract data type (ADT) is the way we look at a data structure, focusing on what it does
and ignoring how it does its job.
Data type: Data type of a variable is the set of values that the variable can take. We
have already read the basic data types in C include int, char, float, and double.
Abstract; The word ‘abstract’ in the context of data structures means considered apart
from the detailed specifications or implementation.
Advantage of using ADTs: In the real world, programs evolve as a result of new
requirements or constraints, so a modification to a program commonly requires a change in
one or more of its data structures. So it is better to separate the use of a data structure from
the details of its implementation.
Asaduzzaman Herok, Lecturer
28 August, 2023 2
Department of Computer Science and Engineering, IUT
Arrays
Scenario: There are 20 students in a class, we have write a program that reads and
prints the marks of all the students. How can we do it?
Advantage:
● An array is a pretty obvious way to store a list, with a big advantage: it enables very fast
access of each item.
Disadvantage:
● First, if we want to insert an item at the beginning or middle of an array, we have to slide
a lot of items over one place to make room. This takes time proportional to the length of
the array.
● Second, an array has a fixed length that can’t be changed. If we want to add items to the
list, but the array is full, we have to allocate a whole new array and move all the items
from the old array to the new one.
➢ Traversing Erasing/Deleting
➢ Find / Search Accessing
➢ Insert
➢ Erase / Delete
➢ Update / Replace
➢ Sorting
➢ Merging Inserting
Updating
Good = Θ(1), Okay = Θ(log(n)), Bad = Θ(n) * only if the array is not full
Good = Θ(1), Okay = Θ(log(n)), Bad = Θ(n) * only if the array is not full
???
There must be a data structure that removes the restrictions on the maximum number of
elements and the storage condition to write efficient programs … …
➔ Linked lists are appropriate when the number of data elements to be represented in
the data structure at once is unpredictable.
➔ Linked lists are dynamic, so the length of a list can increase or decrease as necessary.
➔ Each node does not necessarily follow the previous one physically in the memory.
➔ Linked lists can be maintained in sorted order by inserting an element at the proper
point in the list.
➔ Can be used to implement other data structures like binary trees.
❏ However, linked lists have a big disadvantage compared to arrays. Finding the kth item of a linked list
takes time proportional to k. You have to start at the head of the list and walk forward k - 1 nodes, one
"next" at a time.
Asaduzzaman Herok, Lecturer
28 August, 2023 9
Department of Computer Science and Engineering, IUT
Operations on Linked List
Traversing: accessing the nodes of the list in
order to perform some processing on them.
In a circular linked list, the last node contains a pointer to the first node of the list.
A circular doubly linked list or a circular two-way linked list is a more complex type of linked
list which contains a pointer to the next as well as the previous node in the sequence.
Disadvantage
❏ Finding end of list and loop control is harder (no NULL's to mark the end)
❏ If we at a node and need to go back to the previous node, then we can not do it in
single step (In case of singly circular list). Instead we have to complete the entire
circle by going through the in between nodes.
Rafsanjany Kushol
PhD Student, Dept. of Computing Science,
University of Alberta
Sabbir Ahmed
Assistant Professor
Department of CSE, IUT