390 views
0 votes
0 votes

Which of the following data structured is most efficient in terms of both space and time to reverse a string of characters?

  1. Linked list
  2. Stack
  3. Array
  4. Tree

1 Answer

Best answer
1 votes
1 votes

Stack

Ex Given a string "abcde", Reverse the string

Take a character stack

Keep pushing the characters on the stack, so after all the characters are pushed the stack would look like this.

a b c d e

where top of stack is pointing to e

Now pop the stack  until its empty! :)

selected by

Related questions

1 votes
1 votes
1 answer
2
sh!va asked Jun 21, 2016
1,807 views
Is this language regular? L1:{wxwR∣w,x∈{a,b}∗ and |w|,|x|>0},wR is the reverse of string wPlease explain..
0 votes
0 votes
0 answers
3
1 votes
1 votes
1 answer
4
Pawan Kumar 7 asked Jun 16, 2018
4,437 views
"A bottom up parser tries to find the right most deviation of the given input in the reverse order " what does this line mean Please Explain