SlideShare a Scribd company logo
DATA STRUCTURES AND
ANALYSIS OF ALGORITHM
Presented by: Ninh Bui L.
Professor: Alvin D.
LOGO
Contents
Define Queue1
2
3
Operation on Queue
4 Some applications of the Queue
5
Implementation of a Queue
The 8-Queen Problem
LOGO
1. Define Queues
 Queue is way of organizing the objects stored in
the form of a linear list of objects which the addition
is made in the list and get the object that is made at
the end of the list.
Queue also called type list FIFO (First In First
Out - in front before)
LOGO
1. Define Queues
Imaging
Amaging
LOGO
Operations of Queues
The Basic
Operations
B
E
C
D
A offer()
isempty()
poll()
peek()
size()
LOGO
Operations of Queues
Queue Interface Structure
Method Behavior
E peek() Returns the object at the top of the queue without
removing it. If the queue is empty, returns null.
E poll() Returns the object at the top of the queue and removes it.
If the queue is empty, returns null.
boolean offer(E obj) Appends item obj at the end of queue.
Returns true if successful false otherwise.
LOGO
Operations of Queues
Jonathan
Dustin
Robin
Debbile
Rich
Dustin
Robin
Debbile
Rich
Dustin
Robin
Debbile
Rich
Phillip
Example:
- For Queue names in Figure (a), the
Values of names.isempty() is false:
String first=names.peek();
- Remove”Jonathan” from names in
Figure (b):
String temp=names.remove();
- Add”Phillip” to the end of the Queue in
Figure (c):
Names.offer(“Phillip”);
(a)
(c)(b)
LOGO
Implementation of a Queue
 Implementation of a Queue using Linkedlist
LinkedList implements the Queue interface, so you can declare:
• Queue<String> name = new LinkedList<String>();
Class ListQueue contains a collection of Node<E> Objects
Insertions are at the rear of a queue and removals are from the front
LOGO
Implementation of a Queue
 Implementing a Queue Using a Circular Array
• Need to know the index of the front, the index of the read, the size, and
the capacity.
• Mod can be used to calculate the front and Read positions in a circular
array, therefore avoiding comparisons to the array size
The read of the queue is:
 (front + count - 1) % items.length;
 where count is the number of items currently in the queue.
 After removing an item the front of the queue is:
 (front + 1) % items.length;
LOGO
Implementation of a Queue
//Java Code
Queue<Integer> q = new
ArrayBlockingQueue(6);
q.offer(6);
0 1 2 3 4 5
6
front = 0
count = 01
insert item at (front + count) % items.length
LOGO
Implementation of a Queue
0 1 2 3 4 5
6
front = 0
4 7 3 8
count = 12345
//Java Code
Queue<Integer> q = new
ArrayBlockingQueue(6);
q.offer(6);
q.offer(4);
q.offer(7);
q.offer(3);
q.ofer(8);
LOGO
Implementation of a Queue
0 1 2 3 4 5
6
front = 0
4
make front = (0 + 1) % 6 = 1
1
7 3 8 9
count = 5434
make front = (1 + 1) % 6 = 2
2
//Java Code
Queue<Integer> q = new
ArrayBlockingQueue(6);
q.offer(6);
q.offer(4);
q.offer(7);
q.offer(3);
q.offer(8);
q.poll();//front = 1
q.poll();//front = 2
q.offer(9);
LOGO
Implementation of a Queue
//Java Code
Queue<Integer> q = new
ArrayBlockingQueue(6);
q.offer(6);
q.offer(4);
q.offer(7);
q.offer(3);
q.offer(8);
q.poll();//front = 1
q.poll();//front = 2
q.offer(9);
q.offer(5);
0 1 2 3 4 5
front = 2
7 3 8 95
count = 45
insert at (front + count) % 6
= (2 + 4) % 6 = 0
LOGO
APPLICATIONS
 The direct application
- Queue list
- Access to shared resources (Printers on the local
network)
- Most programming
 The application does not directly
