Showing posts with label B.Tech 2-2. Show all posts
Showing posts with label B.Tech 2-2. Show all posts

Wednesday, 5 November 2014

OPERATING SYSTEM Important

What are two types of low-level operations that higher-level synchronization operations(e.g., semaphores and monitors) can be built upon?
Test-and-set. compare-and-swap. atomic reads and writes. Other atomic operations. enabling
and disabling interrupts.

_______________________________________________________________
What is the difference between a process and a thread?
Every process has its own address space, but multiple threads inside a process share part of
the memory with their parent process. There is less context switching overhead to switch
among threads when compared to switching among threads.

_______________________________________________________________
What is the difference between deadlock and starvation?
In a deadlock situation, none of the involved processes can possibly make progress. In a
starvation situation, a process is ready to execute, but it is not being allowed to execute.
_______________________________________________________________
Suppose our computer system is running five processes (P1,P2,P3,--,P5 ) and has four
separate types of resources (A,B,C,D). We want to see if the system is in a safe state
using the Banker's algorithm. Using the following information about the state of the
system, determine if the state is safe: (11 points)
Total
AB C D
4 5 4 3

Available
AB C D
0 1 0 0

Maximum
A B C D
P1 1 3 3 0
P2 2 2 1 3
P3 1 1 0 1
P4 1 4 1 0
P5 3 1 2 1

Used
A B C D
P1 0 1 2 0
P2 2 0 1 1
P3 1 0 0 1
P4 0 3 1 0
P5 1 0 0 1

A B C D
Total 4 5 4 3

A B C D
Available 0 1 0 0

Total gives the number of instances of each resource in the system; Available gives the
number of unallocated instances of each resource; Maximum refers to the maximum
number of instances of each resource required by each process; Used refers to how many instances of each resource each process currently holds.

Answer:
The Need matrix is as follows:
Need
A B C D
P1 1 2 1 0
P2 0 2 0 2
P3 0 1 0 0
P4 1 1 0 0
P5 2 1 2 0

The state of the system is unsafe. Executing the Banker's algorithm terminates with P2
and P5 unable to complete. We give a possible sequence of execution with "Work" P3 runs (1, 1, 0, 1), P4 runs (1, 4, 1, 1),P1 runs (1, 5, 3, 1). Now neither P2
nor P5 can release its resources because each holds resources the other needs.
------------------------------------------------------------------------------------------------
2. A computer system has m resources of the same type and n processes share these
resources. Prove or disprove the following statement for the system:
This system is deadlock free if sum of all maximum needs of processes is less than m+n.

3. There are four processes which are going to share nine tape drives. Their current and
maximum number of allocation numbers are as follows :
process current maximum
p1 3 6
p2 1 2
p3 4 9
p4 0 2
a. Is the system in a safe state? Why or why not?
b. Is the system deadlocked? Why or why not?


A Process Using Mutual Exclusion:

int me;
while (1) {
/* non critical section code */
enter(me); /* also called entry code */
/* critical section code */
leave(me); /* also called exit code */
}

We assume each process has access to its process ID, which we're calling me in this example. The process can pass its ID into the enter() and leave() functions.
First try: use a lock.

shared int lock = 0;

void enter(int me)
{
while (lock == 1) /* do nothing */;
lock = 1;
}

void leave(int me)
{
lock = 0;
}


Problem: Process 0 can check that the lock is available, and then get preempted. Process 1 can now check the the lock is available, and enter the critical section. While in the critical section, it can be swapped out, and Process 0 restarted. Since Process 0 has already checked the availability of the lock, it can also enter the critical section. This "solution" fails to provide mutual exclusion.
Second try: take turns

shared int turn = 0;

void enter(int me)
{
while (turn != me);
}

void leave(int me)
{
turn = 1 - me;
}

