
























Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!

























EE 232 Data Structures Session-18 , Spring- 2020
Our goals: we will learn ❑ The concept of Abstract Data Types (ADTS) ❑ How to efficiently perform operations on lists ❑ The Stack ADT and its use in implementing recursion ❑ The Queue ADT and its use in operating systems and algorithm design
Abstract Data Type ❖ a set of objects and ❖ the set of operations that can be performed on the objects ❑ Abstract data types are mathematical abstractions; nowhere in an ADT’s definition is there any mention of how the set of operations is implemented.
❑ Objects such as lists, sets, and graphs, along with their operations, can be viewed as ADTs. ❑ For the set ADT, we might have such operations as add, remove, size, and contains. ❑ Alternately, we might only want the two operations union and find, which would define a different ADT on the set. ❑ There is no rule telling us which operations must be supported for each ADT; this is a design decision.
Objects ❖ A general list is of the form A 0
1
N- 1
Set of Operations (Some popular operations): ❖ PrintList : prints the list ❖ MakeEmpty : create an empty list ❖ Find : returns the position of the first occurrence of an item. ❖ list: 34,12, 52, 16, 12. Find (52) → 2 ❖ Insert : insert an object into a given position
❑ The interpretation of what is appropriate for a function is entirely up to the programmer, as is the handling of special cases (for example, what does find(1) return above?). ❑ We could also add operations such as next and previous, which would take a position as argument and return the position of the successor and predecessor, respectively.
Running time of the operations for an array implementation of Lists ❖ The running time for PrintList and Find?
❑ There are many situations where the list is built up by insertions at the high end, and then only array accesses (i.e., findKth operations) occur. ❖ In such a case, the array is a suitable implementation. ❑ If insertions and deletions occur throughout the list and, in particular, at the front of the list, then the array is not a good option. ❖ The alternative is the linked list.
Simple Linked Lists ❖ consists of a series of nodes or structures, which are not necessarily adjacent in memory ❖ Each structure or node contains the element and a link or pointer (called Next ) to a structure containing its successor. The last cell’s next link points to nullptr. A 0 A N- 1
A node in the list Conceptual view of a linked list