# GATE1989-8a

379 views

What is the output produced by the following program, when the input is "HTGATE"

Function what (s:string): string;
var n:integer;
begin
n = s.length
if n <= 1
then what := s
else what :=contact (what (substring (s, 2, n)), s.C [1])
end;


Note

1. type string=record
length:integer;
C:array[1..100] of char
end
2. Substring (s, i, j): this yields the string made up of the $i^{th}$ through $j^{th}$ characters in s; for appropriately defined in $i$ and $j$.
3. Contact $(s_{1}, s_{2})$: this function yields a string of length $s_{1}$ length + $s_{2}$ - length obtained by concatenating $s_{1}$ with $s_{2}$ such that $s_{1}$ precedes $s_{2}$.

edited

This function is reversing the string "HTGATE".

Here, function substring() gives the substring from the 2nd character of the original string till the end and contact(p,q) is concatenating the strings p and q...

n = s.length means n = length of the string. and c[1] means 1st character of the passed string

So, it will work like this:

what(HTGATE)

contact(what(TGATE),H)

contact(contact(what(GATE),T),H)

contact(contact(contact(what(ATE),G),T),H)

contact(contact(contact(contact(what(TE),A),G),T),H)

contact(contact(contact(contact(contact(what(E),T),A),G),T),H)

contact(contact(contact(contact(contact(E,T),A),G),T),H)

contact(contact(contact(contact(ET,A),G),T),H)

contact(contact(contact(ETA,G),T),H)

contact(contact(ETAG,T),H)

contact(ETAGT,H)

ETAGTH

selected by
0
A great full simulation.
TGATET
0
explain plz

## Related questions

1
1.4k views
Find a solution to the following recurrence equation: $T(n)=\sqrt{n}+T(\frac{n}{2})$ $T(1)=1$
2
767 views
A language uses an alphabet of six letters, $\left\{a, b, c, d, e, f\right\}$ ... Design a prefix binary code for the language which would minimize the average length of the encoded words of the language.
3
1k views
An input files has $10$ records with keys as given below: $25\quad 7\quad 34\quad 2\quad 70\quad 9\quad 61\quad 16\quad 49\quad 19$ This is to be sorted in non-decreasing order. Sort the input file using QUICKSORT by correctly positioning ... brackets to demarcate subfiles. Sort the input file using 2-way- MERGESORT showing all major intermediate steps. Use square brackets to demarcate subfiles.
Match the pairs in the following:$\begin{array}{ll|ll}\hline \text{(A)} & \text{$O (\log n)$} & \text{(p)} & \text{Heapsort} \\\hline \text{(B)} & \text{$O (n)$} & \text{(q)}& \text{Depth-first search} \\\hline \text{(C)}& \text{$ ... $} &\text{(s)} & \text{Selection of the$k^{th}$smallest element in a set of$n$elements} \\\hline \end{array}$