You are on page 1of 16

Koneru Lakshmaiah Education Foundation

(Deemed to be University)

FRESHMAN ENGINEERING DEPARTMENT


A Project Based Lab Report

On

ANAGRAM SEARCH

SUBMITTED BY:

I.D NUMBER NAME

2200031930 G.CHANDRA TEJA

<IDNO><NAME>

<IDNO><NAME>

<IDNO><NAME>

UNDER THE GUIDANCE OF

T.GANESAN

Assist.prof CSE

KL UNIVERSITY
Green fields, Vaddeswaram – 522 302
Guntur Dt., AP, India.
DEPARTMENT OF BASIC ENGINEERING SCIENCES-1

CERTIFICATE

This is to certify that the project based laboratory report entitled


“Anagram search” submitted by Mr. G.CHANDRA TEJA bearing Regd. No.
2200031930 to the Department of Basic Engineering Sciences-1, KL
University in partial fulfillment of the requirements for the completion of a
project based Laboratory in “COMPUTATIONAL THINKING FOR STRUCTURED
DESIGN”course in I B Tech I Semester, is a bonafide record of the work carried
out by him/her under my supervision during the academic year 2022 – 2023.

PROJECT SUPERVISOR HEAD OF THE DEPARTMENT

T.GANESAN Dr.D.Haritha
ACKNOWLEDGEMENTS

It is great pleasure for me to express my gratitude to our honorable


President Sri. Koneru Satyanarayana, for giving the opportunity and platform
with facilities in accomplishing the project based laboratory report.

I express the sincere gratitude to our principal Dr. A. Jagadeesh for his
administration towards our academic growth.

I express sincere gratitude to HOD-BES-1 Dr. D. Haritha for her leadership


and constant motivation provided in successful completion of our academic
semester. I record it as my privilege to deeply thank for providing us the efficient
faculty and facilities to make our ideas into reality.

I express my sincere thanks to our project supervisor T.GANESAN for


his/her novel association of ideas, encouragement, appreciation and intellectual
zeal which motivated us to venture this project successfully.

Finally, it is pleased to acknowledge the indebtedness to all those who


devoted themselves directly or indirectly to make this project report success.

Project Associates …
ABSTRACT
C program to check whether two strings are anagrams or not, a string is assumed to consist
of lower-case alphabets only. Two words are said to be anagrams of each other if the letters
of one word can be rearranged to form the other word. So, in anagram strings, all characters
occur the same number of times.

A string t is called an anagram of the string s, if it is possible to rearrange letters in t so


that it is identical to the string s. For example, the string "aab" is an anagram of the string
"aba" and the string "aaa" is not.

The string t is called a substring of the string s if it can be read starting from some
position in the string s. For example, the string "aba" has six substrings: "a", "b", "a", "ab",
"ba", "aba".

You are given a string s, consisting of lowercase Latin letters and characters "?". You are
also given a string p, consisting of lowercase Latin letters only. Let's assume that a string is
good if you can obtain an anagram of the string p from it, replacing the "?" characters by
Latin letters. Each "?" can be replaced by exactly one character of the Latin alphabet. For
example, if the string p = «aba», then the string "a??" is good, and the string «?bc» is not.
INDEX

S.NO TITLE PAGE NO

1 Introduction 6

2 Aim of the Project 8

2.1 Advantages & Disadvantages 9

2.2 Future Implementation 9

3 Software & Hardware Details 10

4 Algorithm 11

5 Flowchart 12

6 Implementation 13

7 Results and Screenshots 15

8 Conclusion 16

INTRODUCTION
Data type declaration
In the C programming language, data types constitute the semantics and
characteristics of storage of data elements. They are expressed in the language
syntax as declarations for memory locations or variables. Data types also determine
the types of operations or methods of processing of data elements.
The C language provides basic arithmetic types, such as integer and real number
types, and syntax to build array and compound types. Several headers in the C
standard library contain definitions of support types, that have additional properties,
such as providing storage with an exact size, independent of the implementation

Strings
Strings are defined as an array of characters. The difference between a character

array and a string is the string is terminated with a special character ‘\0’.

Declaration of strings
Declaring a string is as simple as declaring a one dimensional array. Below is the
basic syntax for declaring a string.

char str_name[size];

In the above syntax str_name is any name given to the string variable and size is

used define the length of the string, i.e the number of characters strings will store.
Please keep in mind that there is an extra terminating character which is the Null
character (‘\0’) used to indicate termination of string which differs strings from
normal character arrays.

Hashing
Hashing is an important Data Structure which is designed to use a special function
Called the Hash function which is used to map a given value with a particular key
For faster access of elements. The efficiency of mapping depends on the efficiency
Of the hash function used.
Let a hash function H(x) maps the value at the index x%10 in an Array . For example
If the list of values is [11,12,13,14,15] it will be stored at positions {1,2,3,4,5} in the
Array or Hash Table respectively

For loop
A for loop is a repetition control structure that allows you to efficiently write a loop

That need to execute a specific number of times

Syntax
The syntax of a for loop in C programming language is –

For(int i ; condition ; increment)

