Average Case Flashcards
What is the intuition behind average case algorithms?

What is the definition of Expectation of variable T?

Find the expectation of T for the following:


Find the expactation of the following:


What is a Randomized Algorithm?

What is the randomized algorithm type: Las Vegas?
What is an example of this algorithm?

What is the randomised algorithm type; Monte Carlo?

What are the advantages/disadvantages of randomized algorithms in general?

What are the advantages/disadvantages of Las Vegas algorithms?

What are the advantages/disadvantages of Monte Carlo algorithms?

Why does it make more sense to think about expected time instead of worst-case time for Las Vegas algorithms?

In general, how is MySQL used in PHP?

What are JSPs?
For scripting languages in general, what benefits that does provide?
Java Server Pages (JSP):
Like PHP, JSPs consist of static elements (normally text and HTML) and JSP “Elements” that generate dynamic content.
JSPs provide:
- Language for developing text-based pages that describe how to process a request to create an HTML response
- A means of accessing server-side objects
- to provide a means of generating the dynamic content using information nt directly avail to the JPS
- A mechanism for extending the JSP language
- Which helps simplify repeated taskss and for future evolution of JSP technology
Which means:
- Separates the “user interface” (html) from content generation (script code)
- so we can change the page layout without changing code generating the dynamic content
- easier and faster development of web applications
- Decreased maintenance effort for web applications
- hence lower cost, more reliable
What tags enclose a Java expression that is to be evaluated for JPS?
The time is
JSP support the embedding of short sequences of Java code, what do we call them?
What tags are used ot do this?
Called “Scriptlets”, these are embedded in HTML pages
Done with the tags (not that the ‘=’ sign is missing)
The time is:
NOTE: The declaration persists across tags
In general how would JSP be used to access submitted form data?
request.getParameter(“fname”) %>
The object request is built into JSPs and refs to the HTTP request recived by the webserver from the web browser (which contains the form data).
With JSPs and declarations, what does one need to remain mindful of?
Declarations are only processed once
Any declared data must be guarded to prevent invalid concurrent access
- because there are multi-threaded
- access must be synchronized
How would you use JSPs to include another page?
could have body here
This is an example of using predefined tags
What are ASPs?
Active Server Pages
- This is mircrosoft’s JSP “equivalent”
- Capabilities of JSPs and ASPs are very similar
- JSPs are tied to java, ASPs are more flexible
- ASP.net allows any .net language
What is required of the web server to run ASP scripts
An ASP-enabled web server supports the execution of server-sive ASP scripts
Such a server will invoke the ASP processory whenever a file with a .asp sufffix is encountered
- These need to be in an ASP enabled folder
In the ASP “Programming” model, what objects are available for use in ASP scripts?

At it’s most basic level what is the ASP Application object?
It represents the entire web application, conisisting of the various pages and associated scripts
It is initialized by the web server when the first client requests a related file
There is only a single Application object for a given application running on a server (even if there are many users)
- which of course would allow for sharing of information between clients
What is an Application object’s physical manifestation?
All the .asp files in it’s corresponding [virtual] directory
- virtual directory = the directory name as viewed by the suers of the system via the web
- A web server often maps from a virtual directory to a different physical directory
- /images to /etc/httpd/images
- A web server often maps from a virtual directory to a different physical directory
Each Application object maintains colelctions of application-level variables and objects that have been added to it.
How are they accessed?
Collections are essentiall object-based associative arrays
Application.Contents - contains the share variables
Application.StaticObjects - maintains the object references
Elements in collections can be manipulated by it’s position index or the associated key
- Assignment
- Application.Contents.Item(“pi”) = 3.14
- Reference
- pi=Application.Contents.Item(“pi”)
- pi=Application.Contents.Item(7)
- Or using the shortcut
- Application.contents(“pi”)
- Application(“pi”)
Application.Contents contains the shared variables, because they are shared what do we need to implement?
Synchronization
- Application.lock
- Application.unlock
Note: this locks the ENTIRE contents of the collection so perfman hit can be VERY HIGH
Example below:

In HTTP the Request and the Response are actually objects.
Request provides access to all the information contained in the HTTP request.
The Request object maintains this information in a number of collections.
What are the collections of interest to us?
Request.Form
Request.QueryString
Request.ServerVariable
Request.Cookies
What does the collection Request.Form contain?
How do you access this information?
contains all the information about the parameters recieved via an HTTP POST request.
Request.Form.Item(“fname”) - to get the string entered on the form in the input field with the name “fname”
or, more commonly Request.Form(“fname”)
What is contained in the collection Request.QueryString?
How is it accessed?
Request.QueryString contains all the informatuon about the parameters recieved via an HTTP GET request.
Accessed by:
Request.QueryString(“fname”)
or Request.QueryString.Item
What collection does Request.ServerVariables contain?
How is it accessed?
Contains all the information about the server’s environment variablles that pertain to the current HTTP request.
There’s a huge list but here are the most important ones:

What does the collection Request.Cookies contain?
Contains all the information about any cookies recieved from the webclient application
Cookies: Are a means by which per-client information can be maintained over time
- Because web servers are stateless, so the state (or data state) is stored at the client in cookies.
In general what does the Response object allow you to do?
Allows your ASP script to send its response back to the web client.
Allows you to control:
- HTTP response message headers
- HTTP response message body
- when and how the response is sent
What are the most important properties (not methods) in the Response object?
- Response.Buffer - wether the response is to be buffered or sent to the client as generated
- useful when sending large responses such as images, sound files
- Response.Expires - Content expiry time
- Response.CacheControl - Cache control
- Response.Cookies.Item - cookies
What ar ethe methods defined for the Response object?

What is the ObjectContext object and what does it provide?
Provides for “transactional execution”
Transactional Execution: guarantees tha either all parts of the “transaciton” complete successfully or none of the affects of any of the parts are applied (“ACID properties”)
- Technically what normally happens is that completed partial-effects are undone
What is transactional execution useful for, provide an example

How does the code work for ObjectContext to ensure transactional execution?
To indicate the code that should be transcation is set by:
In these script you explicitly test by use of:
ObjectContext.SetAbort - if one fails
ObjectContext.SetComplete - after the final one succeeds.
You must specify code to be executed when a transaction aborts or completes
OnTransactionAbort( )
OnTransactionCommit( )
What is the Session object and what does it provide?
Provides a way for per-user interaction information to be stored
- shopping carts as an example
What is the Server object and what does it provide?
It acts as a catch-all for various additional capabilities
Server.ScriptTimeout : used to limit execution time of the corresponding script
- Used to prevent rougue scripe code consuming too much of a server’s resources
- which is a simple DNS attack
It also provides the attached methods/abilities:
