Java: An Introduction to Problem Solving and Programming (7th Edition)
Java: An Introduction to Problem Solving and Programming (7th Edition)
7th Edition
ISBN: 9780133766264
Author: Walter Savitch
Publisher: PEARSON
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
Create an original network topology consisting of at least seven routers and twelve links, assigning arbitrary positive weights to each link. Using this topology, apply Dijkstra's Link-State Algorithm to compute the shortest paths from a source router of your choice to all other routers in the network. Your topology must be entirely your own design and should not resemble any examples from the textbook, lecture slides, or other students' work. Al-generated topologies are not permitted. Create a PowerPoint presentation that follows the format and style of slides 11 to 23 from Lecture Slide Set 06 (LS06). You should copy those slides and make any necessary changes, additions, or deletions to reflect your own topology, shortest-path calculations, and update tables. Do not alter the original slide style, layout, or formatting.
Create an original network topology consisting of at least seven routers and twelve links, assigning arbitrary positive weights to each link. Using this topology, apply Dijkstra's Link-State Algorithm to compute the shortest paths from a source router of your choice to all other routers in the network. Your topology must be entirely your own design and should not resemble any examples from the textbook, lecture slides, or other students' work. Al-generated topologies are not permitted. Create
x3003 x3008 1110 0000 0000 1100 1110 0010 0001 0000 0101 0100 1010 0000 x3004 0010 0100 0001 0011 x3005 0110 0110 0000 0000 X3006 0110 1000 0100 0000 x3007 0001 0110 1100 0100 0111 0110 0000 What does the following LC-3 program do? Trace Step by Step, SHOW ALL YOUR WORK. x3001 x3002 0000 x3009 0001 0000 0010 0001 X300A 0001 0010 0110 0001 x300B 0001 0100 1011 1111 x300C 0000 0011 1111 1000 X300D 1111 0000 0010 0101 x300E 0000 0000 0000 0101 x300F 0000 0000 0000 0100 x3010 0000 0000 0000 0011 x3011 0000 0000 0000 0110 x3012 0000 0000 0000 0010 x3013 x3014 0000 0000 0000 0000 0000 0100 0000 0111 x3015 0000 0000 0000 0110 x3016 0000 0000 0000 1000 x3017 0000 0000 0000 0111 x3018 0000 0000 0000 0101

Chapter 7 Solutions

Java: An Introduction to Problem Solving and Programming (7th 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
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
Definition of Array; Author: Neso Academy;https://www.youtube.com/watch?v=55l-aZ7_F24;License: Standard Youtube License