Data Structures Michael J. Watts

Slides:



Advertisements
Similar presentations
COL 106 Shweta Agrawal and Amit Kumar
Advertisements

Binary Trees CSC 220. Your Observations (so far data structures) Array –Unordered Add, delete, search –Ordered Linked List –??
AVL Tree Smt Genap Outline AVL Tree ◦ Definition ◦ Properties ◦ Operations Smt Genap
Time Complexity of Basic BST Operations Search, Insert, Delete – These operations visit the nodes along a root-to- leaf path – The number of nodes encountered.
©Brooks/Cole, 2003 Chapter 12 Abstract Data Type.
Advanced Data Structures
Balanced Search Trees. 2-3 Trees Trees Red-Black Trees AVL Trees.
1 Balanced Search Trees  several varieties  AVL trees  trees  Red-Black trees  B-Trees (used for searching secondary memory)  nodes are added.
Lists A list is a finite, ordered sequence of data items. Two Implementations –Arrays –Linked Lists.
CS 104 Introduction to Computer Science and Graphics Problems Data Structure & Algorithms (4) Data Structures 11/18/2008 Yang Song.
©Brooks/Cole, 2003 Chapter 12 Abstract Data Type.
Self-Balancing Search Trees Chapter 11. Chapter 11: Self-Balancing Search Trees2 Chapter Objectives To understand the impact that balance has on the performance.
Chapter 12 C Data Structures Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc.
Fall 2007CS 2251 Self-Balancing Search Trees Chapter 9.
Self-Balancing Search Trees Chapter 11. Chapter Objectives  To understand the impact that balance has on the performance of binary search trees  To.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 12 – Data Structures Outline 12.1Introduction.
Summary of lectures (1 to 11)
Week 10: Heap and Priority queue. Any feature here?
1 Foundations of Software Design Fall 2002 Marti Hearst Lecture 17: Binary Search Trees; Heaps.
Important Problem Types and Fundamental Data Structures
Binary Trees Chapter 6.
Introduction to Data Structures. Data Structures A data structure is a scheme for organizing data in the memory of a computer. Some of the more commonly.
1 HEAPS & PRIORITY QUEUES Array and Tree implementations.
Data Structures Arrays both single and multiple dimensions Stacks Queues Trees Linked Lists.
Chapter 12 Data Structure Associate Prof. Yuh-Shyan Chen Dept. of Computer Science and Information Engineering National Chung-Cheng University.
Compiled by: Dr. Mohammad Alhawarat BST, Priority Queue, Heaps - Heapsort CHAPTER 07.
Data Structures Winter What is a Data Structure? A data structure is a method of organizing data. The study of data structures is particularly important.
Introduction to Data Structures. Definition Data structure is representation of the logical relationship existing between individual elements of data.
Connecting with Computer Science 2 Objectives Learn what a data structure is and how it is used Learn about single and multidimensional arrays and how.
Chapter 3 List Stacks and Queues. Data Structures Data structure is a representation of data and the operations allowed on that data. Data structure is.
Data Structures and Abstract Data Types "Get your data structures correct first, and the rest of the program will write itself." - David Jones.
 2007 Pearson Education, Inc. All rights reserved C Data Structures.
