Introduction to Computing Science and Programming CSCI 1226-2 Winter 2019- Array Techniques (Arrays)
Summary This assignment consists of a few basic array-based operations such as search, sort, insert, remove and merge. Details You have been provided with a driver program (TestArrayTechniques.java) and a skeleton of ArrayTechniques.java. Your task is to complete ArrayTechniques.java. Currently, only method stubs are available in ArrayTechniques.java. You have to implement the methods by following the descriptions below. ArrayTechniques.java have the following methods:
• findElement: searches for an element in an array and returns the index of the first occurrence of the element if it is found. If the element is not found, it returns -1. • findFrequency: find the number of occurrences of an element in an array. It returns the number of occurrence if the given element is present in the array. If the element is not present in the array, the method returns 0.
• insertElement: The method receives the array, the element to be inserted and the number of elements in the array (array size and then inserts the element at the end of the array. If the number of elements is equal to the array length (total capacity of the array), then insert operation fails and returns false. If the element is successfully inserted into the array, the method returns a true.
• removeElement Like insert method, this method also receives the array, the element to be removed and the number of elements in the array (array size), and then removes the element from the array if it is found. If the array is empty or the element is not found in the array, then the removal operation fails and returns false. Otherwise, the element is successfully removed from the array, and the method returns a true. To remove an element, you can just overwrite the contents of the array as follows, a[i]=a[i+1], where i starts from the index of the element to be removed.
• findMedian this method returns the median of the array elements. There are different ways one can find median of a set of elements. In this assignment, you may use the Arrays.sort() method to first sort the arry and then return the middle element. Note that if the array size is even, then the median is the average of the two middle elements, and if the array size is odd, the median is the middle element, both in the sorted array.
Leave a Reply
Want to join the discussion?Feel free to contribute!