suppose values is a sorted ArryList of integers. give a pseudocode that describes how a new value, X, can be inserted in its proper position so that the resulting ArrayList stays sorted
import java.util.ArrayList;
public class AddSorted {
public static void addSortedOrder(ArrayList<Integer> list, int item) {
for (int i = 0; i < list.size(); i++) {
if (item < list.get(i)) {
list.add(i, item);
return;
}
}
list.add(item);
}
public static void main(String[] args) {
ArrayList<Integer> list = new ArrayList<>();
addSortedOrder(list, 3);
addSortedOrder(list, 9);
addSortedOrder(list, 1);
addSortedOrder(list, 2);
addSortedOrder(list, 7);
addSortedOrder(list, 5);
System.out.println(list);
}
}


procedure addSortedOrder(list, item)
for i from 0 to size(list)
if (item < list.get(i))
list.add(i, item)
return
end if
end for
list.add(item)
end procedure
suppose values is a sorted ArryList of integers. give a pseudocode that describes how a new...
Question 27 (Mandatory) (1 point) Which sorting algorithm uses the following pseudocode: For each new, unsorted value v in an array, search backward through already sorted values in the array. Move values until a proper position is found for v. Place v in its correct position. Bogo Sort Selection Sort Insertion Sort Ascending Sort Bubble Sort
2. The following (adapted from Wikipedia) gives pseudocode for searching a sorted vector A for a specific element T. Given an array A of n elements with values or records A1 An and target value T, the following subroutine uses binary search to find the index of T in A. 1. Set L to 1 and R ton. 2. If L>R, the search terminates as unsuccessful Set m (the position of the middle element) to the floor of (L+R)/2. 3....
IN JAVA please Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order. Your code will be tested for runtime. Code which does not output a result in logarithmic time (making roughly log(2) N comparisons) will fail the tests. A sample main function is provided so that you may test your code on sample inputs. For testing purposes, the...
Redo the insertionsort algorithm so that the values are inserted into a linked list rather than an array. This eliminates the need to move other values when a new value is inserted, since your algorithm can simply insert a new node where the new value should go. Analyze your algo- rithm to obtain a big-O expression of the worst-case running time. Code your algorithm to produce a complete C++ program that reads in a list of 10 in- tegers, sorts...
Suppose you have a sorted array of positive and negative integers and would like to determine if there exist some value of x such that both x and -x are in the array. Consider the following three algorithms: Algorithm #1: For each element in the array, do a sequential search to see if its negative is also in the array. Algorithm #2:For each element in the array, do a binary search to see if its negative is also in the...
Suppose you have a sorted array of positive and negative integers and would like to determine if there exist some value of x such that both x and -x are in the array. Consider the following three algorithms: Algorithm #1: For each element in the array, do a sequential search to see if its negative is also in the array. Algorithm #2:For each element in the array, do a binary search to see if its negative is also in the...
Now this: Suppose that you have been assigned to take over a project from another programmer who has just been dismissed for writing buggy code. One of the methods you have been asked to rewrite has the following comment and prototype: /* Method: insertValue(value, array) / • Inserts a new value into a sorted array of integers by * creating a new array that is one element larger than the - original array and then copying the old elements into...
2) Write a recursive procedure in pseudocode to implement the binary search algorithm. 3) Explain, how the binary search algorithm can be modified, or used, to insert, a new integer element x, into a sorted list of n intgers.
In this activity, you will work with a sorted linked list of integers, performing the following activity: Code the insert and delete methods to insert and delete nodes in a sorted linked list of ints. The framework will animate your code to give you feedback on the correctness of your code. It will display the state of the sorted linked list at all times. In this task, you will fill in the code inside the insert and delete methods for...
Suppose that we have two unsorted lists of integers A and B. The lists are the same size, n. a) Write an algorithm that outputs how many integers occur in both lists. An integer occurs at most once in each given list. For example: if A = [1,2,5,7,13,19] and B = [2,9,13,14,19,22], then we can see that elements {2, 13, 19} occur in both lists, so the output will be 3. b) If the lists were sorted, say how we...