Chapter 4. Queues - 2 Internet Computing KUT Youn-Hee Han.

Slides:



Advertisements
Similar presentations
Breadth First Search AB F I EH DC G FIFO Queue - front.
Advertisements

Senem Kumova Metin Spring2009 STACKS AND QUEUES Chapter 10 in A Book on C.
Ceng-112 Data Structures I Chapter 5 Queues.
Chapter 6 Structures By C. Shing ITEC Dept Radford University.
Data Structures Lecture 13: QUEUES Azhar Maqsood NUST Institute of Information Technology (NIIT)
ADT Stacks and Queues. Stack: Logical Level “An ordered group of homogeneous items or elements in which items are added and removed from only one end.”
Data Structures(数据结构) Course 5:Queue
CS 206 Introduction to Computer Science II 03 / 27 / 2009 Instructor: Michael Eckmann.
CS 206 Introduction to Computer Science II 11 / 07 / 2008 Instructor: Michael Eckmann.
1 Breadth First Search AB F I EH DC G FIFO Queue - front.
Exercise 4 1. Write a program that simulates coin tossing. For each toss of the coin the program should print Heads or Tails. Let the program toss the.
Event-drive SimulationCS-2303, C-Term Project #3 – Event-driven Simulation CS-2303 System Programming Concepts (Slides include materials from The.
CS Data Structures I Chapter 7 Queues II. 2 Topics Queue Application Simulation Comparison of List, Stack and Queue.
Chapter 7 - Functions. Functions u Code group that performs single task u Specification refers to what goes into and out of function u Design refers to.
© 2006 Pearson Addison-Wesley. All rights reserved8-1 Chapter 8 Queues CS102 Sections 51 and 52 Marc Smith and Jim Ten Eyck Spring 2008.
Programming Assignment #3 CS-2301, B-Term Programming Assignment #3 User-defined Functions Due, November 18, 11:59 PM (Assignment adapted from C:
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 5 - Functions Outline 5.1Introduction 5.2Program.
Cmpt-225 Queues. A queue is a data structure that only allows items to be inserted at the end and removed from the front Queues are FIFO (First In First.
 2007 Pearson Education, Inc. All rights reserved C Functions.
Chapter 7 Queues. © 2005 Pearson Addison-Wesley. All rights reserved7-2 The Abstract Data Type Queue A queue –New items enter at the back, or rear, of.
1 Random numbers Random  completely unpredictable. No way to determine in advance what value will be chosen from a set of equally probable elements. Impossible.
CS 206 Introduction to Computer Science II 03 / 30 / 2009 Instructor: Michael Eckmann.
C Lecture Notes Functions (Cont...). C Lecture Notes 5.8Calling Functions: Call by Value and Call by Reference Used when invoking functions Call by value.
Queues Chapter 8 Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved
Chapter 12 Data Structure Associate Prof. Yuh-Shyan Chen Dept. of Computer Science and Information Engineering National Chung-Cheng University.
© 2006 Pearson Addison-Wesley. All rights reserved8 A-1 Chapter 8 Queues (slightly modified by Dan Fleck)
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. C How To Program - 4th edition Deitels Class 05 University.
Functions in C Outline 1Introduction 2Program Modules in C 3Math Library Functions 4Functions 5Function Definitions 6Function Prototypes 7Header Files.
1 QUEUES. 2 Definition A queue is a linear list in which data can only be inserted at one end, called the rear, and deleted from the other end, called.
 2008 Pearson Education, Inc. All rights reserved Case Study: Random Number Generation C++ Standard Library function rand – Introduces the element.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Functions (Header files and Library Functions) Outline.
Robbie CSCI2100A Data Structures Tutorial
Data Structures: A Pseudocode Approach with C1 Chapter 4 Objectives Upon completion you will be able to: Explain the design, use, and operation of a queue.
CS221 Random Numbers. Random numbers are often very important in programming Suppose you are writing a program to play the game of roulette The numbers.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 5 - Functions Outline 5.1Introduction 5.2Program.
The Abstract Data Type Queue A queue New items enter at the back, or rear, of the queue Items leave from the front of the queue First-in, first-out (FIFO)
Lecture 05 Functions II, Storage Class, Scope, rand() METU Dept. of Computer Eng. Summer 2002 Ceng230 - Section 01 Introduction To C Programming by Ahmet.
Chapter 8 Queues. © 2004 Pearson Addison-Wesley. All rights reserved 8-2 The Abstract Data Type Queue A queue –New items enter at the back, or rear, of.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Ver Chapter 7: Queues Data Abstraction & Problem Solving with C++
CE 221 Data Structures and Algorithms
+ Arrays & Random number generator. + Introduction In addition to arrays and structures, C supports creation and manipulation of the following data structures:
1D Arrays and Random Numbers Artem A. Lenskiy, PhD May 26, 2014.
UNIT 11 Random Numbers.
ONE DIMENSIONAL ARRAYS AND RANDOM NUMBERS. Introduction In addition to arrays and structures, C supports creation and manipulation of the following data.
Function Call Stack and Activation Frame Stack Just like a pile of dishes Support Two operations push() pop() LIFO (Last-In, First-Out) data structure.
Queues CS 367 – Introduction to Data Structures. Queue A queue is a data structure that stores data in such a way that the last piece of data stored,
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Templatized Queue.
CSC2100B Tutorial 6 Hashing Hao Ma Yi LIU Mar 4, 2004.
1 Generating Random Numbers Textbook ch.6, pg
MR. CRONE Generating Random Numbers. Random Numbers Many programs require the computer to generate random numbers Random numbers are used in many applications.
Queues Chapter 4 Objectives Upon completion you will be able to:
Queues.
Queues Chapter 8 Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved
Deitel- C:How to Program (5ed)
Alyce Brady CS 470: Data Structures CS 510: Computer Algorithms
Queues.
Chapter 6 - Functions Outline 5.1 Introduction
CSC 143 Queues [Chapter 7].
Queues Jyh-Shing Roger Jang (張智星)
Breadth First Search - A B C D E F G H I front FIFO Queue.
ECE 103 Engineering Programming Chapter 51 Random Numbers
Visit for more Learning Resources
CE 221 Data Structures and Algorithms
ECE 103 Engineering Programming Chapter 63 Queue Implementation
MECH 3550 : Simulation & Visualization
17CS1102 DATA STRUCTURES © 2016 KL University – The contents of this presentation are an intellectual and copyrighted property of KL University. ALL RIGHTS.
CSCS-200 Data Structure and Algorithms
Functions in C Math Library Functions Functions Function Definitions
Chapter 6 – Queues and Deques
Presentation transcript:

Chapter 4. Queues - 2 Internet Computing KUT Youn-Hee Han

Data Structure2 4. Queuing Theory Queuing theory a field of applied mathematics that is used to predict performance of queues. Queuing Type  Single-server queue Hot-food vender  Multi-server queue Many bank tellers in a bank  Multiple single-server queues Two common Elements in Queuing Theory  Customer Any person or thing needing service  Service Any activity needed to accomplish the required result Two factors affecting a queue  Arrival Rate (  Queue Time)  Service Time Response Time  Queue Time + Service Time ….. Server.…... Customer Queue Servers Leaving Customer Multi-server Queuing System

Data Structure3 5. Queue Applications Business Online Application Customer online requests, jobs, or orders Computer System Job (or process) scheduling Print spool 교재에서 주어진 두 개의 Queue Applications Categorizing data Queue Simulation  To study the performance of any queue application  (Optional Study) PPT 자료에서 주어지는 Queue Application Goal Seeking  BFS (Breadth First Search)

5. Queue Applications Goal of Categorizing Data ( 교재 168~) Rearrange data in separated groups without destroying their original order in each group For example Four different groups  Group 1: less than 10  Group 2: between 10 and 19  Group 3: between 20 and 29  Group 4: between 30 and greater Input Output  Note: the numbers in each group have kept their original order Data Structure | | | | |

5. Queue Applications Structures for Categorizing Data Initialization before calling fillQueues After calling fillQueues Data Structure5

5. Queue Applications Source Codes: Categorizing Data File Name: catagorize.c Data Structure6 #include #include "stdbool.h" #include "queues.h" void fillQueues (QUEUE*, QUEUE*, QUEUE*, QUEUE*); void printQueues (QUEUE*, QUEUE*, QUEUE*, QUEUE*); void printOneQueue (QUEUE* pQueue); int main (void) { QUEUE* q0to9; QUEUE* q10to19; QUEUE* q20to29; QUEUE* qOver29; q0to9 = createQueue (); q10to19 = createQueue (); q20to29 = createQueue (); qOver29 = createQueue (); fillQueues (q0to9, q10to19, q20to29, qOver29); printQueues (q0to9, q10to19, q20to29, qOver29); return 0; }

5. Queue Applications Source Codes: Categorizing Data File Name: catagorize.c Data Structure7 void fillQueues (QUEUE* q0to9, QUEUE* q10to19, QUEUE* q20to29, QUEUE* qOver29) { int category; int item; int* dataPtr; int i; printf("Categorizing data:\n"); srand(79); for (i = 1; i <= 25; i++) { if (!(dataPtr = (int*) malloc (sizeof (int)))) printf("Overflow in fillQueues\a\n"), exit(100); *dataPtr = item = rand() % 51; // (0 ~ RAND_MAX)%51, RAND_MAX=32767 category = item / 10; printf("%3d", item); if (!(i % 11)) printf("\n");

5. Queue Applications Source Codes: Categorizing Data File Name: catagorize.c Data Structure8 switch (category) { case 0 : enqueue (q0to9, dataPtr); break; case 1 : enqueue (q10to19, dataPtr); break; case 2 : enqueue (q20to29, dataPtr); break; default : enqueue (qOver29, dataPtr); break; } printf("\nEnd of data categorization\n\n"); return; }

5. Queue Applications Source Codes: Categorizing Data File Name: catagorize.c Data Structure9 void printQueues (QUEUE* q0to9, QUEUE* q10to19, QUEUE* q20to29, QUEUE* qOver29) { printf("Data 0.. 9:"); printOneQueue (q0to9); printf("Data :"); printOneQueue (q10to19); printf("Data :"); printOneQueue (q20to29); printf("Data over 29:"); printOneQueue (qOver29); return; }

5. Queue Applications Source Codes: Categorizing Data File Name: catagorize.c Data Structure10 void printOneQueue (QUEUE* pQueue) { int lineCount; int* dataPtr; lineCount = 0; while (!emptyQueue (pQueue)) { dequeue (pQueue, (void*)&dataPtr); if (lineCount++ >= 10) { lineCount = 1; printf ("\n "); } printf("%3d ", *dataPtr); } printf("\n"); return; }

5. Queue Applications C 로 Random Number 만들기 void srand(unsigned int seed);  Random Number Generation 에 대한 seed 값 설정  흔히 사용하는 초기화 방법 int rand( void );  하나의 (pseudo-)random number ( 정수 ) 를 하나 발생시킴  발생되는 정수의 범위 : 0 ~ RAND_MAX (32767) 두 함수 모두 를 필요로 함 Data Structure11 time_t seed;//time_t 의 구조체 변수 seed 변수 생성 time(&seed);// 시스템 상의 현재 시간을 seed 에 얻어온다. srand((unsigned int) seed); //srand 호출을 통하여 Random Number Generation 에 대한 seed 값 설정

5. Queue Applications C 로 Random Number 만들기 For example  10 부터 1000 사이의 정수를 Random 하게 개를 만들어서 배열에 저장하라. Data Structure12 #include const int LOW = 10; const int HIGH = 1000; const int NUM_DATA = 50000; int main(void) { int data[50000]; int i; time_t seed; time(&seed); srand((unsigned int) seed); for (i = 0 ; i < NUM_DATA ; i++) { data[i] = rand() % (HIGH - LOW + 1) + LOW; } for (i = 0 ; i < NUM_DATA-1 ; i++) { printf ("%d\t", data[i]); }

Data Structure13 5. Queue Applications Goal Seeking  너비우선탐색 (BFS: Breadth First Search) 소모적 탐색 ( 消耗, Exhaustive Search) 방법의 일종 탐색 순서에 있어서 깊이보다는 폭을 우선적으로 취한다. 탐색 방법  0) A 가 Origin  1) A 에서 거리가 1 인 모든 노드를 방문  2) 다음 방문한 노드에서 부터 거리가 1 인 모든 노드, 즉 A 에서 거리가 2 인 모든 노드들을 방문한다.  3) 위와 같은 방법 반복 F 까지의 경로가 있는가 ?  A-B-G-C-E-H-D-F

Data Structure14 5. Queue Applications BFS 을 위한 Queue 시작 노드를 enqueue dequeue 와 동시에 인접 노드들을 enqueue 한번 enqueue 한 노드는 다시 enqueue 하지 않음 Queue 에서 dequeue 된 노드를 순차적으로 나열하면 그것이 BFS 의 탐색 순서가 됨

Data Structure15 5. Queue Applications BFS 의 Pseudo-code BreadthFirstSearch(Origin) { createQueue(); 새로운 큐를 만들기 enqueue(Origin); 출발지를 큐에 삽입 Mark Origin as Visited; 출발지를 가 본 것으로 표시 while (!queueEmpty( )) { 빈 큐가 아닐 동안 queueFront(Front); 큐 front 에 있는 노드를 Front 로 복사 dequeue( ); 큐 front 제거 for (Each Unvisited Nodes C Adjacent to Front) { enqueue(C); 큐에 삽입 Mark C as Visited; 가 본 것으로 표시 }

Data Structure16 5. Queue Applications DFS vs. BFS