Saturday, December 26, 2015

Digital Electronics Quick Notes:


Digital Counters are of 2 Types:


(i) Synchronous Counters:

    - A Clock is attached to all the FF’s
    - The input to the FF is a function of output(s) of other FF’s
    - D Type FF is used in Synchronous Counters
    - Its faster than Asynchronous Counters
    - Synchronous counters are also called Shift Counters.


    Types of Shift Counters (Synchronous Counters):

    (i) Ring Counter :
        - The output Q of the last FF is connect to the input of first FF.
        - Mod 2 counter have 2 FF’s , can count 2 states.
        - Mod 3 counter have 3 FF’s , can count 3 states.

        Counting States:
        ———————
        For ’N’ FF’s ,  counting states are ’N’
        Ex:  A ring counter with 4 FF’s can counter 4 states.

       

    (ii) Johnson Counter ( or Twisted Ring Counter ) :
        - The output Q” of the last FF is connected to the input of the first FF.
        - Mod 4 counter have 2 FF’s , can count 4 states.
        - Mod 6 counter have 3 FF’s , can count 6 states.

   
        Counting States:
        ———————
        For ’N’ FF’s ,  counting states are ’2N’
        Ex:  A Johnson counter with 3 FF’s can counter 6 states.



(ii)Asynchronous Counters:

    - Asynchronous counters are also called Ripple Counters.
    - A Clock is attached to the first FF.
    - The output of each FF is given as clock signal to the next FF.
    - T Type FF is used in Asynchronous Counters
    - Its slower than Synchronous Counters due to the propagation delay in the FF’s
    - It can be used as Up Counter or Down Counter.
    - Mod 8 counter have 3 FF’s , can count 8 states.


    Counting States:
    ———————
    For ’N’ FF’s ,  counting states are power(2,N)
    Ex:  An Asynchronous counter with 3 FF’s can counter 8 states.

Sunday, December 13, 2015

Compiler Design Quick Notes:



We have seen that a lexical analyser can identify tokens with the help of regular expressions and pattern rules. But a lexical analyser cannot check the syntax of a given sentence due to the limitations of the regular expressions. Regular expressions cannot check balancing tokens, such as parenthesis. Therefore, this phase uses context-free grammar (CFG), which is recognised by push-down automata.

CFG, on the other hand, is a superset of Regular Grammar, as depicted below:






It implies that every Regular Grammar is also context-free, but there exists some problems, which are beyond the scope of Regular Grammar. CFG is a helpful tool in describing the syntax of programming languages.
Context-Free Grammar

In this section, we will first see the definition of context-free grammar and introduce terminologies used in parsing technology.

A context-free grammar has four components:

    A set of non-terminals (V). Non-terminals are syntactic variables that denote sets of strings. The non-terminals define sets of strings that help define the language generated by the grammar.

    A set of tokens, known as terminal symbols (Σ). Terminals are the basic symbols from which strings are formed.

    A set of productions (P). The productions of a grammar specify the manner in which the terminals and non-terminals can be combined to form strings. Each production consists of a non-terminal called the left side of the production, an arrow, and a sequence of tokens and/or on- terminals, called the right side of the production.

    One of the non-terminals is designated as the start symbol (S); from where the production begins.

The strings are derived from the start symbol by repeatedly replacing a non-terminal (initially the start symbol) by the right side of a production, for that non-terminal.









Top Down Parsers:
===============


a) Recursive Descent Parser:
    - There is a recursive function for every Variable.
    - Terminals have a match function



b) LL(1) Parser:

    - Left Recursive grammars are not allowed
    - Ambiguous grammars are not allowed
    - Productions are atomic (i.e not more than one production is allowed in the table rows)
    - First and Follow techniques are used to place productions in the rows of the (Variables , Terminals) table.



Shift-Reduce Parsing
==================

