SlideShare a Scribd company logo
1 of 3
Assignment No 01
Submitted By: Sunawar Khan
Reg No: 813/FBAS/MSCS/F14
Topic:JohnsonTrotterAlgorithm(Permutations)
Submitted To: Dr. R. Aewan
Subject: Advance Algorithm Analysis
Date: 5 October,2015
Department: ComputerScience
International Islamicuniversityislamabad
Algorithm:
//input: the numbernwhose permutationare tobe obtained.
//output:permutationof numbers“n”
 Initializethe firstpermutation with 1L
2L
3L
4L
 While (there existamobile number K) do{
 Findthe largestmobile numberk
 Swapmobile integerkandthe adjacentnumberitsarrow point
 Reverse the directionof all integersthatare the largestthenK
 }
Problem:obtainall possible permutationsusingJohnsonTrotterAlgorithmforn=4
Solution:Asn=4 we will consideraset{1,2, 3, 4} forgenerationpermutation
1:- 1L
2L
3L
4L
Initially4,arrowof 4 pointto 3, exchange 4 with3
2:- 1L
2L
4L
3L
Exchange 2 & 4
3:- 1L
4L
2L
3L
Exchange 4 & 1
4:- 4L
1L
2L
3L
4 isno longermobile asitison the left mostcolumn pointingtothe left.Swap3 & 2 and
change 4’s direction.
5:- 4R
1L
3L
2L
Exchange 4 & 1
6:- 1L
4R
3L
2L
Exchange 4 & 3
7:- 1L
3L
4R
2L
Exchange 4 & 2
8:- 1L
3L
2L
4R
4 isno longermobile asitison the rightmostcolumnpendingtothe right.Swap3 & 4.
Change 4’s direction.
9:- 3L
1L
2L
4L
Exchange 2 & 4
0:- 3L
1L
4L
2L
Exchange 1 & 4
1:- 3L
4L
1L
2L
Exchange 3 & 4
2:- 4L
3L
1L
2L
4 isno longermobile asitison the leftmostcolumnpointingtoleft.3isno longer
mobile nowasthere isno numbersmallerthenitself onitsdirection.Swap 2 & 1.
Change 4 and3 direction.
3:- 4R
3R
2L
1L
Exchange 4 & 3
4:- 3R
4R
2L
1L
Exchange 4 & 2
5:- 3R
2L
4R
1L
Exchange 4 & 1
6:- 3R
2L
1L
4R
4 isno longermobile astoitson the rightmostcolumnpointingtothe right.Swap3 & 2.
Change 4’s direction.
7:- 2L
3R
1L
4L
Exchange 4 & 1
8:- 2L
3R
4L
1L
Exchange 4 & 3
9:- 2L
4R
3R
1L
Exchange 4 & 2
0:- 4L
2L
3R
1L
4 isno longermobile asitison the leftmostcolumnpointingtothe left.Swap3& 1. And
change 4’s direction.
1:- 4R
2L
1L
3R
Exchange 4 & 2
2:- 2L
4R
1L
3R
Exchange 4 & 1
3:- 2L
1L
4R
3R
4:- 2L
1L
3R
4R
No mobile numberare more.
Total Permutations:- 4 != 24

More Related Content

What's hot

Arc Length, Curvature and Torsion
Arc Length, Curvature and TorsionArc Length, Curvature and Torsion
Arc Length, Curvature and Torsionvaani pathak
 
Intuitive Intro to Gödel's Incompleteness Theorem
Intuitive Intro to Gödel's Incompleteness TheoremIntuitive Intro to Gödel's Incompleteness Theorem
Intuitive Intro to Gödel's Incompleteness TheoremIlya Kuzovkin
 
Fundamental theorem of arithmatic
Fundamental theorem of arithmaticFundamental theorem of arithmatic
Fundamental theorem of arithmaticSubhrajeet Praharaj
 
5.5 Injective and surjective functions. Dynamic slides.
5.5 Injective and surjective functions. Dynamic slides.5.5 Injective and surjective functions. Dynamic slides.
5.5 Injective and surjective functions. Dynamic slides.Jan Plaza
 
Logarithm
LogarithmLogarithm
Logarithmitutor
 
3.7 Inverse Functions
3.7 Inverse Functions3.7 Inverse Functions
3.7 Inverse Functionssmiller5
 
The Moore-Spiegel Oscillator
The Moore-Spiegel OscillatorThe Moore-Spiegel Oscillator
The Moore-Spiegel OscillatorAbhranil Das
 
fourier series
fourier seriesfourier series
fourier series8laddu8
 
Math induction principle (slides)
Math induction principle (slides)Math induction principle (slides)
Math induction principle (slides)IIUM
 
Computational logic Propositional Calculus proof system
Computational logic Propositional Calculus proof system Computational logic Propositional Calculus proof system
Computational logic Propositional Calculus proof system banujahir1
 
Real life use of probability.
Real life use of probability.Real life use of probability.
Real life use of probability.Sahil Patel
 

What's hot (20)

Arc Length, Curvature and Torsion
Arc Length, Curvature and TorsionArc Length, Curvature and Torsion
Arc Length, Curvature and Torsion
 
Intuitive Intro to Gödel's Incompleteness Theorem
Intuitive Intro to Gödel's Incompleteness TheoremIntuitive Intro to Gödel's Incompleteness Theorem
Intuitive Intro to Gödel's Incompleteness Theorem
 
Fundamental theorem of arithmatic
Fundamental theorem of arithmaticFundamental theorem of arithmatic
Fundamental theorem of arithmatic
 
5.5 Injective and surjective functions. Dynamic slides.
5.5 Injective and surjective functions. Dynamic slides.5.5 Injective and surjective functions. Dynamic slides.
5.5 Injective and surjective functions. Dynamic slides.
 
Author Topic Model
Author Topic ModelAuthor Topic Model
Author Topic Model
 
Logarithm
LogarithmLogarithm
Logarithm
 
3.7 Inverse Functions
3.7 Inverse Functions3.7 Inverse Functions
3.7 Inverse Functions
 
Limits of functions
Limits of functionsLimits of functions
Limits of functions
 
Ring homomorphism
Ring homomorphismRing homomorphism
Ring homomorphism
 
The Moore-Spiegel Oscillator
The Moore-Spiegel OscillatorThe Moore-Spiegel Oscillator
The Moore-Spiegel Oscillator
 
Topology M.Sc. 2 semester Mathematics compactness, unit - 4
Topology M.Sc. 2 semester Mathematics compactness, unit - 4Topology M.Sc. 2 semester Mathematics compactness, unit - 4
Topology M.Sc. 2 semester Mathematics compactness, unit - 4
 
CONVERGENCE.ppt
CONVERGENCE.pptCONVERGENCE.ppt
CONVERGENCE.ppt
 
Chapter 17 - Multivariable Calculus
Chapter 17 - Multivariable CalculusChapter 17 - Multivariable Calculus
Chapter 17 - Multivariable Calculus
 
fourier series
fourier seriesfourier series
fourier series
 
Math induction principle (slides)
Math induction principle (slides)Math induction principle (slides)
Math induction principle (slides)
 
Fourier series
Fourier seriesFourier series
Fourier series
 
Counting
Counting  Counting
Counting
 
Limit of functions
Limit of functionsLimit of functions
Limit of functions
 
Computational logic Propositional Calculus proof system
Computational logic Propositional Calculus proof system Computational logic Propositional Calculus proof system
Computational logic Propositional Calculus proof system
 
Real life use of probability.
Real life use of probability.Real life use of probability.
Real life use of probability.
 

Viewers also liked

Capa de Enlace - Redes de Computadoras
Capa de Enlace - Redes de ComputadorasCapa de Enlace - Redes de Computadoras
Capa de Enlace - Redes de ComputadorasJesus Jimenez
 
Presentacion informatica
Presentacion informaticaPresentacion informatica
Presentacion informaticaanggie1003
 
Riesgos de la información electrónica
Riesgos de la información electrónicaRiesgos de la información electrónica
Riesgos de la información electrónicaEdgar Rojas
 
Site Manager - Mohamed Aly ElSharkawy
Site Manager - Mohamed Aly ElSharkawySite Manager - Mohamed Aly ElSharkawy
Site Manager - Mohamed Aly ElSharkawymohamed elsharkawy
 
Migración plataformas
Migración plataformasMigración plataformas
Migración plataformasmoika_usagi
 
International Telecommunications Society Conference - Dr. Andy Banerjee
International Telecommunications Society Conference - Dr. Andy BanerjeeInternational Telecommunications Society Conference - Dr. Andy Banerjee
International Telecommunications Society Conference - Dr. Andy BanerjeeSSRS Market Research
 
Teaching Holocaust and Genocide: An Interdisciplinary Approach
Teaching Holocaust and Genocide: An Interdisciplinary ApproachTeaching Holocaust and Genocide: An Interdisciplinary Approach
Teaching Holocaust and Genocide: An Interdisciplinary Approachtimothyhensley
 
Indian patent act 1970
Indian patent act 1970Indian patent act 1970
Indian patent act 1970Akashwani
 
Watson and Analytics
Watson and AnalyticsWatson and Analytics
Watson and AnalyticsJorge W. Hago
 
IBM Watson Analytics - Sales Prediction
IBM Watson Analytics - Sales Prediction IBM Watson Analytics - Sales Prediction
IBM Watson Analytics - Sales Prediction Pragyan Sharma
 
Hakikat Hak Dan Kewajiban Warga Negara
Hakikat Hak Dan Kewajiban Warga NegaraHakikat Hak Dan Kewajiban Warga Negara
Hakikat Hak Dan Kewajiban Warga NegaraR HF Fakhirin
 

Viewers also liked (16)

Cinco de May 2016
Cinco de May 2016Cinco de May 2016
Cinco de May 2016
 
Capa de Enlace - Redes de Computadoras
Capa de Enlace - Redes de ComputadorasCapa de Enlace - Redes de Computadoras
Capa de Enlace - Redes de Computadoras
 
Game of Thrones
Game of ThronesGame of Thrones
Game of Thrones
 
Presentacion informatica
Presentacion informaticaPresentacion informatica
Presentacion informatica
 
Aidah sabila
Aidah sabila Aidah sabila
Aidah sabila
 
Riesgos de la información electrónica
Riesgos de la información electrónicaRiesgos de la información electrónica
Riesgos de la información electrónica
 
National Karaoke Week
National Karaoke WeekNational Karaoke Week
National Karaoke Week
 
Site Manager - Mohamed Aly ElSharkawy
Site Manager - Mohamed Aly ElSharkawySite Manager - Mohamed Aly ElSharkawy
Site Manager - Mohamed Aly ElSharkawy
 
Achillies Tendon Injuries
Achillies Tendon InjuriesAchillies Tendon Injuries
Achillies Tendon Injuries
 
Migración plataformas
Migración plataformasMigración plataformas
Migración plataformas
 
International Telecommunications Society Conference - Dr. Andy Banerjee
International Telecommunications Society Conference - Dr. Andy BanerjeeInternational Telecommunications Society Conference - Dr. Andy Banerjee
International Telecommunications Society Conference - Dr. Andy Banerjee
 
Teaching Holocaust and Genocide: An Interdisciplinary Approach
Teaching Holocaust and Genocide: An Interdisciplinary ApproachTeaching Holocaust and Genocide: An Interdisciplinary Approach
Teaching Holocaust and Genocide: An Interdisciplinary Approach
 
Indian patent act 1970
Indian patent act 1970Indian patent act 1970
Indian patent act 1970
 
Watson and Analytics
Watson and AnalyticsWatson and Analytics
Watson and Analytics
 
IBM Watson Analytics - Sales Prediction
IBM Watson Analytics - Sales Prediction IBM Watson Analytics - Sales Prediction
IBM Watson Analytics - Sales Prediction
 
Hakikat Hak Dan Kewajiban Warga Negara
Hakikat Hak Dan Kewajiban Warga NegaraHakikat Hak Dan Kewajiban Warga Negara
Hakikat Hak Dan Kewajiban Warga Negara
 

More from International Islamic University (20)

Hash tables
Hash tablesHash tables
Hash tables
 
Binary Search Tree
Binary Search TreeBinary Search Tree
Binary Search Tree
 
Graph 1
Graph 1Graph 1
Graph 1
 
Graph 2
Graph 2Graph 2
Graph 2
 
Graph 3
Graph 3Graph 3
Graph 3
 
Greedy algorithm
Greedy algorithmGreedy algorithm
Greedy algorithm
 
Dynamic programming
Dynamic programmingDynamic programming
Dynamic programming
 
Quick sort
Quick sortQuick sort
Quick sort
 
Merge sort
Merge sortMerge sort
Merge sort
 
