אחסון (אירגון) מידע DATA DATA DATA Link Link Link … …

Slides:



Advertisements
Similar presentations
Data Structures Through C
Advertisements

STACKS & QUEUES. Stacks Abstract data types An abstract data type (ADT) is an abstraction of a data structure An ADT specifies : –Data stored –Operations.
Stacks, Queues, and Linked Lists
Data Structure HKOI training /4/2010 So Pak Yeung.
Stack & Queues COP 3502.
Senem Kumova Metin Spring2009 STACKS AND QUEUES Chapter 10 in A Book on C.
ADVANCED DATA STRUCTURES AND ALGORITHM ANALYSIS Chapter 3 Lists, Stacks, and Queues.
1 Stack and Queue. 2 Stack In Out ABCCB Data structure with Last-In First-Out (LIFO) behavior.
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.
E.G.M. Petrakislists, stacks, queues1 Stacks Stack: restricted variant of list –Elements may by inserted or deleted from only one end  LIFO lists –Top:
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.”
Starting Out with C++: Early Objects 5/e © 2006 Pearson Education. All Rights Reserved Starting Out with C++: Early Objects 5 th Edition Chapter 18 Stacks.
 Abstract Data Type Abstract Data Type  What is the difference? What is the difference?  Stacks Stacks  Stack operations Stack operations  Parsing.
E.G.M. Petrakisstacks, queues1 Stacks  Stack: restricted variant of list  elements may by inserted or deleted from only one end : LIFO lists  top: the.
Queue using an array. .head.tail Pointers head and tail always point to the first empty slot before or after elements in the list. Thus, initially they.
Data Structures from Cormen, Leiserson, Rivest & Stein.
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.
EXPANDING STACKS AND QUEUES CS16: Introduction to Data Structures & Algorithms 1 Tuesday, February 10, 2015.
Data Structures - Queues
Objectives of these slides:
DS.L.1 Lists, Stacks, and Queues (Review) Chapter 3 Overview Abstract Data Types Linked Lists, Headers, Circular Links Cursor (Array) Implementation Stacks.
Review 1 Introduction Representation of Linear Array In Memory Operations on linear Arrays Traverse Insert Delete Example.
DATA STRUCTURES AND ALGORITHMS Lecture Notes 4 Prepared by İnanç TAHRALI.
Due: 2007/11/12. Problem 1 Rewrite function Push and Pop (Program 3.10 and 3.12) using an additional variable lastOp as discussed on Page 146. The queue.
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’
Data Structures: Stacks Queues 1. 2 Stack ADT: What is a Stack? a stack is a varying-length, collection of homogeneous elements Insertion and Deletion.
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.
Review 1 Polish Notation Prefix Infix Postfix Precedence of Operators Converting Infix to Postfix Evaluating Postfix.
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.
Computer Science Department Data Structures and Algorithms Queues Lecture 5.
Linear Data Structures
Data Structures David Kauchak cs302 Spring Data Structures What is a data structure? Way of storing data that facilitates particular operations.
 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.
1 Lecture 9: Stack and Queue. What is a Stack Stack of Books 2.
CSC 172 DATA STRUCTURES. A TALE OF TWO STRUCTURES.
Review Array Array Elements Accessing array elements
Data Structure By Amee Trivedi.
G64ADS Advanced Data Structures
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
Chapter 15 Lists Objectives
Objectives In this lesson, you will learn to: Define stacks
Queue data structure.
Stacks and Queues.
Stack and Queue APURBO DATTA.
CSC 172 DATA STRUCTURES.
Stacks Stack: restricted variant of list
STACK CHAPTER 03 Developed By :- Misha Ann Alexander Data Structures.
Visit for more Learning Resources
Stack and Queue.
Mark Allen Weiss, Addison Wesley
Stacks, Queues, and Deques
מבני נתונים מופשטים בסיסיים
18.5 Linked Queues Like a stack, a queue can be implemented using pointers and nodes Allows dynamic sizing, avoids issue of wrapping indices NULL front.
Stacks and Queues CSE 373 Data Structures.
Queues FIFO Enqueue Dequeue Peek.
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.
Stacks and Queues 1.
Mutable Data (define mylist (list 1 2 3)) (bind ((new (list 4)))
Stacks and Queues CSE 373 Data Structures.
CSE 373 Data Structures Lecture 6
Stacks and Queues CSE 373 Data Structures.
Queues Model Operations Pointer Implementations Array Implementation
Queue Applications Lecture 31 Tue, Apr 11, 2006.
CSE 373 Data Structures Lecture 6
Stacks, Queues, and Deques
Presentation transcript:

אחסון (אירגון) מידע DATA DATA DATA Link Link Link … … הערה: כל יחידה מכילה 2 שדות – מידע וקישור ליחידות אחרות. מטרה: אחסון ועיבוד מספר רב של יחידות מידע. מילת מפתח – יעילות! 1. יעילות האחסון (מקום) – תוספת של מקום מעל ההכרחי, ניצול מקום. 2. יעילות העיבוד (זמן) – זמן עבור ביצוע פעולות על המידע. כגון חיפוש, מחיקה, הכנסת, גישה לאיבר במבנה...

דרך מוכרת: מערך – אחסון סידרתי. אחסון לינארי סידרתי דרך מוכרת: מערך – אחסון סידרתי. מאפיינים: 1. מקום: מוגבל, ביזבוז כללי, חסכוני לכל יחידה. ...O(1), גישה לאיבר - O(n)2. זמן: הכנסה,הוצאה - הערה: ניתן לפתור חלק מהבעיות, אבל... מסקנה: באופן כללי לא מספק.

אחסון לינארי מקושר DATA DATA DATA HEAD TAIL NEXT POINTER NEXT POINTER NULL . . .

הוספת איבר Pointer P-new Start

הוספת איבר Pointer Start P-new

מחיקת איבר Pointer Start מחק את זה

מחיקת איבר מחק את זה Pointer Start

מסקנה: שיפור מסוים ביחס למערך, הבעיה העיקרית – זמן גישה. רשימה מקושרת מאפיינים: 1. מקום: לא מוגבל, אין ביזבוז באופן כללי, הוספה של מצביע. ...O(n), גישה לאיבר - O(1)2. זמן: הכנסה,הוצאה - מסקנה: שיפור מסוים ביחס למערך, הבעיה העיקרית – זמן גישה.

רשימה מקושרת דו-כיוונית DATA NEXT PRE DATA NEXT PRE DATA NEXT PRE שיפור יחסי בזמן גישה, הוספת מצביע.

(מחסנית) Stackמימוש 1: מילת מפתח: LIFO אינטואיציה: מחסנית רובה, ניירות על השולחן פקודות: 1. S <- MAKE () 2. TOP (S) 3. POP (S) 4. PUSH (S) 5. EMPTY (S) הערה: פקודות נוספות לא אפשריות

מחסנית במערך i-top 1st 2nd 1. S <- MAKE () 2. TOP (S) 3. POP (S) 4. PUSH (S) 5. EMPTY (S)

סיבוכיות (מחסנית במערך) בעיה: מה עושים כשמערך מתמלא? פתרון: שיטת ההכפלה Doubling 1) הקצה מקום מסוים לטבלה (n) 2) כשהמקום מתמלא והטבלה מכילה n אלמנטים: א) הקצה מקום חדש לטבלה בגודל 2n ב) העתק איברים לטבלה החדשה. ג) שחרר טבלה ישנה.

סיבוכיות (מחסנית במערך) 1) עבור פעולת ׂPER OPERATION) : INSERT) אם אין הכפלה (O(1 אם יש הכפלה (O(n AMORTIZED COST חשוב זמן ממוצע עבור פעולה במקרה הגרוע ביותר. שווה ל: T(n)/n , כאשר (T(n הוא סכום הפעולות על n איברים. AMORTIZED COST O(1)

מחסנית ברשימה מקושרת p-top p-top p-top 1. S <- MAKE () 2. TOP (S) 3. POP (S) 4. PUSH (S) 5. EMPTY (S)

שימוש במחסנית תוכנית לבדיקת פלינדרום: w$wR דוגמא: abcda$adcba ({[]})(] בדיקת תקינות של סוגרים: ({[]})([(){}[{}]]) קריאה לפונקציות: Prog A . x= 17 Call B B() x =7 Call C return C() . x =3 return x=17 x=7

שימוש נוסף במחסנית יצוג ביטוי אלגברי: -+ABC: Prefixא. A+B-C: Infixב. AB+C-: Postfixג. שאלות: ?Postfix, Infix, Prefix1. מה הצורך ב- 2. מה הקשר החזותי בין השיטות? 3. איך מחסנית עוזרת בחישוב הביטוי?

Postfixחישוב ביטוי אלגברי push(S, s) הוא אופרנד -s אם2.1 push(pop(S), s, pop(S)) אחרת - 2.2 ?

דוגמא Infix: 2 * ( 2 + 3 ) + 3 * 4 - 5 * 6 * ( 7 - 4 - 2 ) Postfix:  2 3 + 2 * 3 4 * + 7 4 – 2 – 6 * 5 * - + 3 2 5 2 * 3 4 * + 7 4 – 2 – 6 * 5 * -

דוגמא 5 2 * 3 4 * + 7 4 – 2 – 6 * 5 * - * 2 5 10 3 4 * + 7 4 – 2 – 6 * 5 * -

דוגמא 10 3 4 * + 7 4 – 2 – 6 * 5 * - * 4 3 10 10 12 + 7 4 – 2 – 6 * 5 * -

דוגמא 10 12 + 7 4 – 2 – 6 * 5 * - + 12 10 22 7 4 – 2 – 6 * 5 * -

דוגמא 22 7 4 – 2 – 6 * 5 * - - 4 7 22 22 3 2 – 6 * 5 * -

דוגמא 22 3 2 – 6 * 5 * - - 2 3 22 22 1 6 * 5 * -

דוגמא 22 1 6 * 5 * - * 6 1 22 22 6 5 * -

דוגמא 22 6 5 * - * 5 6 22 22 30 -

דוגמא 22 30 - - 30 22 -8

Postfix ל-Infixהמרה מ- הערות: 1. קדימויות של אופרטורים... 2. קדימויות של סוגריים... 3. מבנה נתונים... 4. סדר של אופרנדים...

אלגוריתם המרה 1. אתחל מחסנית ריקה S(מחסנית האופרטורים). 2.1 אם s אופרנד - תדפיס s 2.2 אחרת: 2.1.1 כל עוד S לא ריקה ו-top(S) קודם ל-s תדפיס pop(S) 2.1.2 push(S, s) 3. כל עוד S לא ריקה – תדפיס pop(S) הערה: מה לגבי סוגריים?

תור - Queue In Out מילת מפתח: FIFO פקודות : 1) Q <- MAKE() 2) ENQUEUE (x,Q) : INSERT (x,END (Q),Q) 3) FRONT (Q) : RET (FIRST (Q), Q) 4) DEQUEUE (Q) : DELETE (FIRST (Q), Q) 5) EMPTY (Q) : TRUE | FALSE

שימו לב: ניתן להכניס רק N-1 איברים!!!!!! תור במערך 1 2 N FRONT - על ראשון, REAR - על אחרון N 1 2 F=R => ריק F+k=R => kאיברים R=F-1=> מלא QUEUE Q.REAR Q.FRONT שימו לב: ניתן להכניס רק N-1 איברים!!!!!!

תור ברשימה מקושרת rear rear front front 1) Q <- MAKE() 2) ENQUEUE (x,Q) : INSERT (x,END (Q),Q) 3) FRONT (Q) : RET (FIRST (Q), Q) 4) DEQUEUE (Q) : DELETE (FIRST (Q), Q) 5) EMPTY (Q) : TRUE | FALSE

שימושים Queue: תור למדפסת .

תור קדימויות In Out שינוי: הוספת מפתח k לכל איבר. הוצאת איבר נעשית לפי המפתח הזה. דוגמאות: עבודת מעבד, מערכת הפעלה, תזמון עבודותVIP, ...

תור קדימויות שינויים בולטים: FRONT(Q) = Maximum(Q) (Minimum(Q)) DEQUEUE(Q) = ExtractMaximum(Q) (ExtractMinimum(Q)) איך לממש? מה סיבוכיות המימוש הנאיבי?