Question

In: Computer Science

Convert this strategy into an algorithm and write it below. remember to provide an algorithm header,...

Convert this strategy into an algorithm and write it below. remember to provide an algorithm header, number the algorithm steps and to use pseudocode conventions.

         Scan the input array A, counting the number of negative, zero and positive numbers. Let these counts be x, y and z respectively.

         Create a new array B of the same size and set a local variable neg to 1, zero to x+1, and pos to x+y+1.

         Scan the input array from left to right, and if the current number being looked at is negative, copy it to B[neg] and increment neg, if it is a zero, copy it to B[zero] and increment zero, and if it is positive, copy it to B[pos] and increment pos.

         Output array B.

Solutions

Expert Solution

Algorithm/Pseudo-Code for given Problem.

1)Start of the Program.

2)Scan the Input array and store it in A.

3)Let the Length of the array is Len.

4)Declare integers x,y,z

5)For loop to traverse the elements of array A one by one.

Let i be the iteration index.
  
for i=1 to Len:
if(A[i]==0)
   y++;
   else if(A[i]<0)
   x++;
   else
   z++;
     
   i++;
     
   end of for loop
     
6) Create a new Array B of length Len same as Array A.

7)Declare and Initialize neg=1, zero=x+1 and pos=x+y+1


8) Scan Array A elements and keep them into Array B.

for i=i to Len:
if(A[i]==0)
   B[zero]=A[i];
   zero++;
  
   else if(A[i]<0)
   B[neg]=A[i];
   neg++;
  
   else
   B[pos]=A[i];
   pos++;
  
   i++;
     
   end of for loop
  
9) Output Array B

10) End of Program

Feel free to ask any doubts, if you face any difficulty in understanding.

Please upvote the answer if you find it helpful


Related Solutions

* the Algorithm: * write a java program to convert infix to postfix create(OpStk) OpStk.push("#") token...
* the Algorithm: * write a java program to convert infix to postfix create(OpStk) OpStk.push("#") token = nextToken() while (token != "#") if (token is an operand) append token to postfix expression else if (token is "(") // Left paren - Start of sub-expr OpStk.push( token ) else if (token is ")") // Right paren - End of sub-expr pop operators off the stack and append to the postfix expression - stop when you've popped a "(" else (token is...
In 300 words or less, write on what strategy is to you and provide THREE examples...
In 300 words or less, write on what strategy is to you and provide THREE examples of different types of strategies exhibited by health care organizations.
Write an algorithm for resolving a battle among the classic Pokemon types. write the algorithm first...
Write an algorithm for resolving a battle among the classic Pokemon types. write the algorithm first        The user should select a type of either fire, water or grass. The computer should randomly select one of those three types as well.       To determine if the user or computer wins, or if it is a draw: fire is stronger than grass, grass is stronger than water, and water is stronger than fire. Whoever chose the stronger type is the winner....
Converting from Decimal to Binary The algorithm you will use in this assignment to convert from...
Converting from Decimal to Binary The algorithm you will use in this assignment to convert from base 10 to base 2 is: If the decimal number is zero, then the binary value is "0" Otherwise, start with an empty String to contain your binary value While your decimal number is not zero Get the remainder of what your current decimal number would be when divided by 2. Prepend this result to the front of your String. Divide your decimal number...
Using the provided dictionary, develop an encryption algorithm that will convert a user-entered string into an...
Using the provided dictionary, develop an encryption algorithm that will convert a user-entered string into an encrypted string. Print the user inputted text and the corresponding encrypted text. cipher = {"A": "T", "B": "D", "C": "L","D": "O", "E": "F","F": "A", \ "G": "G","H": "J", "I": "K", "J": "R", "K": "I","L": "C", "M": "V", \ "N": "P", "O": "W","P": "U", "Q": "X", "R": "Y", "S": "B","T": "E", \ "U": "Z", "V": "Q", "W": "S","X": "N", "Y": "M", "Z": "H"} b) Create...
Write a method in JAVA that does this: Presents the user with a header stating this...
Write a method in JAVA that does this: Presents the user with a header stating this is for assignment: Lab, and the names Bob and Bill Present the user with a menu to run a random method(just make this a dummy method) , another random method method,(just make this a dummy method) or another dummy method (just make this a dummy method) Repeat the menu until the user enters -1.
Write algorithm for LIFO (Last In First Out) Page Replacement Algorithm
Write algorithm for LIFO (Last In First Out) Page Replacement Algorithm
Please provide step by step on how to create the header files for this project. I...
Please provide step by step on how to create the header files for this project. I received code for it but I am getting an error and I know it has to do with my header files. Please provide instructions on how to create these files along with the full code in C++ for the following: Write a C++ program to simulate a service desk. This service desk should be able to service customers that can have one of three...
NOTE: this is at 5th position..not 4th Using the Hamming code algorithm (7, 4), convert a...
NOTE: this is at 5th position..not 4th Using the Hamming code algorithm (7, 4), convert a data message (0110) using 7bit. Identify the number of parity bits needed Evaluate values of parity bits Final message bits with parity bits Inject error (o or 1) at 5th position and identify the error position.
Write a C++ program that design a class definition to be put in a header file...
Write a C++ program that design a class definition to be put in a header file called fizzjazz.h A store sells online FizzJazz which are sound tones made by famous bands. For each FizzJazz, the store wants to keep track of the following attributes: * title - the name of the sound tone * band - Famous band name that created the tone * duration - this is in seconds and may be fractional: examples: 20.0, 34.5 Each attribute will...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT