Question

***********Java Programming********** I would like to use a data structure that can be resized at run...

***********Java Programming**********

I would like to use a data structure that can be resized at run time and is efficient in memory and can be printed out in order. Give an example of any Java implementation of a data structure that fits this description and tell how it can be used.

Homework Answers

Answer #1

If the total size is known, ahead of time, or if O(n) insertions due to resizing (but still O(1) amortized in the average case) are fine, then hash table is the best option. The one-time hit of copying the whole table when resizing can also be distributed over several operations by usingincremental resizing.

Hash table should be partially empty to avoid collisions, which may feel like wasting memory. But with tree-based maps, we usually have at least one additional pointer per item, which will also “waste” a significant amount of memory. Also, with a hash table, we can tweak how much of it to keep empty, partially trading performance for memory (or vice versa).

But there also is a tree-based data structure optimized for looking up recently accessed keys: splay tree. It uses rotations to keep recently used keys near the root, while still maintaining amortized worst case of O(log n) for insertion and searching. (That “amortized” bit is important, some operations can still be O(n)).

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Java program question! If I pass null to a method, how can I use the passed...
Java program question! If I pass null to a method, how can I use the passed value to compare. Here is example code, it might be wrong, please make it could run on eclipse. Public class hw{ public static void main (String args[]) { method1(); } private static void method1() { System.out.println(method(null)); } public static String method(int[] a) { return null; } What I want to get in the output is just "()". It is not just to type the...
JAVA use the concepts in concurrent programming to write a basic multi-threaded program. You will be...
JAVA use the concepts in concurrent programming to write a basic multi-threaded program. You will be creating a program that simulates the sound of soldiers marching: “Left, Left, Left, Right, Left”. You will need one class to print “Left” and one to print “Right”, as well as a class to drive the program. LeftThread.java public class LeftThread extends Thread { public void run() { for(int i = 0; i < 10; i++) { //TODO: Print "Left" //TODO: Print "Left" //TODO:...
Java Programming Stacks Queues Linked List Programming Problems Stack - Implementation. You will be able to...
Java Programming Stacks Queues Linked List Programming Problems Stack - Implementation. You will be able to use the push, pop and peek of Stack concept. Post-Fix calculator - When an arithmetic expression is presented in the postfix form, you can use a stack to evaluate the expression to get the final value. For example: the expression 3 + 5 * 9 (which is in the usual infix form) can be written as 3 5 9 * + in the postfix....
Make each awswer as long as you can i would like most infomation you know anout...
Make each awswer as long as you can i would like most infomation you know anout 1-5 thank you Explain the following for each market structure example: 1. Why do you think each firm would be operating in that market structure? Justify your answer. 2. Would the different firms have market power or would they be price takers? 3. How is market structure determined? 4. How much product differentiation would each firm/industry use to market their product? 5. In which...
Description: Programming can be used to assist users in completing complex calculations very quickly. As seen...
Description: Programming can be used to assist users in completing complex calculations very quickly. As seen in class practices, we were able to calculate the area of geometric shapes, figure out the amount of calories in cookies, and even calculate a restaurant bill. For this assignment, you will take input from the user to provide interactive messages and to solve the following word problem: Engineers often need to convert between different types of units to perform calculations that follow standard...
MySQL data model: Netflix would like for you to build them a data model that tracks...
MySQL data model: Netflix would like for you to build them a data model that tracks the following information: Netflix would like to track the television shows that are watched by subscribers to the service. Subscribers of the service may watch more than one TV show. Shows may be watched by more than one subscriber. For television shows, they would like to track the episodes that comprise the show. Subscribers to the Netflix service watch episodes of various shows and...
Using C programming I have a file that contains earthquake data that I will copy and...
Using C programming I have a file that contains earthquake data that I will copy and paste below. I want to use either bubble or insertion sort to sort the file by latitude in ascending order, then create a new file containing the sorted data. I also want to do this program using multiple threads concurrently in order to speed up the sorting process. example file to sort: time,latitude,longitude,depth,mag,magType,nst,gap,dmin,rms,net 2020-10-17T17:22:03.840Z,32.877,-116.2991667,0.31,1.16,ml,21,119,0.07747,0.26,ci 2020-10-17T17:17:29.980Z,34.1611667,-116.452,2.75,0.87,ml,17,66,0.05224,0.22,ci 2020-10-17T17:03:54.460Z,33.5396667,-116.4613333,8.66,0.63,ml,18,126,0.06084,0.16,ci 2020-10-17T16:55:01.080Z,63.254,-151.5232,8,1.4,ml,,,,0.9,ak
Write an iterative algorithm in Java-like pseudocode for printing a singly linked list in reverse in...
Write an iterative algorithm in Java-like pseudocode for printing a singly linked list in reverse in O(N) time. You can use as much extra space as you need. The original list pointers CAN NOT BE MODIFIED. State in big-O notation how much extra space is used by this algorithm. Write another iterative algorithm in Java-like pseudocode for printing a singly linked list in reverse using O(1) extra space. The original list pointers CAN NOT BE MODIFIED. This algorithm can have...
Research and Discuss variables and data types. 1. What are the various data types you can...
Research and Discuss variables and data types. 1. What are the various data types you can use in C#, Explain memory sizes of these data types? 2. Discuss string variables. What does a string variable provide? Provide details. 3. Provide examples how you would create a values like "Sarah", 2, 3.50, and store into memory. For example, DataType VariableName = "Sarah".
Hello my name is Nartlada, i would like to know how can i create the histograms...
Hello my name is Nartlada, i would like to know how can i create the histograms from the number of the excel file. The question is asking "create histograms illustrating the distributions of the two temperature variables (T1 and T2). correctly the label the x and y axes and give your plot title. We are required to use R program that include the set working directory. I tried to drag the excel file to here or even drag just the...