Data Structure HKOI training 2009 3/4/2010 So Pak Yeung.

Slides:



Advertisements
Similar presentations
STACKS & QUEUES. Stacks Abstract data types An abstract data type (ADT) is an abstraction of a data structure An ADT specifies : –Data stored –Operations.
Advertisements

Stacks, Queues, and Linked Lists
Queues and Linked Lists
Ceng-112 Data Structures I Chapter 5 Queues.
Data Structures Lecture 13: QUEUES Azhar Maqsood NUST Institute of Information Technology (NIIT)
COSC 1P03 Data Structures and Abstraction 9.1 The Queue Whenever you are asked if you can do a job, tell 'em, "Certainly, I can!" Then get busy and find.
Stacks, Queues, and Deques. 2 A stack is a last in, first out (LIFO) data structure Items are removed from a stack in the reverse order from the way they.
Stacks  a data structure which stores data in a Last-in First-out manner (LIFO)  has a pointer called TOP  can be implemented by either Array or Linked.
Introduction to C Programming CE Lecture 12 Circular Queue and Priority Queue Data Structures.
Queue RIZWAN REHMAN CENTRE FOR COMPUTER STUDIES DIBRUGARH UNIVERSITY.
CS Data Structures II Review COSC 2006 April 14, 2017
Data Structures: Lists i206 Fall 2010 John Chuang Some slides adapted from Glenn Brookshear, Brian Hayes, or Marti Hearst.
CS 104 Introduction to Computer Science and Graphics Problems Data Structure & Algorithms (4) Data Structures 11/18/2008 Yang Song.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 12 – Data Structures Outline 12.1Introduction.
Data Structures from Cormen, Leiserson, Rivest & Stein.
Stacks, Queues, and Deques
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.
Stacks, Queues, and Deques. A stack is a last in, first out (LIFO) data structure –Items are removed from a stack in the reverse order from the way they.
Stacks, Queues, and Deques
Chapter 12 Data Structure Associate Prof. Yuh-Shyan Chen Dept. of Computer Science and Information Engineering National Chung-Cheng University.
DATA STRUCTURES AND ALGORITHMS Lecture Notes 4 Prepared by İnanç TAHRALI.
1 Chapter 7 Stacks and Queues. 2 Stack ADT Recall that ADT is abstract data type, a set of data and a set of operations that act upon the data. In a stack,
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’
1 Stacks and Queues Based on D.S. Malik, Java Programming: Program Design Including Data Structures.
Lists, Stacks and Queues in C Yang Zhengwei CSCI2100B Data Structures Tutorial 4.
Data Structures: Advanced Damian Gordon. Advanced Data Structure We’ll look at: – Linked Lists – Trees – Stacks – Queues.
Foundation of Computing Systems Lecture 3 Stacks and Queues.
Stacks And Queues Chapter 18.
1 Linked-list, stack and queue. 2 Outline Abstract Data Type (ADT)‏ Linked list Stack Queue.
Cousin of the Stack.  An abstract data type (container class) in which items are entered at one end and removed from the other end  First In First.
Data Structures. Abstract Data Type A collection of related data is known as an abstract data type (ADT) Data Structure = ADT + Collection of functions.
Linear Data Structures
Computer Engineering Rabie A. Ramadan Lecture 6.
Data Structures David Kauchak cs302 Spring Data Structures What is a data structure? Way of storing data that facilitates particular operations.
1 Midterm 1 on Friday February 12 Closed book, closed notes No computer can be used 50 minutes 4 questions Write a function Write program fragment Explain.
CS6045: Advanced Algorithms Data Structures. Dynamic Sets Next few lectures will focus on data structures rather than straight algorithms In particular,
Chapter 3 Lists, Stacks, Queues. Abstract Data Types A set of items – Just items, not data types, nothing related to programming code A set of operations.
Lecture 16 Stacks and Queues Richard Gesick. Sample test questions 1.Write a definition for a Node class that holds a number. 2.Write a method that sums.
STACKS & QUEUES for CLASS XII ( C++).
Review Array Array Elements Accessing array elements
Elementary data structures
Queues.
G.PULLAIAH COLLEGE OF ENGINEERING AND TECHNOLOGY
G64ADS Advanced Data Structures
Chapter 12 – Data Structures
COSC160: Data Structures: Lists and Queues
Stacks and Queues Chapter 4.
September 29 – Stacks and queues
Program based on queue & their operations for an application
Chapter 15 Lists Objectives
Stacks and Queues CMSC 202.
Lectures Queues Chapter 8 of textbook 1. Concepts of queue
Stacks and Queues.
Queues Queues Queues.
Stack and Queue APURBO DATTA.
Queues Chapter 4.
CMSC 341 Lecture 5 Stacks, Queues
Principles of Computing – UFCFA3-30-1
Stacks, Queues, and Deques
DATA STRUCTURE QUEUE.
Stacks, Queues, and Deques
CSE 214 – Computer Science II Stacks
Stack A data structure in which elements are inserted and removed only at one end (called the top). Enforces Last-In-First-Out (LIFO) Uses of Stacks Evaluating.
CS6045: Advanced Algorithms
Stacks and Queues 1.
Mutable Data (define mylist (list 1 2 3)) (bind ((new (list 4)))
Stacks and Queues.
Stacks, Queues, and Deques
CSCS-200 Data Structure and Algorithms
LINEAR DATA STRUCTURES
Presentation transcript:

Data Structure HKOI training /4/2010 So Pak Yeung

What is data structure? a particular way of storing and organizing data in a computer so that it can be used efficiently. From wikipedia

Outline Stack Stack Queue Queue Linked list Linked list

Stack Last In First Out (LIFO) Last In First Out (LIFO) Operations: Operations: PushPush PopPop

Stack - Push Put an element on the top of the stack Put an element on the top of the stack if (top==MAX_SIZE) //stack is full output error: stack overflow output error: stack overflow else stack[top++] = data; stack[top++] = data;

Stack - Pop Remove the element on the top of the stack Remove the element on the top of the stack if (top==0) //the stack is empty output Error: stack underflow output Error: stack underflow else{ // tmp = stack[--top]; --top;}

Queue First In First Out (FIFO) First In First Out (FIFO) Operations: Operations: EnqueueEnqueue DequeueDequeue

Queue - Enqueue Add an element at the end of the queue Add an element at the end of the queue if (e == MAX) output Error output Error else queue[e++] = data;

Queue: Dequeue Remove the element at the front of the queue Remove the element at the front of the queue if (f==e) //empty queue output error output error else{ // tmp = queue[f]; ++f;}

Queue Not efficient in terms of memory Not efficient in terms of memory Improvement: Improvement: Using linked list to implementUsing linked list to implement Circular QueueCircular Queue

Linked List Data + Pointers Data + Pointers Operations: Operations: InsertionInsertion DeletionDeletion

Linked List data1 data2data3data4 null head

Linked List - Insertion Assume we add a node after node 2 data1 data2data3data4 null head

Linked List - Insertion data1 data2data3data4 null new data head

Linked List - Insertion data1 data2data3data4 null new data head

Linked List - Insertion data1 data2data3data4 null new data head

Linked List - Insertion node* tmp = new node; tmp->data = new_data; tmp->next = target->next; target->next = tmp;

Linked List - Deletion Assume we delete node 3 data1 data2data3data4 null head

Linked List - Deletion data1 data2data3data4 null tmp head

Linked List - Deletion data1 data2data3data4 null tmp head

Linked List - Deletion data1 data2data4 null head

Linked List - Deletion node* tmp = target->next; target->next = tmp->next; delete tmp;

Linked List It is so troublesome when we try to delete the first node / insert before the first node It is so troublesome when we try to delete the first node / insert before the first node Dummy node Dummy node Doubly Linked List Doubly Linked List

Linked List data1 data2data3data4 null head

Types of Linked List Singly-Linked List Singly-Linked List Doubly-Linked List Doubly-Linked List Circularly-Linked List Circularly-Linked List

Questions?