When the index is known, what is the time complexity for accessing an element in an array list?
Review for Exam 1
Score: 0 / 170.0
Exercises
What is the complexity of searching an ArrayList?
What would be the Big O Complexity for a Bubble Sort method?
Modify the Cage
class to implement Comparable
. The definition of the Comparable
interface can be found here. Remember that Comparable has...
Complete the following binary search method. Find the number num
in the array array
. Return -1 if the number is not found. You may assume...
Write a function in Java that takes in the int[] array
, sorts it using bubble sort, then returns back the sorted array.
Return an array with the same contents, but double the size of the array passed in. The new slots will be filled with zeros. Use the...
The following method takes an integer array as a parameter. Write code that loops through the array to find the value 1. If 1 is found,...
The following method is a Selection Sort method. Within the method, there is an error on one line. You job is to find that line and fix...
You have been handed a mysterious piece of data by an unknown person. Judging by his shifty eyes and maniacal laughter you don't think he...
Given a class Answer<E>
, write a method that converts argument e
into String and returns that value. If the value is a primitve, (...
Finish the code to complete the insertion sort method. Each comment denoted with //_________________ is a single line that needs to be...
Use the following recursive method:
public int mysteryMethod(int n) { if (n < 0) { return 5; } else { return mysteryMethod(n - 1) +...
Write a method quicksort that takes in an ArrayList of integers and returns them in ascending order, using a quicksort style of sorting....
Design a recursive method for scrambling Strings of length 3 or more. It must swap the first and last character of the input String, then...
Write an algorithm that takes an ArrayList and uses a recursive binary search to return both the index of a given String, or -1 if the...
Using generics in your program can be very useful considering generic methods and generic classes can handle different datatypes....