Sunday, September 27, 2015

Create a html page to display your class time table using " PRE " tag.

Solution:-
<html>
     <head>
               <title> class time table </title>
     </head>
     <body bgcolor='pink'>
               <pre><h1> &nbsp; &nbsp; &nbsp; Our class time table </h1></pre>
                        <pre><h2><font color='green'>
                                 S.N.  Subject  Period  Time  Teacher </font>
                                 <font color="blue">
                                     1 OM             1<sup>st</sup>    12:30-1:15  Gopal Raj Bhandari
                                     2 Graphics   2<sup>nd</sup>  1:15-2:00    Bhoj Raj Joshi
                                     3 e-learning 3<sup>rd</sup>  2:00-4:00   Reg Bahadur Bhandari
                                                                              OR<br>
                                        3 JAVA & VB.net 3<sup>rd</sup>  2:00-4:00 Romkant Pandey
                                </font>
                       </h2></pre>
        </body>
</html>

What is Queue? Write an Algorithm for the INSERTION & DELETION operations.

Solution:-
Introduction of Queue:-
   *   Queue is Linear , Non – primitive data structure.
   *   Accessed from two ends                 
                 i.    Rear -> To insert item
                 ii.   Front -> To delete item
   *   Queue operations are:
               i.    Insertion (enque)
               ii.   Deletion (deque)
   *   Working principles First in First out (FIFO).

Algorithm:-
Algorithm to insert item in to linear queue (enque )

enque ( queue [maxsize] , item , rear , front )

             Step 1:- if (rear == maxsize -1)
                                     print " QUEUE OVERFLOW "                        
                           Other wise
                                 Read item
                                 if ( front = =  rear  = = -1)
                                           Set rear = 0
                                           Set front = 0
                                 Other wise                                                
                                           Set rear = rear + 1                                 
                                 End if
                                 Set queue[rear]=item
                                 print " SUCCESS INSERT ITEM "
                         End if             
             Step 2:- stop.


Algorithm to delete item from linear queue ( deque )
Deque (queue [maxsize ] , item , front , rear )

               Step 1:- if( front == -1 )
                                       print " QUEUE UNDERFLOW "
                             Otherwise                                       
                                       Set item = queue [front]
                                       if( rear == front )
                                                  Set front = -1
                                                  Set rear = -1
                                       Otherwise
                                                  Set front = front +1
                                       End if
                                       print " SUCCESS DELETE ITEM "
                              End if
               Step 2:- stop.


What is STACK ? Write an Algorithm for the PUSH & POP operation.

Solution:-
STACK Introduction:-
*  Stack is non - primitive linear data structure.
*   Accessed from single end called Top Of Stack (TOS).
*   Stack operations are:
        i.  PUSH --: To insert into stack.
        ii.  POP -> To remove item from stack
 *  Using Last in First output (LIFO) principle

Algorithm:-
Algorithm for PUSH operation
PUSH (stack [maxsize] , item , tos)

   Step 1:- if ( tos == maxsize – 1)
                        print " STACK OVERFLOW"
                 Other wise
                        Read item
                        tos = tos + 1
                        set stack [ tos ] = item
                        print " PUSHED SUCCESSFULLY "
                 end if
Step 2: stop

Algorithm for POP operation
POP ( stack [maxsize ] , item , tos )

          Step 1:- if  ( tos  = =  -1 )
                               print " STACK UNDERFLOW "
                        Other wise
                               item = stack [tos ]
                               tos = tos -1
                               print " POPED SUCCESSFULLY "
                        End if
          Step 2:- stop

Wednesday, September 23, 2015

Write an Algorithm for the Secant Method.

Step1:- Decide two initial points x1 & x2, & accuracy level required, E.
Step2:- Compute f ( x1 ) & f ( x2 )
Step3:- Compute
             x3 = x2 - ( ( f (x2) (x2-x1) ) / ( f (x2) - f (x1) ) )