Shift-reduce parsing uses two unique steps for bottom-up parsing. These steps are known as shift-step and reduce-step.

    Shift step: The shift step refers to the advancement of the input pointer to the next input symbol, which is called the shifted symbol. This symbol is pushed onto the stack. The shifted symbol is treated as a single node of the parse tree.

    Reduce step : When the parser finds a complete grammar rule (RHS) and replaces it to (LHS), it is known as reduce-step. This occurs when the top of the stack contains a handle. To reduce, a POP function is performed on the stack which pops off the handle and replaces it with LHS non-terminal symbol.





Bottom Up Parsers:
================

a) Operator Precedence Parser:

    - Can accept Ambiguous grammars
    - Productions have to be in the form of Operand-operator-Operand
    - Operation relations table and Operation function table are used for Operator precedence and associativity.
    - Operation relations table has space complexity of O(n^2)
    - Operation functions table has space complexity of O(2n)



b) SR Parsers: (Shift Reduce Parsers : Stack is used)

    - All the parsers differ only by their parsing table entries.
    - All the productions uses items i,e (.) in the beginning of the RHS productions.
        Ex. S —> .AA
    - All the parsers use Canonical Collection of LR(0) items (i.e S’ -> .S production)
    - Productions are grouped to represent “Shift” (Transition Production) and “Reduce” (Completed Productions) states.
    - SR (Shift/Reduce) and RR (Reduce/Reduce) issues may appear in Parsing table.



    Types of LR Parsers:

    LR(0) and SLR(1) rely on the canonical LR(0) items

    (i) LR(0) Parser :
            - The reduce step is present across all the entries in the table.

    (ii) SLR(1) Parser :
            - The reduce step is only present for the First of the Left hand side production entry.


    - LALR(1) and CLR(1) rely on the LR(1) item i.e LR(0) + Look head ($) symbols
    - Have more number of entries and statues than the LR(0) items due to the look ahead symbols.
    - Along with each production there is an Look ahead symbol associated, which is computed as First of items after . in each production for each step.
    - CLR(1) parsing table size can be reduced by merging the Shift steps (State numbers), which will make the look aheads irrelevant.  
    - CLR(1) parsing table can be converted to LALR(1) parsing table by joining the States thereby ignoring the look ahead symbols.


    (iii) LALR(1) Parser :
        - The states and look aheads in CLR(1) are merged .
        - May results in RR (reduce/reduce) conflict due to merging of look aheads.

    (iv) CLR(1) Parser :



    Notes:
    =====
    - Number of steps in CLR(1) >= Number of states in LR(0), SLR(1) & LALR(1) parsing table.
    i.e CLR(1)  >=  LR(0) = SLR(1) = LALR(1)  
  


=====================================================================


SDTs : Syntax Directed Translations are of 2 types

(i) S - Attributed SDT :

    - If an SDT uses only synthesised attributes, it is called as S-attributed SDT.
    - These attributes are evaluated using S-attributed SDTs that have their semantic actions     written after the production (right hand side).









(ii) L - Attributed SDT :

    - This form of SDT uses both synthesised and inherited attributes with restriction of not taking values from right siblings.
    - In L-attributed SDTs, a non-terminal can get values from its parent, child, and sibling nodes.
  
    As in the following production
    S → ABC
    S can take values from A, B, and C (synthesised). A can take values from S only. B can take     values from S and A. C can get values from S, A, and B. No non-terminal can get values     from the sibling to its right.



Attributes in L-attributed SDTs are evaluated by depth-first and left-to-right parsing manner.






We may conclude that if a definition is S-attributed, then it is also L-attributed as L-attributed definition encloses S-attributed definitions.




  - SDTs are used for evaluating an arithmetic expression based on arithmetic precedence and associativity.
   - SDTs are also used for infix to postfix translations
Ex. A+B —> AB+

   
=====================================================================









Sunday, December 6, 2015

For NEW students joining IISc


Joining IISc

Bring
  • at least 6 passport size photos and 6 stamp size photos.
  • Original mark sheets and at least two copies of each sheet.
  • Offer letter, fees paid, train tickets for attending interview and joining
  • PAN card and its photocopy for a bank account. For student accounts, there is no need for a PAN card, but if you want a regular account, you need a pan card.
It might be a good idea to arrive a day or two before the reporting date and avail the hostel accommodation (does not apply to UG admissions).
 
Getting to IISc


IISc is 6 km away from the main railway station and bus stand (commonly called Majestic, though the official name is Kempe Gowda Bus stand) and 38 km from the airport. Autos cost Rs 13 per km while taxis cost Rs 18 per km. Prepaid taxis from the railway station and airport cost Rs 300 and Rs 750, respectively. If you are coming for the first time to Bangalore by train or bus, you can take a prepaid auto for Rs. 90 and come to IISc. If you do not have any luggage, you can take a local bus from Majestic (use the overbridge/subway) to cross to the local bus stand. Go to platform 23/24/25 and take any of the 252, 271 series buses. The frequency of the buses is one per two min during peak hours, one per five min during non-peak hours and one per ten min during odd hours (11 pm - 5 am). Ask for Tata Institute (that's what IISc. is commonly known as); that'll get you to 18th cross, Malleswaram or the Yeshwantpur bus stand.

Remember always to ask for Tata Institute, whether it is a bus, auto or taxi. People usually land up at IIM if they ask for IISc.

If you are coming on July 27/28/29/30, then the student council of IISc will pick you up from the Bangalore city station and Yeshwanthpur station. Buses with IISc banners will be there in the parking lot. The main Majestic bus stand is adjacent to the Bangalore city station.

If you are coming from the airport, you can take the Vajra Vayu service (a/c buses) and ask for Mekhri Circle. There are buses almost every 15 minutes from the airport. They will charge you Rs. 150 per person. Get down in Mekhri Circle and ask for Tata Institute. It is 2-3 km and you can take an auto.
First day at IISc

On the date of reporting, go to the faculty hall in the main building. Tokens will be issued as soon as you come and there will be a long queue. You will be called based on this admission number and then your marks sheets, GATE score card etc will be verified. Your photo will be taken and you will be issued an identity card. A 16 digit student registration number (SRN) will be alloted to you. Your first job in IISc is to memorize this number because you will require it everywhere. Please take your photographs with you and you may have to stick it in many places.

Next, visit the hostel office. Pay the hostel fees and show the proof of hostel fees paid and ask for a room allotment. There is a lucky dip and you will be allotted a room. You will be given a room allotment letter, which will serve as your proof of residence.

If you are aware of who will be your research supervisor, be sure to visit his/her office and say hello. Then visit your department office and get all the course registration forms. Each department will hold an orientation program and make sure you get those dates and times.

Next, visit either SBI or Canara Bank and get a new account.

Purchase a SIM card. The BSNL office is near the main building. Private vendors also sell different private phone operators near the hostel office. Many will not sell postpaid options.

Purchase mattresses, pillows etc from the vendors near the hostel office. These vendors are available only during this period. Many other small items like buckets, hangers etc. can be purchased in the stores on IISc campus.

Campus
IISc is a huge residential colony and has all facilities within the campus obviating a need to leave the campus for anything. Take a look at the campus map. 
Here are some places on the campus that you might wish to visit during the next few days. There's the Main Library, the Campus Bookstore (near the Cafe, open noon to 7 pm, except Sundays), the Xerox centres (in the library, near the Cafe and near TMC, open 8:30 am to 8:30 pm), two banks (Canara bank and SBI on your map), and a Health Centre (marked Hospital on your map). For outgoing phones, you may go to the STD/ISD booth west of Canara bank, or to the Telecom Centre (7 am to 10 pm, except Sundays).  The Post office (open 9-5 Mon-Sat) is approached from Prof. CNR Rao circle. It handles registered, speed post, money order etc. in addition to regular mail. The Janatha bazaar (called the Cosmetic Center on your map) is open Mon-Sat and houses a small shop (7-1l am, 5-8 pm), a tailor (10 am-6 pm), a launderer (10 am-8 pm), a cobbler (8 am-8 pm), and a men's hairdresser (7 am-noon, 4-7:30 pm). The launderer, cobbler and hairdresser are also available Sunday mornings. Effective June, 2007, a cycle shop has been opened here. There is a watch repair shop in E-Block (between 4-6 pm on all days except Sunday) and a cycle repair shop near U-Block. There is also a small shopping area at the north end of campus, which has a tailor, travel agent and bookbinder. On the south side of the highway is the Gymkhana. Please do NOT cross the road but use the yellow over-bridge to cross the highway. Inside is a large hall for badminton, table tennis, and movies. In addition there is a carrom room and a TV room; upstairs is a small Library and a music room. Outside is a large playground, a running track and the Students Auditorium. At the Gymkhana, you can obtain permission to use the swimming pool located at the other end of campus (near the guest house). 

Prakurthi (marked Cafe on your map) offers chats, various kinds of food, snacks and coffee/tea from 7:30 am to 3 am  on all days.  Kabini (marked TMC on your map) offers snacks, tea and coffee from 7 am to 6 pm on all days. A good restaurant near Kabini called Nesara is open from 8 am to 11 pm and is slightly more expensive than other eating places on campus but it may be worth it. There is Snacks shop in side of CEDT (opens on week days between 10:45 & 11:30 AM and 3 & 3:45 PM). The small shopping area at the far north end of the campus near the ECE department has a bakery and a fruit/vegetable shop. In addition, vendors seated on the road near TMC, SBI and NCSI offer fresh fruit, groundnuts, etc. in the daytime (but not on Sundays). 



You can learn more about the campus.
Accommodation nearby
If you are coming with your parents, your parents may need to stay in a hotel. A few hotels are listed below

Akshara Regency
No4/20, Mathekere First Main Road, Gokula First stage
Bangalore.
Phone 080 2337 7746, 09036970369
Rate ~ 550-950 Rs for 2 persons


Ujwal Residency
#50, Yeswathpur-Mathikere Main Road
Bangalore
Phone 080 40974573, 09986131989
Rate - 750-1000 Rs for 2 persons

Sree Nandanam Residency
#11 Gokul First Stage
Mathikere Main Road
Bangalore
Phone : 080 40926908, 40926909
Rate: 550-1000 Rs for two persons

Sri Akshaya Deluxe Lodges
#4 Mathikere Main Road
Bangalore
Phone 080 2347 0128, 09731925513
Rate Rs 500- 800 for two persons

Krishinton Suites
# 993, M.S. Ramaiah Main Road, Near IISc
D-Gate, Mathikere, Bangalore - 560 054,
+91 80 4259 5959
Rate 1200-2000 for 2 persons

The Basil
8, Sampige Road, Malleshwaram, Bangalore - 560 003
080- 40402323
Rate 2000 for 2 persons

New Sagar Comforts & Banquets
No.5 & 6-8, 11th Mn Rd, 2nd Phs, 1st STG,
Yeshwanthpur Mn Rd, Gokula Extension, Bangalore - 560054
+(91)-(80)-40084999, 41273453
Rate 400-800

Disclaimer: The above is based on my experience and is personal advice. It does not represent IISc's opinion or represent any commercial interest.

Friday, December 4, 2015

DataStructures Quick Notes:


Complete Binary Tree:
==================

Total number of Nodes :
2pow(n+1)-1


Internal Nodes:
1 to [n/2]


Leaf nodes:
[n/2]+1 to n


Max no. of nodes at a level or height:
n/[2pow(h+1)]


====================================================


How many distinct binary search trees can be created out of 4 distinct keys?
Ans:
No. of BST= 2nCn/(n+1)
Therefore 8C4/5 =14

=======================================================

A binary tree T has 20 leaves. The number of nodes in T having two children is ______.

Ans:
In Binary tree If there are N leaf nodes then the number of Nodes having two children will be N-1. So in this case answer will be 20-1, means 19.

=======================================================

*** A complete graph Kn has  power(n, n-2) spanning trees.

=======================================================


Simple Graph
A graph with no loops and no parallel edges is called a simple graph.
* The maximum number of edges possible in a single graph with ‘n’ vertices is nC2 where nC2 = n(n – 1)/2.

* The number of simple graphs possible with ‘n’ vertices = 2nc2 = 2n(n-1)/2.




The maximum number of edges with n=3 vertices −
nC2 = n(n–1)/2
   = 3(3–1)/2
   = 6/2
   = 3 edges

The maximum number of simple graphs with n=3 vertices −
2nC2 = 2n(n-1)/2
   = 23(3-1)/2
   = 23
   = 8


=======================================================

Example 1:
Let ‘G’ be a simple graph with nine vertices and twelve edges, find the number of edges in 'G-'.

You have, |E(G)| + |E('G-')| = |E(Kn)|

12 + |E('G-')| =  9(9-1) / 2 = 9C2
12 + |E('G-')| = 36

|E('G-')| = 24


=======================================================

Example 2:
‘G’ is a simple graph with 40 edges and its complement 'G−' has 38 edges. Find the number of vertices in the graph G or 'G−'.

Let the number of vertices in the graph be ‘n’.

We have, |E(G)| + |E('G-')| = |E(Kn)|

40 + 38 = n(n-1)/2

156 = n(n-1)

13(12) = n(n-1)

n = 13

=======================================================


Circuit Rank
Let ‘G’ be a connected graph with ‘n’ vertices and ‘m’ edges. A spanning tree ‘T’ of G contains (n-1) edges.
Therefore, the number of edges you need to delete from ‘G’ in order to get a spanning tree = m-(n-1), which is called the circuit rank of G.


Example 1:

For the graph given in the above example, you have m=7 edges and n=5 vertices.

Then the circuit rank is

G = m – (n – 1)
  = 7 – (5 – 1)
  = 3

=======================================================


Example 2:

Let ‘G’ be a connected graph with six vertices and the degree of each vertex is three. Find the circuit rank of ‘G’.

By the sum of degree of vertices theorem,

n

i=1 deg(Vi) = 2|E|

6 × 3 = 2|E|

|E| = 9

Circuit rank = |E| – (|V| – 1)

= 9 – (6 – 1) = 4

=======================================================


Euler’s Path
An Euler’s path contains each edge of ‘G’ exactly once and each vertex of ‘G’ at least once. A connected graph G is said to be traversable if it contains an Euler’s path.
Example

Euler’s Path = d-c-a-b-d-e.


=======================================================


Example 3:

Let ‘G’ be a connected planar graph with 20 vertices and the degree of each vertex is 3. Find the number of regions in the graph.

Solution:

By the sum of degrees theorem,

20

i=1 deg(Vi) = 2|E|

20(3) = 2|E|

|E| = 30


By Euler’s formula,

|V| + |R| = |E| + 2

20+ |R| = 30 + 2

|R| = 12

Hence, the number of regions is 12.

=======================================================

A self-complementary graph is a graph which is isomorphic to its graph complement.

All self-complementary graphs have graph diameter 2 or 3
A disconnected graph has infinite diameter


By definition, a self-complementary graph must have exactly half the total possible number of edges, i.e., n(n-1)/4 edges for a self-complementary graph on n vertices. Since n(n-1) must be divisible by 4, it follows that n=0 or 1 (mod 4).


=======================================================


Red-Black Tree

An extended rooted binary tree satisfying the following conditions:
1. Every node has two children, each colored either red or black.
2. Every tree leaf node is colored black.
3. Every red node has both of its children colored black.
4. Every path from the root to a tree leaf contains the same number (the "black-height") of black nodes.

=======================================================