SlideShare a Scribd company logo
1 of 22
Download to read offline
QUEUE, STACK, HASH TABLE
CONTENT
➤ Stack
➤ Queue
➤ Deque
➤ Hash table
STACK
➤ Definition: ordered collection of items where the addition of new
items and the removal of existing items always takes place at the
same end. This end is commonly referred to as the “top”. The end
opposite the top is known as the “base”.
➤ Order principle: LIFO(last-in, first-out).
➤ The most recently added item is the one that is in position
to be removed first.
➤ Newer items are near the top, while older items are near
the base.
➤ Stack operations:
➤ Stack(): creates a new stack that is empty. It needs no parameters and
returns an empty stack.
➤ push(item): adds a new item to the top of the stack. It needs the item
and returns nothing. O(1).
➤ pop(): removes the top item from the stack. It needs no parameters and
returns the item. The stack is modified. O(1).
➤ peak(): returns the top item from the stack but does not remove it. It
needs no parameters. The stack is not modified. O(1).
➤ isEmpty(): tests to see whether the stack is empty. It needs no
parameters and returns a boolean value. O(1).
➤ size(): returns the number of items on the stack. It needs no parameters
and returns an integer. O(1).
➤ Not a built-in type in python. We need to define it by
ourselves.
QUEUE
➤ Definition: ordered collection of items where the addition of
new items happens at one end, called the “rear”, and the
removal of existing items occurs at the other end, commonly
called the “front”.
➤ Order principle: FIFO(first-in, first-out or first-come first-
served).
➤ Queue operations:
➤ Queue(): creates a new queue that is empty. It needs no
parameters and returns an empty queue.
➤ enqueue(item): adds a new item to the rear of the queue. It needs
the item and returns nothing. O(1)
➤ dequeue(): removes the front item from the queue. It needs no
parameters and returns the item. The queue is modified. O(1)
➤ isEmpty(): tests to see whether the queue is empty. It needs no
parameters and returns a boolean value. O(1)
➤ size(): returns the number of items in the queue. It needs no
parameters and returns an integer. O(1)

➤ Not a built-in type in python. We need to define it by
ourselves.
DEQUE
➤ Definition: ordered collection of items similar to the queue.
It has two ends, a front and a rear, and the items remain
positioned in the collection.
➤ Difference between queue: new items can be added at
either the front or the rear. Likewise, existing items can
be removed from either end.
➤ Order principle: does not require FIFO or LIFO.
➤ Deque operations:
➤ Deque() creates a new deque that is empty. It needs no parameters and returns an empty
deque.
➤ addFront(item) adds a new item to the front of the deque. It needs the item and returns
nothing. O(1)
➤ addRear(item) adds a new item to the rear of the deque. It needs the item and returns
nothing. O(1)
➤ removeFront() removes the front item from the deque. It needs no parameters and
returns the item. The deque is modified. O(1)
➤ removeRear() removes the rear item from the deque. It needs no parameters and returns
the item. The deque is modified. O(1)
➤ isEmpty() tests to see whether the deque is empty. It needs no parameters and returns a
boolean value.
➤ size() returns the number of items in the deque. It needs no parameters and returns an
integer.

➤ Just import…
➤ Implement:
HASH TABLE
…….
[0] [1] [2] [3] [4] [700]
1. An array of records
2. Each record has a special field, called key.
In this example, the key is a long integer field
called number
number: 506643548 3. The number may be
a person’s
identification
number, and the rest
of the record has
information about
person
HASH TABLE
Number:
281942902
Number:
233667136
Number:
506643548 …….
Number:
155778322
[0] [1] [2] [3] [4] [700]
When a hash table is in use, some spots contain
valid records, and other spots are empty.
Number:
281942902
Number:
233667136
Number:
506643548 …….
Number:
155778322
[0] [1] [2] [3] [4] [700]
- In order to insert a new record, the key must
somehow be converted to an array index.
- The index is called the hash value of the key.
Number: 580625685- A typical way to create a hash value:
Number mod 701
-> 580625685 mod 701 = 3
Number:
281942902
Number:
233667136
Number:
580625685
Number:
506643548 …….
Number:
155778322
[0] [1] [2] [3] [4] [700]
Number: 701466868
Hash value -> 701466868 mod 701 = 2
Collision!!!
[5]
TIME COMPLEXITY
➤ Average/best: O(1)
➤ Worst: O(n)
HASH FUNCTION
➤ Good hash function:
➤ Return number 0, …, table size.
➤ Should be efficiently computable: O(1)
➤ Should not waste space.
➤ Should minimize collisions.
➤ The best hash function would distribute keys as evenly as possible in the hash table.
➤ Folding method:
➤ Mid square method:
COLLISION
➤ Collision: occurs when two different keys has to the same value.
➤ Cannot store both data records in the same slot in array.
➤ Collision resolution: a systematic method for placing the second
item in the hash table.
➤ Two methods:
➤ Separate Chaining: Use a dictionary data structure (such
as a linked list) to store multiple items that hash to the
same slot
➤ Closed Hashing (or probing/open addressing): search for
empty slots using a second function and store item in first
empty slot that is found. May go circularly to the start.
HASHING WITH SEPARATE CHAINING
• Put a little dictionary at
each entry
– common case is
unordered linked list
(chain)
CLOSED HASHING/ OPEN ADDRESSING
➤ Disadvantage:
➤ Clustering: If many collisions occur at the same hash value, a number
of surrounding slots will be filled by the linear probing resolution.
This will have impact on other items that are being inserted.
➤ Advance:
➤ Skip slots (rehashing): (pos + skip) % hashtablesize.
➤ Quadratic probing: Instead of using a constant “skip” value, we use a
rehash function that increments the hash value by 1, 3, 5, 7, 9, and so
on. In other words, quadratic probing uses a skip consisting of
successive perfect squares.

