Palindromes and Anagrams Algorithm Implementation in Python

Verified

Added on  2025/04/30

|13
|796
|349
AI Summary
Desklib provides past papers and solved assignments for students. This project focuses on palindrome and anagram detection in Python.
Document Page
ITECH1400 Fundamentals of
Programming
Assignment 1 – Palindromes and
Anagrams
1
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
Table of Contents
Introduction......................................................................................................................................3
Algorithm in pseudo-code...............................................................................................................4
Palindrome...................................................................................................................................4
Angrams.......................................................................................................................................4
Implementation of algorithm in code..............................................................................................5
Palindrome...................................................................................................................................5
Correct Output and Discussion........................................................................................................9
Conclusion.....................................................................................................................................11
References......................................................................................................................................12
Table of figures
Figure 1: Palindrome.......................................................................................................................5
Figure 2: Anagrams 1......................................................................................................................6
Figure 3: Anagrams 2......................................................................................................................7
Figure 4: Palindrome result...........................................................................................................10
Figure 5: Anagrams result.............................................................................................................11
Table of tables
Table 1: test table.............................................................................................................................8
Table 2: Palindrome output table...................................................................................................10
Table 3: Anagram output table......................................................................................................11
2
Document Page
Introduction
In this scenario python programming will be used to develop or solve two algorithms named
palindrome and anagrams. The working of both algorithm will be present in the given scenario.
Python 3.6 will be used for compiling the result (Gries, et al., 2017). This scenario use pycharm
text editor or IDE for coding purpose (Zheng, et al., 2017). After completing this scenario one is
able to easily develop algorithms in python.
3
Document Page
Algorithm in pseudo-code
Palindrome
Start
Open file English.txt in read mode
Print: palindrome strings are:
For l in text:
Reverse the string and store it in l1:
If (l=l1):
Then
Print: l
end
Angrams
Start
Store string s
Convert s into lower
Break string into character list
Sort the list
Open English.txt in read mode
For line in text1:
Convert line into lower
Break line into character list
Sort list
If(s!=line):
Then
If(ns=listLine):
4
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
Print: line
end
Implementation of algorithm in code
Palindrome
Figure 1: Palindrome
In this figure code of palindrome file is shown.
5
Document Page
Figure 2: Anagrams 1
6
Document Page
Figure 3: Anagrams 2
Above figures depicts the code used to develop the anagrams from the given txt file.
7
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
Demonstration that code works correctly using representative samples
Code is tested against the input files so that developer make sure the code works properly. As
testing is the most important part of the development because it is used to debug the program
correctly. Testing involves running the code and analyze the output according to the requirement.
Table 1: test table
Sr No. Objective Expected Result Actual Result Pass/Fail
1. Searching of the
palindrome result
must be very
precise. So that it
gives all the
output very
properly.
All the results
will be shown
when program
runs.
The result is
shown as
expected.
Pass
2. Anagrams must
be found of
every value in
the file.
Every string
anagram has
been found out.
Actual result is
according to the
expectation.
Pass
3. Same string is
not counted in
anagrams.
The result of
anagrams will
not show the
same string.
Result as
expected.
Pass
4. Do not run if
program not
found text file.
Throws an error
message.
Result as
expected.
Pass
5. Execution time. The time taken
by the program
must not be very
large.
Program take lots
of time to
complete its
execution.
Fail
6. Space
complexity.
Program should
required as
minimum space
as possible.
Works according
to the result
expected.
Pass
7. Null character
and spaces.
Null character
and spaces are
removed before
the execution of
the program.
Program
successfully runs
on our
expectations.
Pass
8. Result must be
error free
Result must not
contain same
strings in
anagram search.
In anagrams
same string was
not counted.
Pass
9. All the
palindrome
strings must
All palindrome
strings included
in the result.
As expected Pass
8
Document Page
included in the
result.
10. Anagram of
every string is
founded.
Every string runs
a search of its
anagram.
Result is obtain
according to our
expectation.
Pass
9
Document Page
Correct Output and Discussion
Figure 4: Palindrome result
The above figure depicts the output screen of the palindrome program. The palindrome strings
are finding out from the string.
Table 2: Palindrome output table
Word Is a palindrome Actual output Comment
AAA true True True
C true True True
A.B. false false True
B.A.B. true true True
B\B true true True
CAMAC true true true
10
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
Figure 5: Anagrams result
In this figure anagrams result is shown where every string is compared with every other string in
the txt file.
Table 3: Anagram output table
Word Anagram Actual output Comment
AAE AEA True True
AAU AUA True True
abaissed diabase True True
A&M -- true True
abac cabaa False True
11
Document Page
Conclusion
After completing above scenario one is learn to program in python. As the IDE pyCharm is used
in this scenario the programming finds very easy. Hints provided by the IDE is very useful. In
this scenario two algorithms were solved in python programming language. Python 3.6 is used as
a compiling agent in this scenario. Logics of user will e increased after completing this scenario.
12
chevron_up_icon
1 out of 13
circle_padding
hide_on_mobile
zoom_out_icon
[object Object]