Wednesday, 24 June 2015

Important Points to remember for Operating System

Test and Set Operation:

This operation reads the memory block. If the memory is allocated, then it keep the bit 1 otherwise it allocates the memory and set the bit from 0 to 1

It works as TestAndSet(a,b)

  1. Read the value of b
  2. Value of b goes to a
  3. b=True
It can be used for locking and unlocking memory

System Calls: The System Call is the Request for Running any Program and for Performing any Operation on the System. 

Scheduler:
  • Long term scheduler: determines which programs should be admitted for execution and when and which ones should be exited
  • Middle Term scheduler transfers data from secondary memory to primary memory and vice versa
  • Short time scheduler: timely allocates CPU to ready processes.
Fork System Calls: 
  • Successful: returns ParentID-> childPID and ChildProcess->0
  • Unsuccessful: returns ParentID ->1
Threads: Light weight process because they share code and data. However, every thread have its own register and stack.


Notes of Important concepts of Operating Systems

Detailed Architecture

  • Hardware
  • Machine Code
  • Operating System
  • System Programming Language
  • Compiler
  • Application Programming Language
  • Application Package
Operating System: 
  • Written in Low Level Language
  • Collection of programs which controls the resources of system
Basic Operations:
  • Device Configuration
  • File Management
  • Memory Management
  • Interface platform
Types of Operating Systems:
  • Batch Processing
  • Real Time
  • Time Sharing
Special Features of Operating Systems
  • Multi-tasking
  • Multi-programming
  • Parallel Processing
  • buffering
  • Spooling: Simultaneous Peripheral Operation On-line

Tuesday, 23 June 2015

Discrete Math concepts of National Level Exam (Previous Questions)

1. The number of integers between 1 and 250 that are divisible by 2, 5 and 7 is
(A) 2 (B) 3
(C) 5 (D) 8

2*5*7=70
250/70=3.___=3=B

Concept
Numbers which can be divisible by any of the three: n(A) + n(B) + n(C) - n(A and B) - n(B and C) - n(A and C) + n(A and B and C)
Numbers which can be divisible by all three: n(A and B and C)
Numbers which can be divisible by atleast two of three: n(A and B) - n(B and C) - n(A and C) + n(A and B and C)


2. An undirected graph possesses an eulerian circuit if and only if it is connected and its vertices are
(A) all of even degree
(B) all of odd degree
(C) of any degree
(D) even in number

An Euler path is a path that uses every edge of a graph exactly once. 
An Euler path starts and ends at different vertices.

An Euler circuit is a circuit that uses every edge of a graph exactly once.
An Euler circuit starts and ends at the same vertex.
It may cross/ repeat vertices but not edges
If number of odd vertices in path is exactly 2, then it is Euler Path,
If a graph G has an Euler circuit, then all of its vertices must be even vertices.
In every graph, the sum of the degrees of all vertices equals twice the number of edges. 
To find an Euler path or an Euler circuit:
  1. Make sure the graph has either 0 or 2 odd vertices. 
  2. If there are 0 odd vertices, start anywhere. If there are 2 odd vertices, start at one of them. 
  3. Follow edges one at a time. If you have a choice between a bridge and a non-bridge, always choose the non-bridge. 
  4. Stop when you run out of edges. 
This is called Fleury’s algorithm, and it always works!



Fuzzy Logic in Soft Computing

In our day to day life, we use those terms which are imprecise in nature. It rains heavily. Boy is Good. Whether is cloudy. The question is How much?

Fuzzy deals with handling of this imprecise theory.

Stochastic Uncertainty: (80%)
Lexical Uncertainty: Tall man, hot days, stable currencies.

Conventional Boolean Set Theory:
The answer is 0 or 1.
The crisp boundary is framed

Fuzzy Set Theory:
The answer is varied in between 0 and 1
The boundary is gradual.

Fuzzy Logic: Reasoning with qualitative information
Fuzzy set differs from crisp set in terms of membership

Membership/ Character/ Discriminative predicate

x={1,2,3,4,6,8,10}
u belongs to x.
u is membership function of x which is either 1 or 0. // for crisp set

Us is between 0 and 1 (both are included) // for fuzzy set
Characteristic function: 0 <=Us<=1

Notion of truth can be modeled in fuzzy set
Member functions represent curves

Alpha-cut is a crisp set whose values are greater than 0.
Union: Maximum of both
Intersection: Minimum of both

Converting a fuzzy term in crisp value is called defuzzification
  

Sunday, 21 June 2015

Multi-dimensional Arrays in Programming

Two Dimensional Arrays

int A[4][2]
A[rows][columns]

Storage in memory: row major order. Memory storage is always one dimensional storage.

