Primary Key:
A primary key is a field or combination of fields that uniquely identify a record in a table, so that an individual record can be located without confusion.
http://www.databasedev.co.uk/primary_foreign_key_constraints.html
A primary key is one which uniquely identifies a row of a table. this key does not allow null values and also does not allow duplicate values
http://www.allinterview.com/showanswers/15625.html
A primary key in a database, is simply a useful device (key) that makes each record unique.
Read more: http://wiki.answers.com/Q/What_is_the_purpose_of_a_primary_key_in_a_database#ixzz1sIudT06W
Tuesday, April 17, 2012
foreign key
foreign key - a foreign key is one which will refer to a primary key of another table
http://www.allinterview.com/showanswers/15625.html
A foreign key is a relationship or link between two tables which ensures that the data stored in a database is consistent.
The foreign key link is set up by matching columns in one table (the child) to the primary key columns in another table (the parent)
http://www.visualcase.com/kbase/database_basics_-_foreign_keys.htm
Foreign Key:
A foreign key (sometimes called a referencing key) is a key used to link two tables together.
Typically you take the primary key field from one table and insert it into the other table where it becomes a foreign key
(it remains a primary key in the original table).
A foreign key constraint specifies that the data in a foreign key must match the data in the primary key of the linked table, in the above example we couldn't set the DeptID in the Employee table to 04 as there is no DeptID of 04 in the Department table. This system is called referential integrity, it is to ensure that the data entered is correct and not orphaned (i.e. there are no broken links between data in the tables)
http://www.databasedev.co.uk/primary_foreign_key_constraints.html
http://www.allinterview.com/showanswers/15625.html
A foreign key is a relationship or link between two tables which ensures that the data stored in a database is consistent.
The foreign key link is set up by matching columns in one table (the child) to the primary key columns in another table (the parent)
http://www.visualcase.com/kbase/database_basics_-_foreign_keys.htm
Foreign Key:
A foreign key (sometimes called a referencing key) is a key used to link two tables together.
Typically you take the primary key field from one table and insert it into the other table where it becomes a foreign key
(it remains a primary key in the original table).
A foreign key constraint specifies that the data in a foreign key must match the data in the primary key of the linked table, in the above example we couldn't set the DeptID in the Employee table to 04 as there is no DeptID of 04 in the Department table. This system is called referential integrity, it is to ensure that the data entered is correct and not orphaned (i.e. there are no broken links between data in the tables)
http://www.databasedev.co.uk/primary_foreign_key_constraints.html
Labels:
Database Management Systems
EXISTS Condition
EXISTS Condition
The EXISTS condition is considered "to be met" if the subquery returns at least one row.
The syntax for the EXISTS condition is:
SELECT columns
FROM tables
WHERE EXISTS ( subquery );
Example #1:
Let's take a look at a simple example. The following is an SQL statement that uses the EXISTS condition:
SELECT *
FROM suppliers
WHERE EXISTS
(select *
from orders
where suppliers.supplier_id = orders.supplier_id);
This select statement will return all records from the suppliers table where there is at least one record in the orders table with the same supplier_id.
Example #2 - NOT EXISTS:
The EXISTS condition can also be combined with the NOT operator.
For example,
SELECT *
FROM suppliers
WHERE not exists (select * from orders Where suppliers.supplier_id = orders.supplier_id);
This will return all records from the suppliers table where there are no records in the orders table for the given supplier_id.
http://www.techonthenet.com/sql/exists.php
The EXISTS condition is considered "to be met" if the subquery returns at least one row.
The syntax for the EXISTS condition is:
SELECT columns
FROM tables
WHERE EXISTS ( subquery );
Example #1:
Let's take a look at a simple example. The following is an SQL statement that uses the EXISTS condition:
SELECT *
FROM suppliers
WHERE EXISTS
(select *
from orders
where suppliers.supplier_id = orders.supplier_id);
This select statement will return all records from the suppliers table where there is at least one record in the orders table with the same supplier_id.
Example #2 - NOT EXISTS:
The EXISTS condition can also be combined with the NOT operator.
For example,
SELECT *
FROM suppliers
WHERE not exists (select * from orders Where suppliers.supplier_id = orders.supplier_id);
This will return all records from the suppliers table where there are no records in the orders table for the given supplier_id.
http://www.techonthenet.com/sql/exists.php
Labels:
Database Management Systems
what is multiprogramming ?
- what is multiprogramming ?
Multiprogramming is a rudimentary form of parallel processing in which several programs are run at the same time on a uniprocessor.
Since there is only one processor , there can be no true simultaneous execution of different programs.
Instead, the operating system executes part of one program, then part of another, and so on.
To the user it appears that all programs are executing at the same time.
- What are the advantages of multiprogramming?
Multiprogramming makes effifcient use of the CPU by overlapping the demands for the CPU and its I/O devices from various users. It attempts to increase CPU utilization by always having something for the CPU to execute
http://wiki.answers.com/Q/What_are_the_advantages_of_multiprogramming
- What is the advantage of Multiprogramming?
Multiprogramming increases CPU utilization by organizing jobs so that the CPU always has one to execute.
Several jobs are placed in the main memory and the processor is switched from job to job as needed to keep several jobs advancing while keeping the
peripheral devices in use.
Multiprogramming is the first instance where the Operating system must make decisions for the users.
Therefore they are fairly sophisticated.
Labels:
operating systems
Friday, April 13, 2012
course pages,quizes,tests,exams
CSC 257/457 - Computer Networks (Fall 2008)
http://www.cs.rochester.edu/~bukys/csc257-fall2008/
Computer Networks
http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-829-computer-networks-fall-2002/lecture-notes/
CS 268: Computer Networks, Spring 2003: Syllabus
http://inst.eecs.berkeley.edu/~cs268/sp03/
BBS 676 Veri Iletisimi ve Bilgisayar Aglari
http://www.ee.hacettepe.edu.tr/~toker/BBS676/BBS676-Homepage.html
BIL 472 Bilgisayar Aglari 2006-2007 Bahar Dönemi
http://www.gyte.edu.tr/dosya/104/ders/BIL472/
AYŞE BETÜL OKTAY BTP 213 Ağ Sistemleri
http://www.fatih.edu.tr/~betulg/network.htm
http://www.cs.rochester.edu/~bukys/csc257-fall2008/
Computer Networks
http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-829-computer-networks-fall-2002/lecture-notes/
CS 268: Computer Networks, Spring 2003: Syllabus
http://inst.eecs.berkeley.edu/~cs268/sp03/
BBS 676 Veri Iletisimi ve Bilgisayar Aglari
http://www.ee.hacettepe.edu.tr/~toker/BBS676/BBS676-Homepage.html
BIL 472 Bilgisayar Aglari 2006-2007 Bahar Dönemi
http://www.gyte.edu.tr/dosya/104/ders/BIL472/
AYŞE BETÜL OKTAY BTP 213 Ağ Sistemleri
http://www.fatih.edu.tr/~betulg/network.htm
Labels:
Computer Networks
Trees
- Data Structures - Chapter 3: Tree-part1
http://www.youtube.com/watch?v=7Ac2qNITEYQ&feature=channel&list=UL
- Tree (data structure)
In computer science, a tree is a widely used data structure that simulates a hierarchical tree structure with a set of linked nodes.
A tree can be defined recursively (locally) as a collection of nodes (starting at a root node), where each node is a data structure consisting of a value, together with a list of nodes (the "children"), with the constraints that no node is duplicated.
A tree can be defined abstractly as a whole (globally) as an ordered tree, with a value assigned to each node
Representations
There are many different ways to represent trees; common representations represent the nodes as dynamically allocated records with pointers to their children, their parents, or both, or as items in an array, with relationships between them determined by their positions in the array (e.g., binary heap).
http://en.wikipedia.org/wiki/Tree_(data_structure)
- Trees
we shall extend the use of pointers to define a non-linear structure to model hierarchical relationships, such as a family tree.
In such a tree, we have links moving from an ancestor to a parent, and links moving from the parent to children
A tree is a data structure that is made of nodes and pointers, much like a linked list.
The difference between them lies in how they are organized
The height of a tree is defined to be the length of the longest path from the root to a leaf in that tree ( including the path to root)
Tree Examples
Directory Hierarchies:
In computers, files are stored in directories that form a tree.
The top level directory represents the root.
It has many subdirectories and files
Organization charts:
Biological classifications:
Starting from living being at the root, such a tree can branch off to mammals, birds, marine life etc
Game Trees:
All games which require only mental effort would always have number of possible options at any position of the game.
For each position, there would be number of counter moves.
The repetitive pattern results in what is known a game tree
http://www.cs.ucf.edu/courses/cop3502h.02/trees1.pdf
- Trees have many uses:
representing family genealogies
as the underlying structure in decision-making algorithms
to represent priority queues (a special kind of tree called a heap)
to provide fast access to information in a database (a special kind of tree called a b-tree)
http://pages.cs.wisc.edu/~vernon/cs367/notes/8.TREES.html
Labels:
Data Structures and Algorithms
linked list
- Linked Lists in 10 minutes - I
http://www.youtube.com/watch?v=LOHBGyK3Hbs&feature=related
Disadvantages of arrays are
-when element is added all elements need to be shifted
-fixed size
with linked list these problems are overcame
- linked list in plain english
http://www.youtube.com/watch?v=oiW79L8VYXk
- advantages
The biggest advantage of linked lists is that they can be expanded in constant time without memory overhead.
For example when you make an array you must allocate memory for a certain number of elements.
If you want to add more elements to the array than you allocated for you must create a new array and copy the old array into the new array.
This can take lots of time.
You can prevent this by allocating lots of space initially but then you might allocate more than you need wasting memory.
With a linked list you can start with space for just one element allocated. And add on new elements easily without the need to do any copying and reallocating.
Read more: http://wiki.answers.com/Q/What_are_the_advantages_of_linked_lists#ixzz1xDOa8ksU
- Linked lists have several advantages over dynamic arrays.
Insertion or deletion of an element at a specific point of a list, assuming that we have a pointer to the node (before the one to be removed, or before the insertion point) already, is a constant-time operation, whereas insertion in a dynamic array at random locations will require moving half of the elements on average, and all the elements in the worst case.
While one can "delete" an element from an array in constant time by somehow marking its slot as "vacant", this causes fragmentation that impedes the performance of iteration.
Moreover, arbitrarily many elements may be inserted into a linked list, limited only by the total memory available; while a dynamic array will eventually fill up its underlying array data structure and will have to reallocate — an expensive operation,
http://en.wikipedia.org/wiki/Linked_list#Linked_list_operations
- Linked lists are preferable over arrays when:
a) you need constant-time insertions/deletions from the list (such as in real-time computing where time predictability is absolutely critical)
b) you don't know how many items will be in the list. With arrays, you may need to re-declare and copy memory if the array grows too big
c) you don't need random access to any elements
d) you want to be able to insert items in the middle of the list (such as a priority queue)
- Arrays are preferable when:
a) you need indexed/random access to elements
b) you know the number of elements in the array ahead of time so that you can allocate the correct amount of memory for the array
c) you need speed when iterating through all the elements in sequence. You can use pointer math on the array to access each element, whereas you need to lookup the node based on the pointer for each element in linked list, which may result in page faults which may result in performance hits.
d) memory is a concern. Filled arrays take up less memory than linked lists. Each element in the array is just the data. Each linked list node requires the data as well as one (or more) pointers to the other elements in the linked list.
Array Lists (like those in .Net) give you the benefits of arrays, but dynamically allocate resources for you so that you don't need to worry too much about list size and you can delete items at any index without any effort or re-shuffling elements around. Performance-wise, arraylists are slower than raw arrays.
http://stackoverflow.com/questions/393556/when-to-use-a-linked-list-over-an-array-array-list
- When should I use LinkedList?
When you need efficient removal in between elements or at the start.
When you don't need random access to elements, but can live with iterating over them one by one
- When should I use ArrayList?
When you need random access to elements ("get the nth. element")
When you don't need to remove elements from between others. It's possible but it's slower since the internal backing-up array needs to be reallocated.
Adding elements is amortized constant time (meaning every once in a while, you pay some performance, but overall adding is instantly done)
- Making the decision
If your data is best represented using a multidimensional structure, or the number of elements is known in advance and will remain consistent, an array is best.
If your data is easily represented in one dimension, and the number of elements is unknown or is expected to change often throughout the operation of your program, a linked list is more efficient.
If your data will be searched and accessed often but will change infrequently, the array offers the least overhead for your expected operations.
If you expect to be regularly adding or subtracting elements, especially if you need to maintain a sorted order, the versatility of the linked list will be of greater benefi
http://www.techrepublic.com/article/deciding-whether-to-use-arrays-or-linked-lists/1050183
ArrayList is very useful when a well defined set of data is needed in a List interface as opposed to an array. It can be dynamically changed, but try not to do so frequently throughout the life of the application. LinkedList is there for you to do just that: Manipulating it is very easy, and as long as its used for iteration purposes only and not for random accessing, it’s the best solution. Further, if you need random accessing from time to time, I suggest toArray for that specific moment.
http://chaoticjava.com/posts/linkedlist-vs-arraylist/
- Bagli listeler
Programlama açisindan liste, aralarinda dogrusal iliski olan veriler toplulugu olarak görülebilir.
Yigit ve kuyruklarin genisletilmesi yani üzerlerindeki sinirlamalarin kaldirilmasi ile liste yapisina ulasilir.
Yigitlarda ve kuyruklarin gerçeklestiriminde sirali bellek kullaniminin (dizi) en büyük dezavantaji, hiç kullanilmasa veya az kullanilsa bile sabit miktardaki
bellegin bu yapilara ayrilmis olarak tutulmasidir.
Ayrica sabit bellek miktari asildiginda da tasma olusmasi ve eleman ekleme isleminin yapilamamasidir.
Bagli listeler üzerinde gerçeklestirildiklerinde ise bu problemler ortadan kalkmaktadir.
Bir bagli listenin n. elemanina erismek için n tane islem yapmak yani kendinden önceki (n-1) eleman üzerinden geçmek gerekmektedir.
Elemanlarin bellekteki yerleri dizilerdeki gibi sirali olmadigindan elemanlar ve siralari ile yerlestikleri bellek bölgeleri arasinda bir iliski yoktur.
Circular Linked Lists
Son elemanin bagi NULL degildir; ilk elemani gösterir.
Doubly Linked Lists
Her dügümü iki bag içerdigi bagli listelerdir.
ilk bag kendinden önceki dügümü gösterirken ikincisi de kendinden sonraki dügümü gösterir
Çift bagli listelerde, tek bagli listelerdeki geriye dogru listeleme ve dolasmadaki zorluklar ortadan kalkar.
Circular Doubly Linked Lists
ilk dügümden önceki dügüm son, son dügümden sonraki dügüm de ilk dügümdür.
Labels:
Data Structures and Algorithms
Stack
Data Structures - Chapter 1: Stack
http://www.youtube.com/watch?v=_EyhFWwnvcs
Stack is a first in last out data structure
you can't do selective removal from a stack
selective removal is possible with data structure like array and linked list
push()
pop()
size()
isempty()
top()
to implement stack we use an array
linked list also can be used to implement stack
http://www.youtube.com/watch?v=_EyhFWwnvcs
Stack is a first in last out data structure
you can't do selective removal from a stack
selective removal is possible with data structure like array and linked list
push()
pop()
size()
isempty()
top()
to implement stack we use an array
linked list also can be used to implement stack
- Polish notation (prefix notation)
It refers to the notation in which the operator is placed before its two operands . Here no parentheses are required, i.e.,
+AB
Reverse Polish notation(postfix notation) –
It refers to the analogous notation in which the operator is placed after its two operands. Again, no parentheses is required in Reverse Polish notation, i.e.,
AB+
Stack organized computers are better suited for post-fix notation then the traditional infix ntation.
Thus the infix notation must be converted to the post-fix notation. The conversion from infix notation to post-fix notation must take into consideration the operational hierarchy.
Highest: Exponentiation (^)
Next highest: Multiplication (*) and division (/)
Lowest: Addition (+) and Subtraction (-)
Now we need to calculate the value of these arithmetic operations by using stack.
The procedure for getting the result is:
Convert the expression in Reverse Polish notation( post-fix notation).
Push the operands into the stack in the order they are appear.
When any operator encounter then pop two topmost operands for executing the operation.
After execution push the result obtained into the stack.
After the complete execution of expression the final result remains on the top of the stack.
For example –
Infix notation: (2+4) * (4+6)
Post-fix notation: 2 4 + 4 6 + *
Result: 60
From Postfix to Answer
•The reason to convert infix to postfix expression is that we can compute the answer of postfix expression easier by using a stack.
Postfix Expression
•Infix expression is the form AOB
–A and B are numbers or also infix expression
–O is operator ( +, -, *, / )
•Postfix expression is the form ABO
–A and B are numbers or also postfix expression
–O is operator ( +, -, *, / )
From Postfix to Answer
•Algorithm: maintain a stack and scan the postfix expression from left to right–If the element is a number, push it into the stack
–If the element is a operator O, pop twice and get A and B respectively. Calculate BOAand push it back to the stack
–When the expression is ended, the number in the stack is the final answer
Transform Infix to Postfix
•Observation 1: The order of computation depends on the order of operators
–The parentheses must be added according to the priority of operations.
–The priority of operator * and / is higher then those of operation + and –
–If there are more than one equal-priority operators, we assume that the left one’s priority is higher than the right one’s
•This is called left-to-right parsing.
https://faculty.utrgv.edu/john.abraham/6314/assignments/postfix%20tutorial.pdf
Infix to Postfix Conversion
•We use a stack
•When an operand is read, output it
•When an operator is read
–Pop until the top of the stack has an element of lower precedence
–Then push it
•When ) is found, pop until we find the matching (
•( has the lowest precedence when in the stack
•but has the highest precedence when in the input
•When we reach the end of input, pop until the stack is empty
https://cs.nyu.edu/courses/fall10/V22.0102-004/lectures/InfixToPostfixExamples.pdf
- Infix to postfix conversion algorithm
A summary of the rules follows:
1. Print operands as they arrive.
2. If the stack is empty or contains a left parenthesis on top, push the incoming operator onto the stack.
3. If the incoming symbol is a left parenthesis, push it on the stack.
4. If the incoming symbol is a right parenthesis, pop the stack and print the operators until you see a left parenthesis. Discard the pair of parentheses.
5. If the incoming symbol has higher precedence than the top of the stack, push it on the stack.
6. If the incoming symbol has equal precedence with the top of the stack, use association. If the association is left to right, pop and print the top of the stack and then push the incoming operator. If the association is right to left, push the incoming operator.
7. If the incoming symbol has lower precedence than the symbol on the top of the stack, pop the stack and print the top operator. Then test the incoming operator against the new top of stack.
8. At the end of the expression, pop and print all operators on the stack. (No parentheses should remain.)
http://csis.pace.edu/~wolf/CS122/infix-postfix.htm
Labels:
Data Structures and Algorithms
Queue
Data Structures - Chapter 2: Queue
http://www.youtube.com/watch?v=XBuScARSmAQ&feature=channel&list=UL
queue is a first in first out data structure
enqueue() to add
dequeue() to delete
size() return the # of elements
isempty()
front()
selective removal is not possible with queue data structure
queue can be implemented by array or linked list
Labels:
Data Structures and Algorithms
course pages,quizes,tests,exams
bil222-veri-yapıları-ve-algoritmalar-2008-lec5.mpg
http://www.youtube.com/watch?v=xGwTZAfM6XE&feature=results_main&playnext=1&list=PLCF7B4C6E92388118
SEN 890 Data Structures
http://www.bhecker.com/itu/viewforum.php?f=1051
204 Data Structures (3+1)
http://yzgrafik.ege.edu.tr/~ugur/11_12_Fall/DS/index11.html
Lecture 1: Introduction to Data Structures and Algorithms - Richard Buckland
http://www.youtube.com/watch?v=RpRRUQFbePU
CSE 373: Data Structures & Algorithms, Autumn 2011
http://www.cs.washington.edu/education/courses/cse373/11au/
CS 124: Data Structures and Algorithms
http://www.fas.harvard.edu/~libcs124/cs124/lecture_notes.html
Data Structures Fall 2006
Professor Evan Korth
http://www.cs.nyu.edu/courses/fall06/V22.0102-001/index.html
Data Structures and Algorithms
http://www.cise.ufl.edu/~sahni/cop3530/
CIS300: Data structures and algorithms
http://people.cis.ksu.edu/~schmidt/300s05/Lectures/home.html
EENG212 Algorithms & Data Structures
http://faraday.ee.emu.edu.tr/eeng212/
CENG 707 - Data Structures and Algorithms (Fall 2011-2012)
http://www.ceng.metu.edu.tr/~tcan/ceng707_f1112/Schedule/index.shtml
Algorithms: Design and Analysis, Part I
https://www.coursera.org/
Algorithms (cs215)
http://www.udacity.com/
Introduction to Algorithms
http://courses.csail.mit.edu/6.006/spring11/notes.shtml
http://www.youtube.com/watch?v=xGwTZAfM6XE&feature=results_main&playnext=1&list=PLCF7B4C6E92388118
SEN 890 Data Structures
http://www.bhecker.com/itu/viewforum.php?f=1051
204 Data Structures (3+1)
http://yzgrafik.ege.edu.tr/~ugur/11_12_Fall/DS/index11.html
Lecture 1: Introduction to Data Structures and Algorithms - Richard Buckland
http://www.youtube.com/watch?v=RpRRUQFbePU
CSE 373: Data Structures & Algorithms, Autumn 2011
http://www.cs.washington.edu/education/courses/cse373/11au/
CS 124: Data Structures and Algorithms
http://www.fas.harvard.edu/~libcs124/cs124/lecture_notes.html
Data Structures Fall 2006
Professor Evan Korth
http://www.cs.nyu.edu/courses/fall06/V22.0102-001/index.html
Data Structures and Algorithms
http://www.cise.ufl.edu/~sahni/cop3530/
CIS300: Data structures and algorithms
http://people.cis.ksu.edu/~schmidt/300s05/Lectures/home.html
EENG212 Algorithms & Data Structures
http://faraday.ee.emu.edu.tr/eeng212/
CENG 707 - Data Structures and Algorithms (Fall 2011-2012)
http://www.ceng.metu.edu.tr/~tcan/ceng707_f1112/Schedule/index.shtml
Algorithms: Design and Analysis, Part I
https://www.coursera.org/
Algorithms (cs215)
http://www.udacity.com/
Introduction to Algorithms
http://courses.csail.mit.edu/6.006/spring11/notes.shtml
Labels:
Data Structures and Algorithms
Data Structure & Algorithms Interview Questions
Data Structure & Algorithms Interview Questions And Answers
http://sites.google.com/site/interviewquestionsandanswers/data-structure-algorithms-interview-questions-and-answers
50 Algorithms Interview Questions
http://www.learn.geekinterview.com/resources/interview-articles/50-algorithms-interview-questions.html
Data Structures Questions and Answers for Technical Interviews
http://technical-interview.com/datastructures.aspx
http://sites.google.com/site/interviewquestionsandanswers/data-structure-algorithms-interview-questions-and-answers
50 Algorithms Interview Questions
http://www.learn.geekinterview.com/resources/interview-articles/50-algorithms-interview-questions.html
Data Structures Questions and Answers for Technical Interviews
http://technical-interview.com/datastructures.aspx
Labels:
Data Structures and Algorithms
Recursion
- Recursion
Java #20 - Recursion Part 1
http://www.youtube.com/watch?v=Bu0X20xOxIs&feature=channel&list=UL
- Java #21 - Recursion Part 2
http://www.youtube.com/watch?v=Mo59NNK8POE&feature=autoplay&list=ULBu0X20xOxIs&lf=channel&playnext=1
- Fibonacci Series
- Example-Fibonacci Numbers
- Fibonacci numbers (Java)
- What are advantages and disadvantages of recursive calling
?
Through Recursion one can Solve problems in
its iterative solution is
Ex
You reduce size of the code when you use
Disadvantages
Recursive solution is always logical
difficult to trace.
Recursive procedures are huge memory hogs. Also, they're a nightmare to debug. Finally, it's
Read more: http://wiki.answers.com/Q/What_are_the_disadvantages_of_recursion#ixzz1xDJz1EG4
- Use of recursion in an algorithm has both advantages and disadvantages. The main advantage is usually simplicity. The main disadvantage is often that the algorithm may require large amounts of memory if the depth of the recursion is very large.
http://en.wikipedia.org/wiki/Recursion
- Advantages
Although at most of the times
The recursion is very flexible in
Using recursion,
Disadvantages
It requires extra storage space.
If the programmer forgets to specify the exit condition in the recursive function, the program will execute out of memory. In such a situation user has to press Ctrl+ break to pause and stop the function.
The recursion function is not efficient in execution speed and time.
If possible, try to solve a problem with iteration instead of recursion
http://my.safaribooksonline.com/book/programming/c/9788131760314/functions/section_10.20
- Rule of the thumb: use recursion when it will shorten your development effort (usually in tree structures) and when performance is not an issue.
Recursive functions are perfect for tree structures. Loops are perfect for iterations and sequences.
public List
{
List
{
files
}
}
Advantages of Recursion
The code may be much easier to write.
Some situations are naturally recursive.
Naturally recursive data structures:
Linked lists.
Binary trees.
Naturally recursive problems:
Traversing linked lists.
Traversing binary trees.
Differentiating functions.
The Triangle
Disadvantages of Recursion
Recursive functions are
Excessive recursion may
One must be very careful when writing recursive
functions; they can be tricky.
There is shallow recursion and there is deep recursion.
Shallow recursion will not
take an excessively long time to execute.
Deep recursion is
The time and space overhead used by the stack on each call is a disadvantage of recursion. You should always minimize the number and size of the recursive function's arguments.
- Recursion
Recursion means "defining a problem in terms of itself
This can be a
Recursion comes directly from
http://www.cs.utah.edu/~
- A brute force algorithm
In the worst case the algorithm has to check each available combination
https://janosch.woschitz.org/a-simple-brute-force-algorithm-in-c-sharp/
Finding a Brute Force Solution
- Recursive Backtracking
A brute force algorithm is a simple but
Try all combinations until you find one that works
This approach isn’t clever, but computers are fast
Then
http://www.cs.utexas.edu/~
Labels:
Data Structures and Algorithms
course pages,quizes,tests,exams
course pages,quizes,tests,exams
Bil354 Veri Tabani Sistemleri
http://web.cs.hacettepe.edu.tr/~ssen/teaching/bil354.html
BIL106 Veritabani Sistemleri
http://edogdu.etu.edu.tr/course/bil106/
Database Management Systems
http://myweb.brooklyn.liu.edu/gnarra/database/
Database Management Systems CIS 3400
http://cisnet.baruch.cuny.edu/holowczak/classes/3400/notes.html
CSC1270: Database Management Systems
http://www.cs.brown.edu/courses/cs127/
Bil354 Veri Tabani Sistemleri
http://web.cs.hacettepe.edu.tr/~ssen/teaching/bil354.html
BIL106 Veritabani Sistemleri
http://edogdu.etu.edu.tr/course/bil106/
Database Management Systems
http://myweb.brooklyn.liu.edu/gnarra/database/
Database Management Systems CIS 3400
http://cisnet.baruch.cuny.edu/holowczak/classes/3400/notes.html
CSC1270: Database Management Systems
http://www.cs.brown.edu/courses/cs127/
Labels:
Database Management Systems
Thursday, April 12, 2012
Relational Algebra - Select and Project Operators
- Relational Algebra - Select and Project Operators
http://www.youtube.com/watch?v=yVh_LcOcQdg
- Relational Algebra
Relational SELECT
SELECT is used to obtain a subset of the tuples of a relation that satisfy a select condition.
For example, find all employees born after 1st Jan 1950:
SELECTdob '01/JAN/1950'(employee)
Relational PROJECT
The PROJECT operation is used to select a subset of the attributes of a relation by specifying the names of the required attributes.
For example, to get a list of all employees surnames and employee numbers:
PROJECTsurname,empno(employee)
http://db.grussell.org/section010.html#_Toc67114472
- Relational Algebra: 5 Basic Operations
• Selection () Selects a subset of rows from
relation (horizontal).
• Projection () Retains only wanted columns
from relation (vertical).
• Cross-product (x) Allows us to combine two
relations.
• Set-difference (–) Tuples in r1, but not in r2.
• Union ( ) Tuples in r1 and/or in r2.
https://docs.google.com/viewer?a=v&q=cache:VDokuEkCX5wJ:inst.eecs.berkeley.edu/~cs186/sp06/lecs/lecture8Alg.ppt+&hl=en&pid=bl&srcid=ADGEESgiCeJZcOiv5iPRotaxu6pomoztERrMYuEVScwpi1kqlrF3ep4OJFlHIAWi4oJY0lFzFdq_eN73o0g7LQQo0Hvq34G_A9_pPIHPycr-NpyCL8B4brQhGmZwtReFMTuvHpynj-w5&sig=AHIEtbS3ZRzsDc-Udg4I5DzR4P1muwA-VA
- Relational Algebra
An algebra is a formal structure consisting of sets and operations on those sets.
Relational algebra is a formal system for manipulating relations.
Operands of this algebra are relations.
Operations of this algebra include the usual set operations (since relations are sets of tuples), and special operations defined for relations
selection
projection
join
http://www.cs.rochester.edu/~nelson/courses/csc_173/relations/algebra.html
- relational schema for a music albums database.
The attributes should be self-evident.
For a given music track, we code the title, its play length in time (minutes:seconds), its genre (pop, metal, jazz, etc.) and a 5 star maximum rating.
The musicians, singers and instrumentalists are all listed in on their contribution to the track.
A person may have 1 or more listing for a track. For example someone may both sing and play the piano.
The album is a collection of tracks. An album is distributed and owned by a company called the label and has a producer and an engineer.
For a given music track, we code the title, its play length in time (minutes:seconds), its genre (pop, metal, jazz, etc.) and a 5 star maximum rating.
The musicians, singers and instrumentalists are all listed in on their contribution to the track.
A person may have 1 or more listing for a track. For example someone may both sing and play the piano.
The album is a collection of tracks.
An album is distributed and owned by a company called the label and has a producer and an engineer.
PEOPLE (PID, name, address, zip, phone)
CSZ (zip, city, state)
TRACKS (trID, title, length, genre, rating, albID) //trID is unique across all albums
ALBUMS (albID, albumTitle, year, label, prodPID, engPID, length, price)
CONTRIBS (trID, PID, role)
Use the R.A. notation below.
BE EXPLICIT in the join condition which attributes make the join where necessary.
Syntax reminder for Relational Algebra expressions:
SELECT : condition(relation)
PROJECT : attribute-list(relation)
SET Operations and JOIN: relation1 OP relation2, where OP is , , - , , , and ||condition
RENAME: relation[new attribute names]
ASSIGN: new-relation(attrs) R.A. expression
a) List all names and phone numbers of people from zip 90210.
name, phone(zip=90210(PEOPLE))
b) List album titles and labels with a list price of more than $18.
albumTitle, label(price>18(ALBUMS))
c) List all the musicians and what they played or contributed to on all jazz type tracks.
name, role(genre= ‘jazz’(TRACKS |X| trID=trID CONTRIBS |X| PID= PID PEOPLE))
d) Get a list of names of people who produced OR engineered an album, but did not perform on any track. (Hint: set operations are very helpful)
d) name(((prodPID ALBUMS)[PID] (engrPID ALBUMS)[PID]) - PID CONTRIB)
|X| PID= PID PEOPLE)
e) List names of musicians who have contributed in at least two different roles on the same tracks with ratings 4 or higher. (Hint: self-join)
name, role(rating>= 4 and role <>role2
(CONTRIBS |X| trID=trID and PID=PID CONTRIBS[trID, PID, role2] )
|X| PID= PID PEOPLE))
http://jcsites.juniata.edu/faculty/rhodes/dbms/funcdep.html
- relational algebra
Consider the following relation database
schema of people who places book orders.
Book(BookID,title,price)
Person(PersonID,Name,Zip)
Orders(PersonID,BookID,quantity,BillingID)
Billing(BillingID,PersonID,CreditCardNum)
Answer the following questions based on this schema. Pay particular attention to the language we
ask for the query in.
(a) Write a query in Relational Algebra to find the title of the book(s) with the lowest price. (3
points)
(b) Write a query in Relational Algebra to find Zip of every person who ordered the book with
the title ’Database Systems’. (4 points)
(c) Write a query in SQL to create the table Billing. Remember to specify the Primary Key and
the foriegn key constraints. All columns are of type Varchar(255). No column is allowed to
be NULL. (4 points)
(d) Write a query in SQL to find how much money has been spent on the books. (4 points)
Solution:
(a) πtitle(Book) − πB1.title(ρB1(Book) c ρB2(Book))
Where c = B1.price > B2.price
(b) πZip(σtitle= DatabaseSystems ((Book c1 Orders) c2 P erson))
Where c1 = Book.BookID = Orders.BookID
Where c2 = Orders.PersonID = Person.PersonID
(c) CREATE TABLE Billing (
BillingID Varchar(255) PRIMARY KEY,
PersonID Varchar(255) NOT NULL,
CreditCardNum Varchar(255) NOT NULL,
FOREIGN KEY (PersonID) REFERENCES Person(PersonID)
)
(d) SELECT SUM(booksales) FROM (SELECT (price*quantity) AS booksales FROM Orders o
LEFT JOIN Book b ON o.BookID = b.BookID)
webcache.googleusercontent.com/search?q=cache:8vRupC7L9OYJ:https://wiki.engr.illinois.edu/download/attachments/227743489/CS411-F2011-Final-Sol.pdf%3Fversion%3D1%26modificationDate%3D1380470739000+&cd=3&hl=tr&ct=clnk&gl=tr&client=firefox-a
Labels:
Database Management Systems
Why paging is used?
Paging is solution to external fragmentation problem which is to permit the logical address space of a process to be noncontiguous, thus allowing a process to be allocating physical memory wherever the latter is available.
http://www.techinterviews.com/operating-system-questions
Labels:
operating systems
Disk-scheduling algorithms
- Disk Scheduling
The seek time is the time for the disk arm to move the heads to the cylinder containing the desired sector.
The rotational latency is the additional time for the disk to rotate the desired sector to the disk head.
Disk-scheduling algorithms.
- FCFS Scheduling
The simplest form of disk scheduling is the first-come, first-served (FCFS) algorithm. This algorithm is intrinsically fair, but it generally does not provide the fastest service.
- SSTF Scheduling
It seems reasonable to service all the requests close to the current head position before moving the head far away to service other requests. This assumption is the basis for the shortest-seek-time-first (SSTF) algorithm.
- SCAN Scheduling
The SCAN algorithm is sometimes called the elevator algorithm, since the disk arms behaves just like an elevator in a building, first servicing all the requests going up and then reversing to service requests the other way.
- C-SCAN Scheduling
Circular SCAN (C-SCAN) scheduling is a variant of SCAN designed to provide a more uniform wait time
When the head reaches the other end, however, it immediately returns to the beginning of the disk, without servicing any requests on the return trip
- LOOK Scheduling
LOOK scheduling improves upon SCAN by looking ahead at the queue of pending requests, and not moving the heads any farther towards the end of the disk than is necessary.
http://siber.cankaya.edu.tr/ozdogan/OperatingSystems/ceng328/node263.html
- TYPES OF DISK SCHEDULING ALGORITHMS
Given the following queue -- 95, 180, 34, 119, 11, 123, 62, 64 with the Read-write head initially at the track 50 and the tail track being at 199 let us now discuss the different algorithms.
1. First Come -First Serve (FCFS)
All incoming requests are placed at the end of the queue. Whatever number that is next in the queue will be the next number served.
To determine the number of head movements you would simply find the number of tracks it took to move from one request to the next. For this case it went from 50 to 95 to 180 and so on. From 50 to 95 it moved 45 tracks. If you tally up the total number of tracks you will find how many tracks it had to go through before finishing the entire request. In this example, it had a total head movement of 640 tracks. The disadvantage of this algorithm is noted by the oscillation from track 50 to track 180 and then back to track 11 to 123 then to 64. As you will soon see, this is the worse algorithm that one can use.
2. Shortest Seek Time First (SSTF)
In this case request is serviced according to next shortest distance
Starting at 50, the next shortest distance would be 62 instead of 34 since it is only 12 tracks away from 62 and 16 tracks away from 34
For example the next case would be to move from 62 to 64 instead of 34 since there are only 2 tracks between them and not 18 if it were to go the other way.
Although this seems to be a better service being that it moved a total of 236 tracks
The reason for this is if there were a lot of requests close to eachother the other requests will never be handled since the distance will always be greater.
3. Elevator (SCAN)
This approach works like an elevator does. It scans down towards the nearest end and then when it hits the bottom it scans up servicing the requests that it didn't get going down. If a request comes in after it has been scanned it will not be serviced until the process comes back down or moves back up. This process moved a total of 230 tracks
4. Circular Scan (C-SCAN)
Circular scanning works just like the elevator to some extent. It begins its scan toward the nearest end and works it way all the way to the end of the system. Once it hits the bottom or top it jumps to the other end and moves in the same direction. Keep in mind that the huge jump doesn't count as a head movement. The total head movement for this algorithm is only 187 track, but still this isn't the mose sufficient.
5. C-LOOK
This is just an enhanced version of C-SCAN. In this the scanning doesn't go past the last request in the direction that it is moving. It too jumps to the other end but not all the way to the end. Just to the furthest request. C-SCAN had a total movement of 187 but this scan (C-LOOK) reduced it down to 157 tracks.
http://www.cs.iit.edu/~cs561/cs450/disksched/disksched.html
- https://www.cs.washington.edu/education/courses/451/04au/section/section7.pdf
- The set of requests is 98 183 37 122 14 124 65 67
and the disk head starts at cylinder 53.
Where direction is important (LOOK and SCAN), the disk head is moving outward.
Order of Service
algorithm request order
fcfs 98 183 37 122 14 124 65 67
pickup 65 67 98 122 124 183 37 14
sstf 65 67 37 14 98 122 124 183
scan 37 14 65 67 98 122 124 183
look 37 14 65 67 98 122 124 183
c-scan 65 67 98 122 124 183 14 37
c-look 65 67 98 122 124 183 14 37
Head Motion
This chart shows how far the disk heads move to service each request, and the mean and standard deviation of the head motion.
algorithm total number of cylinders moved total avg stdev
fcfs 45 85 146 85 108 110 59 2 640 80.00 44.47
pickup 12 2 31 24 2 59 146 23 299 37.38 47.57
sstf 12 2 30 23 84 24 2 59 236 29.50 28.62
scan 16 23 79 2 31 24 2 59 236 29.50 26.97
look 16 23 51 2 31 24 2 59 208 26.00 20.72
c-scan 12 2 31 24 2 59 231 23 384 48.00 76.18
c-look 12 2 31 24 2 59 169 23 322 40.25 55.16
http://nob.cs.ucdavis.edu/classes/ecs150-2008-02/handouts/io/io-example.html
Labels:
operating systems
Swapping
Swapping
A process must be in memory to be executed. A process, however, can be swapped temporarily out of memory to a backing store (disk) and then brought back into memory for continued execution.
http://siber.cankaya.edu.tr/ozdogan/OperatingSystems/ceng328/node179.html
A process must be in memory to be executed. A process, however, can be swapped temporarily out of memory to a backing store (disk) and then brought back into memory for continued execution.
http://siber.cankaya.edu.tr/ozdogan/OperatingSystems/ceng328/node179.html
Labels:
operating systems
memory-mapping
Rather than accessing data files directly via the file system with every file access, data files can be paged into memory the same as process files, resulting in much
faster accesses ( except of course when page-faults occur. ) This is known as memory-mapping a file.
9.7.2 Shared Memory in the Win32 API
Windows implements shared memory using shared memory-mapped files
http://www.cs.uic.edu/~jbell/CourseNotes/OperatingSystems/9_VirtualMemory.html
faster accesses ( except of course when page-faults occur. ) This is known as memory-mapping a file.
9.7.2 Shared Memory in the Win32 API
Windows implements shared memory using shared memory-mapped files
http://www.cs.uic.edu/~jbell/CourseNotes/OperatingSystems/9_VirtualMemory.html
Labels:
operating systems
Page Replacement Algoritms
Page Replacement Algoritms
9.4.2 FIFO Page Replacement
A simple and obvious page replacement strategy is FIFO, i.e. first-in-first-out.
An interesting effect that can occur with FIFO is Belady's anomaly, in which increasing the number of frames available can actually increase the number of page faults
that occur!
9.4.3 Optimal Page Replacement
The discovery of Belady's anomaly lead to the search for an optimal page-replacement algorithm, which is simply that which yields the lowest of all possible page-
faults, and which does not suffer from Belady's anomaly.
This algorithm is simply "Replace the page that will not be used for the longest time in the future."
9.4.4 LRU Page Replacement
The prediction behind LRU, the Least Recently Used, algorithm is that the page that has not been used in the longest time is the one that will not be used again in the
near future. ( Note the distinction between FIFO and LRU: The former looks at the oldest load time, and the latter looks at the oldest use time. )
9.4.5 LRU-Approximation Page Replacement
http://www.youtube.com/watch?v=pGWbb7QIapQ
http://www.youtube.com/watch?v=GUL2txPndHs
http://www.cs.uic.edu/~jbell/CourseNotes/OperatingSystems/9_VirtualMemory.html
Fixed Number of Frames
First In/First Out (FIFO)
Optimal (OPT, MIN)
Least Recently Used (LRU)
Not-Recently-Used or Not Used Recently (NRU, NUR)
Clock
Second-chance Cyclic
Variable Number of Frames
Working Set (WS)
Page Fault Frequency (PFF)
http://nob.cs.ucdavis.edu/classes/ecs150-2008-02/handouts/memory/mm-pagexample.html
• If a page is not in physical memory
– find the page on disk
– find a free frame
– bring the page into memory
• What if there is no free frame in memory?
Page Replacement
Basic idea
if there is a free page in memory, use it
if not, select a victim frame
write the victim out to disk
read the desired page into the now free frame
update page tables
restart the process
Page Replacement
• Main objective of a good replacement algorithm is to achieve a low page fault rate
– insure that heavily used pages stay in memory
– the replaced page should not be needed for
some time
• Secondary objective is to reduce latency of a page fault
– efficient code
– replace pages that do not need to be written out
https://docs.google.com/viewer?a=v&q=cache:Z21kbpmJIh4J:pages.cs.wisc.edu/~mattmcc/cs537/notes/Replacement.ppt+&hl=en&pid=bl&srcid=ADGEESj7uIgxkdOGy1nM__CGFctASur2ho79p326r_SPmkGuw_5G0sBrMh9curCHZ-yMfReLi5KTfYDWT-26pMp-ua-0JlYqejMr0MuE5K_g7otBipb33lvXDxWBWmql18tZhNjMFp1J&sig=AHIEtbRh8mSv8F9CqmQBImgSfm0uSEen-g
Want lowest page-fault rate
Evaluate algorithm by running it on a particular string of memory references (reference string)
and computing the number of page faults on that string
https://docs.google.com/viewer?a=v&q=cache:1EsrAb83UboJ:www.cs.gsu.edu/~sguo/slides/4320/ch9.ppt+&hl=en&pid=bl&srcid=ADGEESg9YCt0XM4M5Kbx0qMipuZRja3jt3YNkX9El58HVxjyc5YUBhRQnDNWjEb-g82gxVAZSnZku0E0YPDcStMOlsGvxNfpe_D9KVxt-Hj-sl2E2H8al0Cf5ovtlio0vk7empKIc3eg&sig=AHIEtbRmJmBULv6rfF0J5nUwxXhs6qZKKA
http://www.sal.ksu.edu/faculty/tim/ossg/Memory/virt_mem/page_replace.html
http://www.cs.uiuc.edu/class/sp06/cs241/Animations/PageReplace/replacement.html
CPU cache
Web server cache of web pages
Buffered I/O (file) caches
https://docs.google.com/viewer?a=v&q=cache:87q4IkXXN4wJ:www.sju.edu/~ggrevera/csc4035/csc4035-4-4.ppt+&hl=en&pid=bl&srcid=ADGEESiss2DUzrHjwkVrMB7ryPxqMJcbpPULKDK2dgWPwLRBZeaGOjjtIwvnJ4Gub_0Niz5e9C5QF7pA1plk2Wi_6AWcZuAmGgZ5RL0JyYLSc6CjWrBGH0u3qvVgPk1vkbOvesVwLywL&sig=AHIEtbSiMSED0PP13zzQIvs5KiXkHgbjCg
A page replacement algorithm picks a page to paged out and free up a frame
https://docs.google.com/viewer?a=v&q=cache:s6l_kPSedtYJ:www.cs.utah.edu/~mflatt/past-courses/cs5460/lecture10.pdf+&hl=en&pid=bl&srcid=ADGEEShMd71xSLfqZl12xDeMg6Ttawvbf94YiUSaGHHDw4vYKerSTntGWld6kN2iJEt2fdIzlJTrJw1Pp7M1rJaTXQaYSKUpIKMOtSttnmXTdjqgoFks2wwE_1n1SEKXZsDzwPRBN2d8&sig=AHIEtbQa2NhT70uDN_TLxB2fuPQ5dUnOwQ
9.4.2 FIFO Page Replacement
A simple and obvious page replacement strategy is FIFO, i.e. first-in-first-out.
An interesting effect that can occur with FIFO is Belady's anomaly, in which increasing the number of frames available can actually increase the number of page faults
that occur!
9.4.3 Optimal Page Replacement
The discovery of Belady's anomaly lead to the search for an optimal page-replacement algorithm, which is simply that which yields the lowest of all possible page-
faults, and which does not suffer from Belady's anomaly.
This algorithm is simply "Replace the page that will not be used for the longest time in the future."
9.4.4 LRU Page Replacement
The prediction behind LRU, the Least Recently Used, algorithm is that the page that has not been used in the longest time is the one that will not be used again in the
near future. ( Note the distinction between FIFO and LRU: The former looks at the oldest load time, and the latter looks at the oldest use time. )
9.4.5 LRU-Approximation Page Replacement
http://www.youtube.com/watch?v=pGWbb7QIapQ
http://www.youtube.com/watch?v=GUL2txPndHs
http://www.cs.uic.edu/~jbell/CourseNotes/OperatingSystems/9_VirtualMemory.html
- Page Replacement Algorithms
Fixed Number of Frames
First In/First Out (FIFO)
Optimal (OPT, MIN)
Least Recently Used (LRU)
Not-Recently-Used or Not Used Recently (NRU, NUR)
Clock
Second-chance Cyclic
Variable Number of Frames
Working Set (WS)
Page Fault Frequency (PFF)
http://nob.cs.ucdavis.edu/classes/ecs150-2008-02/handouts/memory/mm-pagexample.html
- Paging
• If a page is not in physical memory
– find the page on disk
– find a free frame
– bring the page into memory
• What if there is no free frame in memory?
Page Replacement
Basic idea
if there is a free page in memory, use it
if not, select a victim frame
write the victim out to disk
read the desired page into the now free frame
update page tables
restart the process
Page Replacement
• Main objective of a good replacement algorithm is to achieve a low page fault rate
– insure that heavily used pages stay in memory
– the replaced page should not be needed for
some time
• Secondary objective is to reduce latency of a page fault
– efficient code
– replace pages that do not need to be written out
https://docs.google.com/viewer?a=v&q=cache:Z21kbpmJIh4J:pages.cs.wisc.edu/~mattmcc/cs537/notes/Replacement.ppt+&hl=en&pid=bl&srcid=ADGEESj7uIgxkdOGy1nM__CGFctASur2ho79p326r_SPmkGuw_5G0sBrMh9curCHZ-yMfReLi5KTfYDWT-26pMp-ua-0JlYqejMr0MuE5K_g7otBipb33lvXDxWBWmql18tZhNjMFp1J&sig=AHIEtbRh8mSv8F9CqmQBImgSfm0uSEen-g
- Page Replacement Algorithms
Want lowest page-fault rate
Evaluate algorithm by running it on a particular string of memory references (reference string)
and computing the number of page faults on that string
https://docs.google.com/viewer?a=v&q=cache:1EsrAb83UboJ:www.cs.gsu.edu/~sguo/slides/4320/ch9.ppt+&hl=en&pid=bl&srcid=ADGEESg9YCt0XM4M5Kbx0qMipuZRja3jt3YNkX9El58HVxjyc5YUBhRQnDNWjEb-g82gxVAZSnZku0E0YPDcStMOlsGvxNfpe_D9KVxt-Hj-sl2E2H8al0Cf5ovtlio0vk7empKIc3eg&sig=AHIEtbRmJmBULv6rfF0J5nUwxXhs6qZKKA
- Page Replacement Algoritms
http://www.sal.ksu.edu/faculty/tim/ossg/Memory/virt_mem/page_replace.html
- Simulation
http://www.cs.uiuc.edu/class/sp06/cs241/Animations/PageReplace/replacement.html
- Page replacement algorithms
CPU cache
Web server cache of web pages
Buffered I/O (file) caches
https://docs.google.com/viewer?a=v&q=cache:87q4IkXXN4wJ:www.sju.edu/~ggrevera/csc4035/csc4035-4-4.ppt+&hl=en&pid=bl&srcid=ADGEESiss2DUzrHjwkVrMB7ryPxqMJcbpPULKDK2dgWPwLRBZeaGOjjtIwvnJ4Gub_0Niz5e9C5QF7pA1plk2Wi_6AWcZuAmGgZ5RL0JyYLSc6CjWrBGH0u3qvVgPk1vkbOvesVwLywL&sig=AHIEtbSiMSED0PP13zzQIvs5KiXkHgbjCg
- Page-Replacement Algorithms
A page replacement algorithm picks a page to paged out and free up a frame
https://docs.google.com/viewer?a=v&q=cache:s6l_kPSedtYJ:www.cs.utah.edu/~mflatt/past-courses/cs5460/lecture10.pdf+&hl=en&pid=bl&srcid=ADGEEShMd71xSLfqZl12xDeMg6Ttawvbf94YiUSaGHHDw4vYKerSTntGWld6kN2iJEt2fdIzlJTrJw1Pp7M1rJaTXQaYSKUpIKMOtSttnmXTdjqgoFks2wwE_1n1SEKXZsDzwPRBN2d8&sig=AHIEtbQa2NhT70uDN_TLxB2fuPQ5dUnOwQ
Labels:
operating systems
Page Replacement
Page Replacement
In order to make the most use of virtual memory, we load several processes into memory at the same time. Since we only load the pages that are actually needed by each
process at any given time, there is room to load many more processes than if we had to load in the entire process
what happens if some process suddenly decides it needs more pages and there aren't any free frames available?
This is known as page replacement, and is the most common solution. There are many different algorithms for page replacement
9.4.1 Basic Page Replacement
page-fault processing assumed that there would be free frames available on the free-frame list
Now the page-fault handling must be modified to free up a frame if necessary
Find a free frame:
If there is a free frame, use it.
If there is no free frame, use a page-replacement algorithm to select an existing frame to be replaced, known as the victim frame.
http://www.cs.uic.edu/~jbell/CourseNotes/OperatingSystems/9_VirtualMemory.html
In order to make the most use of virtual memory, we load several processes into memory at the same time. Since we only load the pages that are actually needed by each
process at any given time, there is room to load many more processes than if we had to load in the entire process
what happens if some process suddenly decides it needs more pages and there aren't any free frames available?
This is known as page replacement, and is the most common solution. There are many different algorithms for page replacement
9.4.1 Basic Page Replacement
page-fault processing assumed that there would be free frames available on the free-frame list
Now the page-fault handling must be modified to free up a frame if necessary
Find a free frame:
If there is a free frame, use it.
If there is no free frame, use a page-replacement algorithm to select an existing frame to be replaced, known as the victim frame.
http://www.cs.uic.edu/~jbell/CourseNotes/OperatingSystems/9_VirtualMemory.html
Labels:
operating systems
Virtual Memory
Virtual Memory
Virtual memory is a technique that allows the execution of processes that are not completely in memory.
One major advantage of this scheme is that programs can be larger than physical memory.
Further, virtual memory abstracts main memory into an extremely large, uniform array of storage, separating logical memory as viewed by the user from physical
memory.
http://siber.cankaya.edu.tr/ozdogan/OperatingSystems/ceng328/node191.html
Virtual memory is a technique that allows the execution of processes that are not completely in memory.
One major advantage of this scheme is that programs can be larger than physical memory.
Further, virtual memory abstracts main memory into an extremely large, uniform array of storage, separating logical memory as viewed by the user from physical
memory.
http://siber.cankaya.edu.tr/ozdogan/OperatingSystems/ceng328/node191.html
Labels:
operating systems
Segmentation
Segmentation
An important aspect of memory management that became unavoidable with paging is the separation of the user's view of memory and the actual physical memory.
The user's view of memory is not the same as the actual physical memory. The user's view is mapped onto physical memory.
This mapping allows differentiation between logical memory and physical memory.
http://siber.cankaya.edu.tr/ozdogan/OperatingSystems/ceng328/node188.html
An important aspect of memory management that became unavoidable with paging is the separation of the user's view of memory and the actual physical memory.
The user's view of memory is not the same as the actual physical memory. The user's view is mapped onto physical memory.
This mapping allows differentiation between logical memory and physical memory.
http://siber.cankaya.edu.tr/ozdogan/OperatingSystems/ceng328/node188.html
Labels:
operating systems
Paging
- Paging
Paging is a memory-management scheme that permits the physical address space of a process to be non-contiguous.
Eliminates problems with fragmentation by allocating memory in equal sized blocks known as pages.
The basic idea behind paging is to divide physical memory into a number of equal sized blocks called frames,
and to divide a programs logical memory space into blocks of the same size called pages
Any page ( from any process ) can be placed into any available frame.
The page table is used to look up what frame a particular page is stored in at the moment
http://www.cs.uic.edu/~jbell/CourseNotes/OperatingSystems/8_MainMemory.html
- Paging
http://www.youtube.com/watch?v=-Ypa8Uwf5YA&feature=related
paging provides shared memory among multiple userspace processes
Labels:
operating systems
Wednesday, April 11, 2012
Deadlocks
- Deadlocks
A deadlock situation can arise if the following four conditions hold simultaneously in a system:
*Mutual exclusion. At least one resource must be held in a nonsharable mode;
That is, only one process at a time can use the resource.
If another process requests that resource, the requesting process must be delayed until the resource has been released.
*Hold and wait. A process must be holding at least one resource and waiting to acquire additional resources that are currently being held by other processes.
*No preemption. Resources cannot be preempted; that is, a resource can be released only voluntarily by the process holding it, after that process has completed its task.
*Circular wait. A set $ \{P_0,P_1,\ldots,P_n\}$ of waiting processes must exist such that
http://siber.cankaya.edu.tr/ozdogan/OperatingSystems/ceng328/node155.html
- Deadlock
A deadlock is a situation in which two or more competing actions are each waiting for the other to finish, and thus neither ever does
http://en.wikipedia.org/wiki/Deadlock
Labels:
operating systems
Process Synchronization
Process Synchronization
Cooperating processes can
either directly share a logical address space (that is, both code and data)
or be allowed to share data only through files or messages.
Concurrent access to shared data may result in data inconsistency.
Race Condition
A potential problem; the order of instructions of cooperating processes
The Critical-Section Problem
How do we avoid race conditions? What we need is mutual exclusion
Various proposals for achieving mutual exclusion, so that while one process is busy updating shared memory in its CS, no other process will enter its CS and cause trouble.
Disabling Interrupts
Lock Variables
Strict Alternation
Peterson's Solution
The TSL instructions (Hardware approach)
Semaphores
A synchronization tool called semaphore.
Semaphores are variables that are used to signal the status of shared resources to processes.
Classic Problems of Synchronization
a number of synchronization problems as examples of a large class of concurrency-control problems.
The Bounded-Buffer Problem
The Readers-Writers Problem
The Dining-Philosophers Problem
6.7 Monitors
Semaphores can be very useful for solving concurrency problems, but only if programmers use them properly. If even one process fails to abide by the proper use of semaphores, either accidentally or deliberately, then the whole system breaks down. ( And since concurrency problems are by definition rare events, the problem code may easily go unnoticed and/or be heinous to debug. )
A monitor is essentially a class, in which all data is private, and with the special restriction that only one method within any given monitor object may be active at the same time. An additional restriction is that monitor methods may only access the shared data within the monitor and any data passed to them as parameters. I.e. they cannot access any data external to the monitor.
http://siber.cankaya.edu.tr/ozdogan/OperatingSystems/ceng328/node150.html
Cooperating processes can
either directly share a logical address space (that is, both code and data)
or be allowed to share data only through files or messages.
Concurrent access to shared data may result in data inconsistency.
Race Condition
A potential problem; the order of instructions of cooperating processes
The Critical-Section Problem
How do we avoid race conditions? What we need is mutual exclusion
Various proposals for achieving mutual exclusion, so that while one process is busy updating shared memory in its CS, no other process will enter its CS and cause trouble.
Disabling Interrupts
Lock Variables
Strict Alternation
Peterson's Solution
The TSL instructions (Hardware approach)
Semaphores
A synchronization tool called semaphore.
Semaphores are variables that are used to signal the status of shared resources to processes.
Classic Problems of Synchronization
a number of synchronization problems as examples of a large class of concurrency-control problems.
The Bounded-Buffer Problem
The Readers-Writers Problem
The Dining-Philosophers Problem
6.7 Monitors
Semaphores can be very useful for solving concurrency problems, but only if programmers use them properly. If even one process fails to abide by the proper use of semaphores, either accidentally or deliberately, then the whole system breaks down. ( And since concurrency problems are by definition rare events, the problem code may easily go unnoticed and/or be heinous to debug. )
A monitor is essentially a class, in which all data is private, and with the special restriction that only one method within any given monitor object may be active at the same time. An additional restriction is that monitor methods may only access the shared data within the monitor and any data passed to them as parameters. I.e. they cannot access any data external to the monitor.
http://siber.cankaya.edu.tr/ozdogan/OperatingSystems/ceng328/node150.html
Labels:
operating systems
Subscribe to:
Posts (Atom)