More Related Content

What's hot (20)

Queue
QueueQueue
Queue
 
2.1 STACK & QUEUE ADTS
2.1 STACK & QUEUE ADTS2.1 STACK & QUEUE ADTS
2.1 STACK & QUEUE ADTS
 
Lesson11
Lesson11Lesson11
Lesson11
 
List interface
List interfaceList interface
List interface
 
Stack project
Stack projectStack project
Stack project
 
Stack in Sata Structure
Stack in Sata StructureStack in Sata Structure
Stack in Sata Structure
 
Queues
Queues Queues
Queues
 
Stack and queue
Stack and queueStack and queue
Stack and queue
 
DS- Stack ADT
DS- Stack ADTDS- Stack ADT
DS- Stack ADT
 
The Ring programming language version 1.2 book - Part 10 of 84
The Ring programming language version 1.2 book - Part 10 of 84The Ring programming language version 1.2 book - Part 10 of 84
The Ring programming language version 1.2 book - Part 10 of 84
 
Stack
StackStack
Stack
 
computer notes - Data Structures - 32
computer notes - Data Structures - 32computer notes - Data Structures - 32
computer notes - Data Structures - 32
 
STACKS AND QUEUES CONCEPTS
STACKS AND QUEUES CONCEPTSSTACKS AND QUEUES CONCEPTS
STACKS AND QUEUES CONCEPTS
 
stacks and queues
stacks and queuesstacks and queues
stacks and queues
 
Computer notes - Binary Search
Computer notes - Binary SearchComputer notes - Binary Search
Computer notes - Binary Search
 
Array within a class
Array within a classArray within a class
Array within a class
 
stacks and queues
stacks and queuesstacks and queues
stacks and queues
 
The Ring programming language version 1.2 book - Part 11 of 84
The Ring programming language version 1.2 book - Part 11 of 84The Ring programming language version 1.2 book - Part 11 of 84
The Ring programming language version 1.2 book - Part 11 of 84
 
The Ring programming language version 1.2 book - Part 9 of 84
The Ring programming language version 1.2 book - Part 9 of 84The Ring programming language version 1.2 book - Part 9 of 84
The Ring programming language version 1.2 book - Part 9 of 84
 
The Ring programming language version 1.2 book - Part 12 of 84
The Ring programming language version 1.2 book - Part 12 of 84The Ring programming language version 1.2 book - Part 12 of 84
The Ring programming language version 1.2 book - Part 12 of 84
 

Similar to 6

23 stacks-queues-deques
23 stacks-queues-deques23 stacks-queues-deques
23 stacks-queues-dequesRishabh Jindal
 
Bsc cs ii dfs u-2 linklist,stack,queue
Bsc cs ii  dfs u-2 linklist,stack,queueBsc cs ii  dfs u-2 linklist,stack,queue
Bsc cs ii dfs u-2 linklist,stack,queueRai University
 
Bca ii dfs u-2 linklist,stack,queue
Bca ii  dfs u-2 linklist,stack,queueBca ii  dfs u-2 linklist,stack,queue
Bca ii dfs u-2 linklist,stack,queueRai University
 
Advanced s and s algorithm.ppt
Advanced s and s algorithm.pptAdvanced s and s algorithm.ppt
Advanced s and s algorithm.pptLegesseSamuel
 
Basic data structures in python
Basic data structures in pythonBasic data structures in python
Basic data structures in pythonLifna C.S
 
DS-UNIT 3 FINAL.pptx
DS-UNIT 3 FINAL.pptxDS-UNIT 3 FINAL.pptx
DS-UNIT 3 FINAL.pptxprakashvs7
 
Stacks Data structure.pptx
Stacks Data structure.pptxStacks Data structure.pptx
Stacks Data structure.pptxline24arts
 
Revisiting a data structures in detail with linked list stack and queue
Revisiting a data structures in detail with linked list stack and queueRevisiting a data structures in detail with linked list stack and queue
Revisiting a data structures in detail with linked list stack and queuessuser7319f8
 
data structures and algorithms Unit 3
data structures and algorithms Unit 3data structures and algorithms Unit 3
data structures and algorithms Unit 3infanciaj
 
Data Structure (Dynamic Array and Linked List)
Data Structure (Dynamic Array and Linked List)Data Structure (Dynamic Array and Linked List)
Data Structure (Dynamic Array and Linked List)Adam Mukharil Bachtiar
 
Stacks,queues,linked-list
Stacks,queues,linked-listStacks,queues,linked-list
Stacks,queues,linked-listpinakspatel
 
Lecture#5 - Stack ADT.pptx
Lecture#5 - Stack ADT.pptxLecture#5 - Stack ADT.pptx
Lecture#5 - Stack ADT.pptxSLekshmiNair
 

Similar to 6 (20)

Stacks, Queues, Deques
Stacks, Queues, DequesStacks, Queues, Deques
Stacks, Queues, Deques
 
23 stacks-queues-deques
23 stacks-queues-deques23 stacks-queues-deques
23 stacks-queues-deques
 
LEC3-DS ALGO(updated).pdf
LEC3-DS  ALGO(updated).pdfLEC3-DS  ALGO(updated).pdf
LEC3-DS ALGO(updated).pdf
 
Bsc cs ii dfs u-2 linklist,stack,queue
Bsc cs ii  dfs u-2 linklist,stack,queueBsc cs ii  dfs u-2 linklist,stack,queue
Bsc cs ii dfs u-2 linklist,stack,queue
 
Bca ii dfs u-2 linklist,stack,queue
Bca ii  dfs u-2 linklist,stack,queueBca ii  dfs u-2 linklist,stack,queue
Bca ii dfs u-2 linklist,stack,queue
 
STACK1.pptx
STACK1.pptxSTACK1.pptx
STACK1.pptx
 
Advanced s and s algorithm.ppt
Advanced s and s algorithm.pptAdvanced s and s algorithm.ppt
Advanced s and s algorithm.ppt
 
Basic data structures in python
Basic data structures in pythonBasic data structures in python
Basic data structures in python
 
Stack.pptx
Stack.pptxStack.pptx
Stack.pptx
 
DS-UNIT 3 FINAL.pptx
DS-UNIT 3 FINAL.pptxDS-UNIT 3 FINAL.pptx
DS-UNIT 3 FINAL.pptx
 
Stacks Data structure.pptx
Stacks Data structure.pptxStacks Data structure.pptx
Stacks Data structure.pptx
 
9 python data structure-2
9 python data structure-29 python data structure-2
9 python data structure-2
 
Revisiting a data structures in detail with linked list stack and queue
Revisiting a data structures in detail with linked list stack and queueRevisiting a data structures in detail with linked list stack and queue
Revisiting a data structures in detail with linked list stack and queue
 
data structures and algorithms Unit 3
data structures and algorithms Unit 3data structures and algorithms Unit 3
data structures and algorithms Unit 3
 
U3.stack queue
U3.stack queueU3.stack queue
U3.stack queue
 
Data Structure (Dynamic Array and Linked List)
Data Structure (Dynamic Array and Linked List)Data Structure (Dynamic Array and Linked List)
Data Structure (Dynamic Array and Linked List)
 
Stacks
StacksStacks
Stacks
 
Data structures
Data structuresData structures
Data structures
 
Stacks,queues,linked-list
Stacks,queues,linked-listStacks,queues,linked-list
Stacks,queues,linked-list
 
Lecture#5 - Stack ADT.pptx
Lecture#5 - Stack ADT.pptxLecture#5 - Stack ADT.pptx
Lecture#5 - Stack ADT.pptx
 

More from EasyStudy3

