Algorithm Part 1

mutex

semaphore

Abstract Factory is a super-factory which creates other factories (Factory of factories).
An application usually needs only one instance of the Concrete Factory class per family product. This means that it is best to implement it as a Singleton.

Command pattern

The Command pattern allows requests to be encapsulated as objects, thereby allowing clients to be parameterized with different requests. The “check” at a diner is an example of a Command pattern. The waiter or waitress takes an order or command from a customer and encapsulates that order by writing it on the check. The order is then queued for a short order cook. Note that the pad of “checks” used by each waiter is not dependent on the menu, and therefore they can support commands to cook many different items.

The mediator object: encapsulates all interconnections, acts as the hub of communication, is responsible for controlling and coordinating the interactions of its clients, and promotes loose coupling by keeping objects from referring to each other explicitly.

Mediator and Observer are competing patterns. The difference between them is that Observer distributes communication by introducing “observer” and “subject” objects, whereas a Mediator object encapsulates the communication between other objects. We’ve found it easier to make reusable Observers and Subjects than to make reusable Mediators.

An ArrayList, or a dynamically resizing array, is an array that resizes itself as needed while still providing O(1) access. A typical implementation is that when a vector is full, the array doubles in size. Each doubling takes O(n) time, but happens so rarely that its amortized time is still O(1).

What is the running time of this code?

O(n^2) where n is the number of letters in sentence. Here’s why: each time you append a string to sentence, you create a copy of sentence and run through all the letters in sentence to copy them over. If you have to iterate through up to n characters each time in the loop, and you’re looping at least n times, that gives you an O(n^2) run time. Ouch!

you should not allow an ill-behaved client to ruin a server. You want to isolate failures from one module to the next, so that a failure in one module can’t break a second module. It’s a defense against intentional failures, as in hacking. And more commonly, it’s a defense against sloppy programming or against bad documentation, where a user of some module doesn’t understand his responsibilities in terms of modifying or not modifying some data object.

 

Leave a Reply

Your email address will not be published. Required fields are marked *