Linear timesorting
Linear timesortingLinear timesorting
Linear timesorting
 
Facial Expression Recognitino
Facial Expression RecognitinoFacial Expression Recognitino
Facial Expression Recognitino
 
Lecture#4
Lecture#4Lecture#4
Lecture#4
 
Lecture#3
Lecture#3 Lecture#3
Lecture#3
 
Lecture#2
Lecture#2 Lecture#2
Lecture#2
 
Case study
Case studyCase study
Case study
 
Arrays
ArraysArrays
Arrays
 
Pcb
PcbPcb
Pcb
 
Data transmission
Data transmissionData transmission
Data transmission
 
Basic organization of computer
Basic organization of computerBasic organization of computer
Basic organization of computer
 
Sorting techniques
Sorting techniquesSorting techniques
Sorting techniques
 

Recently uploaded

psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docxPoojaSen20
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxVishalSingh1417
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Shubhangi Sonawane
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin ClassesCeline George
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfSanaAli374401
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterMateoGardella
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxnegromaestrong
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.MateoGardella
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingTeacherCyreneCayanan
 

Recently uploaded (20)

psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdf
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch Letter
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 

Johnson Trotter Algorithm(Permutation)

  • 1. Assignment No 01 Submitted By: Sunawar Khan Reg No: 813/FBAS/MSCS/F14 Topic:JohnsonTrotterAlgorithm(Permutations) Submitted To: Dr. R. Aewan Subject: Advance Algorithm Analysis Date: 5 October,2015 Department: ComputerScience International Islamicuniversityislamabad
  • 2. Algorithm: //input: the numbernwhose permutationare tobe obtained. //output:permutationof numbers“n”  Initializethe firstpermutation with 1L 2L 3L 4L  While (there existamobile number K) do{  Findthe largestmobile numberk  Swapmobile integerkandthe adjacentnumberitsarrow point  Reverse the directionof all integersthatare the largestthenK  } Problem:obtainall possible permutationsusingJohnsonTrotterAlgorithmforn=4 Solution:Asn=4 we will consideraset{1,2, 3, 4} forgenerationpermutation 1:- 1L 2L 3L 4L Initially4,arrowof 4 pointto 3, exchange 4 with3 2:- 1L 2L 4L 3L Exchange 2 & 4 3:- 1L 4L 2L 3L Exchange 4 & 1 4:- 4L 1L 2L 3L 4 isno longermobile asitison the left mostcolumn pointingtothe left.Swap3 & 2 and change 4’s direction. 5:- 4R 1L 3L 2L Exchange 4 & 1 6:- 1L 4R 3L 2L Exchange 4 & 3 7:- 1L 3L 4R 2L Exchange 4 & 2 8:- 1L 3L 2L 4R 4 isno longermobile asitison the rightmostcolumnpendingtothe right.Swap3 & 4. Change 4’s direction. 9:- 3L 1L 2L 4L Exchange 2 & 4 0:- 3L 1L 4L 2L Exchange 1 & 4 1:- 3L 4L 1L 2L Exchange 3 & 4
  • 3. 2:- 4L 3L 1L 2L 4 isno longermobile asitison the leftmostcolumnpointingtoleft.3isno longer mobile nowasthere isno numbersmallerthenitself onitsdirection.Swap 2 & 1. Change 4 and3 direction. 3:- 4R 3R 2L 1L Exchange 4 & 3 4:- 3R 4R 2L 1L Exchange 4 & 2 5:- 3R 2L 4R 1L Exchange 4 & 1 6:- 3R 2L 1L 4R 4 isno longermobile astoitson the rightmostcolumnpointingtothe right.Swap3 & 2. Change 4’s direction. 7:- 2L 3R 1L 4L Exchange 4 & 1 8:- 2L 3R 4L 1L Exchange 4 & 3 9:- 2L 4R 3R 1L Exchange 4 & 2 0:- 4L 2L 3R 1L 4 isno longermobile asitison the leftmostcolumnpointingtothe left.Swap3& 1. And change 4’s direction. 1:- 4R 2L 1L 3R Exchange 4 & 2 2:- 2L 4R 1L 3R Exchange 4 & 1 3:- 2L 1L 4R 3R 4:- 2L 1L 3R 4R No mobile numberare more. Total Permutations:- 4 != 24