I appreciate any help with the follow programming questions. Thank you ! 1) Cons
ID: 3851219 • Letter: I
Question
I appreciate any help with the follow programming questions. Thank you !
1) Consider you have an array of char declared and initialized in your Java program as follows:
char[] myCharArray = {'h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd'};
To sort it, what method of the Arrays clas would you use?
2) Please order the following functions according to their growth rates from fastest to slowest.
f(n) = n2
g(n) = 1
h(n) = n log n
3) Please show an application or a situation in which it is convenient to use an array to store the data of the application.
4) Please describe an application or a situation in which it is not convenient to use a linked list to store the data of the application.
f(n) = n2
g(n) = 1
h(n) = n log n
Explanation / Answer
1. Arrays class has a static method 'sort' which takes an array as input and returns an array as output. This method uses quick sort to sort the array
2. Given growth rates are n^2, 1 and nlogn
Fastest to slowest is g(n) = 1, h(n) = nlogn f(n) = n^2
3. Arrays are used in an application when the amount of data we have is fixed and won't change. If we are writing an application to deal with the marks of a student, its better to use Arrays since the number of students in class won't change and using Arrays facilitate us to use sorting methods much easily. We access any element using index. But deletion and insertion takes a lot of time in an array as the missing gaps have to be filled
4. Linked list is preferred in an application when the amount of data we have to deal with is not known in advance. We can grow the size of linked list by adding nodes or by removing nodes dynamically. Imagine we are dealing with the customers of a bank. We can insert and remove a node easily on the fly. But sorting is tidious in a linked list and random access is not possible since indexing is not supported,
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.