Home » Programming Languages » Page 1

I have to sort a set of 100000 integers as a part of a programming
Q. The time limit is pretty restrictive, so I have to use the most
time-efficient approach possible.

My current code -

using namespace std;

int main() {
int n,d[100000],i;
for(i=0;i<n;++i) {

Would this approach be more efiicient?

int main() {
int n,d[100000],i;
for(i=0;i<n;++i) {

What is the most efficient way to sort a large dataset?

Note - Not homework...

I know that profiling is useful to identify bottlenecks and
determining what parts of the code require how much time to execute.
The latter isn't always very easy to track in the midst of other paths
being executed, so once I decide what I want to optimize it might be
problematic to see the improvement in numbers. This is especially true
in desktop apps which run constantly and it is difficult to: execute
the same path and execute it the same number of times to have reliable

It won't help me if before optimization the function ran X times
and took 500 milliseconds, and after optimization it run Y times and
took 400 milliseconds.

In such cases, can I somehow use a profiler to determine
improvement or do I have to resolve to other options?

I'm following this tutorial: href="http://wiki4.caucho.com/Building_a_simple_listing_in_JSP"
It creates a basic web application in Eclipse using the MVC pattern
with Resin as the web container. Here's the part I don't understand.

For the model, it creates a POJO, Interface and Interface
Implementation. The data represents a Book. When we get to the
controller, it creates a simple servlet. It calls the interface
instead of the interface implementation. How does the interface to
execute the implementation class? Also what if there were two impl
classes, how would the interface know which to call?

I am trying to learn webdesign using the MVC design pattern. Right
now, I am stuck at a point where my code gets more complex, and I am
unsure about the structure and where to put which code parts.

I started with an index.php file as my controller, which right now
does not much more than loading the Slim framework to render the
different views

$app->get('/', function() use ($app){  

Then I built a complex content.php where I do a lot of form data
reading from a server directory, and echoing the results mixed with
html tags. That surely will violate the MVC pattern, right?

What is the general approach to this? Should I put all the logic
inside the index.php, store the results in an array, and pass that to
the framework's render function, like this:

$app->get('/', function() use ($app){ 

//Do something and store results in an Array

$app->render('header.php', anArray());
$app->render('content.php', anArray());
$app->render('footer.php', anArray());

How can I prevent index.php becoming too complex when doing so? Is
there a different approach to take?

Often DIP is known as the Hollywood principle: "Don't call us,
we'll call you.".

But doesn't always higher level module calls lower level module,
whether there is dependency inversion or not?

Then why is DIP called the Hollywood principle?

Am I missing something? Thanks!

There are a couple of answers on SE comparing single-row table vs.
name-value-pair table used for config settings, but I haven't seen
anyone arguing for using XML (or JSON) as a name-value pair

Option A

UserID     AppID     ParamID    Value
1 1 10 5.40
1 1 11 John Smith
2 1 10 4.40
2 1 11 Jane Smith

Option B

UserID     AppID     Settings
1 1
2 1

Option A is plain key-value pair solution, and Option B uses only
one serialized XML settings per user/app.

Is there any value in using XML instead of a plain key-value

If I'm starting a new JVM project and need a particular section of
code to be really fast, should I write it in a naively compiled
language or just let the JIT handle things?

What is even the point of the href="http://docs.oracle.com/javase/7/docs/technotes/guides/jni/"
rel="nofollow">JNI if the href="http://docs.oracle.com/cd/E15289_01/doc.40/e15058/underst_jit.htm"
rel="nofollow">JIT compiler exists?

I am doing some research on how to write a Minecraft server wrapper
program. Right now I run a minecraft server with the
minecraft_server.jar file from Minecraft.net. When I want to execute
complex commands I usually draft them in a text editor and copy and
paste them into my Mac's terminal where the server is running. This
more tedious than I would like it to be, so I have decided to see if
it would be feasible to write a program that will run the server and
read to the server commands that I have composed in a file. I think
this is basically like enabling me to make scripts for my server.

Here is an illustration of the basic idea. I would communicate with
the server wrapper program, and the server wrapper program would
communicate with the server sending it my commands and also running
scripts of commands for me.

src="http://i.stack.imgur.com/nXvOv.png" alt="communication

Here is a sketch of the GUI I would like to build. It would show
the normal server output which currently is fed to the console window
running the server. It also has a field for allowing me to run
commands as usual. Next there is a selectable list of scripts, a
button that prompts the user for a script, and a button that will run
the selected script.

src="http://i.stack.imgur.com/R9jCK.png" alt="GUI layout">

There may be programs out there on the internet that already do
this type of thing, but I am interested in writing this to practice my
programming/Java skills. Some classes that I think I will be using are
JFrame, other Swing stuff,
and others.

Write now I have three classes:

  • MinecraftServerWrapper,

  • ServerOutputThread, and

  • ServerInputThread.

MinecraftServerWrapper is the main class which uses
ProcessBuilder to execute minecraft_server.jar,
then it creates a ServerOutputThread instance and a
ServerInputThread instance which take in the process and
access its input and output streams to read from
System.in and write to the server's input stream and take
the server's output stream and writes it to System.out.
My next step is to send that output to a GUI and be able to use the
GUI to send the input to the server.

Question: I am primarily concerned about how much this
kind of application can handle, i.e., how long of scripts could it
handle at once. Does this approach seem reasonable, or does it seem
like I might be missing something conceptually?

I am looking for an efficient algorithm to find the k'th minimum
element in an unsorted array of n elements, where 1 <= k
<= n
. The obvious thing is to sort the array first, then
pick the k'th element, which will result in a running time of
O(n * log(n)) But I guess it can be done in a more
efficient way, since sorting the array seems to do "too much". For
example, for k=1 the task is to find the minimum of the array, which
can be done in O(n).

Does anyone know a better algorithm for k>=2?

I am currently working on JavaEE application (Spring, Hibernate). I
have to put a big XML file (more than 1 gigabyte) on a relational
database (Postgres).

The application does not use batch processing. I've done some
searching but I did not find any solution for the design of the DAO
layer: if I use only one transaction, the server will not response to
any request until it finishes the insertion of rows (a huge number of
rows). So, using 1 transaction is not a good idea.
I can split XML file basing on its tags data: every tag content will
be inserted on a row.
The idea is to use multithreading to manage transactions (every
transaction inserts a defined number of rows).
I have found a difficulties to would know how to define the necessary
number of transactions to maintain a good time response of the
application. I also search how to manage failure of certain
transactions. For example, If only 3 transactions write over 1000000
fail, I should try again all the transactions?

When searching, I find that batch processing like Spring batch
manages database records and transactions failure. But in my
application, we did not use batch processing.

Unfortunately, I can not change the database to Nsql database or
add Spring Batch framework to the project.

- Technology - Languages
+ Webmasters
+ Development
+ Development Tools
+ Internet
+ Mobile Programming
+ Linux
+ Unix
+ Apple
+ Ubuntu
+ Mobile & Tablets
+ Databases
+ Android
+ Network & Servers
+ Operating Systems
+ Coding
+ Design Software
+ Web Development
+ Game Development
+ Access
+ Excel
+ Web Design
+ Web Hosting
+ Web Site Reviews
+ Domain Name
+ Information Security
+ Software
+ Computers
+ Electronics
+ Hardware
+ Windows
+ C/C++/C#
+ VB/VB.Net
+ Javascript
+ Programming
Privacy Policy - Copyrights Notice - Feedback - Report Violation 2018 © BigHow