Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Question 1: A palindrome is a word (sequence of characters) that reads the same

ID: 3754335 • Letter: Q

Question

Question 1: A palindrome is a word (sequence of characters) that reads the same backward as forward (e.g. civic, refer). Write the most efficient algorithm (one for each data structure) to check if a word w is a palindrome by using: a.Stacks b.Queues c.Deques For each data structure, your input is a queue with the sequence of characters in the word. For instance, for the word "hello the input of your algorithm is a queue: (front) h, e, I, I, o (rear). If you need to duplicate the input queue or any other container (stack, queue, deque) you can use an operation duplicate(container) that runs in Oin) and returns a replica of the given container. Specify and justify your choice of implementation for each ADT being used (static array, incremental/doubling growable array, singly linked list, doubly linked list). Show the overall cost of your three algorithms and justify your answer. What is the best data structure among those three to solve the problem Explain why based on time and space costs

Explanation / Answer

Question 1:

Illustrate a word / string is Palindrome Using Stacks

Pre-Requistive: Input String is Needed from End-User

Code is Stated Below:

#include<stdio.h>

#include<stdlib.h>

#include<string.h>

#define SIZE 30

int t=-1,f=0; /* t is top and f is for front of the Stack */

int s[SIZE]; //holds the MAX SIZE of the String to be passed on

void push(char); //insert char to the stack

void pop(); //delete from stack

void main()

{

int i;

char s1[SIZE], b;

printf("Enter the String to be Verified for Palindrome ");

scanf("%s",s1);

for(i = 0;s1[i] != '';i++) //loop y until NULL Termination String

{

b=s1[i];

push(b);

}

for(i=0;i<(strlen(s1) / 2 );i++)

{

if(s[t] == s[f])

{

pop();

f++;

}

else

{

printf("Entered String %s is Not a palindrome",s1);

}

}

if((strlen(s1) / 2) == f)

{

printf("Enter String %s is Palindrome",s1);

}

f = 0;

t = -1;

}

void push(char a)

{

t++;

s[t] = a;

}

void pop()

{

t--;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote