Select and declare file structures to meet design storage requirements - java

If this was a question posted to you about a program you wrote what sort of response would they be looking for, quite a basic understanding coder.

Your question is not very clear, but it seems that you are being asked about what data structures you used that fit the given requirements in order to implement your solution (e.g., a hashtable, tree, etc.)

Related

Making Sense of the SurveyMonkey API JSON data returned from get_responses

I am tasked with creating a very similar output to the excel output that is generated from the SurveyMonkey application. Most of the answer-to-answer mapping is pretty straight forward, but mapping matrix type questions seems overly complicated. Has anyone come up with a reliable way to map this data in order to export it to a list-based response? The best thing I have come up with is building an in-memory tree mapping the collectors to respondents to questions to answers to (selected) answers.
To me, this seems like a lot of unnecessary mapping, and I'm just wondering if anyone has come up with a better way.
See the related question:
What are the expected values for the various "ENUM" types returned by the SurveyMonkey API?
I give a lot of skeleton VBA code at
Accessing SurveyMonkey API from VBA
Good luck
Patrick

When to use which Data Structure? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I am studying Data Structures in a Fundamentals of Software Development course. I have encountered the following data structures:
Structs
Arrays
Lists
Queues
Hash Tables
... among others. I have a good understanding of how they work, but I'm struggling to understand when and where to use them.
I can identify the use of the Queue Data structure, as this would be helpful in printer and/or thread queuing and prioritizing.
Knowing the strengths and weaknesses of a data structure and implementing it in code are different things, and I am finding the former difficult.
What is a simple example of the use of each of the data structures listed above?
For example:
Queue: first-in, first-out → used for printer queue to queue docs
I had trouble understanding them when i first started programming and so i decided to give a heads up to start with.
I am trying to be as simple as possible. Try Oracle Docs fro further details
Struct: When ever you need Object like structure, where you can group related data, use structs. Structs are very rarely used in java though(as objects are created in their place)
Arrays: Arrays are contiguous memory. when ever you want fixed time access based on index, unlike linkedlist, arrays are very fast and so use them.
But the backlog with arrays is that you need to know the size at the time of initialization. Also arrays does not support higher level methods such as add(), remove(), clear(),contains(), indexOf() etc.
List: is an interface which can be implemented using Arrays(ArrayList)
or LinkedLists (LinkedList). They support all the higher level methods specified earlier.
Also Lists re-sizes themselves whenever it is getting out of space. You can specify the initial size which the underlying Arrays or LinkedLists will be created, but whenever the limit is reached, it created the underlying structure with a bigger size and then copies the contents of the initial one.
Queue or Stack: is an implementation technique and not really a data structure. If you want FIFO implementation, you implement Queue on either Arrays or LinkedList(yes, you can implement this technique on both these data structures)
https://en.wikibooks.org/wiki/Data_Structures/Stacks_and_Queues
HashMap: Hashmap is used whenever you want to store key value pairs. if you notice, you cannot use arrays or linked lists or any other mentioned data structure for this purpose. a key can be any thing from String to Object(but note that it has to be an object and cannot be a primitive) and a value can also be any object
google out each data structure for more details
It depends on what you need. If you read and learn more about these data structures you will find convenient ways for their implementation.
Maybe read this book? http://www.amazon.com/Data-Structures-Abstraction-Design-Using/dp/0470128704
All these data structures are used based on their needs in the program. Try to find advantages of one data structure to the other. That should get things more clear for you.What I say wouldn't be much clear, but i'll give it a shot
Like for example,
Structs are used to create a data type, say you want to have a data type for Book & have the names of the bookBook Structure.
Lists are easier to access both ways if you use linked lists & are better than array some times. Queues, well, you can imagine them as real life queues, First In will be First Out. So you can use them when you need to set this priority.
Like I said, looking for advantages of one over the other should get things clear for you.

