Testing takes time, but one simple test can find a lot of problems like fake sticks. Just write the three byte pattern 0x55AAFF over and over, and then verify it. If it is a fake stick, the 3 byte pattern will go wrong. To speed writing an checking, you can extend the 3 byte block to 24 bytes so 8 byte writes can be used.

If that works, do again with a 1 and then 2 byte stagger in the pattern, so all bits are tested both ways with adjacent bits opposed.

Writing and reading a 32G stick 3 times takes quite a while. Frauds depend on this to mask their faking!

From the bubble sort you can evolve to many other in memory sorts.

A simple speedup would be to use bisection search the sorted list for the insert point.

One that works well to optimize cache locality of reference is to consider the array as n sorted lists of 1 item, merge the list in a binary fashion, 1 to 2, 3 to 4, 1+2 to 3+4, 5 to 6, 7 to 8, 5+6 to 7+8, 1+2+3+4 to 5+6+7+8, .... You can use the current count bits to tell you what to do next. Since you are referencing small sets then larger, doubling as you go, it gracefuly shifts from l1 cache speed to l2 cache speed to RAM row-page speed to RAM many-row speed to disk (VM) speed.

Other sorts exploit sorted data well, treating input a n sets of sorted data to be discovered, then merged, on disk/vm perhaps shortest to longest, so you merge to long sets the least number of times. If the data is sorted, that is discovered on the first pass. If the data is one item and a sorted list of n-1 items, finding the insertion point serially is costly.

In practice, all systems have APIs available that sort, such as the tree list tsearch() http://linux.die.net/man/3/tsearch, qsort() http://linux.die.net/man/3/qsort or OO containers that sort like JAVA TreeMap Class Template https://docs.oracle.com/javase/7/docs/api/java/util/TreeMap.html or C++ STL map: http://www.sgi.com/tech/stl/Map.html

You can also popen() http://linux.die.net/man/3/popen a sort http://linux.die.net/man/1/sort and let it do the heavy lifting. You can have the ...

When you talk about executing code, php loads the server but ecmascript loads the clients, which is better for scaling. However, you have to cost out the amount of code and supporting data you are shipping, for cpu speed is still much cheaper than bandwidth.

Print %, as 100*(sorted size/total size)^2, since simple bubble sort effort is n^2 scaled.

You are writing an HTML page with your web service. Suppose the jpg file is in the web subtree, one way or another, and the web root relative path is in the database column. When composing the web page for such a situation, you need to create an element to make the browser fetch the jpg file, perhaps with something like this in SQL:
'<img src="' + rtrim(column) + '" alt="column_name" ... >'
Of course, options in the (alt="column_name" ...) are up to your needs. I am a big fan of 'width="xx%"'; it works on all devices.

Now, if the file is outside the web root subtree or elsewhere, you need to have a server of some sort to fetch it and create a fuller corresponding URL for the src attribute. It could be anonymous ftp, http, or whatever else browsers speak. If the database column value is the locally valid URL, the above works no matter where the file is. If the database column just has the base file name, you need to add prefixes to make it a valid local URL in the above. For instance "http://other_host/images_path/xxx.jpg" is a valid URL anywhere, being absolute, but "/images_path/xxx.jpg" is only a valid local URL for files in this local web server root subtree. If your database column just has "xxx" or "xxx.jpg", you need to provide the "http://other_host/images_path/" or "/images_path/" prefix in the constant string above, and for "xxx" a '.jpg' suffix.

Location as URL or path on server? You need to query it as a URL inside an to get the browser to pick it up. You might need to create a service to get the file from path to URL, if it is a path. If you want to serve the image directly, you need to open the file and copy it to the browser socket after the http header that says it is content type image/jpg. It'd be nice to fetch the file size so the header can specify the size, but EOF on a simple socket is usually sufficient. For persistent connection http/1.1, length is probably mandatory.

Why the .strWhere, when 'where ... between' already in SQL? Is it just a title, since it is not a legal SQL 'IN'? Id the input date in a form native to this SQL engine? Try "YYYY-mm-dd HH:MM:SS.ssssss" (ISO date).

It seems you have the deck be any stack of cards, and many decks, so it is hard to tell if all cards are still in some deck. Shuffling is faster/free of dups if you rand times numner of cards left to pick the next card from a deck originally in some normal order. You could track cards as being in the supply pile, discard, or player hand 1 to N, all in one container. While your decks are tied to each other linked list, they are arrays. Since you need to adjust decks a lot, you might make the decks linked lists of cards, and the list of decks an array: 0=pile, 1=discard, 2=played, 3-N = player hands or some pointers and an array. The cards played onto the table might just be a separate list, as you need to know who owns what but they all end up in the discard, for a tricks sort of game.

Excel stores dates as floating point days since their epoch 1900 (not the unix 1970 epoch in seconds). Some adjustment is required, both in scale and in offset. You don't need a date diff tool, just the right constants for multiply (86400 sec/day) and subtract (days, 1900 to 1970 = 2208988800/86400).

You could create an "insert ... select ... union select ... union select ...." from your array within batch and statement size limits. The pipe and file input methods are more for ETL situations. The biggest challenge of RDBMS is getting stuff in! A bcp to a staging table in tempdb (global named or by bcp calls within the same session) is also very fast, but again, very ETL oriented.

For C I/O in a line oriented text milieu, fgets() is fine: returns null on error or EOF, is supported by ferror(), perror(), feof() (not necessary, as if a null return is not an error, it is EOF). The only caveat is that you need a long line detection, which can simply be that if the last byte of your buffer is set to null and the prior byte is not a linefeed, your buffer was too short for the line, and you have just the first part of the line. How you handle that is policy: ignore, error out or realloc() a bigger buffer and fgets() on top of the trailing null byte for additional space plus 1.

Yes, much faster. It depends on a client running on the same box as the RDBMS, so the local file or pipe can be opened and read in the database engine by the UDF. The UDF opens the file, and calls to the UDF determine if the file has delimited lines or fixed length records and fields. The selection of fields by length for fixed files has the side effect of allowing substringing of delimited fields, as the former is treated as a one delimited field record. A UDF call in the where clause reads the next record or stops the insert at EOF.

This was a very similar technique to the mapping of files as tables, such as in Oracle.

We configured our RDBMS with a flat file or pipe as a selectable table, so we could do an insert-select and just write to the pipe all the data we wanted to insert. We did this with the combination of UDFs and a stored procedure that generated the rows. Each UDF call would take the next cell from somewhere in the input record based on the call's input parameters. The insert rate was way above other methods.

Now, if stdin is a pipe or such, a read() too big will stall, so many apps read() one byte at a time to get earlier access to input.

Well, popen sort is text oriented, simplest, no struct or linked list or such. A qsort can do arrays. Make sure the text is nicely formatted as output, padded to standard length with *printf() or the like.

Of course, the error is pointing to your header line, which is not the mormal line. Did you want to concatenate the constant 'content-type:' with the variable string $rec[2]? http://php.net/manual/en/language.operators.string.php says try:

header( "content-type:" . $rec[2] );

Semicolons also seem to be missing, as mentioned above. Linefeeds are not so magic in webby languages.

So is N2 a child of N1 ? No facility for siblings, half-siblings, step-siblings, adopted siblings?

What is sorted order? Depth or breadth walk first?

The real trick is deciding wht the prof wants. Reality is secondary in school, interviews and under tech managers with high self esteem.

You need to define sl, such as a table of the from clause: ... from tbl_files sl where sl.no = ...

Not sure what sort of database structure mysql allows you to refer to without a from clause anchor. If sl is a column of some advanced datatype, then I suppose you could dot into the innards.

Every read overwrites the prior read. Try read and print. Does read() the method produce a null term string, or return a size somewhere?

http://www.cplusplus.com/reference/istream/istream/read/ inherited from
http://www.cplusplus.com/reference/fstream/ifstream/

No, no, so I would avoid it, or use the supporting calls that tell you what will be read. How were the names 'framed'? In binary, you make the protocol. Maybe no loop, just read that size chunk. Maybe verify that size is available. Otherwise, size is your caller's problem. Since you open every call, only good for reading first bytes of the file.

You never defined 'sl'.

You can sort as you go, manually or using a sorted container like tsearch, or sort later, like with qsort() or popen( "sort", "w" ).
http://linux.die.net/man/3/tsearch
http://linux.die.net/man/3/qsort
http://linux.die.net/man/3/popen

You can also exit a loop (and subroutine) with a raised exception that is caught by a specialty handler 'upstairs', which is closer to the setjmp/longjmp() of C (which essentially readjusts the stack pointer and program counter as if you had returned and then done a goto).