Problem: If process 0 never attempts to enter the critical section, process 1 is never allowed to enter it (and, if 0 has entered once, it can never enter again until 1 endters). This "solution" fails to guarantee progress. Can you convince yourself it does in fact provide mutual exclusion (so it does meet some of the criteria, but not all)?
Third try: Keep track of whether the other guy wants in

shared int flag[2];

void enter(int me)
{
flag[me] = 1;
while (flag[1-me]);
}

void leave(int me)
flag[me] = 0;
}

Problem: Doesn't satisfy the progress condition. Both processes can get stuck in the entry code and wait there forever, in other words "deadlocked".

Fourth and last try: (Peterson's Algorithm): combine second and third

The basic approach here is that we're going to keep track of both whether the other process wants in, and also whose turn it is. If the other process wants to get in, we'll let it in if it's its turn. But if it doesn't want in, we'll take its place.

shared int flag[2];
shared int turn;

void enter(int me)
{
flag[me] = 1;
turn = 1-me;
while (flag[1-me] && (turn == (1-me)));
}

void leave(int me)
{
flag[me] = 0;
}

CRITICAL SECTION

1.


// functions to enter/leave the
// critical section
void critical_section_enter_t0()
{
while (turn != T0)
continue;
}
void critical_section_leave_t0()
{
turn = T1;
}


// functions
void critical_section_enter_t1()
{
while (turn != T1)
continue;
}
void critical_section_leave_t1()
{
turn = T0;
}


i. Does this proposal provide mutual exclusion for the critical
section? Justify your answer!

Yes, it does. The variable ‘turn’ is either T0 or T1, and if it is T0, then
only thread T0 can progress past ‘critical_section_enter_t0’, and vice
versa.

ii. Is this proposal a satisfactory solution to the critical section
problem? Justify your answer!


No, it is not. It does not guarantee progress. In particular, thread T0
cannot reenter the critical section after it has left it unless thread T1
entered and left the critical section in the interim since critical_section_leave_t0() sets turn = T1. Only critical_section_leave_t1() can change it back to T0 again.

Consider:
critical_section_enter_t0();
critical_section_leave_t0();
// may block even though t1 is not in the critical section
critical_section_enter_t0();
critical_section_leave_t0();

Database Quiz


1. Set of permitted values of each attributes are called
A . Row
B. Column
C. Domain
D. Schema

2. Which of the following statements is not true
A. All primary keys are super keys
B. A candidate key can have a proper subset which is a super key
C. All super keys are not candidate keys
D. A candidate key may not be a super key

3. Entity integrity means that
A. A primary key cannot be null.
B. A foreign key cannot be null.
C. A primary key can be partially null.
D. A foreign key can be partially null.

4. The target of a foreign key should be
A. Foreign key in another table
B. Primary key in another table
C. Super key in another table
D. Primary key in the same table

5. Which of the following can not be the mapping cardinality of a foreign key
A. One- one
B. Many - many
C. Many- one

6. SQL is a
A. Host language
B. Application language
C. Data manipulation language

7. In the following ER diagram,


mapping cardinality of the relation is many one, which means
one manager can manage

A. zero or more departments
B. one or more departments
C. more than one department
D. exactly one department

8. Entity, that can not be uniquely identified by its own attributes , is called
A . Composite entity
B. Strong entity
C. Weak entity
D. Simple entity

In schema S = {A,B,C,D,E,F,G,H}, suppose the following hold for S.
AB --> CD
E --> F
F --> G

9. Which of the following holds true with respect to the above schema
A. CD --> AB
B. AB --> ACD
C. A --> CD
D. AB --> C

10. Which of the following does not hold true.
A. E --> G
B. ABE -->CDE
C. AB --> ABH
D. AB --> null set

Solutions
  1. A B A B B C A C D C

DATABASE MANAGEMENT SYSTEMS

Important link for learning DBMS

INTRODUCTION : PPS
THE ENTITY RELATIONSHIP MODEL : PPS
THE RELATIONAL  MODEL: PPS

THE RELATIONAL  MODEL : PPS


ER TO RELATIONAL TRANSFORMATION : PPS
FUNCTIONAL DEPENDENCIES AND NORMALIZATION IN DATABASES : PPS


DESIGN, STORAGE, INDEXING : PPTp1  and  PPTp2
SYSTEM CATALOG AND QUERY OPTIMIZATION : PPS 

TRANSACTION PROCESSING AND CONCURRENCY CONTROL : PPS

RECOVERY : PPS

SECURITY : PPS

  • Dynamic Coalition Problem  - Overheads: PPT
DISTRIBUTED DBMS, DATA WAREHOUSES AND DATA MINING, WEB-BASED DB ARCHITECTURES
SOFTWARE  DESIGN, JAVA, REQUIREMENTS 
UML: UNIFIED MODELING LANGUAGE 
All the best

Design of Algorithms

Algorithms

Number Date Topic Source Text
1 1/16 Introduction, administration, time and space complexity --
2 1/18 Basics: asymptotic notation PPT 3.1-3.2
3 1/21 Basics: recurrences (mergesort) PPT 4.1
4 1/23 Basics: recurrences continued, master theorem PPT 4.3, 6.1-6.2
5 1/25 Sorting: intro to heapsort PPT 6, 7.1-7.3
6 1/28 Sorting: heapsort, priority queues PPT 7.4
7 1/30 Sorting: quicksort PPT 5.1-5.3
8 2/1 Sorting: quicksort average case analysis PPT 5.4 last section
9 2/4 Sorting: linear time sorting algorithms PPT 8.1-8.2
10 2/6 Sorting: linear time algorithms continued;
Order statistics: selection in expected linear time
PPT 8.3-8.4
9.1-9.2
11 2/8 Order statistics: selection in worst-case linear time PPT 9.3
12 2/11 Review for exam PPT
EXAM 2/13 EXAM 1: Basics, Sorting, Order Statistics
--
13 2/15 Structures: binary search trees PPT 12.1-12.3
14 2/18 Structures: red-black trees PPT 13.1-13.2
15 2/20 Structures: red-black trees (insertion) PPT 13.3-13.4
16 2/22 Structures: skip lists PPT --
17 2/25 Structures: skip lists, hash tables  PPT 11.1-11.2
18 2/27 Structures: hash tables (hash functions) PPT 11.3-11.4
19 3/1 Structures: hash tables (universal hashing) PPT 11.3-11.4
20 3/4 Augmenting structures: dynamic order statistics PPT 14.1-14.2
21 3/6 Augmenting structures: interval trees PPT 14.3
22 3/8 Graph algorithms: the basics PPT 22.1-22.3
-- -- SPRING BREAK
--
23 3/18 Graph algorithms: BFS PPT 22.3
24 3/20 Graph algorithms: DFS PPT 23.1
EXAM 3/22 EXAM 2: Data structures
--
-- 3/25 Go over exam
--
25 3/27 Minimum spanning trees PPT 23.2
26 3/29 Shortest paths: Bellman-Ford PPT 24.1-24.3
27 4/1 Shortest paths: DAG, Dijkstra's algorithm PPT
28 4/3 Finish Dijkstra's.  Kruskals algorithm; disjoint sets PPT 21.1-21.3, 23.2
29 4/5 Disjoint sets; amortized analysis PPT 17.1-17.2
30 4/8 Amortized analysis continued PPT 17.3-17.4
31 4/10 Dynamic programming  PPT 15.1, 15.3
32 4/12 Dynamic programming (longest common subsequence) PPT 15.4
33 4/15 Dynamic programming (knapsack problem) PPT
34 4/17 Greedy algorithms  PPT 16.1-16.2
35 4/19 NP-Completeness PPT 34.1-34.2
36 4/22 NP-Completeness continued PPT 34.1-34.2
37 4/24 NP-Completeness: reductions PPT 34.3-4
38 4/26 NP-Completeness: reductions PPT 34.3-4