Question: Hello, i need help in java language Lab 3 - Linear Search & Binary Search Algorithms Create a class called Lab3Search which stores an ArrayList
Hello, i need help in java language
Lab 3 - Linear Search & Binary Search Algorithms
Create a class called Lab3Search which stores an ArrayList of Integers in sorted order, you can use Collections.sort() to keep the ArrayList sorted. You must implement binary search to find items in the list. Write your own code to implement the Binary Search algorithm. Do NOT use built-in binarysearch() method. Instead, create your own custom recursively implemented method called recursiveBinarySearch() inside Lab3Search class to perform a binary search of the arrayList. Also create another method called recursiveLinearSearch() inside Lab3Search class that will perform a linear search of the arrayList. Create a test driver class called TestSearch containing the main method and a showMenu() method for testing your Lab3Search class. Implement the menu as follows:
- Add Item
- Search for Item using Linear and Binary search
- Display List
- Exit
Your menu must be displayed over and over until Exit is selected. Use the switch statement for menu selections. Add Item and Search for Item should prompt the user for an integer. Display List should display the list items using the ArrayList toString() method.
the sample output:
Please Enter: 1. Add Item 2. Search for Item Linear and Binary search 3. Display List 4. Exit 1 Please specify an Integer: 1 Please Enter: 1. Add Item 2. Search for Item Linear and Binary search 3. Display List 4. Exit 1 Please specify an Integer: 2 Please Enter: 1. Add Item 2. Search for Item Linear and Binary search 3. Display List 4. Exit 1 Please specify an Integer: 5 Please Enter: 1. Add Item 2. Search for Item Linear and Binary search 3. Display List 4. Exit 1 Please specify an Integer: 6 Please Enter: 1. Add Item 2. Search for Item Linear and Binary search 3. Display List 4. Exit 3 Arraylist contains [1, 2, 5, 6] Please Enter: 1. Add Item 2. Search for Item Linear and Binary search 3. Display List 4. Exit 2 Please specify an Integer: 6 Linear Search: Index of Integer is: 3 Binary Search: Index of Integer is: 3 Please Enter: 1. Add Item 2. Search for Item Linear and Binary search 3. Display List 4. Exit 2 Please specify an Integer: 11 Linear Search: Index of Integer is: Not Found Binary Search: Index of Integer is: Not Found Please Enter: 1. Add Item 2. Search for Item Linear and Binary search 3. Display List 4. Exit 5 Invalid option, Try 1-4 again.. Please Enter: 1. Add Item 2. Search for Item Linear and Binary search 3. Display List 4. Exit J Invalid option, Try 1-4 again.. Please Enter: 1. Add Item 2. Search for Item Linear and Binary search 3. Display List 4. Exit 4 Exiting...
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
