Unit 1 - Introducing Abstract Data Type (ADT) Part 3 – Slides 1 to 11
Unit Objectives Solve a problem using a concrete data type (CDT) ◦ Apply 4 steps of software development process Side trip -> UML class diagram Solve same problem using an abstract data type ◦ Introduce abstract data type (ADT) ◦ Introduce our first ADT -> List Design ADT List First implementation: array-based List Side trip -> pointers and linked lists Second implementation: link-based List ◦ Compare both ADT List implementations Side trip -> efficiency analysis CMPT Anne Lavergne2 Part 3
Side Trip – Pointers and linked lists CMPT Anne Lavergne3
Let’s first talk about Array Data structure (or CDT) Diagram of an array Indexing data structure ◦ Direct access CMPT Anne Lavergne4
What can you do with an Array 1. Insert 2. Delete 3. Traverse 4. Number of elements 5. Expand CMPT Anne Lavergne5
Problems with Array? Capacity required when creating an array ◦ Overestimate array’s capacity ◦ Underestimate array’s capacity May run out of space Solution: expand array How expensive is this operation? CMPT Anne Lavergne6
linked list To understand linked list, we first need to understand pointers If we are unfamiliar with pointers or would like to refresh our knowledge of pointers ◦ See Reading list for Lecture 7 on our course web site CMPT Anne Lavergne7
Let’s now talk about linked list Linked data structure (or CDT) ◦ Sequential access Diagram of an linked list CMPT Anne Lavergne8
linked list - Components Visually Head of linked list Node or link of linked list CMPT Anne Lavergne9
Examples of linked lists CMPT Anne Lavergne10
What can we do with a linked list 1. Insert 2. Delete 3. Traverse 4. Number of elements 5. Concat CMPT Anne Lavergne11