Question

Hello, I need the array pseudocode for the following: "take input from the user on what...

Hello, I need the array pseudocode for the following: "take input from the user on what value they want to search for, then if that value is found - output that the value is found and what index number it is contained in, otherwise output that the value is not found."

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Array pseudocode for the question:

There are two methods for the above question:
1)Linear search
2)binary search

1) Pseudocode for the linear search

-------------------------------------------------------------------------------------------------------------------------------------------------------------

DECLARE array = ARRAY[1,n]  of INT

TAKE input from user valueToSearch

procedure linear_search (array, valueToSearch)

   for each item in the array
   if match item == valueToSearch
       Print Element value Found at
   Print the item's location
   end if
   else
       Print value is not found
   end else
   end for
end procedure

-------------------------------------------------------------------------------------------------------------------------------------------------------------
2) Pseudocode for the binary search

-------------------------------------------------------------------------------------------------------------------------------------------------------------

DECLARE A = SORTED_ARRAY[1,n]  of INT
DECLARE n = size of array
TAKE input from user x = valueToSearch

Procedure binary_search
Set lowerBound = 1
Set upperBound = n

while x not found
if upperBound < lowerBound
EXIT: x does not exists.

set midPoint = lowerBound + ( upperBound - lowerBound ) / 2
  
if A[midPoint] < x
set lowerBound = midPoint + 1

if A[midPoint] > x
set upperBound = midPoint - 1

if A[midPoint] = x
EXIT: Element x found at location midPoint
end while

end procedure

-------------------------------------------------------------------------------------------------------------------------------------------------------------

Add a comment
Know the answer?
Add Answer to:
Hello, I need the array pseudocode for the following: "take input from the user on what...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Create a Raptor Flowchart and Pseudocode for the following: That searches an array of size 15...

    Create a Raptor Flowchart and Pseudocode for the following: That searches an array of size 15 that holds a collection of numbers, for the value 7. First we take input from the user to fill each element in the array. Then we search the array for value 7. If value 7 is not found we output: "Value 7 is not contained in array[]", otherwise if the value 7 is found output: "Value 7 is contained in array[] at index" and...

  • Hello, I need the pseudocode / flowchart for the following : read input from a file...

    Hello, I need the pseudocode / flowchart for the following : read input from a file by adding all the numbers in a file to an array, then iterate through the array to count how many times each number appears in the array (the frequency of each number) - then write the summation results to a file: summary.txt. Need to use a numbers.txt file that looks like this:

  • PSEUDOCODE HELP i need for this to be in the most basic form of pseudocode. thanks...

    PSEUDOCODE HELP i need for this to be in the most basic form of pseudocode. thanks for your time. Create the logic for an application that contains an array of 10 multiple-choice questions related to your favorite hobby. Each question contains three answer choices. Also create a parallel array that holds the correct answer to each question—A, B, or C. Display each question and verify that the user enters only A, B, or C as the answer—if not, keep prompting...

  • I need help making this work correctly. I'm trying to do an array but it is...

    I need help making this work correctly. I'm trying to do an array but it is drawing from a safeInput class that I am supposed to use from a previous lab. The safeInput class is located at the bottom of this question I'm stuck and it is not printing the output correctly. The three parts I think I am having most trouble with are in Bold below. Thanks in advance. Here are the parameters: Create a netbeans project called ArrayStuff...

  • c++ The program will be recieved from the user as input name of an input file...

    c++ The program will be recieved from the user as input name of an input file and and output.file. then read in a list of name, id# and score from input file (inputFile.txt) and initilized the array of struct. find the student with the higher score and output the students info in the output file obtain the sum of all score and output the resurl in output file. prompt the user for a name to search for, when it find...

  • Java Question, I need a program that asks a user to input a string && then...

    Java Question, I need a program that asks a user to input a string && then asks the user to type in an index value(integer). You will use the charAt( ) method from the string class to find and output the character referenced by that index. Allow the user to repeat these actions by placing this in a loop until the user gives you an empty string. Now realize that If we call the charAt method with a bad value...

  • Write a program which will take a list of integer number from the user as input...

    Write a program which will take a list of integer number from the user as input and find the maximum and minimum number from the list. First, ask the user for the size of the array and then populate the array. Create a user define function for finding the minimum and maximum numbers. You have to use pointer variables for solving the problem. Finally, you need to print the entire list along with the max and min numbers ALSO NEED:...

  • USING RAPTOR For the following Programming Challenges, use the modular approach and pseudocode to design a suitable program to solve it. Create a program that allows the user to input a list of first...

    USING RAPTOR For the following Programming Challenges, use the modular approach and pseudocode to design a suitable program to solve it. Create a program that allows the user to input a list of first names into one array and last names into a parallel array. Input should be terminated when the user enters a sentinel character. The output should be a list of email addresses where the address is of the following from: [email protected]

  • I need help writing a pseudocode: JAVA Write a pseudocode algorithm that asks the user for...

    I need help writing a pseudocode: JAVA Write a pseudocode algorithm that asks the user for their grades in CSE 1321, along with their attendance, then calculates their final grade. Note, perfect attendance rounds up your final grade by 1.5 points – otherwise, it’s a fraction out of 30. The tests and quiz average are worth 20% each. Sample Output: Enter your grade for Test 1: 95 Enter your grade for Test 2: 85 Enter your grade for Test 3:...

  • Hello in C#. I need help understanding and knwoing what i missed in my program. The...

    Hello in C#. I need help understanding and knwoing what i missed in my program. The issue is, the program is supposed to have user input for 12 family members and at the end of the 12 it asks for user to input a name to search for. When i put a correct name, it always gives me a relative not found message. WHat did i miss. And can you adjust the new code so im able to see where...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT