EBK STARTING OUT W/JAVA:...DATA...
EBK STARTING OUT W/JAVA:...DATA...
4th Edition
ISBN: 9780134757179
Author: GADDIS
Publisher: PEARSON CO
Expert Solution & Answer
Book Icon
Chapter 16.3, Problem 16.16CP

Explanation of Solution

The following algorithm is presented on checkpoint 16.15CP and its worst case complexity is discussed as follows,

Pseudocode:

Input: Two integer arrays “a[]” and “b[]” of size “n”.

Size of Input: The size specifies the number “n” of array entries.

Output: The condition is “true” of each element of “a[]” is also an element of “b[]” otherwise, it display “false”.

The following is the pseudocode for given data,

  Boolean Contains =true

  int i=0

  While Contains && i<n do

  Contains=Linearsearch(a[i],b)

  i++;

  End while

  Print Contains

Explanation:

  • In the given code, set the Boolean variable “Contains” is equal to “true”.
  • Execute the while loop if the condition is true,
    • The condition must be “i” less than “n” and the variable “Contains” must be “true”.
    • If it is true, then it calls for Linearsearch() function.
    • Increment the value of “i”.
  • Thus, the while loop is executed until the condition satisfies and then finally it print the Boolean value either “True” or “False”.

Pseudocode for LinearSearch:

Input: An integer “X” and an array “b[]” of size “n”.

Size of input: The size specifies the number “n” of array entries.

Output: It returns true if “X” contains in “b[]”, otherwise “false”.

The following is the pseudocode for linear search,

Boolean LinSearch(int x, int[] b)

Begin

  int k=0;

  Boolean found =false;

  While !found && k<n do

  if(X==b[k])

  found =true;

  else   

  K++

  End If

  End While

Return found

End LinSearch

Explanation:

  • The given code performs the linear search algorithm concept which process to find an item in an array...

Blurred answer
Students have asked these similar questions
Implement an algorithm backtracking for the Knight's tour PROBLEM, starting from one of the corner. Enter the time in seconds and present the solution.
How can i find the number of paths possible for 0 toN stairs when the user may jumps 1 ,2 & 3 stairs at a time. Take the n from the user. Please solve this in linear time in Java programming language.
Imagine that you have a problem P that you know is N P-complete. For this problem you have two algorithms to solve it. For each algorithm, some problem instances of P run in polynomial time and others run in exponential time (there are lots of heuristic-based algorithms for real N P-complete problems with this behavior). You can’t tell beforehand for any given problem instance whether it will run in polynomial or exponential time on either algorithm. However, you do know that for every problem instance, at least one of the two algorithms will solve it in polynomial time. (a) What should you do? (b) What is the running time of your solution? 564 Chap. 17 Limits to Computation (c) What does it say about the question of P = N P if the conditions described in this problem existed?
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education