java embedded library on-disk key-value database [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 6 years ago.
Improve this question
What I think I'm looking for is a no-SQL, library-embedded, on disk (ie not in-memory) database, thats accessible from java (and preferably runs inside my instance of the JVM). That's not really much of a database, and I'm tempted to roll-my-own. Basically I'm looking for the "should we keep this in memory or put it on disk" portion of a database.
Our model has grown to several gigabytes. Right now this is all done in memory, meaning we're pushing the JVM for upward of several gigabytes. It's currently all stored in a flat XML file, serialized and deserialized with xstream and compressed with Java'a built in gzip libraries. That's worked well when our model stays under 100MB, but now that its larger than that its becoming a problem.
loosely speaking that model can be broken down as
Project
configuration component (directed-acyclic-graph), not at all database friendly
a list of a dozen "experiment" structures
each containing a list of about a dozen "run-model" structures.
each run-model contains hundreds of megs of data. Once written they are never edited.
What I'd like to do is have something that conforms to a map interface, of guid -> run-model. This mini-database would keep a flat table of these objects. On our experiment model, we would replace the list of run-models with a list of guids, and add, at the application layer, a get call to this map, which would pull it off the disk and into memory.
That means we can keep configuration of our program in XML (which I'm very happy with) and keep a table of the big data in a DBMS that will keep us from consuming multi-GB of memory. On program start and exit I could then load and unload the two portions of our model (the config section in XML, and the run-models in the database format) from an archiving format.
I'm sort've feeling gung-ho about this, and think that I could probably implement it with some of X-Stream's XML inspection strategies and a custom map implementation, but something a voice in the back of my head is telling me I should find a library to do it instead.
Should I roll my own or is there a database that's small enough to fit this bill?
Thanks guys,
-Geoff
http://www.mapdb.org/
Also take a look at this question: Alternative to BerkeleyDB?
Since MapDB is a possible solution for your problem, Chronicle Map is also worth consideration. It's an embeddable Java key-value store, optionally persistent, offering a very similar programming model to MapDB: it also via the vanilla java.util.Map interface and transparent serialization of keys and values.
The major difference is that according to third-party benchmarks, Chronicle Map is times faster than MapDB.
Regarding stability, no bugs were reported about the Chronicle Map data storage for months now, while it is in active use in many projects.
Disclaimer: I'm the developer of Chronicle Map.

Is this Java reply to a job questionnaire valid? [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I was asked this in WRITTEN form through a recruiter, with the previous question being string related, and the previous one being about Inversion of Control:
How would you find the second largest element in an array?
Being a Project manager who has is self teaching/learning JAVA, my response was:
How is large defined (integers? parsing of: strings/objects? ) How large is the array? Bubble sort , then return the second to last index. Temporarily store the largest and second to largest variable, sort through the array, replacing the appropriate variables, then return the second largest variable. There are many ways, however to develop an appropriate function that isn’t expensive would require more information. If the range is very wide, make several lean methods, measure the array length, and apply the appropriate method on the array.
Is this a valid response to the question, and if not, what do you think it needs improvement on? I'm asking this because of the extreme gap presented in the common recruitment atmosphere, and am having difficult understanding the actual intended purpose of similar structured questions, and need your feedback to understand what/how to approach/reply.
UPDATE I received notification that they typically see code, but provided no parameters or guidelines, and replied with this:
I can not provide a codified answer, not knowing at least the first two pieces of information. The first will allow for parsing, as numbers are sorted universally, while strings, objects, and others are parsed subjectively. The second part, dealing with the array length, and whether or not it is static, is definitely relavent as a developer, as expensive code (whether in computation time facing the user, or hardware costs to the client) can be costly. The question is worded poorly for an exact technical response, especially given that it is in written format, where there is no feedback. I am merely typing my considerations as a reply, the same as if it were asked in person. The context I am given from the previous questions is that they are looking for someone who understands IoC practices (bullet 3) and would be parsing Strings (given bullet 2) in potentially a transaction (try/catch) situation (bullet 4) and then find (current issue). If the questionnaire's purpose is to see how I approach a problem, then my response is valid. If they would like further clarification, I would be happy to accomodate, but if they are requiring a codified answer AND unwilling to provide the necessary context, then I am unwilling to work with them, as it would highlight there misunderstanding of how to interact with external customers, who DO need guidance when one "simple" question is asked, but other pieces of information are needed to best accommodate, the central reason behind any business seeking outside specialized help. I hope this response in not read in a harsh tone, as my cadence when replying out loud is quite the opposite, as further information is required, including if sole development in JAVA is within the scope of this job, as I am skilled in JS and Python as well, and this was not discussed yesterday. Hopefully you and your client can understand that with the recruiter method, a layer of abstraction can be beneficial in many areas, but in situations like this, it can hinder and cloud perceptions without direct communication and feedback. Please feel free to provide this in addition to my answer.
and received acclaim for this reply. Thank you for your help, as I am really trying to get a programming job, but have no prior formal experience and this guidance really helps.
In this case, I think the interviewer really wants to know in order to find 2nd largest element, does one have to sort the entire array(and pick the second element) or is there any better approach?
The answer is you don't have to sort the entire array in order to find top k elements. Sorting will take O(nlgn) time whereas finding top k items will take only O(nlogk).
You can explain the answer using simple example. If you have to find 2nd largest card in 100 cards with numbers ranging some low to high. The cards are not sorted. To find 2nd largest card, all of you have to do is hold top 2 cards that you have seen so far in your hand. As you pick new cards, see if it is larger than the one in your hand, if so replace the new largest with the smallest in hand. At the end of this process, you will end up holding top 2 cards.
EDIT: Like others said, bubble sort has worst runtime O(n^2). For fun, Check out President Obama's answer to sorting interview question. http://www.youtube.com/watch?v=k4RRi_ntQc8
The most efficient to do the needed task is obvious: iterate once on the array and looking for the "largest" element, all the while storing also the previous "largest" element. At the end of the array, your previous "largest" element is the one your method needs to return.
To formulate your answer, I see 2 choices:
Beginning your answer by "Assuming the array contains int elements..." or something approaching.
Using an undefined isLargest() or isLarger() method and explain that the purpose of the method is to check if the current element is largest currently examined, whatever it means.
This is pretty subjective, but frankly I agree with your question-about-the-question -- they should have defined what it is your array contains.
What you could have done is written something like "Assuming the elements in the array are all integers, here's how I'd do it" and then give your answer with that assumption.
I'd follow the same steps with your other requests for additional info -- make an assumption, declare your assumption, then proceed with that assumption in mind.
Seems valid - I just fear they wanted CODE. I think maybe you should have just assumed integers and written something IN ADDITION to what you said.
My initial gut reaction would be "Modified Merge Sort", implemented using a ForkJoinPool. It's still O(n log[n]), but the actual runtime would be faster than a serial implementation.
You may ask why not quicksort, and it's because worst case for quicksort is O(n^2), which would be bad for an extremely large dataset. Modified Merge Sort has more predictable performance and a better worst case scenario O(n log[n])

Good 15 minute Java question to ask recent college graduate [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
When interviewing college coops/interns or recent graduates it helps to have a Java programming question that they can do on a white board in 15 minutes. Does anyone have examples of good questions like this? A C++ question I was once asked in an interview was to write a string to integer function which is along the lines of the level of question I am looking for examples of.
Is there any reason why it has to be on a whiteboard? Personally, I'd rather sit them in front of a keyboard and have them write some code. Our test used to be a simple 100 (IIRC) line Swing text editor. We then broke it a few simple ways, some making the code not compile and some a little more subtle, and gave the candidates half and hour and a list of problems to fix.
Even if you can't have them do anything hands on make sure that you do give them some explicitly technical questions. In another round of interviews there were a surprising number of recent graduates who were just buzzword-spouting IDE-jockeys, so they could look OKish waving their hands around in front of a whiteboard talking about Enterprise-this and SOA-that, but when given a simple Java fundamentals multiple choice exam asking things about what final and protected meant did horrifyingly badly.
I've always thought that algorithmic questions should be language agnostic. If you want to test the java level of a student, focus on the language: its keywords (from common one like static to more exotic one, like volatile), generics, overloading, boxing/unboxing of variable, standard libraries.
Some stuff that has showed up on SO:
IsPalindrome(string s)
ReverseWordsInString(string s): "I know java" --> "java know I"
Other stuff that springs to mind:
multiply a Vector with a Matrix (can this be done OO-Style?)
echo (yes, a simple clone of the unix tool)
cat (15 min should be enough, should weed out the clueless)
a simple container for ints. Like ArrayList. Bonus question: Generic?
Write a function to swap variable values using pointers (Really poor ones will fall for this)
Write a program to find the distance between two points in the XY plane. Make use of a class to store the points.
Demonstrate the use of polymorphism in java using as simple program.
Write a program to print the first n prime numbers.
Write a program to replace a string in a file with another.
If you don't know what questions to ask them, then may be you are not the right one to interview them in Java. With all due respect, I hate when people ask me questions in interviews which they themselves don't know answers for. Answers for most of the questions can be found online by googling in a few secs. If someone has experience in Java, they will definitely know Abstract class, interface etc as they are the core building blocks. If he/she does not know 'volatile' keyword - big deal.
I agree with Nicolas in regards to separating the algorithmic questions from the actual language questions.
One thing that you might want to consider is giving them a couple simple algorithm questions that they can write up the pseudo code for on the white board (ex. "Explain to me the Bubble sort and show me the pseudo code for it."
Then once they have demonstrated their algorithmic knowledge you can move on to the Java questions. Since some people work better in front of a computer than in front of the whiteboard, I would give them something simple, but leveraging their knowledge of Java, that they can implement in 30 minutes or so in using the same IDE that you are using at the company. This way if they claim to know the IDE you can also get an idea of how well they know it.
Write a function that merges two sorted lists -- stopping at limit. Look for the easy optimizations and correct boundary checks / sublist calls. Tell them T implements compareTo.
public List<T> merge(List<T> one, List<T> two, int limit)
Write a function that returns true if any two integers in the array sum to the given sum. Have them try to do better than n squared using some sort of set or data structure.
public boolean containsSum(int[] nums, int sum)
I would avoid asking them questions that would have been covered in their undergrad classes. I would be more curious about their ability to apply everything they've learned to solve complex technical problems. If your business has a specific need for an IT solution you could use that as a starting point. You could ask the candidate what technologies they would use and the pros and cons of using those technologies versus alternate technologies. As the discussion progresses you could get a feel for their technical skills, problem solving skills, interpersonal skills, etc. I think it is important to avoid coaching them, even in awkward moments. This is important to weed out the BSers.

Categories