Two Dimensional arrays are always rows followed by columns

It is just like there are 10 classes, each class have 10 students and 1 monitor and every all monitors are ordered by one teacher.

Teacher[10][10].

Teacher

  • Monitor1
    • Student 1
    • Student 2
    • Student 3
    • [upto 10]
  • Monitor2
    • Student 1
    • Student 2
    • Student 3
    • [upto 10]
  • Monitor3
    • Student 1
    • Student 2
    • Student 3
    • [upto 10]
  • and so on
Similarly with 3 Dimensions 

It will go at 3 levels. 

Introduction to Functions in Programming

Functions is a module which takes input and gives some output.

It can be

  • inbuilt
  • user defined
What happens in black-box is not required and is hidden. These hidden details are said to be abstract. 

Break large program into smaller problems and compose them together into one unit later on. Using of standard library functions is good programming practice to save time.

Functions are used to
  • Hiding the details
  • incorporate changes
  • Facilitates modular programming
  • Reusable
We have caller and callee. Caller can give any number of calls to callee. This is called re-usability.

Function cannot be written completely in other function. Main() is the very first function which is used. The control flow can move from one function to another as called by caller and return back. 

Prototype tells the blackbox description of function i.e. inputs, number of inputs, types of inputs, return types etc. 

Calling programs pass actual parameters. Information is accessed by called functions using formal parameters. 

Accessing arrays with pointers | Strings in Programming

We can access array using *(ptr+i)

So, let us see what this means

(ptr+i) for i=0, means ptr i.e. *(ptr+i) for i=0 is *ptr
When we add i, it means adding i number of locations to ptr and finding its value at ptr+i.

sizeof(x) operator tells the size of that variable x.

Arithmetic with Pointers

Increment/ Decrements
Comparing pointers
Subtraction with pointers

String

Sequence of character is referred to as string. The last character of string is '\0' null character.

char s1[]="H"; //constant pointer to string
char s2='H'; //
char *s3="H"; //pointer to constant string

sizeof(s1); //gives 2
sizeof(s2); //gives 1
sizeof(s3); //gives 2

Notion of the string is not a basic datatype in C. String is an array of character i.e. it is an aggregate data type of characters.

Functions of String:
char* strcmp(char *str1,char *str2)




Understanding of Pointers in Programming

Recap:

int k;

k is a variable which hold some value and is saved at some location.

Pointer: int *p;

* is not a valid character in variable p;
p is supposed to be a pointer of type integer.
p contains memory location instead of actual value

int means we use pointers to pointer the memory location of integer type.

p as a variable is allocated value 100 which means it points to the location 100 which in turn is indicated by some other variable holding a value.

It can only hold one address at a time because it is a variable

Concept of L-value and R-value

L-value means address of memory location. R-value is the actual value which you are going to put in.
L-value lies at left hand side and R-value lies on right hand side.

Using pointers, you can actually access and manipulate the L-value also. Memory required by the pointer depends upon the size of the memory in the machine.

Let pointer of size = 8 bits
It can only point to 256 memory locations

Task of allocation of memory to pointers is left to machine.

Instance

int *p;
int k=38;
p=&k; // address of k is stored in p.
*p=5 //value of k gets changed to 5

To print address, use %p as specifier

Null Pointer: Pointer which is not pointing to any address. No other valid pointer (no other pointer which is actually storing any value) will ever compare equal to null pointer.

This constant NULL is usually defined in <stdio.h>

C provides pointer of type Void. Void pointer is like generic pointer. We can make it point to any datatype.

Note: Anything that we do using Array, can be done by pointers. In that way, pointer is more powerful than arrays.

The name is array is synonym for 0th location of array which means;
int *ptr;
int a[10];
ptr=&a[10]; // is similar to ptr=a;

arrays name is constant pointer i.e. the name of the array cannot be changed. pointers can be assigned and/ or incremented.



Saturday, 20 June 2015

Arrays in Programming

Aggregated datatype of

  • Homogeneous type of elements: Array
  • Heterogeneous type of elements: Structure
Arrays

Arrays have fixed size and sequentially indexed

int a[10]; 

It says that a is the variable which contains 10 integer values which are contiguously stored in memory. 

Each element can be thought of as a variable. '&' is used to get location in the memory.

Note: We assign value from a[0] to a[9] and we cannot assign value for a[10].
We may have arrays of 2D and 3D

Generic Programs

#define N 6

Preprocessor replace the value of N with 6 where ever it comes in program
When ever we change source code of the program, we need to save, recompile and run.

Arrays can also be used as Counters








 

Compound Statements in Programming

Compound Statement

if(<expression>)
expression evaluation should be true or false

Sequential Structure works step by step (one after other)
Selection statements can change the flow of the program.