{
statements(s);

Anagram
An anagram is a word or phrase formed by rearranging the letters of a different
word or phrase, typically using all the original letters exactly once. [1] For example,
the word anagram can be rearranged into nag a ram, or the word binary into brainy
or the word adobe into abode.
The original word or phrase is known as the subject of the anagram. Any word or
phrase that exactly reproduces the letters in another order is an anagram.
Someone who creates anagrams may be called an "anagrammatist", and the goal of
a serious or skilled anagrammatist is to produce anagrams that reflect or comment
on their subject.

AIM

Your task is to find the number of good substrings of the string s (identical substrings
must be counted in the answer several times).

Input
The first line is non-empty string s, consisting of no more than 105 lowercase Latin letters
and characters "?". The second line is non-empty string p, consisting of no more than 105
lowercase Latin letters. Please note that the length of the string p can exceed the length of
the string s.

Output
Print the single number representing the number of good substrings of string s.

Two substrings are considered different in their positions of occurrence are different. Thus,
if some string occurs several times, then it should be counted the same number of times.

Advantages:- C string are very fast in processing because it stored in array and we utilize
array indexing to accessing part of string or whole.

Disadvantages:- Because C string does not contain length itself and use NUL character
as marker to indicate end of string and sometimes string handling make more trouble
(accessing part of memory which are not part of memory or NUL is not inserted at end of
string etc). Some string library (string.h,strings.h) have dangerous function which continue
without checking buffer size until new line(\n) not found and overwrites other memory area
(e.g. gets(),strcpy(),strlen() all work based on NUL character not size of string) . C string are
mutable hence its not thread safe.

Future enhancements:-
In future there may be new techniques will be invented to solve anagrams in low time
complexity. While anagramming is certainly a recreation first, there are ways in which
anagrams are put to use, and these can be more serious, or at least not quite frivolous and
formless. r this new techniques may be implemented there are many languages for
programming so that small and good program may be created for anagram searching

SYSTEM REQUIREMENTS

 SOFTWARE REQUIREMENTS:
The major software requirements of the project are as follows:
Language : Turbo-C
Operating system:Windows Xp or later.

 HARDWARE REQUIREMENTS:
The hardware requirements that map towards the software are as follows:

RAM : 2GB OR 2GB Plus

Processor : Intel® Pentium® or compatible, 1.6 GHz minimum (2GHz+


recommended)

ALGORITHM
Step 1- Start
step 2- Read string s and a.
step 3-Put string length of s and a in int k and respectively step
4- Declare int b[127],c,diff step 4-If i<127
step 4.1- do b[i]=0,c[i]=0 then i++ then back to step 4. Step
4.2- else i=0,then if i<1
step 4.2.1- do c then i++
step 4.2.2- else do i=0 then go to
step 5- Check if i<=k-1
step 5.1- do diff=0, j=0, g=0 then
step 5.1.1-check if g<127
step 5.1.2- do b{g}=0 then g++ then go back to 5.1.1
step 5.1.3- else do d=i step 5.1.4- check ifd<i+1
Do d++ then go to 5.1.4
Else i++ and go to step 5

Step 5.2- else do d++

Step 5.2.1- check if s[d]==’?’Do diff++ then go to 5.2.2

Step 5.2.2- else count=0

Step 6- z=97

Step 6.1- check if z<=122

Step 6.1.1- if true then check b[z]==c[z]

Do count = count+b then go to step 6.1.2

Step 6.1.2- else z++ then go to step 6.1

Step 6.2- if z>122 then check count==l||count+diff<=l

Step 6.2.1- do same++ then go to 6.2.2

Step 6.2.2- else print same

Step 7-Stop
FLOWCHART
IMPLEMENTATION
#include<stdio.h>

#include<string.h>

int main()

int n,i,j,k,p;

char s[1000],a[1000],t=0;

scanf("%s%s",s,a);

k=strlen(s);

p=strlen(a);

int b[127]={0},c[127]={0};

int diff;

for(i=0;i<p;i++)

c[a[i]]++;

for(i=0;i<=k-p;i++)

diff=0;j=0;

int b[127]={0};

int d;

for(d=i;d<i+p;d++)

b[s[d]]++;

if(s[d]=='?')

{
diff++;}

int cont=0;int x;

for(x=97;x<=122;x++)

if(b[x]==c[x])

cont=cont+b[x];

if(cont==p||cont+diff>=p)

t++;

printf("%d",t);

}
RESULTS AND SCREENSHOTS
OUTPUTS
Screen Shots:
CONCLUSION
we have successfully completed our project by using strings concept and different data
structures and datatypes like strings, characters, integers and some operators like
increment and decrement operators and loops like ‘for’ loop and ‘while’ loop in our project.
we understood the implementation of loops. we even used strings concept and string
functions in our project and we understood the implementation of string functions. we used
hashing technique to find out anagrams in a string. we learnt what is anagram? And where it
is used? And we had learnt the advantages and disadvantages of our project. The main thing
is we understood about team work. We used hashing is the process of indexing your data
for faster retrieval, in some cases insertion also, but again for better retrieval. You can
implement hashing in c programming.

You might also like