Concept explainers
Explanation of Solution
Complete program:
//Import required packages
import java.util.*;
//Definition of class Sum
public class Sum
{
//Definition of class main
public static void main(String[] args)
{
//Declare array "a"
int a[] = new int[7];
int value, key;
//Create an object for scanner class
Scanner sc = new Scanner(System.in);
//Get the array values
System.out.println("Enter the array values:");
//For loop to get the values from the user
for (int i = 0; i<a.length; i++)
{
//Get the values
value = sc.nextInt();
//Assign the values to the array
a[i] = value;
}
//Get the key value from the user
System.out.println("Enter key values to be search index:");
key = sc.nextInt();
//Call the method "trinarySearch()"
int result = ternarySearch(a, key, 0, a.length - 1);
System.out.println("Value found at position: " + result);
}
//Definition of method "trinarySearch()"
public static int ternarySearch(int data[], int target,
int front, int end)
{
//Declare the variable "res"
int res;
//Check whether the front is greater than end
if (front > end)
//Assign "-1" to "res"
res = -1;
else {
/*Divide the first half of the array by "3"*/
int firstHalf = (2 * front + end) / 3;
/*Divide the second half of the array by "3"*/
int secondHalf = (front + 2 * end) / 3;
/*Check whether the given number in the first half of the array*/
if (target == data[firstHalf])
;&#x...
Want to see the full answer?
Check out a sample textbook solutionChapter 11 Solutions
Java: An Introduction To Problem Solving And Programming Plus Mylab Programming With Pearson Etext -- Access Card Package (8th Edition)
- What are the steps you will follow in order to check the database and fix any problems with it and normalize it? Give two references with your answer.arrow_forwardWhat are the steps you will follow in order to check the database and fix any problems with it? Have in mind that you SHOULD normalize it as well. Consider that the database offline is not allowed since people are connected to it and personal data might be bridged and not secured. Provide three refernces with you answer.arrow_forwardShould software manufacturers should be tolerant of the practice of software piracy in third-world countries to allow these countries an opportunity to move more quickly into the information age? Why or why not?arrow_forward
- I would like to know about the features of Advanced Threat Protection (ATP), AMD-V, and domain name space (DNS).arrow_forwardPlease show the code for the Tikz figurearrow_forwardWhat is Windows Server and what is the Differences between Windows Server 2019 and the Windows Operating System that people have installed on their personal computer.arrow_forward
- solve and show the tree on paperarrow_forwardI need help to resolve the following activityarrow_forwardModern life has been impacted immensely by computers. Computers have penetrated every aspect of oursociety, either for better or for worse. From supermarket scanners calculating our shopping transactionswhile keeping store inventory; robots that handle highly specialized tasks or even simple human tasks,computers do much more than just computing. But where did all this technology come from and whereis it heading? Does the future look promising or should we worry about computers taking over theworld? Or are they just a necessary evil? Provide three references with your answer.arrow_forward
- What are the steps you will follow in order to check the database and fix any problems with it? Have in mind that you SHOULD normalize it as well. Describe in full, consider the following:• Taking the database offline is not allowed since people are connected to it.• Personal data might be bridged and not secured. Provide three refernces with you answerarrow_forwardYou are called by your supervisor to go and check a potential data bridge problem. What are the stepsyou will follow in order to check the database and fix any problems with it? Have in mind that youSHOULD normalize it as well. Describe in full, consider the following:• Taking the database offline is not allowed since people are connected to it.• Personal data might be bridged and not secured. Provide three refernces with you answerarrow_forward(A) A cellular system has 12 microcells with 10 channels per cell. The microcells are split into 3 microcells, and each microcell is further split into 4 picocells. Determine the number of channels available in system after splitting into picocelles.arrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:CengageNew Perspectives on HTML5, CSS3, and JavaScriptComputer ScienceISBN:9781305503922Author:Patrick M. CareyPublisher:Cengage Learning
- Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTC++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr