 2006 Pearson Education, Inc. All rights reserved. 1 21 Data Structures.

Slides:



Advertisements
Similar presentations
Chapter 25 Lists, Stacks, Queues, and Priority Queues
Advertisements

Stacks, Queues, and Linked Lists
Chapter 24 Lists, Stacks, and Queues
CHP-5 LinkedList.
Data Structures: A Pseudocode Approach with C
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Data Structures.
1 Chapter 24 Lists Stacks and Queues. 2 Objectives F To design list with interface and abstract class (§24.2). F To design and implement a dynamic list.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L11 (Chapter 20) Lists, Stacks,
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Sixth Edition Chapter 17: Linked Lists.
 2009 Pearson Education, Inc. All rights reserved Data Structures Many slides modified by Prof. L. Lilien (even many without an explicit message).
Chapter 12 C Data Structures Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc.
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.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 12 – Data Structures Outline 12.1Introduction.
Chapter 4 Linked Lists. © 2005 Pearson Addison-Wesley. All rights reserved4-2 Preliminaries Options for implementing an ADT List –Array has a fixed size.
Summary of lectures (1 to 11)
 2006 Pearson Education, Inc. All rights reserved Data Structures.
 2006 Pearson Education, Inc. All rights reserved Data Structures.
Self Referential Structure. A structure may not contain a member of its own type. struct check { int item; struct check n; // Invalid };
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 22 Lists, Stacks, Queues, and Priority.
C o n f i d e n t i a l Developed By Nitendra NextHome Subject Name: Data Structure Using C Title: Overview of Data Structure.
Chapter 12 Data Structure Associate Prof. Yuh-Shyan Chen Dept. of Computer Science and Information Engineering National Chung-Cheng University.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Custom Templatized Data Structures.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Ver Chapter 4: Linked Lists Data Abstraction & Problem Solving with.
Chapter 8 Data Abstractions Introduction to CS 1 st Semester, 2015 Sanghyun Park.
Implementation of Linked List For more notes and topics visit: eITnotes.com.
 Pearson Education, Inc. All rights reserved Data Structures.
 2007 Pearson Education, Inc. All rights reserved C Data Structures.
Introduction to Data Structures Systems Programming.
1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 22 November 17, 2009.
Adapted from instructor resources Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights.
Comp 245 Data Structures Linked Lists. An Array Based List Usually is statically allocated; may not use memory efficiently Direct access to data; faster.
Lecture 14 Linked Lists 14-1 Richard Gesick. Linked Lists Dynamic data structures can grow and shrink at execution time. A linked list is a linear collection.
(1 - 1) Introduction to C Data Structures & Abstract Data Types Instructor - Andrew S. O’Fallon CptS 122 (August 26, 2015) Washington State University.
Chapter 8 Data Abstractions. © 2005 Pearson Addison-Wesley. All rights reserved 8-2 Chapter 8: Data Abstractions 8.1 Data Structure Fundamentals 8.2 Implementing.
Self-Referential Classes A Self-referential class is a class that contains a reference to an object that has the same class type. –A self-referential class.
Introduction to Data Structures Systems Programming Concepts.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Stacks.
1 Chapter 17 – Data Structures Outline Introduction Self-Referential Classes Dynamic Memory Allocation Linked Lists Stacks Queues Trees.
Lists Chapter 8. 2 Linked Lists As an ADT, a list is –finite sequence (possibly empty) of elements Operations commonly include: ConstructionAllocate &
Copyright © 2012 Pearson Education, Inc. Chapter 17: Linked Lists.
Programming Practice 3 - Dynamic Data Structure
Copyright © 2002 Pearson Education, Inc. Slide 1.
Subject Name : Data Structure Using C Title : Linked Lists
Data Structures for Midterm 2. C++ Data Structure Runtimes.
Java How to Program, 9/e © Copyright by Pearson Education, Inc. All Rights Reserved.
Linked Lists. Introduction In linked list each item is embedded in a link Each item has two parts – Data – Pointer to the next item in the list Insert,
Circular linked list A circular linked list is a linear linked list accept that last element points to the first element.
By Anand George SourceLens.org Copyright. All rights reserved. Content Owner - Meera R (meera at sourcelens.org)
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Linked Lists Outline Introduction Self-Referential Structures.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Seventh Edition by Tony Gaddis, Judy.
Copyright © 2014, 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Eighth Edition by Tony Gaddis,
CMSC 202 Computer Science II for Majors. CMSC 202UMBC Topics Templates Linked Lists.
Copyright © 2012 Pearson Education, Inc. Chapter 17: Linked Lists.
Data Structure By Amee Trivedi.
17 Data Structures.
Chapter 12 – Data Structures
Pointers and Linked Lists
5.13 Recursion Recursive functions Functions that call themselves
Linked Lists Chapter 6 Section 6.4 – 6.6
12 C Data Structures.
Data Structure Interview Question and Answers
12 C Data Structures.
Chapter 22 Custom Generic Data Structures
Intro to Data Structures
Chapter 4 Linked Lists.
Introduction to Data Structures
Review & Lab assignments
Chapter 17: Linked Lists.
(1 - 2) Introduction to C Data Structures & Abstract Data Types
21 Data Structures.
Presentation transcript:

 2006 Pearson Education, Inc. All rights reserved Data Structures

 2006 Pearson Education, Inc. All rights reserved. 2 Much that I bound, I could not free; Much that I freed returned to me. — Lee Wilson Dodd ‘Will you walk a little faster?’ said a whiting to a snail, ‘There’s a porpoise close behind us, and he’s treading on my tail.’ — Lewis Carroll There is always room at the top. — Daniel Webster Push on — keep moving. — Thomas Morton I’ll turn over a new leaf. — Miguel de Cervantes

 2006 Pearson Education, Inc. All rights reserved. 3 OBJECTIVES In this chapter you will learn:  To form linked data structures using pointers, self- referential classes and recursion.  To create and manipulate dynamic data structures such as linked lists, queues, stacks and binary trees.  To use binary search trees for high-speed searching and sorting.  To understand various important applications of linked data structures.  To understand how to create reusable data structures with class templates, inheritance and composition.

 2006 Pearson Education, Inc. All rights reserved Introduction 21.2 Self-Referential Classes 21.3 Dynamic Memory Allocation and Data Structures 21.4 Linked Lists 21.5 Stacks 21.6 Queues 21.7 Trees 21.8 Wrap-Up

 2006 Pearson Education, Inc. All rights reserved. 5 Fig | Two self-referential class objects linked together.

 2006 Pearson Education, Inc. All rights reserved. 6 Common Programming Error 21.1 Not setting the link in the last node of a linked data structure to null (0) is a (possibly fatal) logic error.

 2006 Pearson Education, Inc. All rights reserved. 7 Performance Tip 21.1 An array can be declared to contain more elements than the number of items expected, but this can waste memory. Linked lists can provide better memory utilization in these situations. Linked lists allow the program to adapt at runtime. Note that class template vector (introduced in Section 7.11) implements a dynamically resizable array- based data structure.

 2006 Pearson Education, Inc. All rights reserved. 8 Performance Tip 21.2 Insertion and deletion in a sorted array can be time consuming—all the elements following the inserted or deleted element must be shifted appropriately. A linked list allows efficient insertion operations anywhere in the list.

 2006 Pearson Education, Inc. All rights reserved. 9 Performance Tip 21.3 The elements of an array are stored contiguously in memory. This allows immediate access to any array element, because the address of any element can be calculated directly based on its position relative to the beginning of the array. Linked lists do not afford such immediate “direct access” to their elements. So accessing individual elements in a linked list can be considerably more expensive than accessing individual elements in an array. The selection of a data structure is typically based on the performance of specific operations used by a program and the order in which the data items are maintained in the data structure. For example, it is typically more efficient to insert an item in a sorted linked list than a sorted array.

 2006 Pearson Education, Inc. All rights reserved. 10 Performance Tip 21.4 Using dynamic memory allocation (instead of fixed-size arrays) for data structures that grow and shrink at execution time can save memory. Keep in mind, however, that pointers occupy space and that dynamic memory allocation incurs the overhead of function calls.

 2006 Pearson Education, Inc. All rights reserved. 11 Fig | A graphical representation of a list.

 2006 Pearson Education, Inc. All rights reserved. 12 Outline Listnode.h (1 of 2)

 2006 Pearson Education, Inc. All rights reserved. 13 Outline Listnode.h (2 of 2)

 2006 Pearson Education, Inc. All rights reserved. 14 Outline List.h (1 of 7)

 2006 Pearson Education, Inc. All rights reserved. 15 Outline List.h (2 of 7)

 2006 Pearson Education, Inc. All rights reserved. 16 Outline List.h (3 of 7)

 2006 Pearson Education, Inc. All rights reserved. 17 Outline List.h (4 of 7)

 2006 Pearson Education, Inc. All rights reserved. 18 Outline List.h (5 of 7)

 2006 Pearson Education, Inc. All rights reserved. 19 Outline List.h (6 of 7)

 2006 Pearson Education, Inc. All rights reserved. 20 Outline List.h (7 of 7)

 2006 Pearson Education, Inc. All rights reserved. 21 Outline Fig21_05.cpp (1 of 6)

 2006 Pearson Education, Inc. All rights reserved. 22 Outline Fig21_05.cpp (2 of 6)

 2006 Pearson Education, Inc. All rights reserved. 23 Outline Fig21_05.cpp (3 of 6)

 2006 Pearson Education, Inc. All rights reserved. 24 Outline Fig21_05.cpp (4 of 6)

 2006 Pearson Education, Inc. All rights reserved. 25 Outline Fig21_05.cpp (5 of 6)

 2006 Pearson Education, Inc. All rights reserved. 26 Outline Fig21_05.cpp (6 of 6)

 2006 Pearson Education, Inc. All rights reserved. 27 Error-Prevention Tip 21.1 Assign null (0) to the link member of a new node. Pointers should be initialized before they are used.

 2006 Pearson Education, Inc. All rights reserved. 28 Fig | Operation insertAtFront represented graphically.

 2006 Pearson Education, Inc. All rights reserved. 29 Fig | Operation insertAtBack represented graphically.

 2006 Pearson Education, Inc. All rights reserved. 30 Fig | Operation removeFromFront represented graphically.

 2006 Pearson Education, Inc. All rights reserved. 31 Fig | Operation removeFromBack represented graphically.

 2006 Pearson Education, Inc. All rights reserved. 32 Fig | Circular, singly linked list.

 2006 Pearson Education, Inc. All rights reserved. 33 Fig | Doubly linked list.

 2006 Pearson Education, Inc. All rights reserved. 34 Fig | Circular, doubly linked list.

 2006 Pearson Education, Inc. All rights reserved. 35 Outline Stack.h (1 of 2)

 2006 Pearson Education, Inc. All rights reserved. 36 Outline Stack.h (2 of 2)

 2006 Pearson Education, Inc. All rights reserved. 37 Outline Fig21_14.cpp (1 of 3)

 2006 Pearson Education, Inc. All rights reserved. 38 Outline Fig21_14.cpp (2 of 3)

 2006 Pearson Education, Inc. All rights reserved. 39 Outline Fig21_14.cpp (3 of 3)

 2006 Pearson Education, Inc. All rights reserved. 40 Outline Stack composition.h (1 of 2)

 2006 Pearson Education, Inc. All rights reserved. 41 Outline Stack composition.h (2 of 2)

 2006 Pearson Education, Inc. All rights reserved. 42 Outline Queue.h (1 of 2)

 2006 Pearson Education, Inc. All rights reserved. 43 Outline Queue.h (2 of 2)

 2006 Pearson Education, Inc. All rights reserved. 44 Outline Fig21_17.cpp (1 of 3)

 2006 Pearson Education, Inc. All rights reserved. 45 Outline Fig21_17.cpp (2 of 3)

 2006 Pearson Education, Inc. All rights reserved. 46 Outline Fig21_17.cpp (2 of 3)

 2006 Pearson Education, Inc. All rights reserved. 47 Fig | A graphical representation of a binary tree.

 2006 Pearson Education, Inc. All rights reserved. 48 Fig | A binary search tree.

 2006 Pearson Education, Inc. All rights reserved. 49 Outline Treenode.h (1 of 2)

 2006 Pearson Education, Inc. All rights reserved. 50 Outline Treenode.h (2 of 2)

 2006 Pearson Education, Inc. All rights reserved. 51 Outline Tree.h (1 of 6)

 2006 Pearson Education, Inc. All rights reserved. 52 Outline Tree.h (2 of 6)

 2006 Pearson Education, Inc. All rights reserved. 53 Outline Tree.h (3 of 6)

 2006 Pearson Education, Inc. All rights reserved. 54 Outline Tree.h (4 of 6)

 2006 Pearson Education, Inc. All rights reserved. 55 Outline Tree.h (5 of 6)

 2006 Pearson Education, Inc. All rights reserved. 56 Outline Tree.h (6 of 6)

 2006 Pearson Education, Inc. All rights reserved. 57 Outline Fig21_22.cpp (1 of 3)

 2006 Pearson Education, Inc. All rights reserved. 58 Outline Fig21_22.cpp (2 of 3)

 2006 Pearson Education, Inc. All rights reserved. 59 Outline Fig21_22.cpp (3 of 3)

 2006 Pearson Education, Inc. All rights reserved. 60 Fig | A binary search tree.