SlideShare a Scribd company logo
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

PPTX
Tuesday 7th July 2020
PDF
Camp Half Blood: Trivia
PPTX
St Vincent de Paul Y5 Home Learning W1 6.1.21
PPTX
Stoy telling the cat in the hat
PPTX
Portafolios electronicos
PDF
PDF
Tutorial slideshare
PPTX
Announcing ACEO Forums
Tuesday 7th July 2020
Camp Half Blood: Trivia
St Vincent de Paul Y5 Home Learning W1 6.1.21
Stoy telling the cat in the hat
Portafolios electronicos
Tutorial slideshare
Announcing ACEO Forums

Viewers also liked (8)

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

More from Amrith Krishna (16)

PDF
Unsupervised program synthesis
PDF
Analyzing Stack Overflow - Problem
PDF
Roller Coaster Problem - OS
PDF
File Watcher - Lab Assignment
PDF
R - Eigen vector centrality with product reviews
PDF
Skipl List implementation - Part 2
PDF
Skipl List implementation - Part 1
PDF
Maach-Dal-Bhaat Problem
PDF
QGene Quiz 2016
PDF
Named Entity recognition in Sanskrit
PDF
Astra word Segmentation
PDF
Segmentation in Sanskrit texts
PDF
PDF
Ferosa - Insights
PDF
Taddhita Generation
PPT
Windows Architecture
Unsupervised program synthesis
Analyzing Stack Overflow - Problem
Roller Coaster Problem - OS
File Watcher - Lab Assignment
R - Eigen vector centrality with product reviews
Skipl List implementation - Part 2
Skipl List implementation - Part 1
Maach-Dal-Bhaat Problem
QGene Quiz 2016
Named Entity recognition in Sanskrit
Astra word Segmentation
Segmentation in Sanskrit texts
Ferosa - Insights
Taddhita Generation
Windows Architecture
Ad

Recently uploaded (20)

PDF
LDMMIA Reiki Yoga Finals Review Spring Summer
PPTX
Introduction to Building Materials
PPTX
UNIT III MENTAL HEALTH NURSING ASSESSMENT
PDF
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
PDF
Weekly quiz Compilation Jan -July 25.pdf
PPTX
History, Philosophy and sociology of education (1).pptx
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
Complications of Minimal Access Surgery at WLH
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
Hazard Identification & Risk Assessment .pdf
PPTX
Orientation - ARALprogram of Deped to the Parents.pptx
PDF
RMMM.pdf make it easy to upload and study
PDF
Classroom Observation Tools for Teachers
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PDF
What if we spent less time fighting change, and more time building what’s rig...
PPTX
Cell Types and Its function , kingdom of life
PDF
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
PPTX
Lesson notes of climatology university.
PPTX
Chinmaya Tiranga Azadi Quiz (Class 7-8 )
PDF
Trump Administration's workforce development strategy
LDMMIA Reiki Yoga Finals Review Spring Summer
Introduction to Building Materials
UNIT III MENTAL HEALTH NURSING ASSESSMENT
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
Weekly quiz Compilation Jan -July 25.pdf
History, Philosophy and sociology of education (1).pptx
Supply Chain Operations Speaking Notes -ICLT Program
Complications of Minimal Access Surgery at WLH
Final Presentation General Medicine 03-08-2024.pptx
Hazard Identification & Risk Assessment .pdf
Orientation - ARALprogram of Deped to the Parents.pptx
RMMM.pdf make it easy to upload and study
Classroom Observation Tools for Teachers
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
What if we spent less time fighting change, and more time building what’s rig...
Cell Types and Its function , kingdom of life
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
Lesson notes of climatology university.
Chinmaya Tiranga Azadi Quiz (Class 7-8 )
Trump Administration's workforce development strategy

Asterix and the Maagic Potion - Suffix tree problem