if(x%3 ==0)
                printf("x is a multiple of 3");

Else always attach itself to the nearest if statement if in-case we do not provide braces.

Switch Statement:  A multi-way decision statement

When we use case in switch, C allows the constant values in case but not variables.
Multiple values in single case are not allowed. However, we can use multiple values using equivalent number of multiple cases.

Looping

Loops are of two kinds

  • Counter Controlled
  • Sentinel Controlled
In While loop, expression value should change in body otherwise it will enter into infinite loop.

Two ways to change the loop behavior

  • continue 
  • break




Introduction to C Programming Syntax

Output Statement

Printf(format string, var1, var2..)

printf("Hello World");

  • It displays the string. It is supposed to be printed as it is as long as we introduce some valuable string.
 printf("Given Value is %d", a);

  • %d is a specifier which takes value of a. The number of specifiers are mentioned, so are the number of variables given to printf.
Printf returns number of characters printed

Input Statement

scanf(format string, &var1, &var2)

Everything else is same but we give & when we enter any variable. & is the pointer which is used to store the address location for variable.

Other format specifiers
%d: Integer
%f: Float
%c: Character
%e: exponential

Scanf returns 1 for correct input and 0 for wrong input

Statements
  • Simple Statements
  • Compound Statements
    • Conditional
      • If else
      • Switch
    • Loops
      • For
      • While
      • Do while


Basics of Programming

Every memory location is given a name. This name is called variable. When we consider variable, it have some kind of data types which are attached to them. All data should be of certain number of bytes to which we call one word. For eg., int is of 4 bytes

Instructions perform operations.
Steps:

  • Pick instruction in sequence
  • Get the value of variables
  • Perform operations
  • Store the results
  • Go back and pick next instructions
Equal symbol is called the assignment operator. 


Variable is something that can change during execution of a program but constant cannot.
Variable names are case sensitive. Maximum size for variable name is 31. Keywords are reserved words.

While using operators, it is good practice to use parenthesis rather than relying on precedence rule, although this rule works. Expression is evaluated from left to right.

Precedence rule:

  1. Parenthesis and sub-expressions
  2. *, / , %
  3. +, -

Unusual Operators:
Using increment (++) and decrements (--) operator

Let n= 4;
a=n++;
b=++n;

n=4, a=4, b=6, n=6





Fundamentals of Problem Solution and Programming

Find Largest Number

Let there are three variables given: A, B and C
We need to check the largest number among all three

Find if A>B

  • True:
    • A>C
      • True: A is the largest
      • False: C is the largest
  • False:
    • B>C
      • True: B is the largest
      • False: C is the largest
Check by putting Example: A=1, B=2, C=3

Polynomial Multiplication

Given: ax+b, cx+d
Product: (ac)(x^2) +(ad+bc)x + cd

Take input as a, b, c, d.
Calculate and give their value in equation

int a, b, c, d means it allocated the storage for these four variables.
This storage is in the main memory.

Int stands for integer. This is called data type. Any variable have to be of some data type. There are few inbuilt data types available in language and others can be build by programmer

Memory point of View

Initially memory locations are empty. When we declare variables in main memory, we indicate the name of each location with some variable.

How reading input changes the memory: As soon as we give input/ assign some value to the variable, the location stores that value. If no value is assigned, it just means that the value is unknown (it does not means that it do not have any value).

 ALU performs operations on these variables. It takes the value of variable, performs operation and stores it into another memory location. 


Introduction to Computers

ENIAC: First digital computer. It was built in 1940's. It is quite huge (almost like house in size).
Intel Pentium 4: In 2000. It can perform 1.5 billion operations/ sec : Clock Speed: 1.5 GHz

Google Data Center is equipped with huge number of machines, power systems, cooling systems etc build up of computing machines.

The Computing Machine have memory and processor. We have memory to store information just like houses in colony.

Memory is divided for 

  • Program
  • Data
There are different type of instructions: some are to be executed whereas some are used to control

Building Blocks of Computer:
  • Input
  • Memory
  • ALU: Control Unit and Arithmetic Unit
  • Output
CPU:
  • Fetch Instruction
  • Execute Instructions
  • Store Instructions
  • Runs sequence of instructions
CPU performs operations on bits. 

High Level Instructions: X= Y + Z
Low Level Instructions: Add Y,Z

Compilers

Set of tools which convert High Level Language to Assembly Code.
Assembler converts Assembly Code to Machine Code

Program=Solutions

Program is sequence of instructions. It is a solution to a program. It is source code. 
Any solftware developing process starts with problem. 

Given: Problem
Understand specification, Analyze steps, solve problem and program it.

C Programming Language

C is a General purpose language.