<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Learn Software Development &#187; Algorithms</title>
	<atom:link href="http://learnsoftwareprocesses.com/category/algorithms/feed/" rel="self" type="application/rss+xml" />
	<link>http://learnsoftwareprocesses.com</link>
	<description>All about the processes involved in software development</description>
	<lastBuildDate>Sun, 20 May 2012 19:17:40 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>First-Come-First-Served (FCFS) Scheduling</title>
		<link>http://learnsoftwareprocesses.com/2009/08/25/first-come-first-served-fcfs-scheduling/</link>
		<comments>http://learnsoftwareprocesses.com/2009/08/25/first-come-first-served-fcfs-scheduling/#comments</comments>
		<pubDate>Tue, 25 Aug 2009 14:52:34 +0000</pubDate>
		<dc:creator>ashish</dc:creator>
				<category><![CDATA[Algorithms]]></category>
		<category><![CDATA[Benefits]]></category>
		<category><![CDATA[FCFS]]></category>
		<category><![CDATA[Algorithm]]></category>
		<category><![CDATA[CPU]]></category>
		<category><![CDATA[First-Come-First-Served]]></category>
		<category><![CDATA[Process]]></category>

		<guid isPermaLink="false">http://learnsoftwareprocesses.com/?p=315</guid>
		<description><![CDATA[<p>First-Come-First-Served algorithm is the simplest scheduling algorithm is the simplest scheduling algorithm. Processes are dispatched according to their arrival time on the ready queue. Being a non-preemptive discipline, once a process has a CPU, it runs to completion. The FCFS scheduling is fair in the formal sense or human sense of fairness but it is [...]]]></description>
			<content:encoded><![CDATA[<p>First-Come-First-Served algorithm is the simplest scheduling algorithm is the simplest scheduling algorithm. Processes are dispatched according to their arrival time on the ready queue. Being a non-preemptive discipline, once a process has a CPU, it runs to completion. The FCFS scheduling is fair in the formal sense or human sense of fairness but it is unfair in the sense that long jobs make short jobs wait and unimportant jobs make important jobs wait.<br />
FCFS is more predictable than most of other schemes since it offers time. FCFS scheme is not useful in scheduling interactive users because it cannot guarantee good response time. The code for FCFS scheduling  is simple to write and understand. One of the major drawback of this scheme is that the average time is often quite long. </p>
<p>CHARACTERISTICS :<br />
o Non-preemptive.<br />
o Ready queue is a FIFO queue.<br />
o Jobs arriving are placed at the end of queue.<br />
o Dispatcher selects first job in queue and this job runs to completion of CPU burst.</p>
<p>Advantages:<br />
- Simple.<br />
- Low overhead.<br />
Disadvantages:<br />
- Inappropriate for interactive systems.<br />
- Large fluctuations in average turnaround time are possible.</p>
<p>Example :<br />
Process	Burst Time<br />
P1	24<br />
P2 	3<br />
P3	3<br />
Suppose that the processes arrive in the order: P1 , P2 , P3.<br />
Waiting time for P1  = 0; P2  = 24; P3 = 27<br />
Average waiting time:  (0 + 24 + 27)/3 = 17</p>
<p>Suppose that the processes arrive in the order P2 , P3 , P1.<br />
Waiting time for P1 = 6; P2 = 0; P3 = 3<br />
Average waiting time:   (6 + 0 + 3)/3 = 3<br />
Much better than previous case.</p>
<div class="addthis_toolbox addthis_default_style " addthis:url='http://learnsoftwareprocesses.com/2009/08/25/first-come-first-served-fcfs-scheduling/' addthis:title='First-Come-First-Served (FCFS) Scheduling '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_button_google_plusone" g:plusone:size="medium"></a><a class="addthis_counter addthis_pill_style"></a></div>]]></content:encoded>
			<wfw:commentRss>http://learnsoftwareprocesses.com/2009/08/25/first-come-first-served-fcfs-scheduling/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Overview Of Mutual Exclusions in Operating Systems</title>
		<link>http://learnsoftwareprocesses.com/2009/08/25/overview-of-mutual-exclusions-in-operating-systems/</link>
		<comments>http://learnsoftwareprocesses.com/2009/08/25/overview-of-mutual-exclusions-in-operating-systems/#comments</comments>
		<pubDate>Tue, 25 Aug 2009 14:29:40 +0000</pubDate>
		<dc:creator>ashish</dc:creator>
				<category><![CDATA[Algorithms]]></category>
		<category><![CDATA[Deadlock]]></category>
		<category><![CDATA[Mutual Exclusion]]></category>
		<category><![CDATA[Resources]]></category>
		<category><![CDATA[Algorithm]]></category>
		<category><![CDATA[Deadlocks]]></category>
		<category><![CDATA[Lock]]></category>
		<category><![CDATA[Mutex]]></category>
		<category><![CDATA[Mutual Exclusions]]></category>
		<category><![CDATA[Unlock]]></category>

		<guid isPermaLink="false">http://learnsoftwareprocesses.com/?p=313</guid>
		<description><![CDATA[<p>A way of making sure that if one process is using a shared modifiable data, the other processes will be excluded from doing the same thing. Formally, while one process executes the shared variable, all other processes desiring to do so at the same time moment should be kept waiting; when that process has finished [...]]]></description>
			<content:encoded><![CDATA[<p>A way of making sure that if one process is using a shared modifiable data, the other processes will be excluded from doing the same thing.<br />
  Formally, while one process executes the shared variable, all other processes desiring to do so at the same time moment should be kept waiting; when that process has finished executing the shared variable, one of the processes waiting; while that process has finished executing the shared variable, one of the processes waiting to do so should be allowed to proceed. In this fashion, each process executing the shared data (variables) excludes all others from doing so simultaneously. This is called Mutual Exclusion.<br />
  Mutual exclusion (often abbreviated to mutex) algorithms are used in concurrent programming to avoid the simultaneous use of a common resource, such as a global variable, by pieces of computer code called critical sections. A critical section is a piece of code where a process or thread accesses a common resource. The critical section by itself is not a mechanism or algorithm for mutual exclusion. A program, process, or thread can have critical section in it without any mechanism or algorithm, which implements mutual exclusion.<br />
  Examples of such resources are fine-grained flags, counters or queues, used to communicate between code that runs concurrently, such as an application and its interrupt handlers. The problem is acute because a thread can be stopped or started at any time.</p>
<p>How Mutual Exclusion is Done ?<br />
We need to stop the two threads from working on the same data at the same time. The most common way to do this today is by using locks. A lock can be either locked or unlocked. As long as you do not forget to lock or unlock the door, this algorithms guarantees mutual exclusion and protects the so called critical region.<br />
C:<br />
   1. omp_set_lock (&#038;my_lock);<br />
   2. i++;<br />
   3. omp_unset_lock (&#038;my_lock);<br />
Actually, the lock needs to be initialized beforehand and destroyed sometime afterwards as well, but that&#8217;s not too difficult either.<br />
C:<br />
   1. #pragma omp critical<br />
   2. {<br />
   3.   i++;<br />
   4. }<br />
Or even simpler, like this:<br />
C:<br />
   1. #pragma omp atomic<br />
   2. i++;<br />
This basically does the same thing, except you do not need to worry about initialization and destruction of the lock and you cannot forget to unlock the mutex accidentally.</p>
<div class="addthis_toolbox addthis_default_style " addthis:url='http://learnsoftwareprocesses.com/2009/08/25/overview-of-mutual-exclusions-in-operating-systems/' addthis:title='Overview Of Mutual Exclusions in Operating Systems '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_button_google_plusone" g:plusone:size="medium"></a><a class="addthis_counter addthis_pill_style"></a></div>]]></content:encoded>
			<wfw:commentRss>http://learnsoftwareprocesses.com/2009/08/25/overview-of-mutual-exclusions-in-operating-systems/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Effort estimation techniques</title>
		<link>http://learnsoftwareprocesses.com/2008/08/10/effort-estimation-techniques/</link>
		<comments>http://learnsoftwareprocesses.com/2008/08/10/effort-estimation-techniques/#comments</comments>
		<pubDate>Sun, 10 Aug 2008 18:38:50 +0000</pubDate>
		<dc:creator>ashish</dc:creator>
				<category><![CDATA[Algorithms]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Model]]></category>
		<category><![CDATA[Requirements]]></category>
		<category><![CDATA[Resources]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Techniques]]></category>

		<guid isPermaLink="false">http://learnsoftwareprocesses.com/2008/08/10/effort-estimation-techniques/</guid>
		<description><![CDATA[<p>A new project is being thought of (or even an extension of the current product). As an example, say you want to build a new shopping cart application for your website. In order to get started, besides knowing exactly what you want to build (the product details), you also need to start estimating how many [...]]]></description>
			<content:encoded><![CDATA[<p>A new project is being thought of (or even an extension of the current product). As an example, say you want to build a new shopping cart application for your website. In order to get started, besides knowing exactly what you want to build (the product details), you also need to start estimating how many people you will need and how long it will take. And this process of estimation is probably one of the more difficult parts of software development, something that can make or break a project. Suppose your estimation goes wrong, and you estimate too little effort for the project. In such a case, you will be forced to make compromises / overwork the people involved / deliver a low quality work. All of these are major factors that could cause the project to fail. Fortunately, there are a number of different effort estimation techniques that could be employed (this post just has brief descriptions, details for each of these will be covered in future posts):</p>
<p># Function Point Analysis (FPA): A way to break down the work into units to express the amount of business function an information system provides to a user<br />
# Parametric Estimating / Estimation Theory: Estimating the value based on measured / empirical data<br />
# Wideband Delphi: A estimation theory that works on the basis of developing a consensus for the estimation (typically based on a series of group meetings)<br />
# Cocomo: An algorithmic estimation model, using a regression formula derived from historical data and current project details<br />
# Putnam Model: Taking data from the project (such as effort and size and fitting these data to a curve). This is an empirical model.<br />
# SEER-SEM Parametric Estimation of Effort, Schedule, Cost, Risk.: System Evaluation and Estimation of Resources &#8211; Software Estimating Model. This model is based on a mixture of statistics and algorithms<br />
# Proxy-based estimating (PROBE) (from the Personal Software Process): Proxy based estimating produces size estimates based on previous developments in similar application domains<br />
# The Planning Game (from Extreme Programming): This is the process that depends on release planning and iteration planning (inside iteration planning, requirements are broken down into tasks and tasks are estimated by the programmers)<br />
# Program Evaluation and Review Technique (PERT): PERT is intended for very large-scale, one-time, complex, non-routine projects, and has a great advantage of being able to incorporate uncertainty<br />
# Analysis Effort method: This method is best suited to producing initial estimates for the length of a job based on a known time duration for preparing a specification<br />
# TruePlanning Software Model: Parametric model that estimates the scope, cost, effort and schedule for software projects<br />
# Work Breakdown Structure: In this technique, all the individual tasks are laid out with their estimates and description, and they can be summed to display the total effort</p>
<div class="addthis_toolbox addthis_default_style " addthis:url='http://learnsoftwareprocesses.com/2008/08/10/effort-estimation-techniques/' addthis:title='Effort estimation techniques '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_button_google_plusone" g:plusone:size="medium"></a><a class="addthis_counter addthis_pill_style"></a></div>]]></content:encoded>
			<wfw:commentRss>http://learnsoftwareprocesses.com/2008/08/10/effort-estimation-techniques/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Deadlock &#8211; Algorithms</title>
		<link>http://learnsoftwareprocesses.com/2008/05/25/deadlock-algorithms/</link>
		<comments>http://learnsoftwareprocesses.com/2008/05/25/deadlock-algorithms/#comments</comments>
		<pubDate>Sun, 25 May 2008 05:12:41 +0000</pubDate>
		<dc:creator>ashish</dc:creator>
				<category><![CDATA[Algorithms]]></category>
		<category><![CDATA[Deadlock]]></category>

		<guid isPermaLink="false">http://learnsoftwareprocesses.com/2008/05/25/deadlock-algorithms/</guid>
		<description><![CDATA[<p>BANKER’S ALGORITHM </p> <p>Consider an example:</p> <p>There are four customers: A, B, C and D, which are analogous to four processes. The credit unit is like the resource The banker himself is the OS Assume each credit unit = Rs. 1000.</p> <p>Not all customers need their maximum credit immediately. Hence only 10 credit units are [...]]]></description>
			<content:encoded><![CDATA[<p>BANKER’S ALGORITHM </p>
<p>Consider an example:</p>
<p>There are four customers: A, B, C and D, which are analogous to four processes.<br />
The credit unit is like the resource<br />
The banker himself is the OS<br />
Assume each credit unit = Rs. 1000.</p>
<p>Not all customers need their maximum credit immediately. Hence only 10 credit units are reserved.<br />
Process Current Max. Free = 10<br />
A 0 6     B 0 5     C 0 4     D 0 7</p>
<p>How does the Algorithm Work?</p>
<p>When a new process (customer) enters the system, it (he) must declare the maximum number of instances of each resource type (credit units) that it (he) may need. This number may not exceed the total number of resources (credit units) in the system. When a user (customer) requests a set of resources (credit unit), the system must determine whether the allocation of these resources will leave the system in a safe state. If it will,<br />
the resources are allocated; otherwise, the process must wait until some other process releases enough resources. Consider current allocation to various processes is as shown below.<br />
Process Current Max. Free = 2<br />
A 1 6    B 1 5    C 2 4    D 4 7<br />
Would the System be in a Safe State?<br />
‘C’ requests 2 additional units and gets them. It then runs to completion and frees all the resources it has.<br />
Process Current Max. Free = 4<br />
A 1 6     B 1 5     C 0 &#8211;    D 4 7<br />
Now either ‘B’ or ‘D’ can request and run to completion. Assume ‘B’ requests 4 additional units and gets them. It then runs to completion and frees all its resources. Process Current Max. Free = 5<br />
A 1 6     B 0 &#8211;    C 0 &#8211;    D 4 7<br />
Now ‘D’ runs and requests 3 additional resources and gets them. It then runs to completion and releases all its resources.Process Current Max. Free = 9<br />
A 1 6     B 0 &#8211;    C 0 &#8211;    D 0 -<br />
Finally ‘A’ runs and requests 5 additional resources and gets them. It then runs to completion and releases all its resources. Process Current Max. Free = 10<br />
A 0 &#8211;     B 0 &#8211;    C 0 &#8211;    D 0 -<br />
Here is the complete banker’s algorithm: </p>
<p>Several data structures must be maintained to implement banker’s algorithm. Let n be the number of processes and m be the number of resource types. The data structures needed are:<br />
• Available : A vector of length m indicates number of available resources of each type. If Available[j] = k, there are k instances of resource type Rj available.<br />
• Max : A n*m matrix defines the maximum demand of each process. If Max[i,j]=k, then Pi may request at most k instances of resource type Rj.<br />
• Allocation : An n*m matrix defines the number of resources of each type currently allocated to each process. If Allocation[i,j]=k, then process Pi is currently allocated k instances of resource type rj.<br />
• Need : An n*m matrix indicates the remaining resource need of each process. If Need[i,j]=k, then Pi may need k more instances of resource type Rj to complete its task. Need[i,j]=Max[I,j] – Allocation[I,j].</p>
<p>After defining the data structures, algorithm moves into two phases :<br />
• Safety Algorithm<br />
• Resource Request Algorithm</p>
<p>SAFETY ALGORITHM</p>
<p>The safety algorithm is for finding out whether or not a system is in a safe state. It is described below:</p>
<p>1. Let work and finish be vectors of length m and n<br />
respectively. Initialize work = Available and Finish[I] = false for all I = 1, 2, …, n.<br />
2. Find an I such that both<br />
 • Finish[I] = false<br />
 • Needi <= work<br />
If no such I exists, go to step 4.<br />
3. Work = work + allocationi<br />
finish[I] = true<br />
go to step 2</p>
<p>4. If finish[I] = true for all I, then the system is in a safe state. This algorithm may require an order of m * n2 operations to decide whether a state is safe.</p>
<p>RESOURCE – REQUEST ALGORITHM</p>
<p>Having determined that the system is safe, this algorithm grants the requested resources to the process. Let Request i be the request vector for process Pi. If Request[j] = k, then process Pi wants k instances of resource type Rj. When this request is made, the following actions are taken:</p>
<p>1. If request I <= need I, then go to step 2. Otherwise raise an error condition because the process has exceeded its maximum claim.<br />
2. If request I <= available, go to step 3. Otherwise, Pi must wait since the resources are not available.<br />
3. Have the system pretend to have allocated the requested resources to process Pi by modifying the state as follows:<br />
a. Available = available – request I<br />
b. Allocation = allocation + request I<br />
c. Need I = Need I – request I<br />
4. Call the Safety algorithm. If the state is safe, then transaction is completed and process Pi is allocated the resources. If the new state is unsafe, then Pi must wait and the old resource allocation state is restored.</p>
<div class="addthis_toolbox addthis_default_style " addthis:url='http://learnsoftwareprocesses.com/2008/05/25/deadlock-algorithms/' addthis:title='Deadlock &#8211; Algorithms '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_button_google_plusone" g:plusone:size="medium"></a><a class="addthis_counter addthis_pill_style"></a></div>]]></content:encoded>
			<wfw:commentRss>http://learnsoftwareprocesses.com/2008/05/25/deadlock-algorithms/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