2. polynomial interpolation
2. polynomial interpolation2. polynomial interpolation
2. polynomial interpolationEasyStudy3
 
Chapter2 slides-part 2-harish complete
Chapter2 slides-part 2-harish completeChapter2 slides-part 2-harish complete
Chapter2 slides-part 2-harish completeEasyStudy3
 
Chapter 12 vectors and the geometry of space merged
Chapter 12 vectors and the geometry of space mergedChapter 12 vectors and the geometry of space merged
Chapter 12 vectors and the geometry of space mergedEasyStudy3
 
Chapter 5 gen chem
Chapter 5 gen chemChapter 5 gen chem
Chapter 5 gen chemEasyStudy3
 
Topic 4 gen chem guobi
Topic 4 gen chem guobiTopic 4 gen chem guobi
Topic 4 gen chem guobiEasyStudy3
 
Gen chem topic 3 guobi
Gen chem topic 3  guobiGen chem topic 3  guobi
Gen chem topic 3 guobiEasyStudy3
 
Gen chem topic 1 guobi
Gen chem topic 1 guobiGen chem topic 1 guobi
Gen chem topic 1 guobiEasyStudy3
 

More from EasyStudy3 (20)

Week 7
Week 7Week 7
Week 7
 
Chapter 3
Chapter 3Chapter 3
Chapter 3
 
Week 6
Week 6Week 6
Week 6
 
2. polynomial interpolation
2. polynomial interpolation2. polynomial interpolation
2. polynomial interpolation
 
Chapter2 slides-part 2-harish complete
Chapter2 slides-part 2-harish completeChapter2 slides-part 2-harish complete
Chapter2 slides-part 2-harish complete
 
L6
L6L6
L6
 
Chapter 5
Chapter 5Chapter 5
Chapter 5
 
2
22
2
 
Lec#4
Lec#4Lec#4
Lec#4
 
Chapter 12 vectors and the geometry of space merged
Chapter 12 vectors and the geometry of space mergedChapter 12 vectors and the geometry of space merged
Chapter 12 vectors and the geometry of space merged
 
Week 5
Week 5Week 5
Week 5
 
Chpater 6
Chpater 6Chpater 6
Chpater 6
 
Chapter 5
Chapter 5Chapter 5
Chapter 5
 
Lec#3
Lec#3Lec#3
Lec#3
 
Chapter 16 2
Chapter 16 2Chapter 16 2
Chapter 16 2
 
Chapter 5 gen chem
Chapter 5 gen chemChapter 5 gen chem
Chapter 5 gen chem
 
Topic 4 gen chem guobi
Topic 4 gen chem guobiTopic 4 gen chem guobi
Topic 4 gen chem guobi
 
Gen chem topic 3 guobi
Gen chem topic 3  guobiGen chem topic 3  guobi
Gen chem topic 3 guobi
 
Chapter 2
Chapter 2Chapter 2
Chapter 2
 
Gen chem topic 1 guobi
Gen chem topic 1 guobiGen chem topic 1 guobi
Gen chem topic 1 guobi
 

Recently uploaded

Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...jaredbarbolino94
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentInMediaRes1
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...M56BOOKSTORE PRODUCT/SERVICE
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupJonathanParaisoCruz
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 

Recently uploaded (20)

Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media Component
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized Group
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 

