[Show with no answers] [Show with all answers]
The following algorithm
Count the number of primitive operations (evaluating an expression, indexing into an array). What is the time complexity of this algorithm in big-O notation?
for all i = n down to 1 do
for all j = n down to i do
print A[i] A[j]
end for
end for
Develop an algorithm to determine
if a character array of length n
encodes a palindrome —
that is, it reads the same forward and backward.
For example, racecar
is a palindrome.
Write the algorithm in pseudocode.
Analyse the time complexity of your algorithm.
Implement your algorithm in C. Your program should accept a single command line argument, and check whether it is a palindrome. Examples of the program executing are
./palindrome racecar yes ./palindrome reviewer no
Hint:
You may use the standard library function strlen(3),
which has prototype size_t strlen(char *)
,
is defined in <string.h>
,
and which computes the length of a string
(without counting its terminating '\0'
-character).