GATE Computer ScienceModerateGATE CS (PYQ pattern)
The words tea, ten, to, inn, in, i, ted, tent, tenant, tens, ton are inserted into an initially empty trie (one node per character, root not counted; a word end is just a marker on an existing node). How many nodes does the trie have?
- A. 18
- B. 15
- C. 13
- D. 34
Correct answer: B. 15
Shared prefixes are stored once: t-e-a, t-e-n(-t-(a-n-t)), t-e-d, t-e-n-s, t-o(-n), i-n-n gives 15 nodes, against 34 characters in total.
Practise more Programming and Data Structures (GATE) questionsProgramming and Data Structures (GATE): notes and key points
More Programming and Data Structures (GATE) questions
- An array A[-2..5][1..6][0..3] of 4-byte elements has base address 1000 (address of A[-2][1][0]). What is the address of A[3][4][2] in…
- Only the non-zero band of a 20 x 20 tridiagonal matrix (entries with |i - j| <= 1, rows and columns numbered from 1) is stored in a 1-D…
- void f(int n) { if (n <= 1) return; f(n - 1); f(n / 2); } Each activation record takes 32 bytes. What is the peak stack usage in bytes…
- void swap(int x, int y) { x ^= y; y ^= x; x ^= y; } int main() { int a[5] = {3, 7, 9, 12, 5}; for (int i = 0; i < 5; i++) swap(&a[i], &a[4…
- for (i = 2; i <= 100; i++) if (!comp[i]) for (j = i i; j <= 100; j += i) { comp[j] = 1; cnt++; } With comp[] initially all 0, what is the…
- long p(long x, int n) { if (n == 0) return 1; if (n % 2 == 0) { long h = p(x, n / 2); return h h; } return x p(x, n - 1); } How many…