Data Structures Michael J. Watts http://mike.watts.net.nz.

Slides:



Advertisements
Similar presentations
CS261 Data Structures AVL Trees. Goals Pros/Cons of a BST AVL Solution – Height-Balanced Trees.
Advertisements

AVL Tree Smt Genap Outline AVL Tree ◦ Definition ◦ Properties ◦ Operations Smt Genap
©Brooks/Cole, 2003 Chapter 12 Abstract Data Type.
Data Structures Michael J. Watts
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.
Chapter 12 C Data Structures Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 12 – Data Structures Outline 12.1Introduction.
Chapter 4: Trees Binary Search Trees
Important Problem Types and Fundamental Data Structures
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.
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.
 2007 Pearson Education, Inc. All rights reserved C Data Structures.
Starting at Binary Trees
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.
CPS120: Introduction to Computer Science Nell Dale John Lewis Abstract Data Types.
CSE373: Data Structures & Algorithms Lecture 8: AVL Trees and Priority Queues Linda Shapiro Spring 2016.
CPS120: Introduction to Computer Science Sorting.
Partially Ordered Data ,Heap,Binary Heap
Binary Search Trees Implementing Balancing Operations Hash Tables
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
COMP 53 – Week Fourteen Trees.
AVL TREES.
Trees Chapter 11 (continued)
Lecture 7 Queues Stacks Trees.
Week 7 - Friday CS221.
Top 50 Data Structures Interview Questions
Data Structure Interview Question and Answers
Trees Chapter 11 (continued)
12 C Data Structures.
Lecture 15 AVL Trees Slides modified from © 2010 Goodrich, Tamassia & by Prof. Naveen Garg’s Lectures.
Stacks and Queues.
CSE373: Data Structures & Algorithms Lecture 7: AVL Trees
AVL Tree 27th Mar 2007.
Introduction to Data Structure
O(lg n) Search Tree Tree T is a search tree made up of n elements: x0 x1 x2 x3 … xn-1 No function (except transverse) takes more than O(lg n) in the.
AVL Trees "The voyage of discovery is not in seeking new landscapes but in having new eyes. " - Marcel Proust.
Introduction to Data Structures
CSE373: Data Structures & Algorithms Lecture 7: AVL Trees
Binary Tree and General Tree
Map interface Empty() - return true if the map is empty; else return false Size() - return the number of elements in the map Find(key) - if there is an.
structures and their relationships." - Linus Torvalds
original list {67, 33,49, 21, 25, 94} pass { } {67 94}
structures and their relationships." - Linus Torvalds
Data Structures and Algorithms
Balanced-Trees This presentation shows you the potential problem of unbalanced tree and show two way to fix it This lecture introduces heaps, which are.
CSE 326: Data Structures Lists
ITEC 2620M Introduction to Data Structures
Introduction to Data Structures
Heaps Chapter 11 has several programming projects, including a project that uses heaps. This presentation shows you what a heap is, and demonstrates.
Balanced-Trees This presentation shows you the potential problem of unbalanced tree and show two way to fix it This lecture introduces heaps, which are.
Data Structures & Algorithms
Binary Tree Traversals
Lecture No.20 Data Structures Dr. Sohail Aslam
Introduction to Data Structures
Lecture 9: Self Balancing Trees
Important Problem Types and Fundamental Data Structures
การวิเคราะห์และออกแบบขั้นตอนวิธี
OPIM 915 Fall 2010 Data Structures 23-38,
CSE 373 Data Structures Lecture 8
Lecture 9: Intro to Trees
structures and their relationships." - Linus Torvalds
Presentation transcript:

Data Structures Michael J. Watts http://mike.watts.net.nz

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