Good formatting is very supportive of both review, debug and future maintenance. You, too, deserve cleanly formatted code. I like to put one boolean predicate on a line, indented, use parentheses even if unnecessary due to operator priority, use curly braces always. White space is cheap, errors are costly. Of course, complete error checking is also helpful in debug! I often set complex constructs like if off with blank lines, so only one line commands are stacked tight. I like to set off declarations from conmmands with a blank line, and generally declare at the head of a curly brace as required in C, just to keep C++ and JAVA declarations easy to find and not mixed with commands. This does not preclude nice things like late model JAVA "for (type x : type_name[] )", where the declaration is essentially local to the following loop body.

A simple way to design a loop is to continue until you are about to repeat a step, and then add the loop and adjust any calculations for changing variables within the loop. Next, decide where to exit and insert an "if ( conditons ) break, goto or return".

Be careful you are not in a 'switch-case' (great for comment documentation of logic) within the loop, as 'break' is now overloaded to serve it, but a 'goto' or 'return' has no such limitation. The 'goto' is not as clear and maintainable way to loop or exit a loop, so it is strongly depricated, if allowed in the language at all, but in essence the compiler turns the higher loop constucts into 'if' and 'goto'.

Now, if the loop is not always entered even once, a 'for' or 'while' might be a good control, as they test before the loop. If the test is at the end, then it is naturally a 'do-while'.

In actual practice, the discovered optimal loop is actually an unconditional 'do-while' or 'while' with a conditional break/return in the middle. For instance, in selecting multiple database rows, after the row fetch one discovers no row was fetched as the cursor is exhausted (empty). Sadly, sometimes steps are repeated to make a loop fit a 'while', 'for' or 'do-while' form, which partially defeats the economy of the loop. Of course, an optimizing compiler may unroll the loop for better speed, in which case the value of the loop ...

Consider a proposed short booking sliding down the schedule (forward in time) across a prior booking. The collison begins when the end date-time of the proposed exceeds the start date-time of the prior, and continues as the proposed is slid forward in time until the start date-time of the proposed equals or exceeds the end date-time of the prior.

If you have a reservation id, why do you need any other keys?

The quicker query is where . . . testing_start <= book_end and testing_end >= book_start. This covers bookings that are within, without, overlapping start, overlapping end and identical. Since end is always > start, this takes care of it all. No between, simpler, better for index use (range scan).

If you insert your booking with such a where, the atomic nature of insert precludes the need for a transaction. If the booking is tenative, you might want to have an indexed flag or expire date, so a periodic scan can remove them even if the booking is abandoned in the middle. The same scan might archive/delete/move history, so the next exporations are at the nose of the index, making the check very cheap and fast.

Some sort of cache of recent images would allow images not immediately used to be reused without reload/new. It could include images in use so they can be used many places, too.

You are talking about keeping the book, just like a stock exchange or a hotel clerk. The book is a durable database of rooms and for each room, an ordered list of times booked. The book needs to be cleaned periodically to remove/archive expired data. The book needs locks so only one user can update a room at a time. If you organize time into blocks, like hours for the next 2-3 months, you can lock hour by hour, or just lock by room, or you can simply lock the whole for every update, or use a single updating thread that reads an ordered, multiple access message queue. How much churn bandwidth do you need? How much query bandwidth? You might need to segment the database for high activity levels, to multiply the max bandwidth using separate resources for each segment. First, tune up your requirements.

Your first question is, is this a stateless server? In a stateless server, the storage of all intermediate state is achieved by sending it back to the client, which reiterates it on the next service request, like with browser cookies or embedded variables in dynamically generated response forms.

The stateful server needs to assign a state container with each connection, where the progress of that connection (session) is stored. These container could be created and destroyed or precreated empty and disconnected, used and then cleaned for reuse.

You need to design how the server will filter the client input against the session state, and how it will deal with invalid responses.

There should be logging of progress and errors of every session, so the app can be debugged and later production supported. The log should be easy to sort and filter for each session, one at a time in order. Since many sessions may simultaneously share the same log, all logging must be in full lines!

UDP is connectionless, so you need to create virtual TCP connectivity in your session state, to deal with lost packets and broken connections: keep-alive packets, client packet timeout, last packet storage for retransmisson, client session timeout. Even at close, you must preserve the session in case a retransmission is needed of the last packet. You have to write the protocol under UDP to make it into TCP! Steal! On the plus side, one thread and one socket can service infinite clients, as life is ...