SlideShare a Scribd company logo
1 of 3
Download to read offline
Assignment 5 
 
 
Asterix and the Magic Potion: 
 
 
In the village of Gaul, the druid Getafix used to create the Magic Potion that used to give them 
temporary superhuman strength. But he soon got tired of it and decided to go for a pilgrimage, 
stating that he wouldn’t return. 
Now the Gauls were left with a big problem as none of them knew how to prepare the potion. 
Getafix being his moody self, decided to share the secret ingredients, but only with the worthiest 
of them. 
He provided each of them with a parchment which had a string of length N and asked them to 
“Find the list of all substrings (may be overlapping) of that string that appeared at least 
two times.” These would serve as the key to finding the ingredients of the Magic Potion. 
To make sure only the worthiest find the answer, he made sure that the writing on the paper 
would disappear if the answer was not found in O(N3
). 
The villagers think of you as Asterix and look upto you to solve their crisis. 
 
The problem requires you to build a Suffix Tree and then use it to find the answer. 
 
In a Suffix Tree, the paths from the root to the leaves contains all possible suffixes of a word. 
As an example the Suffix Tree for BOOK is shown below. 
 
 
 
 
Node Structure Of Suffix Tree: 
 
 
Each node of the tree should contain at least: 
● Node number (root is 0) 
● An array of children 
● An array of start and end positions of the substring in the string 
 
 
For example let us take the word BOOK as input 
 
B  O  O  K 
      0       1      2       3 
 
The tree will be as shown above and the node information will be as follows. 
 
 
Node 0:  
Child[0]  is Node 1 
Child[1] is Node 2 
Child[2] is  Node 3 
Start[0] is  0 and End[0] is 3  
Start[1] is  3 and End[1] is 3  
Start[2] is  1 and End[2] is 1  
 
 
Node 3: 
Child[0]  is Node 4 
Child[1] is Node 5 
Start[0] is  3 and End[0] is 3  
Start[1] is  2 and End[1] is 3  
 
 
 
Input: 
 
A string of length N 
 
 
 
 
Functions and Outputs: 
 
 
● print_suffix_intermediate_tree(i) 
Show all the paths in the Intermediate Suffix Tree, from the root to the leaves (printing 
tabs between the edges along the same path) for index i < N 
For i=3, the output should be: 
BOOK 
K 
O K 
O OK 
 
 
● print_bfs_intermediate_tree(i) 
Show BFS (Level Ordering) of the Intermediate Suffix Trees for index i < N 
For i=3, the output should be: 
0 BOOK 1 
0 K 2 
0 O 3 
3 K 4 
3 OK 5 
 
 
● print_suffix_final_tree(N) 
All the Suffixes of the Final Suffix Tree 
For the given input, the output should be: 
BOOK 
OOK 
OK 
K 
 
 
● print_final_substrings(N) 
All the substrings as mentioned in the problem 
For the input ABABAB, the output should be: 
A 
B 
AB 
BA 
ABA 
BAB 
ABAB 

More Related Content

Viewers also liked

Scott St.Clair - Technical Support
Scott St.Clair - Technical SupportScott St.Clair - Technical Support
Scott St.Clair - Technical SupportScott St.Clair
 
Microarray and its application
Microarray and its applicationMicroarray and its application
Microarray and its applicationprateek kumar
 
Línea 6 Plan de Desarrollo Antioquia la más educada
Línea 6 Plan de Desarrollo Antioquia la más educadaLínea 6 Plan de Desarrollo Antioquia la más educada
Línea 6 Plan de Desarrollo Antioquia la más educadaUrabaAntioquia
 
Materiales Locales y Normas Técnicas (Nicaragua) - Axel Martínez Nieto
Materiales Locales y Normas Técnicas (Nicaragua) - Axel Martínez NietoMateriales Locales y Normas Técnicas (Nicaragua) - Axel Martínez Nieto
Materiales Locales y Normas Técnicas (Nicaragua) - Axel Martínez NietoAxel Martínez Nieto
 
Humedad de los Agregados - Axel Martinez Nieto
Humedad de los Agregados - Axel Martinez NietoHumedad de los Agregados - Axel Martinez Nieto
Humedad de los Agregados - Axel Martinez NietoAxel Martínez Nieto
 
Diseño de mezcla de mortero en 6 pasos
Diseño de mezcla de mortero en 6 pasosDiseño de mezcla de mortero en 6 pasos
Diseño de mezcla de mortero en 6 pasosAxel Martínez Nieto
 
Applications of microarray
Applications of microarrayApplications of microarray
Applications of microarrayprateek kumar
 

Viewers also liked (8)

Tecnologías limpias
Tecnologías limpiasTecnologías limpias
Tecnologías limpias
 
Scott St.Clair - Technical Support
Scott St.Clair - Technical SupportScott St.Clair - Technical Support
Scott St.Clair - Technical Support
 
Microarray and its application
Microarray and its applicationMicroarray and its application
Microarray and its application
 
Línea 6 Plan de Desarrollo Antioquia la más educada
Línea 6 Plan de Desarrollo Antioquia la más educadaLínea 6 Plan de Desarrollo Antioquia la más educada
Línea 6 Plan de Desarrollo Antioquia la más educada
 
Materiales Locales y Normas Técnicas (Nicaragua) - Axel Martínez Nieto
Materiales Locales y Normas Técnicas (Nicaragua) - Axel Martínez NietoMateriales Locales y Normas Técnicas (Nicaragua) - Axel Martínez Nieto
Materiales Locales y Normas Técnicas (Nicaragua) - Axel Martínez Nieto
 
Humedad de los Agregados - Axel Martinez Nieto
Humedad de los Agregados - Axel Martinez NietoHumedad de los Agregados - Axel Martinez Nieto
Humedad de los Agregados - Axel Martinez Nieto
 
Diseño de mezcla de mortero en 6 pasos
Diseño de mezcla de mortero en 6 pasosDiseño de mezcla de mortero en 6 pasos
Diseño de mezcla de mortero en 6 pasos
 
Applications of microarray
Applications of microarrayApplications of microarray
Applications of microarray
 

More from Amrith Krishna

Unsupervised program synthesis
Unsupervised program synthesisUnsupervised program synthesis
Unsupervised program synthesisAmrith Krishna
 
Analyzing Stack Overflow - Problem
Analyzing Stack Overflow - ProblemAnalyzing Stack Overflow - Problem
Analyzing Stack Overflow - ProblemAmrith Krishna
 
Roller Coaster Problem - OS
Roller Coaster Problem  - OSRoller Coaster Problem  - OS
Roller Coaster Problem - OSAmrith Krishna
 
File Watcher - Lab Assignment
File Watcher - Lab AssignmentFile Watcher - Lab Assignment
File Watcher - Lab AssignmentAmrith Krishna
 
R - Eigen vector centrality with product reviews
R - Eigen vector centrality with product reviewsR - Eigen vector centrality with product reviews
R - Eigen vector centrality with product reviewsAmrith Krishna
 
Skipl List implementation - Part 2
Skipl List implementation - Part 2Skipl List implementation - Part 2
Skipl List implementation - Part 2Amrith Krishna
 
Skipl List implementation - Part 1
Skipl List implementation - Part 1Skipl List implementation - Part 1
Skipl List implementation - Part 1Amrith Krishna
 
Maach-Dal-Bhaat Problem
Maach-Dal-Bhaat ProblemMaach-Dal-Bhaat Problem
Maach-Dal-Bhaat ProblemAmrith Krishna
 
Named Entity recognition in Sanskrit
Named Entity recognition in SanskritNamed Entity recognition in Sanskrit
Named Entity recognition in SanskritAmrith Krishna
 
Astra word Segmentation
Astra word SegmentationAstra word Segmentation
Astra word SegmentationAmrith Krishna
 
Segmentation in Sanskrit texts
Segmentation in Sanskrit textsSegmentation in Sanskrit texts
Segmentation in Sanskrit textsAmrith Krishna
 

More from Amrith Krishna (16)

Unsupervised program synthesis
Unsupervised program synthesisUnsupervised program synthesis
Unsupervised program synthesis
 
Analyzing Stack Overflow - Problem
Analyzing Stack Overflow - ProblemAnalyzing Stack Overflow - Problem
Analyzing Stack Overflow - Problem
 
Roller Coaster Problem - OS
Roller Coaster Problem  - OSRoller Coaster Problem  - OS
Roller Coaster Problem - OS
 
File Watcher - Lab Assignment
File Watcher - Lab AssignmentFile Watcher - Lab Assignment
File Watcher - Lab Assignment
 
R - Eigen vector centrality with product reviews
R - Eigen vector centrality with product reviewsR - Eigen vector centrality with product reviews
R - Eigen vector centrality with product reviews
 
Skipl List implementation - Part 2
Skipl List implementation - Part 2Skipl List implementation - Part 2
Skipl List implementation - Part 2
 
Skipl List implementation - Part 1
Skipl List implementation - Part 1Skipl List implementation - Part 1
Skipl List implementation - Part 1
 
Maach-Dal-Bhaat Problem
Maach-Dal-Bhaat ProblemMaach-Dal-Bhaat Problem
Maach-Dal-Bhaat Problem
 
QGene Quiz 2016
QGene Quiz 2016QGene Quiz 2016
QGene Quiz 2016
 
Named Entity recognition in Sanskrit
Named Entity recognition in SanskritNamed Entity recognition in Sanskrit
Named Entity recognition in Sanskrit
 
Astra word Segmentation
Astra word SegmentationAstra word Segmentation
Astra word Segmentation
 
Segmentation in Sanskrit texts
Segmentation in Sanskrit textsSegmentation in Sanskrit texts
Segmentation in Sanskrit texts
 
ShutApp
ShutAppShutApp
ShutApp
 
Ferosa - Insights
Ferosa - InsightsFerosa - Insights
Ferosa - Insights
 
Taddhita Generation
Taddhita GenerationTaddhita Generation
Taddhita Generation
 
Windows Architecture
Windows ArchitectureWindows Architecture
Windows Architecture
 

Recently uploaded

Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
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
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docxPoojaSen20
 
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
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
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
 
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
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
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
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfUmakantAnnand
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
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
 

Recently uploaded (20)

Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
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
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docx
 
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
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
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
 
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
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
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 ...
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.Compdf
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
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
 

Asterix and the Maagic Potion - Suffix tree problem