- Data structure algorithms support
- How components of other data structures
LOGO8-Queen Problems
The eight queens puzzle is the problem of placing eight chess queens on
an 8 8 chessboard so that no two queens attack each other. Thus, a
solution requires that no two queens share the same row, column, or
diagonal.
LOGO
8-Queen Problems Using Back Tracking
Backtracking is a general algorithm for
finding all (or some) solutions to
some computational problem, that
incrementally builds candidates to the
solutions, and abandons each partial
candidate c ("backtracks") as soon as it
determines that c cannot possibly be
completed to a valid solution
LOGO
Step Revisited- Backtracking
1.Place the first queen in the left upper corner of the table.
2. Save the attacked positions
3. Move to the next queen(which can only be placed to the next line).
4. Search for a valid position. If there is one go to step 8.
5. There is not a valid position for the queen. Delete it ( the x
coordinate is 0).
6. Move to the previous queen.
7. Go to step 4.
8. Place it to the first valid position.
9. Save the attacked posotions.
10. If the queen processed is the last stop otherwise go to step 3.
LOGO
Algorithm
public static void Try(int j){
for (int i = 1; i<=8; i++)
{
if (a[i]&& b[i+j]&&c[i-j+7])
{
x[j] = i;
a[i] = false;
b[i+j] = false;
c[i-j+7] = false;
if(j<8) Try(j+1);
else Print(x);
a[i] = true;
b[i+j] = true;
c[i-j+7] = true;
}
LOGO
Solution
 There are 92 solutions to the 8 x 8 problem.
 Many of these are reflections and rotations of some of the
others, and if we de-duplicate against this, purists state that
there are only 12 distinct solutions (92 does not divide equally
by 12 because many of the reflections and rotations of a pure
solutions are not unique).
Queue- 8 Queen

More Related Content

What's hot

Knapsack problem using fixed tuple
Knapsack problem using fixed tupleKnapsack problem using fixed tuple
Knapsack problem using fixed tuple
Mohanlal Sukhadia University (MLSU)
 
algorithm Unit 4
algorithm Unit 4 algorithm Unit 4
algorithm Unit 4
Monika Choudhery
 
Back tracking
Back trackingBack tracking
5.5 back track
5.5 back track5.5 back track
5.5 back track
Krish_ver2
 
5.5 back tracking
5.5 back tracking5.5 back tracking
5.5 back tracking
Krish_ver2
 
Backtracking
BacktrackingBacktracking
Backtracking
Sally Salem
 
algorithm unit 1
algorithm unit 1algorithm unit 1
algorithm unit 1
Monika Choudhery
 
Q
QQ
algorithm Unit 5
algorithm Unit 5 algorithm Unit 5
algorithm Unit 5
Monika Choudhery
 
44 randomized-algorithms
44 randomized-algorithms44 randomized-algorithms
44 randomized-algorithms
AjitSaraf1
 
Back tracking and branch and bound class 20
Back tracking and branch and bound class 20Back tracking and branch and bound class 20
Back tracking and branch and bound class 20
Kumar
 
Algorithm chapter 11
Algorithm chapter 11Algorithm chapter 11
Algorithm chapter 11
chidabdu
 
algorithm Unit 2
algorithm Unit 2 algorithm Unit 2
algorithm Unit 2
Monika Choudhery
 
algorithm Unit 3
algorithm Unit 3algorithm Unit 3
algorithm Unit 3
Monika Choudhery
 
Sudoku
SudokuSudoku
Sudoku
Yara Ali
 
Branch and bound
Branch and boundBranch and bound
Branch and bound
Nv Thejaswini
 
Lec5
Lec5Lec5
Lec22
Lec22Lec22
Lec10
Lec10Lec10
Lec4
Lec4Lec4

What's hot (20)

Knapsack problem using fixed tuple
Knapsack problem using fixed tupleKnapsack problem using fixed tuple
Knapsack problem using fixed tuple
 
algorithm Unit 4
algorithm Unit 4 algorithm Unit 4
algorithm Unit 4
 
Back tracking
Back trackingBack tracking
Back tracking
 
5.5 back track
5.5 back track5.5 back track
5.5 back track
 
5.5 back tracking
5.5 back tracking5.5 back tracking
5.5 back tracking
 
Backtracking
BacktrackingBacktracking
Backtracking
 
algorithm unit 1
algorithm unit 1algorithm unit 1
algorithm unit 1
 
Q
QQ
Q
 
algorithm Unit 5
algorithm Unit 5 algorithm Unit 5
algorithm Unit 5
 
44 randomized-algorithms
44 randomized-algorithms44 randomized-algorithms
44 randomized-algorithms
 
Back tracking and branch and bound class 20
Back tracking and branch and bound class 20Back tracking and branch and bound class 20
Back tracking and branch and bound class 20
 
Algorithm chapter 11
Algorithm chapter 11Algorithm chapter 11
Algorithm chapter 11
 
algorithm Unit 2
algorithm Unit 2 algorithm Unit 2
algorithm Unit 2
 
algorithm Unit 3
algorithm Unit 3algorithm Unit 3
algorithm Unit 3
 
Sudoku
SudokuSudoku
Sudoku
 
Branch and bound
Branch and boundBranch and bound
Branch and bound
 
Lec5
Lec5Lec5
Lec5
 
Lec22
Lec22Lec22
Lec22
 
Lec10
Lec10Lec10
Lec10
 
Lec4
Lec4Lec4
Lec4
 

Similar to Queue- 8 Queen

basics of queues
basics of queuesbasics of queues
basics of queues
sirmanohar
 
Queue in Data Structure
Queue in Data StructureQueue in Data Structure
Queue in Data Structure
Muhazzab Chouhadry
 
U3.stack queue
U3.stack queueU3.stack queue
U3.stack queue
Ssankett Negi
 
LEC4-DS ALGO.pdf
LEC4-DS  ALGO.pdfLEC4-DS  ALGO.pdf
LEC4-DS ALGO.pdf
MuhammadUmerIhtisham
 
Lecture 2d queues
Lecture 2d queuesLecture 2d queues
Lecture 2d queues
Victor Palmar
 
Queue data structure
Queue data structureQueue data structure
Queue data structure
Mekk Mhmd
 
Data structure.ppt
Data structure.pptData structure.ppt
Data structure.ppt
SajalFayyaz
 
stacks and queues for public
stacks and queues for publicstacks and queues for public
stacks and queues for public
iqbalphy1
 
Queue
QueueQueue
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data Structure
Lovely Professional University
 
Queue - Data Structure - Notes
Queue - Data Structure - NotesQueue - Data Structure - Notes
Queue - Data Structure - Notes
Omprakash Chauhan
 
Queue
QueueQueue
Lecture_14Sorting.pptx
Lecture_14Sorting.pptxLecture_14Sorting.pptx
Lecture_14Sorting.pptx
jeevankjeevan
 
9 python data structure-2
9 python data structure-29 python data structure-2
9 python data structure-2
Prof. Dr. K. Adisesha
 
Unit 4 queue
Unit   4 queueUnit   4 queue
Unit 4 queue
Dabbal Singh Mahara
 
Dsoop (co 221) 1
Dsoop (co 221) 1Dsoop (co 221) 1
Dsoop (co 221) 1
Puja Koch
 
Unit – iv queue
Unit – iv    queueUnit – iv    queue
Unit – iv queue
Tribhuvan University
 
computer notes - Priority queue
computer notes -  Priority queuecomputer notes -  Priority queue
computer notes - Priority queue
ecomputernotes
 
C++ STL (quickest way to learn, even for absolute beginners).pptx
C++ STL (quickest way to learn, even for absolute beginners).pptxC++ STL (quickest way to learn, even for absolute beginners).pptx
C++ STL (quickest way to learn, even for absolute beginners).pptx
Abhishek Tirkey
 
C++ STL (quickest way to learn, even for absolute beginners).pptx
C++ STL (quickest way to learn, even for absolute beginners).pptxC++ STL (quickest way to learn, even for absolute beginners).pptx
C++ STL (quickest way to learn, even for absolute beginners).pptx
GauravPandey43518
 

Similar to Queue- 8 Queen (20)

basics of queues
basics of queuesbasics of queues
basics of queues
 
Queue in Data Structure
Queue in Data StructureQueue in Data Structure
Queue in Data Structure
 
U3.stack queue
U3.stack queueU3.stack queue
U3.stack queue
 
LEC4-DS ALGO.pdf
LEC4-DS  ALGO.pdfLEC4-DS  ALGO.pdf
LEC4-DS ALGO.pdf
 
Lecture 2d queues
Lecture 2d queuesLecture 2d queues
Lecture 2d queues
 
Queue data structure
Queue data structureQueue data structure
Queue data structure
 
Data structure.ppt
Data structure.pptData structure.ppt
Data structure.ppt
 
stacks and queues for public
stacks and queues for publicstacks and queues for public
stacks and queues for public
 
Queue
QueueQueue
Queue
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data Structure
 
Queue - Data Structure - Notes
Queue - Data Structure - NotesQueue - Data Structure - Notes
Queue - Data Structure - Notes
 
Queue
QueueQueue
Queue
 
Lecture_14Sorting.pptx
Lecture_14Sorting.pptxLecture_14Sorting.pptx
Lecture_14Sorting.pptx
 
9 python data structure-2
9 python data structure-29 python data structure-2
9 python data structure-2
 
Unit 4 queue
Unit   4 queueUnit   4 queue
Unit 4 queue
 
Dsoop (co 221) 1
Dsoop (co 221) 1Dsoop (co 221) 1
Dsoop (co 221) 1
 
Unit – iv queue
Unit – iv    queueUnit – iv    queue
Unit – iv queue
 
computer notes - Priority queue
computer notes -  Priority queuecomputer notes -  Priority queue
computer notes - Priority queue
 
C++ STL (quickest way to learn, even for absolute beginners).pptx
C++ STL (quickest way to learn, even for absolute beginners).pptxC++ STL (quickest way to learn, even for absolute beginners).pptx
C++ STL (quickest way to learn, even for absolute beginners).pptx
 
C++ STL (quickest way to learn, even for absolute beginners).pptx
C++ STL (quickest way to learn, even for absolute beginners).pptxC++ STL (quickest way to learn, even for absolute beginners).pptx
C++ STL (quickest way to learn, even for absolute beginners).pptx
 

Recently uploaded

Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems S.M.S.A.
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
Matthew Sinclair
 
Large Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial ApplicationsLarge Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial Applications
Rohit Gautam
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
KAMESHS29
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
innovationoecd
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
Matthew Sinclair
 
Data structures and Algorithms in Python.pdf
Data structures and Algorithms in Python.pdfData structures and Algorithms in Python.pdf
Data structures and Algorithms in Python.pdf
TIPNGVN2
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
Neo4j
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
名前 です男
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
Adtran
 
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Speck&Tech
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AIEnchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Vladimir Iglovikov, Ph.D.
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
Kari Kakkonen
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
DianaGray10
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
shyamraj55
 
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
Neo4j
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Malak Abu Hammad
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 

Recently uploaded (20)

Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
 
Large Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial ApplicationsLarge Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial Applications
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
 
Data structures and Algorithms in Python.pdf
Data structures and Algorithms in Python.pdfData structures and Algorithms in Python.pdf
Data structures and Algorithms in Python.pdf
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
 
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AIEnchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
 
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 

Queue- 8 Queen

  • 1. DATA STRUCTURES AND ANALYSIS OF ALGORITHM Presented by: Ninh Bui L. Professor: Alvin D.
  • 2. LOGO Contents Define Queue1 2 3 Operation on Queue 4 Some applications of the Queue 5 Implementation of a Queue The 8-Queen Problem
  • 3. LOGO 1. Define Queues  Queue is way of organizing the objects stored in the form of a linear list of objects which the addition is made in the list and get the object that is made at the end of the list. Queue also called type list FIFO (First In First Out - in front before)
  • 5. LOGO Operations of Queues The Basic Operations B E C D A offer() isempty() poll() peek() size()
  • 6. LOGO Operations of Queues Queue Interface Structure Method Behavior E peek() Returns the object at the top of the queue without removing it. If the queue is empty, returns null. E poll() Returns the object at the top of the queue and removes it. If the queue is empty, returns null. boolean offer(E obj) Appends item obj at the end of queue. Returns true if successful false otherwise.
  • 7. LOGO Operations of Queues Jonathan Dustin Robin Debbile Rich Dustin Robin Debbile Rich Dustin Robin Debbile Rich Phillip Example: - For Queue names in Figure (a), the Values of names.isempty() is false: String first=names.peek(); - Remove”Jonathan” from names in Figure (b): String temp=names.remove(); - Add”Phillip” to the end of the Queue in Figure (c): Names.offer(“Phillip”); (a) (c)(b)
  • 8. LOGO Implementation of a Queue  Implementation of a Queue using Linkedlist LinkedList implements the Queue interface, so you can declare: • Queue<String> name = new LinkedList<String>(); Class ListQueue contains a collection of Node<E> Objects Insertions are at the rear of a queue and removals are from the front
  • 9. LOGO Implementation of a Queue  Implementing a Queue Using a Circular Array • Need to know the index of the front, the index of the read, the size, and the capacity. • Mod can be used to calculate the front and Read positions in a circular array, therefore avoiding comparisons to the array size The read of the queue is:  (front + count - 1) % items.length;  where count is the number of items currently in the queue.  After removing an item the front of the queue is:  (front + 1) % items.length;
  • 10. LOGO Implementation of a Queue //Java Code Queue<Integer> q = new ArrayBlockingQueue(6); q.offer(6); 0 1 2 3 4 5 6 front = 0 count = 01 insert item at (front + count) % items.length
  • 11. LOGO Implementation of a Queue 0 1 2 3 4 5 6 front = 0 4 7 3 8 count = 12345 //Java Code Queue<Integer> q = new ArrayBlockingQueue(6); q.offer(6); q.offer(4); q.offer(7); q.offer(3); q.ofer(8);
  • 12. LOGO Implementation of a Queue 0 1 2 3 4 5 6 front = 0 4 make front = (0 + 1) % 6 = 1 1 7 3 8 9 count = 5434 make front = (1 + 1) % 6 = 2 2 //Java Code Queue<Integer> q = new ArrayBlockingQueue(6); q.offer(6); q.offer(4); q.offer(7); q.offer(3); q.offer(8); q.poll();//front = 1 q.poll();//front = 2 q.offer(9);
  • 13. LOGO Implementation of a Queue //Java Code Queue<Integer> q = new ArrayBlockingQueue(6); q.offer(6); q.offer(4); q.offer(7); q.offer(3); q.offer(8); q.poll();//front = 1 q.poll();//front = 2 q.offer(9); q.offer(5); 0 1 2 3 4 5 front = 2 7 3 8 95 count = 45 insert at (front + count) % 6 = (2 + 4) % 6 = 0
  • 14. LOGO APPLICATIONS  The direct application - Queue list - Access to shared resources (Printers on the local network) - Most programming  The application does not directly - Data structure algorithms support - How components of other data structures
  • 15. LOGO8-Queen Problems The eight queens puzzle is the problem of placing eight chess queens on an 8 8 chessboard so that no two queens attack each other. Thus, a solution requires that no two queens share the same row, column, or diagonal.
  • 16. LOGO 8-Queen Problems Using Back Tracking Backtracking is a general algorithm for finding all (or some) solutions to some computational problem, that incrementally builds candidates to the solutions, and abandons each partial candidate c ("backtracks") as soon as it determines that c cannot possibly be completed to a valid solution
  • 17. LOGO Step Revisited- Backtracking 1.Place the first queen in the left upper corner of the table. 2. Save the attacked positions 3. Move to the next queen(which can only be placed to the next line). 4. Search for a valid position. If there is one go to step 8. 5. There is not a valid position for the queen. Delete it ( the x coordinate is 0). 6. Move to the previous queen. 7. Go to step 4. 8. Place it to the first valid position. 9. Save the attacked posotions. 10. If the queen processed is the last stop otherwise go to step 3.
  • 18. LOGO Algorithm public static void Try(int j){ for (int i = 1; i<=8; i++) { if (a[i]&& b[i+j]&&c[i-j+7]) { x[j] = i; a[i] = false; b[i+j] = false; c[i-j+7] = false; if(j<8) Try(j+1); else Print(x); a[i] = true; b[i+j] = true; c[i-j+7] = true; }
  • 19. LOGO Solution  There are 92 solutions to the 8 x 8 problem.  Many of these are reflections and rotations of some of the others, and if we de-duplicate against this, purists state that there are only 12 distinct solutions (92 does not divide equally by 12 because many of the reflections and rotations of a pure solutions are not unique).