SlideShare uma empresa Scribd logo
1 de 20
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

Mais conteúdo relacionado

Mais procurados (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
 

Semelhante a Queue- 8 Queen

Semelhante a 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
 

Último

Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityWSO2
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistandanishmna97
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Victor Rentea
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelDeepika Singh
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxRemote DBA Services
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Victor Rentea
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Zilliz
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 

Último (20)

Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 

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).