Question 17304 – NTA UGC NET Dec 2023 Paper-1
January 8, 2024Question 15318 – DSSSB PGT 2021
January 8, 2024Question 11089 – Programming
The following C function takes two ASCII strings and determines whether one is an anagram of the other. An anagram of a string s is a string obtained by permuting the letters in s.
int anagram (char *a, char *b) { int count [128], j; for (j = 0; j < 128; j++) count[j] = 0; j = 0; while (a[j] && b[j]) { A; B; } for (j = 0; j < 128; j++) if (count [j]) return 0; return 1; }
Choose the correct alternative for statements A and B.
Correct Answer: D
Question 1 Explanation:
A: Increments the count by 1 at each index that is equal to the ASCII value of the alphabet, it is pointing at.
B: Decrements the count by 1 at each index that is equal to the ASCII value of the alphabet it is pointing at. Also it increments the loop counter for next iteration.
If one string is permutation of other, there would have been equal increments and decrements at each index of array, and so count should contain zero at each index, that is what the loop checks at last and if any non-zero elements is found, it returns 0 indicating that strings are not anagram to each other.
B: Decrements the count by 1 at each index that is equal to the ASCII value of the alphabet it is pointing at. Also it increments the loop counter for next iteration.
If one string is permutation of other, there would have been equal increments and decrements at each index of array, and so count should contain zero at each index, that is what the loop checks at last and if any non-zero elements is found, it returns 0 indicating that strings are not anagram to each other.
A : count [a[j]]++ and B : count[b[j]]–
A : count [a[j]]++ and B : count[b[j]]++
A : count [a[j++]]++ and B : count[b[j]]–
A : count [a[j]]++and B : count[b[j++]]–
Subscribe
Login
0 Comments