top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How to reverse a string using binary search?

0 votes
715 views

I am looking to reverse a string using binary search algorithm but no clue. Can someone share the algo and may be C/C++ code?

posted Mar 13, 2016 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

Might be I am not correct but following steps can be followed to get the desired result :
1. Create a binary tree from the characters of the input string.
2. First node will contain the first character.
3. Second character will go the left of side of the first node and third character will go the right side of the first node.
Now both left and right nodes are present to the first node.
4. Take the left node fill its both child and then take right node of the first node and fill its both child
5. Follow the above approach until you finish the input string.

Once the binary tree is prepared, start retrieving nodes from level "n", level "n-1", level "n-2" and so on
The way of traversal nodes should be in order from right to left.
Example : Input string : Ahmed
Output as binary tree : A
| |
h m
| |
e d

            Traversal result : d e m h A (reverse of the input string)

Another approach is to create left skewed or right skewed binary tree. We can get the same result but both left-skewed and right-skewed binary tree.
There might be another approach to solve the same problem in different ways. Please share if someone knows another ways to solve this problem.

answer Mar 13, 2016 by Vikram Singh
Question about binary search your solution is binary tree..May be try binary search tree..
For me this question does not make any sense at all.
Similar Questions
+2 votes

Given a list of space separated words, reverse the order of the words. Each line of text contains L letters and W words. A line will only consist of letters and space characters. There will be exactly one space character between each pair of consecutive words.
for example :

Input:
this is a test

Output:
test a is this

+1 vote

How to find first unrepeated character in string using C/C++?

Input       Output     
abc         a    
aabcd       b
aabddbc     c
0 votes

Find the first non repeating character in a string.

For example
Input string: "abcdeabc"
Output: "e"

+1 vote

A binary string will be given to us and we need to print its 1s and 2s complement of that? C code would be helpful?

...