Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
4th Edition
ISBN: 9780134787961
Author: Tony Gaddis, Godfrey Muganda
Publisher: PEARSON
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
Write a recurrence for this algorithm and solve it to obtain a tight upper bound on the worst case runtime of this algorithm. You can use any method you like for solving this recurrence.
Suppose a candidate solution p, where p is a phenotype consisting of 4 vertices. Suppose that minimum fitness occurs when no pair of vertices in p are connected, and maximum fitness occurs when all pairs of vertices in p are connected. Write a pseudocode on how to calculate the fitness F of p.
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.

Chapter 16 Solutions

Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)

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