Connecting with Computer Science, 2e Chapter 8 Data Structures.
Introduction to Data Structures Fall 2008 Dr. David A. Gaitros
Lecture 10 Trees –Definiton of trees –Uses of trees –Operations on a tree.
© 2011 Pearson Addison-Wesley. All rights reserved 11 B-1 Chapter 11 (continued) Trees.
Chapter 6 Binary Trees. 6.1 Trees, Binary Trees, and Binary Search Trees Linked lists usually are more flexible than arrays, but it is difficult to use.
Chapter 9 (modified) Abstract Data Types and Algorithms Nell Dale John Lewis.
9-1 Abstract Data Types Abstract data type A data type whose properties (data and operations) are specified independently of any particular implementation.
P p Chapter 10 has several programming projects, including a project that uses heaps. p p This presentation shows you what a heap is, and demonstrates.
Starting at Binary Trees
Trees  Linear access time of linked lists is prohibitive Does there exist any simple data structure for which the running time of most operations (search,
© 2010 Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of CHAPTER 12: Multi-way Search Trees Java Software Structures: Designing.
1 Joe Meehean.  We wanted a data structure that gave us... the smallest item then the next smallest then the next and so on…  This ADT is called a priority.
Data Structures Types of Data Structure Data Structure Operations Examples Choosing Data Structures Data Structures in Alice.
1 5. Abstract Data Structures & Algorithms 5.1 Data Structure Fundamentals.
Data Structures Chapter 6. Data Structure A data structure is a representation of data and the operations allowed on that data. Examples: 1.Array 2.Record.
Chapter 4: Trees Part I: General Tree Concepts Mark Allen Weiss: Data Structures and Algorithm Analysis in Java.
Balanced Search Trees Chapter 19 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
1 CompSci 105 SS 2006 Principles of Computer Science Lecture 17: Heaps cont.
CIS 068 Welcome to CIS 068 ! Lesson 12: Data Structures 3 Trees.
Week 15 – Wednesday.  What did we talk about last time?  Review up to Exam 1.
AVL TREES By Asami Enomoto CS 146 AVL Tree is… named after Adelson-Velskii and Landis the first dynamically balanced trees to be propose Binary search.
BINARY TREES Objectives Define trees as data structures Define the terms associated with trees Discuss tree traversal algorithms Discuss a binary.
Chapter 9 Abstract Data Types and Algorithms Nell Dale John Lewis.
ISOM MIS 215 Module 5 – Binary Trees. ISOM Where are we? 2 Intro to Java, Course Java lang. basics Arrays Introduction NewbieProgrammersDevelopersProfessionalsDesigners.
INTRODUCTION TO DATA STRUCTURES 1. DATA STRUCTURES A data structure is a scheme for organizing data in the memory of a computer. Some of the more commonly.
Nov 2, 2001CSE 373, Autumn Hash Table example marking deleted items + choice of table size.
Data Structure By Amee Trivedi.
Set Collection A Bag is a general collection class that implements the Collection interface. A Set is a collection that resembles a Bag with the provision.
Chapter 12 – Data Structures
Data Structures Michael J. Watts
Lecture 7 Queues Stacks Trees.
Data Structure Interview Question and Answers
12 C Data Structures.
structures and their relationships." - Linus Torvalds
Binary Tree Traversals
Important Problem Types and Fundamental Data Structures
structures and their relationships." - Linus Torvalds
Presentation transcript:

Data Structures Michael J. Watts

Lecture Outline Arrays Matrices Structures Stacks Queues Trees

Introduction Selection of an appropriate data structure is an important part of programming  Efficiency  Flexibility Choice depends on problem  Rate of new data acquisition / insertion  Type of data being stored  Desired method of data access

Arrays Basic data structure for most programming languages Collection of data values Usually a single data type  cf MATLAB cell arrays Contents accessed by index numbers Problems with searching for specific elements Good for fixed numbers of items

Matrices Array of arrays Basis of MATLAB One dimensional matrices are arrays  Row / column vectors Can be > 2D Accessed via row / column indices Same problems with searching as arrays Makes certain mathematical operations easier

Structures Collection of named pieces of data Multiple data types within a structure Elements within a structure are called fields Contents accessed by field name Good for grouping related items together

Stacks Like a stack of plates Oldest items are at the bottom Newest items are at the top New items are 'pushed' onto the top of the stack Retrieved items are 'popped' off of the top of the stack First in, last out data structure

Stacks Often used to provide temporary storage of data values Can't be searched  Have to pop each value out to find the one you're looking for Simple to implement Can be used for evaluating expressions

Queues Like a queue at the supermarket Sequential data structure Oldest items are at the front Newest items are at the back Elements are 'enqueued' at the end Elements are 'dequeued' at the front First in, first out data structure

Queues Used to control access to finite resources  Petrol pumps, checkouts, printers Sequential access only Unordered Problems with searching

Trees Way of storing data values in order Two dimensional structure Collection of nodes and edges  Nodes are data items  Edges connect nodes Position of an item in the structure depends on the value of a key Many types of tree in existence

Trees Navigate by the vales of the nodes Much faster than sequential search  Don't need to examine every item  Adding a level to the tree adds just one more comparison A level can have many items Search speed scales as to the log of N  N is the number of items in the tree

B-Trees Binary trees Each node has zero or more subtrees  Left and right  Node without a subtree is a leaf  First node is the root Values in left subtree are smaller Values in right subtree are greater

B-Trees Allow for efficient searches  Search for value of key Often used in indexing  Databases, file systems Can degenerate  Sequential values  Becomes a list Inefficient

AVL Trees Adel'son-Vel'skii and Landis trees Balanced binary trees Height between left and right subtree differ by at most one  Height measured between bottom-most nodes Height difference maintained by rotations  Single / double rotate left / right

AVL Trees Don't become degenerate Always efficient searching  Close to the theoretical maximum Rotations can be expensive  Frequent insertions / deletions Other optimisations for in-order iterations

Summary Selection of a data structure is problem dependent Arrays and structures are built into most programming languages Stacks are often used for temporary storage Queues control access to a resource Trees are efficient for retrieval B-Trees can degenerate AVL trees are balanced