bartleby

Videos

Expert Solution & Answer
Book Icon
Chapter 7, Problem 19E

Explanation of Solution

Sequential search method definition:

//Define "SequentialSearchTest" class

public class SequentialSearchTest

{

  /* Define the method "arraySequentialSearch".

This method is used to returns index location of given value if the value is found. Otherwise returns "-1" */

public static int arraySequentialSearch(int[] sorted_arrValues, int value)

{

//Set index position to "-1"

int index_position = -1;

//Compute the given element is found or not using "for" loop

for (int i = 0; i < sorted_arrValues.length; i++)

{

//If the given value is found in array, then

  if (sorted_arrValues[i] == value)

  {

  //Set index position to "i"

  index_position = i;

  break;

  }

  //Otherwise

  else if (sorted_arrValues[i] > value)

  {

  //Break the loop

  break;

  }

  }

  //Returns the index position of given element

  return index_position;

  }

  //Define main function

  public static void main(String[] args)

  {

  //Initializes given array values

  int[] arr = { 2, 4, 6, 8 };

  //Initializes two elements

  int element1 = 6;

  int element2 = 5;

  //Display given statement

System.out.println("The integers values in the given arrays ");

//Display array values

for (int idx = 0; idx < arr.length; idx++)

System.out.println(arr[idx] + "");

  System.out.println();

//Compute index of element 1 by calling the method "arraySequentialSearch"

int value_index1 = arraySequentialSearch(arr, element1);

/* If the given index of element 1 is less than "0", then */

if (value_index1 < 0)

//Display given statement

System.out.println("The given value " + element1 + " is not found in the sorted array. ");

  //Otherwise

  else

  //Display the index of given element

System...

Explanation of Solution

Reasons:

  • From the given question, the given array values 2, 4, 6, and 8 are in sorted order.
  • Here, the searching value for given array is “5”.
  • From the above method definition of sequential search,
    • First compare “5” with integer at each position that is starting from “0”. The value at index position “0” is “2”...

Blurred answer
Students have asked these similar questions
Objective: The objective of this assignment is to gain practice with pen testing a live web application running on a remote server. The live web application is a known vulnerable web application called DVWA (Damn Vulnerable Web Application) with security settings set to low. The web app is running on an AWS EC2 (Elastic Compute Cloud) instance running Ubuntu 22. Note: The point of this assignment is to step it up a notch, we learnt about different web application vulnerabilities and applied that knowledge, now we are going to pen test and enumerable the vulnerabilities of a web app + the underlying infrastructure it is running on. Before you begin please find out what your IP address is and place it in this sheet so that I can track who is doing what: IP Addresses.docx . Tasks: 1- Start by connecting to the target, I did not install a TLS certificate on purpose that is why you are going to connect via http and not via https: http://3.99.221.134/dvwa/login.php 2- Broken Authentication:…
No AI solutions please
No AI solutions please

Chapter 7 Solutions

Java: An Introduction To Problem Solving And Programming Plus Mylab Programming With Pearson Etext -- Access Card Package (8th Edition)

Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Text book image
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Text book image
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:9781337102124
Author:Diane Zak
Publisher:Cengage Learning
Definition of Array; Author: Neso Academy;https://www.youtube.com/watch?v=55l-aZ7_F24;License: Standard Youtube License