1 Chapter 3 Data Representation Part 1. 2 Goals Introduce the different ways in which data may be represented Concepts –Abstract data types –Formula-based,

Slides:



Advertisements
Similar presentations
Pointers.
Advertisements

Lists CS 3358.
COMP171 Fall 2005 Lists.
Stacks, Queues, and Linked Lists
Linked Lists.
Linear Lists – Array Representation
Lists A list is a finite, ordered sequence of data items. Important concept: List elements have a position. Notation: What operations should we implement?
Data Structures ADT List
DATA STRUCTURES USING C++ Chapter 5
Lists: An internal look
Chapter 3 – Lists A list is just what the name implies, a finite, ordered sequence of items. Order indicates each item has a position. A list of size 0.
Chapter 1 Object Oriented Programming 1. OOP revolves around the concept of an objects. Objects are created using the class definition. Programming techniques.
David Weinberg presents Linked Lists: The Background  Linked Lists are similar to ArrayLists in their appearance and method of manipulation  They do.
Queue Definition Ordered list with property: –All insertions take place at one end (tail) –All deletions take place at other end (head) Queue: Q = (a 0,
Templates in C++ Template function in C++ makes it easier to reuse classes and functions. A template can be viewed as a variable that can be instantiated.
Chapter 17 Linked List Saurav Karmakar Spring 2007.
Skip List & Hashing CSE, POSTECH.
Data Structures: A Pseudocode Approach with C 1 Chapter 5 Contd... Objectives Explain the design, use, and operation of a linear list Implement a linear.
Chapter 1 Object Oriented Programming. OOP revolves around the concept of an objects. Objects are crated using the class definition. Programming techniques.
1 Data Structures Data Structures Topic #2. 2 Today’s Agenda Data Abstraction –Given what we talked about last time, we need to step through an example.
Starting Out with C++: Early Objects 5/e © 2006 Pearson Education. All Rights Reserved Starting Out with C++: Early Objects 5 th Edition Chapter 17 Linked.
Chapter 4 Linked Lists. © 2005 Pearson Addison-Wesley. All rights reserved4-2 Preliminaries Options for implementing an ADT List –Array has a fixed size.
Monday, 11/18/02, Slide #1 CS 106 Intro to CS 1 Monday, 11/18/02  QUESTIONS??  Today:  Hand back, discuss HW #4  Discussion of Lab 10  Exam #2 Friday.
Data Structures Using C++ 2E
Linear Lists – Linked List Representation CSE, POSTECH.
Review 1 Introduction Representation of Linear Array In Memory Operations on linear Arrays Traverse Insert Delete Example.
L.Chen1 Chapter 3 DATA REPRESENTATION(2) L.Chen A Chain Iterator Class A Chain Iterator Class ( 遍历器类 )  An iterator permits.
Linked Lists list elements are stored, in memory, in an arbitrary order explicit information (called a link) is used to go from one element to the next.
Implementation of Linked List For more notes and topics visit: eITnotes.com.
Lecture DS & Algorithms:09 Abstract Data Types. Lecture DS & Algorithms:09 2 Abstract Data Types Data Type: A data type is a collection of values and.
1 Chapter 16-1 Linked Structures Dale/Weems. 2 Chapter 16 Topics l Meaning of a Linked List l Meaning of a Dynamic Linked List l Traversal, Insertion.
Chapter 1 Object Oriented Programming. OOP revolves around the concept of an objects. Objects are created using the class definition. Programming techniques.
Linked Lists part 2 CS 244 Brent M. Dingle, Ph.D. Game Design and Development Program Department of Mathematics, Statistics, and Computer Science University.
1 Chapter 16 Linked Structures Dale/Weems. 2 Chapter 16 Topics l Meaning of a Linked List l Meaning of a Dynamic Linked List l Traversal, Insertion and.
1 Chapter 16 Linked Structures Dale/Weems/Headington.
Prof. amr Goneid, AUC1 CSCE 110 PROGRAMMING FUNDAMENTALS WITH C++ Prof. Amr Goneid AUC Part 16. Linked Lists.
1 Linked-list, stack and queue. 2 Outline Abstract Data Type (ADT)‏ Linked list Stack Queue.
Lists Chapter 8. 2 Linked Lists As an ADT, a list is –finite sequence (possibly empty) of elements Operations commonly include: ConstructionAllocate &
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide
Copyright © 2012 Pearson Education, Inc. Chapter 17: Linked Lists.
Linked List Chapter Data Abstraction separates the logical properties of a data type from its implementation LOGICAL PROPERTIES – What are the.
APS105 Lists. Structures Arrays allow a collection of elements –All of the same type How to collect elements of different types? –Structures; in C: struct.
1 Chapter 7 Skip Lists and Hashing Part 2: Hashing.
Data Structures Using C++1 Chapter 5 Linked Lists.
List Interface and Linked List Mrs. Furman March 25, 2010.
1 Classes II Chapter 7 2 Introduction Continued study of –classes –data abstraction Prepare for operator overloading in next chapter Work with strings.
2/21/20161 List Operations Advanced Programming Ananda Gunawardena.
Circular linked list A circular linked list is a linear linked list accept that last element points to the first element.
Chapter 17: Linked Lists. Objectives In this chapter, you will: – Learn about linked lists – Learn the basic properties of linked lists – Explore insertion.
Data Structure & Algorithms
 Data Type is a basic classification which identifies different types of data.  Data Types helps in: › Determining the possible values of a variable.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 17: Linked Lists.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 18: Linked Lists.
Arrays, Link Lists, and Recursion Chapter 3. Sorting Arrays: Insertion Sort Insertion Sort: Insertion sort is an elementary sorting algorithm that sorts.
CMSC 202 Computer Science II for Majors. CMSC 202UMBC Topics Templates Linked Lists.
CC 215 DATA STRUCTURES LINKED LISTS Dr. Manal Helal - Fall 2014 Lecture 3 AASTMT Engineering and Technology College 1.
LINKED LISTS.
Copyright © 2012 Pearson Education, Inc. Chapter 17: Linked Lists.
CSCE 210 Data Structures and Algorithms
Linked List ADT used to store information in a list
Chapter 4 Linked Lists.
List Representation - Array
Chapter 16-2 Linked Structures
Chapter 4 Link Based Implementations
Chapter 18: Linked Lists.
11-3 LINKED LISTS A linked list is a collection of data in which each element contains the location of the next element—that is, each element contains.
Chapter 16 Linked Structures
Lecture No.02 Data Structures Dr. Sohail Aslam
Data Structures & Algorithms
LINEAR DATA STRUCTURES
Presentation transcript:

1 Chapter 3 Data Representation Part 1

2 Goals Introduce the different ways in which data may be represented Concepts –Abstract data types –Formula-based, linked, indirect addressing, and simulated-pointer representations –Chains, circular lists, and doubly linked lists Applications –Bin sort, radix sort –Equivalence class –Convex hull

3 Data objects A set of instances or values Boolean = {false, true} Digit = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} Letter = {A, B, C, …, Z, a, b, … z} Natural Number = {0, 1, 2, …} Integer = {0, ±1, ±2, ±3, …} String = {a, b, …, aa, ab, ac, …}