6

  • 2. CONTENT ➤ Stack ➤ Queue ➤ Deque ➤ Hash table
  • 3. STACK ➤ Definition: ordered collection of items where the addition of new items and the removal of existing items always takes place at the same end. This end is commonly referred to as the “top”. The end opposite the top is known as the “base”.
  • 4. ➤ Order principle: LIFO(last-in, first-out). ➤ The most recently added item is the one that is in position to be removed first. ➤ Newer items are near the top, while older items are near the base.
  • 5. ➤ Stack operations: ➤ Stack(): creates a new stack that is empty. It needs no parameters and returns an empty stack. ➤ push(item): adds a new item to the top of the stack. It needs the item and returns nothing. O(1). ➤ pop(): removes the top item from the stack. It needs no parameters and returns the item. The stack is modified. O(1). ➤ peak(): returns the top item from the stack but does not remove it. It needs no parameters. The stack is not modified. O(1). ➤ isEmpty(): tests to see whether the stack is empty. It needs no parameters and returns a boolean value. O(1). ➤ size(): returns the number of items on the stack. It needs no parameters and returns an integer. O(1).
  • 6. ➤ Not a built-in type in python. We need to define it by ourselves.
  • 7. QUEUE ➤ Definition: ordered collection of items where the addition of new items happens at one end, called the “rear”, and the removal of existing items occurs at the other end, commonly called the “front”.
  • 8. ➤ Order principle: FIFO(first-in, first-out or first-come first- served).
  • 9. ➤ Queue operations: ➤ Queue(): creates a new queue that is empty. It needs no parameters and returns an empty queue. ➤ enqueue(item): adds a new item to the rear of the queue. It needs the item and returns nothing. O(1) ➤ dequeue(): removes the front item from the queue. It needs no parameters and returns the item. The queue is modified. O(1) ➤ isEmpty(): tests to see whether the queue is empty. It needs no parameters and returns a boolean value. O(1) ➤ size(): returns the number of items in the queue. It needs no parameters and returns an integer. O(1)

  • 10. ➤ Not a built-in type in python. We need to define it by ourselves.
  • 11. DEQUE ➤ Definition: ordered collection of items similar to the queue. It has two ends, a front and a rear, and the items remain positioned in the collection. ➤ Difference between queue: new items can be added at either the front or the rear. Likewise, existing items can be removed from either end. ➤ Order principle: does not require FIFO or LIFO.
  • 12. ➤ Deque operations: ➤ Deque() creates a new deque that is empty. It needs no parameters and returns an empty deque. ➤ addFront(item) adds a new item to the front of the deque. It needs the item and returns nothing. O(1) ➤ addRear(item) adds a new item to the rear of the deque. It needs the item and returns nothing. O(1) ➤ removeFront() removes the front item from the deque. It needs no parameters and returns the item. The deque is modified. O(1) ➤ removeRear() removes the rear item from the deque. It needs no parameters and returns the item. The deque is modified. O(1) ➤ isEmpty() tests to see whether the deque is empty. It needs no parameters and returns a boolean value. ➤ size() returns the number of items in the deque. It needs no parameters and returns an integer.

  • 14. HASH TABLE ……. [0] [1] [2] [3] [4] [700] 1. An array of records 2. Each record has a special field, called key. In this example, the key is a long integer field called number number: 506643548 3. The number may be a person’s identification number, and the rest of the record has information about person
  • 15. HASH TABLE Number: 281942902 Number: 233667136 Number: 506643548 ……. Number: 155778322 [0] [1] [2] [3] [4] [700] When a hash table is in use, some spots contain valid records, and other spots are empty.
  • 16. Number: 281942902 Number: 233667136 Number: 506643548 ……. Number: 155778322 [0] [1] [2] [3] [4] [700] - In order to insert a new record, the key must somehow be converted to an array index. - The index is called the hash value of the key. Number: 580625685- A typical way to create a hash value: Number mod 701 -> 580625685 mod 701 = 3
  • 17. Number: 281942902 Number: 233667136 Number: 580625685 Number: 506643548 ……. Number: 155778322 [0] [1] [2] [3] [4] [700] Number: 701466868 Hash value -> 701466868 mod 701 = 2 Collision!!! [5]
  • 18. TIME COMPLEXITY ➤ Average/best: O(1) ➤ Worst: O(n)
  • 19. HASH FUNCTION ➤ Good hash function: ➤ Return number 0, …, table size. ➤ Should be efficiently computable: O(1) ➤ Should not waste space. ➤ Should minimize collisions. ➤ The best hash function would distribute keys as evenly as possible in the hash table. ➤ Folding method: ➤ Mid square method:
  • 20. COLLISION ➤ Collision: occurs when two different keys has to the same value. ➤ Cannot store both data records in the same slot in array. ➤ Collision resolution: a systematic method for placing the second item in the hash table. ➤ Two methods: ➤ Separate Chaining: Use a dictionary data structure (such as a linked list) to store multiple items that hash to the same slot ➤ Closed Hashing (or probing/open addressing): search for empty slots using a second function and store item in first empty slot that is found. May go circularly to the start.
  • 21. HASHING WITH SEPARATE CHAINING • Put a little dictionary at each entry – common case is unordered linked list (chain)
  • 22. CLOSED HASHING/ OPEN ADDRESSING ➤ Disadvantage: ➤ Clustering: If many collisions occur at the same hash value, a number of surrounding slots will be filled by the linear probing resolution. This will have impact on other items that are being inserted. ➤ Advance: ➤ Skip slots (rehashing): (pos + skip) % hashtablesize. ➤ Quadratic probing: Instead of using a constant “skip” value, we use a rehash function that increments the hash value by 1, 3, 5, 7, 9, and so on. In other words, quadratic probing uses a skip consisting of successive perfect squares.