What does that mean? In general there are two aspects:

Slides:



Advertisements
Similar presentations
Lists A list is a finite, ordered sequence of data items. Two Implementations –Arrays –Linked Lists.
Advertisements

CS 104 Introduction to Computer Science and Graphics Problems Data Structure & Algorithms (4) Data Structures 11/18/2008 Yang Song.
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.
Dr. Andrew Wallace PhD BEng(hons) EurIng
Stacks and Queues Dr. Andrew Wallace PhD BEng(hons) EurIng
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.
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.
Foundation of Computing Systems Lecture 3 Stacks and Queues.
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.
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.
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.
Data Structures David Kauchak cs302 Spring Data Structures What is a data structure? Way of storing data that facilitates particular operations.
Data structures Binomial Heaps - Binomial Trees B0B0 BkBk B k-1.
CPS120: Introduction to Computer Science Nell Dale John Lewis Abstract Data Types.
Priority Queues and Heaps Tom Przybylinski. Maps ● We have (key,value) pairs, called entries ● We want to store and find/remove arbitrary entries (random.
Heaps and Priority Queues What is a heap? A heap is a binary tree storing keys at its internal nodes and satisfying the following properties:
Priority Queues A priority queue is an ADT where:
Partially Ordered Data ,Heap,Binary Heap
Lecture: Priority Queue
CSC317 Selection problem q p r Randomized‐Select(A,p,r,i)
Elementary data structures
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
Heap Chapter 9 Objectives Define and implement heap structures
Chapter 12 – Data Structures
Andreas Klappenecker [partially based on the slides of Prof. Welch]
Heaps (8.3) CSE 2011 Winter May 2018.
Stacks – review A Last-In First-Out (LIFO) structure Basic Operations:
Chapter 15 Lists Objectives
Heaps 8/2/2018 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and M. H. Goldwasser,
Programming Abstractions
Stack and Queue APURBO DATTA.
Source: Muangsin / Weiss
Part-D1 Priority Queues
Bohyung Han CSE, POSTECH
Heaps 9/13/2018 3:17 PM Heaps Heaps.
Cse 373 April 26th – Exam Review.
CS 583 Analysis of Algorithms
Elementary Data Structures
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.
Basic Data Types Queues
Stacks – review A Last-In First-Out (LIFO) structure Basic Operations:
Algorithms Part III. Data Structures
Initializing A Max Heap
Part-D1 Priority Queues
Heapsort Heap & Priority Queue.
Priority Queues.
CS200: Algorithm Analysis
Heaps 11/27/ :05 PM Heaps Heaps.
Chapter 8: Data Abstractions
Priority Queues.
אחסון (אירגון) מידע DATA DATA DATA Link Link Link … …
ITEC 2620M Introduction to Data Structures
Tree Representation Heap.
Heaps 12/4/2018 5:27 AM Heaps /4/2018 5:27 AM Heaps.
Lesson 6. Types Equality and Identity. Collections.
Dynamic Sets (III, Introduction)
CS6045: Advanced Algorithms
Mutable Data (define mylist (list 1 2 3)) (bind ((new (list 4)))
Heaps © 2014 Goodrich, Tamassia, Goldwasser Heaps Heaps
Priority Queues & Heaps
HEAPS.
Heapsort Sorting in place
Important Problem Types and Fundamental Data Structures
A Heap Is Efficiently Represented As An Array
Heaps 9/29/2019 5:43 PM Heaps Heaps.
Heaps.
Presentation transcript:

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 organization The basic possibilities are to store data either in arrays: or to link them with pointers:

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

Some types of “linked objects” Trees:

Implementation of linked lists Key Pointer 1

Implementation of binary trees Key Pointer 1 Pointer 2

Implementation of general trees

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, )

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

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

Stacks - MakeStack, Push 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 - Pop, IsEmpty 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

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

Queues - MakeQueue 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 - Enqueue 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 - Dequeue, IsEmpty 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

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

Heaps - Examples This may be Heap

Heaps - Examples This may be Heap

Heaps - Examples This can not be Heap

Heaps - Examples This can not be Heap

Heaps - Examples This is Heap 1 2 12 3 45 13 14

Heaps - Examples This is not Heap 1 2 12 3 45 5 14

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

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)

Heaps - Implementation with an array 1 LC(j) = 2j – n – 1 RC(j) = 2j – n – 2 2 12 P(j) = 1 + (j + n)/2 3 45 13 13 45 3 12 2 1

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

Heaps - Insert 2 3 12 7 45 13 1 T(n) = (h) = (log n)

Heaps - Delete 2 3 12 7 45 13 14 T(n) = (h) = (log n)

Heaps - ExtractMin 1 3 12 7 45 13 14 T(n) = (h) = (log n)