4 Primitive and composed data object Primitive (or atomic) data objects Composed data objects Relationships among instances, e.g., order Functions associated with data objects

5 Data structures Data structure: a data object together with the relationships that exist among the instances, usually expressed by functions/operations Data structure = data + functions Standard data types - int, float, bool User defined data types - using enumeration, grouping facility such as class, array, and pointers, e.g., char s[MaxSize];

6 Linear Lists Data object in the form (e 1, e 2, …, e n ) where n is a finite natural number elements - e i ’s length - n empty list - when n = 0 Order - e 1 precedes e 2, e 2 precedes e 3, and so on

7 Examples of linear lists An alphabetized list of students in a class a list of exam scores in nondecreasing order an alphabetized list of members of Congress a list of gold-medal winners in the Olympics men’s basketball event

8 ADT specification

9 Formula-based representation Use an array to represent the instances of a linear list Cell (or node) holds an instance of the data object Locations of each element is given by a mathematical formula, e.g., location(i) = i-1

10 An example

11 Class Definition

12 Class Definition (Continue)

13 What if new fails?

14 Constructor

15 Find and Search

16 Delete

17 Insert

18 Output

19 A client program

20 A client program (continue)

21 Output of the client program

22 Evaluation Merits –Fast: Search, Delete, and Insert functions have a worst complexity that is linear Shortcomings –Inefficient use of space

23 Enhancement: Represent multiple lists in a single array

24 Insertion

25 Insertion (continue) Cost: a single insertion may require as many as MaxSize-1 moves

26 Linked representation Each node keeps an explicit information (link or pointer) about the the location of other relevant nodes Singly linked list, also called chain

27 Chain

28 Chain (continue)

29 Destructor - Θ(n)

30 Length - Θ(n)

31 Find - O(k)

32 Find - O(n)

33 Output - Θ(n)

34 Delete the fourth node Locate the third and fourth nodes Link the third node to the fifth Free the fourth node

35 Delete

36 Delete (continue)

37 Insertion Two cases: k=0 and k<>0

38 Insert function

39 Insert function (continue) - O(k)

40 Extensions to the Class Chain Erase : delete the nodes in the chain

41 Chain last = 0; }

42 Chain (continue), *last ;

43 Append : add an element to the end of a chain - Θ(1)

44 In case we need to visit elements of the whole chain Chain L; …….. int len = L.Length(); int x, sum =0; for (int i = 1; i <= len; i++) { L.Find(i, x); sum = sum + x; } The complexity of this code is Θ(n 2 ) It is necessary to define a function which traverse the chain in Θ(n) time

45 Chain Iterator Class Location Initialize() next() ChainIterator Chain first

46 Chain Iterator Class

47 Traverse the chain using Iterator Chain L; ……. ….. int *p; ChainIterator c; p = c.Initialize(L);// c is iterator of chain L while (p != NULL) { sum = sum + (*p); p = c.Next();// advance p to point to next // node in the chain }

48 Circular List singly linked circular list add the head node at the front of the list

49 Search a circular list - O(n)

50 Comparison with formula-based representation

51 Doubly linked list

52 Class definition

53 Class definition (continue)

54 The end of Chapter 3 Part 1