QuestionQuestion

ASSIGNMENT:   
      
1. Implement binary search on an ordered linked list. As a starting point, you can use the LinkedList we have already used in this class (from the jsjf package).
a. Implement the binary search on the list and test your code by searching item 7 in the list, the return should be 4 (i.e., 7 is index 4 in the list).
b. Insert the following numbers to the list: 2,3,4,5,7,8,9 in sequence.
c. What is the time complexity of binary search on an ordered linked list? Is it faster than binary search on an array-based ordered list?

2. Implement insertion sort on a linked list. If you wish, you may use a doubly-linked list. If you use a doubly-linked, stat that here on the grade sheet.
a. Implement the insertion sort.
b. Insert the following numbers to the list and then sort the list: 3,5,7,2,1,8,9
c. Does your implementation use a singly-linked list or a doubly-linked list?
What is the time complexity of your insertion sort on a linked list?
Is the time complexity higher than that of insertion sort on an array-based list?

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

public class BinarySearchLinkedList {

    private void binarySearch(DoublyLinkedList.Node head, DoublyLinkedList.Node tail, int item, int index) {

       if(head != null && tail != null){
            int leftValue = (Integer) head.getValue();
            int rightValue = (Integer) tail.getValue();

            if(leftValue <= rightValue){

                DoublyLinkedList.Node mid = head;
                DoublyLinkedList.Node tmp = head;

                int idx = 0;
                while (tmp != tail && (Integer)tmp.getValue() < (Integer) tail.getValue()){
                   mid = mid.getNext();
                   idx++;
                   tmp = tmp.getNext();
                   tmp = tmp.getNext();
                }

                if((Integer) mid.getValue() == item){
                   System.out.println("" + item + " is found at: " +(index+idx) + " position");
                }else if((Integer) mid.getValue() > item){
                   binarySearch(head, mid.getPrev(), item, index);
                }else {
                   binarySearch(mid.getNext(), tail, item, index+idx+1);
                }...

By purchasing this solution you'll be able to access the following files:
Solution1.java and Solution2.java.

50% discount

Hours
Minutes
Seconds
$45.00 $22.50
for this solution

or FREE if you
register a new account!

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Data Structures and Algorithms Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats