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

2. (a) A pointer start points to the first element of a doubly-linked list of in

ID: 3743630 • Letter: 2

Question

2. (a) A pointer start points to the first element of a doubly-linked list of integers, L Write an algorithm that inserts a new integer x after the last occurrence of an integer k in L Determine the asymptotic upper bound for the number of times the statement "yy (b) is executed in each of the following algorithms. while (i21) for j = 1 to n (ii) for i 1 to n for/1 to n for k 1 to i y y+1 A palindrome is a string of characters that reads the same forward or backward. (Examples of palindromes: rotor, civic, level.) Write the pseudo-code of an algorithm for determining whether a string of n characters is a palindrome. (c)

Explanation / Answer

A) Algorithm for insering element at last occurence of integer in Doubly Linked List

InsertElementAtLast(data,prev,next,start,end)

1.create a new node and address in assigned to ptr.

2.check[overflow] if(ptr=NULL)

write:overflow and exit

3.set data[ptr]=item;

4.if(start=NULL)

set prev[ptr] = next[ptr] = NULL

set start = end = ptr

else

set prev[ptr] = end

next[end] = ptr

set ptr[next] = NULL

set end = ptr

[end if]

5.Exit.

C) Pseudo Code for Palindrome of a String.