1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
hram777 [196]
3 years ago
7

Give a recursive algorithm that takes as input a string s, removes the blank characters and reverses the string. For example, on

input "Hello There", the algorithm should return "erehTolleH". The function IsBlank(c) returns a boolean value indicating whether the character c is the blank character. Your algorithm should not use a loop.
Computers and Technology
1 answer:
Dmitriy789 [7]3 years ago
8 0

Answer:

#include <iostream>

using namespace std;

void recReverse(string exp)

{

if (exp.size() == 0)   //check for empty string

{

 return;

}

if (exp[0] == ' ')

{

 recReverse(exp.substr(1));  //only subtracting, not printing the spaces

}

else

{

 recReverse(exp.substr(1)); //subtracting the previously first element

 cout << exp[0]; //printing new first element

}

}

int main()

{

string exp = "Hello There";

recReverse(exp);

return 0;

}

Explanation:

A recursive function calls itself and works kind of like a loop. A russian doll, if you will. The downside of this program is that if the statement becomes too long it becomes very slow. The upside is, that i some cases, it provides elegant solutions.

In the above code, we have first made sure that we don't have a blank string input. In case we do, we've made sure the function exits before doing any extra work.  Then if the next element of the string is a space, we haven't printed it. Instead we've omitted the 'cout' and carried on with our recursion. Finally, in the else statement, we are printing the character along with subtracting it. Giving us our final recursive call backwards printing.

You might be interested in
How many times is the body of the loop executed?
Flura [38]

Answer:

The loop will run 5 times.

3 0
2 years ago
PlZZZZZZZ help will give Brainliest
dalvyx [7]

Answer:

Phone

Explanation:

3 0
2 years ago
Read 2 more answers
You work in an office that uses Linux servers and Windows servers. The network uses both the TCP/IP protocol. The Linux server i
kap26 [50]

Answer:

The answer is "ifconfig".

Explanation:

The ifconfig. me is indeed a website that shows basic network packets, like IP address, hostname, user agent string. It provides a simple interface that may be queried with the assistance of the command prompt to obtain the required information. The whole function provides the essential information about a certain program's interface.

5 0
3 years ago
In a batch operating system, three jobs are submitted for execution. Each job involves an I/O activity, CPU time and another I/O
Ilia_Sergeevich [38]

Answer:

a) CPU utilization for uniprogramming system = 18.2%

b) CPU utilization for multiprogramming system = 41.379%

Explanation:

IO time = total time – CPU time

For JOB 1  

CPU time = 3ms ,

total time= 23ms

IO time = 23-3 = 20ms ,

For JOB 2

CPU time =5ms

total = 29ms

IO time = 29-5 = 24ms  

For JOB 3  

CPU time = 4ms

total = 14ms

IO time = 14-10 =10ms  

1.) In uniprogramming system, operations are performed sequentially

CPU utilization=total CPU time / total real time

CPU utilization =(3+5+4) / (23+29+14)

CPU utilization =0.182 or 18.2%

2) In multiprogramming system, jobs wait for the CPU to get free while performing IO operations concurrently

steps followed by the os

1. IO for 1st job                           at 0ms

2. IO for 2nd job                          at 0ms

3. IO for 3rd job                          at 0ms

4. CPU time for 3rd job              at 5ms

5. Next IO job for 3rd job           at 9ms END at 14ms

6. CPU time for 1st job              at 9ms

7. Next IO job for 1st job           at 14ms END at 23ms

8. CPU time for 2nd job             at 14ms

9. Next IO job for 2nd job          at 15ms END at 29ms

CPU time is 3+5+4 =12ms

Total execution time = 29ms

CPU utilization = 12*100/29= 41.379%

5 0
2 years ago
Which of the following is true about sorting functions?
il63 [147K]

Answer: Option D -- Sorting an already sorted array of size n with quicksort takes O(n log n) time.

Explanation:

Sorting an already sorted array of size n with quicksort takes O(n log n) time is true about sorting functions while other options are wrong.

8 0
3 years ago
Other questions:
  • The strFirstName and strLastName variables contain the strings "Jane" and "Jones," respectively. Which of the following statemen
    14·1 answer
  • Suppose a retailer who has no technology expertise wishes to set up an online presence for his business. He ________. a. ​can us
    6·1 answer
  • Which of the following is NOT a safe skill you can use to reduce your risk
    11·2 answers
  • 次のうち、ビジネスレターに適したフォントとポイントサイズの選択はどれですか?<br> 私を助けてください!私はあなたを最高にブランコにします!
    12·2 answers
  • Who initially developed what is now known as the internet?
    5·1 answer
  • A high school in a low-income area offers special programs to help students acquire the technical skills needed to find jobs as
    12·1 answer
  • My computer screen keeps flashing black, it's on a very low brightness level and I very rarely put it up to high level unless I
    13·2 answers
  • Importance of computer​
    15·1 answer
  • Which of the following technologies does NOT facilitate the transferring of data between computers in adjacent buildings?
    12·1 answer
  • Connect research concepts to their definitions
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!