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...
Write an algorithm to describe how to convert a user input from ounces to grams, drams...
Write an algorithm to describe how to convert a user input from ounces to grams, drams and pounds. Use enough detail that you have between five and ten steps. List any assumptions.          a) Assumptions          b) Steps
Write three to four paragraphs using the below scenario and attach your submission. Remember to check...
Write three to four paragraphs using the below scenario and attach your submission. Remember to check the rubric before submitting. Sharing Trade Secrets Scenario Suppose there are two large, competing telecommunication firms in your city (Company X and Company Y). The companies are hostile to each other. You have worked for Company X for five years in a position that gives you access to company trade secrets. You are now interviewing for a job with Company Y that would be...
Write pseudocode for quick find algorithm anf quick union algorithm Write pseudocode for quick find algorithm...
Write pseudocode for quick find algorithm anf quick union algorithm Write pseudocode for quick find algorithm and quick union algorithm
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.
use c++ Provide a header file as well. So for this question provide Rational.h, Rantional.cpp Create...
use c++ Provide a header file as well. So for this question provide Rational.h, Rantional.cpp Create a class called Rantional for performing arithmatic with fractions. Then write a program to test your class. Use integer variables to represent the private data of the class, meaning the numerator and the denominator. Provide a constructor that enables an object of this class to be initialized when it's declared. The constructor should contain default values in case no initializers are provided and should...
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...
implement the algorithm described in this chapter to convert a prefix expression to postfix form. involve...
implement the algorithm described in this chapter to convert a prefix expression to postfix form. involve the classes that programming problems 4 and 5 describe This is to be written in C++. I cannot provide anymore information, I cannot provide any class information, etc. This is all the problem that book gave me. This is for Data Structures and algorithms.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT