Data structures What does that mean? In general there are two aspects: how data will be organized in computer memory what will be the operations that will.

Slides:



Advertisements
Similar presentations
Chapter 6 Structures By C. Shing ITEC Dept Radford University.
Advertisements

Heaps1 Part-D2 Heaps Heaps2 Recall Priority Queue ADT (§ 7.1.3) A priority queue stores a collection of entries Each entry is a pair (key, value)
Binary Trees CS 110: Data Structures and Algorithms First Semester,
1 Chapter 6 Priority Queues (Heaps) General ideas of priority queues (Insert & DeleteMin) Efficient implementation of priority queue Uses of priority queues.
Priority Queues. Container of elements where each element has an associated key A key is an attribute that can identify rank or weight of an element Examples.
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.
Dijkstra/Prim 1 make-heap |V| insert |V| delete-min |E| decrease-key Priority Queues make-heap Operation insert find-min delete-min union decrease-key.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L12 (Chapter 20) Lists, Stacks,
Chapter 12 C Data Structures Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc.
Priority Queues. Container of elements where each element has an associated key A key is an attribute that can identify rank or weight of an element Examples.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 12 – Data Structures Outline 12.1Introduction.
Dr. Andrew Wallace PhD BEng(hons) EurIng
Stacks and Queues Dr. Andrew Wallace PhD BEng(hons) EurIng
Binomial Heaps Jyh-Shing Roger Jang ( 張智星 ) CSIE Dept, National Taiwan University.
1 Stack Data : a collection of homogeneous elements arranged in a sequence. Only the first element may be accessed Main Operations: Push : insert an element.
Important Problem Types and Fundamental Data Structures
Priority Queues and Heaps Bryce Boe 2013/11/20 CS24, Fall 2013.
Chapter 12 Data Structure Associate Prof. Yuh-Shyan Chen Dept. of Computer Science and Information Engineering National Chung-Cheng University.
PRIORITY QUEUES (HEAPS). Queues are a standard mechanism for ordering tasks on a first-come, first-served basis However, some tasks may be more important.
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.
Chapter 8: Data Abstractions Senem Kumova Metin. 8-2 Chapter 8: Data Abstractions 8.1 Basic Data Structures – Arrays – Lists, Stacks, Queues – Trees 8.2.
12-CRS-0106 REVISED 8 FEB 2013 CSG2A3 ALGORITMA dan STRUKTUR DATA.
ECE 103 Engineering Programming Chapter 61 Abstract Data Types Herbert G. Mayer, PSU CS Status 6/4/2014 Initial content copied verbatim from ECE 103 material.
Elementary Data Structures Data Structures and Algorithms A. G. Malamos.
October 18, Algorithms and Data Structures Lecture V Simonas Šaltenis Nykredit Center for Database Research Aalborg University
1 Trees A tree is a data structure used to represent different kinds of data and help solve a number of algorithmic problems Game trees (i.e., chess ),
For Monday Read Weiss, chapter 7, sections 1-3. Homework –Weiss, chapter 4, exercise 6. Make sure you include parentheses where appropriate.
The Binary Heap. Binary Heap Looks similar to a binary search tree BUT all the values stored in the subtree rooted at a node are greater than or equal.
Data Structures (part 2). Stacks An Everyday Example Your boss keeps bringing you important items to deal with and keeps saying: “Put that last ‘rush’
CSC2100B Tutorial 2 List and stack implementation.
Lists, Stacks and Queues in C Yang Zhengwei CSCI2100B Data Structures Tutorial 4.
Foundation of Computing Systems Lecture 3 Stacks and Queues.
Chapter 2: Basic Data Structures. Spring 2003CS 3152 Basic Data Structures Stacks Queues Vectors, Linked Lists Trees (Including Balanced Trees) Priority.
1 Binomial Tree Binomial tree. n Recursive definition: B k-1 B0B0 BkBk B0B0 B1B1 B2B2 B3B3 B4B4.
Data Structure II So Pak Yeung Outline Review  Array  Sorted Array  Linked List Binary Search Tree Heap Hash Table.
Chapter 16 – Data Structures and Recursion. Data Structures u Built-in –Array –struct u User developed –linked list –stack –queue –tree Lesson 16.1.
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.
Programming Abstractions Cynthia Lee CS106X. Topics:  Priority Queue › Linked List implementation › Heap data structure implementation  TODAY’S TOPICS.
Heaps and basic data structures David Kauchak cs161 Summer 2009.
Stacks Queues Introduction to Trees. Stacks An Everyday Example Your boss keeps bringing you important items to deal with and keeps saying: “Put that.
Priority Queues CS 110: Data Structures and Algorithms First Semester,
Data Structures David Kauchak cs302 Spring Data Structures What is a data structure? Way of storing data that facilitates particular operations.
COSC 2P03 Week 21 Stacks – review A Last-In First-Out (LIFO) structure Basic Operations: –push : insert data item onto top of stack –pop : remove data.
Lecture: Priority Queue. Questions Is array a data structure? What is a data structure? What data structures are implemented by array? Priority queue.
Data structures Binomial Heaps - Binomial Trees B0B0 BkBk B k-1.
CS6045: Advanced Algorithms Data Structures. Dynamic Sets Next few lectures will focus on data structures rather than straight algorithms In particular,
 In general, Queue is line of person waiting for their turn at some service counter like ticket window at cinema hall, at bus stand or at railway station.
CPS120: Introduction to Computer Science Nell Dale John Lewis Abstract Data Types.
Priority Queues A priority queue is an ADT where:
Partially Ordered Data ,Heap,Binary Heap
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.
Lists, Stacks and Queues in C
Chapter 12 – Data Structures
Andreas Klappenecker [partially based on the slides of Prof. Welch]
Chapter 15 Lists Objectives
Programming Abstractions
Stack and Queue APURBO DATTA.
What does that mean? In general there are two aspects:
CS 583 Analysis of Algorithms
Basic Data Types Queues
Algorithms Part III. Data Structures
Priority Queues.
Priority Queues.
ITEC 2620M Introduction to Data Structures
Dynamic Sets (III, Introduction)
Binary Tree Traversals
CS6045: Advanced Algorithms
Mutable Data (define mylist (list 1 2 3)) (bind ((new (list 4)))
Presentation transcript:

Data structures What does that mean? In general there are two aspects: how data will be organized in computer memory what will be the operations that will be performed with them

Data structures Data organization The basic possibilities are to store data either in arrays: or to link them with pointers:

Data structures Some types of “linked objects” Linked lists: Double-linked lists:

Data structures Some types of “linked objects” Trees:

Data structures Implementation of linked lists KeyPointer 1

Data structures Implementation of binary trees KeyPointer 1Pointer 2

Data structures Implementation of general trees

Data structures Operations with data structures Dynamic Dictionaries LookUp(Key) Insert(Key) Delete(Key) Make() Priority Queues Min() ExtractMin() DecreaseKey(Key) Insert(Key) Delete(Key) Make() Other popular operations with data structures - unify elements of 2 data structures into one (Union, Meld,  )

Data structures Stacks Operations MakeStack() Push(Key,S) Pop(S) IsEmpty(S) [Picture from J.Morris]

Data structures Stacks Operations MakeStack() Push(Key,S) Pop(S) IsEmpty(S) LIFO Last - in - first - out

Data structures struct Cell{int Key, pointer Next} struct Stack{pointer Head} procedure MakeStack(): S  new Stack S.Head  0 return S procedure Push(int Key, Stack S): C  new Cell C.Next  S.Head C.Key  Key S.Head  C Stacks - MakeStack, Push

Data structures procedure Pop(Stack S): C  S.Head Key  C.Key S.Head  C.Next delete C return Key procedure IsEmpty(Stack S): if S.Head  0 then return 0 else return 1 Stacks - Pop, IsEmpty

Data structures Queues Operations MakeQueue() Enqueue(Key,Q) Dequeue(Q) IsEmpty(Q) FIFO First - in - first - out

Data structures struct Cell{int Key, pointer Next} struct Queue{pointer Head, pointer Tail} procedure MakeQueue(): Q  new Queue Q.Head  0 Q.Tail  0 return Q Queues - MakeQueue

Data structures procedure Enqueue(int Key, Queue Q): C  new Cell C.Next  0 C.Key  Key if Q.Head = 0 then Q.Head  C else Tail  Q.Tail Tail.Next  C Q.Tail  C Queues - Enqueue

Data structures procedure Dequeue(Queue Q): C  Q.Head Key  C.Key Q.Head  C.Next if Q.Head = 0 then Q.Tail  0 delete C return Key procedure IsEmpty(Queue Q): if Q.Head  0 then return 0 else return 1 Queues - Dequeue, IsEmpty

Data structures Heaps They are binary trees with all levels completed, except the lowest one which may have uncompleted section on the right side They satisfy so called Heap Property - for each subtree of heap the key for the root of subtree must not exceed the keys of its (left and right) children

Data structures Heaps - Examples This may be Heap

Data structures Heaps - Examples This may be Heap

Data structures Heaps - Examples This can not be Heap

Data structures Heaps - Examples This can not be Heap

Data structures Heaps - Examples This is Heap

Data structures Heaps - Examples This is not Heap

Data structures Heaps - Operations Min() ExtractMin() DecreaseKey(Key) Insert(Key) Delete(Key) MakeHeap() Heapify() InitialiseHeap()

Data structures Heaps - Relation between size and height Theorem For heap with n elements the height h of the corresponding binary tree is  log n , i.e. h =  (log n)

Data structures Heaps - Implementation with an array LC(j) = 2j – n RC(j) = 2j – n – 1 P(j) =  (j + n)/2 

Data structures Heaps - Implementation with an array [Adapted from T.Cormen, C.Leiserson, R. Rivest]

Data structures Heaps - Insert T(n) =  (h) =  (log n)

Data structures Heaps - Delete T(n) =  (h) =  (log n)

Data structures Heaps - ExtractMin T(n) =  (h) =  (log n) 1