Step4:- Test for accuracy of x3.
             If absolute value of (x3 – x2) / x3 > E, then
                  Set x1 = x2 & f1 = f2
                  Set x2 = x3 & f2 = f (x3)
                  Go to step 3
            otherwise,
                  set root = x3
            print results.
Step5:- Stop



Write an Algorithm for the Newton - Raphson Method.

Step1:-  Assign an initial value to x, say x0 & set value of E.
Step2:-  Evaluate f ( x0 ) & f ' ( x0 ) .
Step3:-  Find the improved estimate to x0.
              x1 = x0 - ( f (x0) / f ' (x0) )
Step4:-  Check for accuracy of the latest estimate.
              Compare relative error to a predefined value E.
              If absolute value of (x1 - x0) / x1 ≤  E
                   Stop.
              else
                  Continue.
Step5:-  Replace x0 by x1 & repeat Step 3 & Step 4.



Write an Algorithm for the Bisection Method.

Step1:-  Decide initial values for x1 & x2 & stopping criteria, E.
Step2:-  Compute f1 = f ( x1 ) & f2 = f ( x2 ).
Step3:-  If ( f1 * f2) > 0,  x1 & x2 do not bracket any root & go to step 7.
             Otherwise continue.
Step4:-  Compute x0 = ( x2 - x1 ) / x2 & compute f0 = f ( x0 ).
Step5:-  If ( f1 = f0 ) < 0 then
                    Set x2 = x0
              else
                    Set x1 = x0
                    Set f1 = f0
 Step6:-  If absolute value of ( x2 - x1 ) /  x2 is less than error E, then
                    root = ( x2 - x1 ) / 2
                    write the value of root
                    go to step 7.
              else
                    go to step 4.
Step7:-  Stop.



Explain the different types of normalization form.

Solution:-

TYPES OF NORMALIZATION FORM:-

       A. First normalization (1NF):-

                  i. Each attribute of the table should be unique.
                  ii. Each value of the table should be atomic.
                  iii. There should not be any duplicate rows.

        B. Second normalization (2NF):-

                   i. It should be in first normal form.
                   ii. Non-key attributes are functionally dependent on the key – attribute. X à y or, X
                        determines Y
                   Or, X determinant and Y is dependent.
                    iii. If the key has more than one attributes then no non-key attributes should be
                          functionally dependent upon a past of the key attributes.

         C. Third normalization ( 3NF ):-

                     A relation is 3NF if and only if it satisfies 2NF and every non-key attributes is
                     non-transitively dependent on the primary key.
                     Roll_no à year , year à hostel_name , Roll_no à hostel_name

         D. Boyce-code normal form (BCNF):-

                      A 3NF relation will not be BCNF if there are multiple candidate keys in the
                      relation such that,
                      i. The candidate keys in the relation are composite keys &
                      ii. The keys   are  not disjoint , that is candidate keys overlap.

What are the different types of join? Explain with example.

Solution:-

 JOIN:-    
             The ‘JOIN’ keyword is used in an SQL statement to query date from two or more tables, based on relationship between certain columns in these tables. 
                                                                                                                        

 Types of JOIN:-

I.        Join (Inner-Join):- Return all rows when there is at least one match

       in both tables.

Example:- 

                Join (Inner Join):-

                SELECT Fname , Lname , order_no

                From cusromers inner join orders

                On customers.c_id = order.c_id ;



II.       Left Join (Left Outer Join):- Return all rows from the left table, even if there are
            no matches in the right table.
            Example:- 
                Left Join (Left Outer Join):-

                SELECT Fname , Lname , order_no

                From cusromers Left join orders

                On customers.c_id = order.c_id ;



III.     Right Join (Right Outer Join):- Return all rows from Right table  even if there
            are no matches in the left table.
     Example:- 
                Right Join (Right Outer Join):-

                SELECT Fname , Lname , order_no

                From cusromers Right  join orders

                On customers.c_id = order.c_id ;


IV.     Full Join(Full Outer Join):- Returns roes when there is a match in one of the 
           table.

Tuesday, September 22, 2015

Define DDL , DML and DCL.

Solution:-
         DDL (Data Definition Language) is used by the database designers and programmers to specify the content and structure of the table. Commands are:- CREATE , DROP , RENAME etc.

Example:- 
 CREATE DATABASE campus ;
CREATE TABLE student ( Roll_no int , Fname varchar(25) , Lname varchar(25) , Address varchar(25) ) ;

            DML (Data Manipulation Language) is related with manipulations of record such as retrieval , sorting , display &amp; deletion of record of data. Commands are:- SELECT , UPDATE , INSERT etc.
Example:- 
 INSERT INTO student values(1001 , “NP”, “Rijal”, “KTM” ) ;
SELECT * FROM student ;
UPDATE student SET Address=”VKT” WHERE Roll_no=1001 ;

           DCL (Data Control Language) is used in controlling the transaction that happened in the database. Example, Rollback commit are DCL and we can use commit statement to finalize the transaction in the database. Once the transaction is committed it cannot be rolled back.
Example are:- GRANT , REVOKE etc.
Example:-
GRANT SELECT ON student TO netra;
REVOKE SELECT ON student to netra;

Design the following table using nested table in HTML.



Logo (image)
Message
Menu Item 1(link)
Menu Item 2(link)
Menu Item 3(link)

Content 1
News 1
Content 2
News 2

Copyright
Facebook, Twitter(link)
Powered By

Solution:-
<html>
     <head>
            <title> table </title>
     </head>
     <body>
              <CENTER><h1> Single table </h1>
                       <table border='1' WIDTH=50%>
                                <TR>
                                        <td> Logo (image)</TD>
                                        <TD COLSPAN=2> Message </TD>
                                </TR>
                                <TR>
                                <td><center>
                               <table border='1' width=95%>
                                      <tr>
                                             <td> Menu Item 1 (Link) </td>
                                      </tr>
                                      <tr>
                                             <td> Menu Item 2 (Link) </td>
                                      </tr>
                                      <tr>
                                            <td> Menu Item 3 (Link) </td>
                                      </tr>
    `                         </table>
                              </center></td>
                             <td colspan=2><center>
                             <table border='1' width=95%>
                                      <tr>
                                            <td> Conternt 1 </td>
                                            <td> News 1 </td>
                                      </tr>
                                      <tr>
                                            <td> Content 2 </td>
                                            <td> News 2 </td>
                                      </tr>
                             </table>
                            </center> </td>
                      </tr>
                      <TR>
                              <TD> Copyright </TD>
                              <TD> Facebook, Twitter(Link) </TD>
                              <td> Powered By </td>
                      </TR>
               </TABLE>
         </CENTER>
     </body>
</html>

Output:-


Design the following single table using HTML.



A
BB
C
D
E
F
G
H
J
K
L
M

 Solution:-
<html>
     <head>
             <title> table </title>
     </head>
     <body bgcolor='pink' text='grey'>
            <CENTER><h1> Single table </h1>
                     <table border='1' WIDTH=50%>
                              <tr>
                                    <td> A </TD>
                                   <TD COLSPAN=2> BB </TD>
                                   <TD> C </TD>
                                   <TD> D </TD>
                             </TR>
                             <TR>
                                   <TD COLSPAN=4 ROWSPAN=2> E </TD>
                                   <TD> F </TD>
                            </TR>
                            <TR>
                                    <TD> G </TD>
                            </TR>
                            <TR>
                                   <TD COLSPAN=2> H </TD>
                                   <TD COLSPAN=2> J </TD>
                                   <TD> K </TD>
                             </TR>
                             <TR>
                                     <TD COLSPAN=3> L </TD>
                                     <TD COLSPAN=2> M </TD>
                              </TR>
                  </TABLE>
             </center>
     </body>
</html>

Output:-