Sunday, 21 October 2012

TCS Pattern Questions-2

Pattern 6 
1. Susan made a block with small cubes of 8 cubic cm volume to make a block ,3 small cubes long, 9 small cubes wide and 5 small cubes deep. She realizes that she has used more small cubes than she really needed. She realized that she could have glued a fewer number of cubes together to lock like a block with same dimensions, if it were made hollow. What is the minimum number of cubes that she needs to make the block?a) 114        b) 135         c) 21         d) 71
Solution: I do not know perfectly but I got some solutions from internet I do not know correctly whether it is true or not,((3*9*5))-((3-2)*(9-2)*(5-2))  so answer is 114.

2. A boy wants to make cuboids of dimension 5m, 6m and 7m from small cubes of .03 m3. Later he realized he can make same cuboids by making it hollow. Then it takes some cubes less. What is the number of the cubes to be removed?
a) 2000      b) 5000           c) 3000       d) 7000

3. Smita was making a cube with dimensions 5*5*5 using 1*1*1 cubes. What is the number of cubes needed to make a hollow cube looking of the same shape?
a) 98            b) 104          c) 100         d) 61

 4. Leena cut small cubes of 10 cm dimension each. She joined it to make a cuboid of length 100 cm, width 50 cm and depth 50 cm. How many more cubes does she need to make a perfect cube?
 a)500          b)250         c)750        d)650

 5. Leena cut small cubes of 3 cubic cm each. She joined it to make a cuboid of length 10 cm, width 3 cm and depth 3 cm. How many more cubes does she need to make a perfect cube?
a) 910         b) 250          c) 750        d) 650

6. A lady builds 9cm length, 10cm width,3cm height box using 1 cubic cm cubes. What is the minimum number of cubes required to build the box?
 a) 730          b) 270          c) 720          d) 310

 Pattern 7:
1. (40*40*40 – 31*31*31)/(40*40+40*31+31*31)=?
 a)8        b)9        c )71         d)51
 Solution: a3 -b3 =(a-b)*(a2+a*b+b2)
so from this formula we will find (a-b) value

2. (98*98*98 – 73*73*73)/( 98*98*98 – 73*73*73)=?
a).171      b).4        c).420         d).415


3. (209*144)^2 + (209*209)+(209*144)+(144*144) = ?
 a)905863729      b)905368729      c)905729368      d)65

Pattern 8:
1. ((4x+3y)+(5x+9y))/(5x+5y) = ? as (x/2y) = 2
a)8      b)none      c)16      d)15
Solution: substitute x=4y  in above we can find solution

2. x/2y = 2a,then 2x/x-2ay=?
a)4     b)8     c)16     d)2

 3. 3X/5Y = 5Y/3X…..Find the value of X/Y
a)3/5     b)5/3    c)2/5     d)5/2

 4. What is the value of (3X+8Y)/(X-2Y), if X/2Y=2
 a)8      b)none    c)10    d)13

5. (4x+3y)+(5x+9y))/(5x+5y) = ? as (x/2y) = 2 a)48/5 b)46/5 c)47/5 d)49/5 6. ((4x+2y)/(4x-2y)= ? as (x/2y) = 2
a)8/7     b)9/7     c)11/7     d)6/7

Pattern 9:
1. A girl has to make pizza with different toppings. There are 8 different toppings. In how many ways can she make pizzas with 2 different toppings?
 a)16 b)56 c)112 d)28
Solution: 8c2

2. A pizza shop made pizzas with many flavors. There are 10 different flavors, in that 7 flavors are taken to make pizza. In how many ways they can arrange?
 a)240    b)120    c)65    d)210

 3. A pizza shop made pizzas with many flavors. There are 9 different flavors, in that 2 flavors are taken to make pizza. In how many ways they can arrange?
a)16    b)26     c)36     d)46

 Pattern 10:
1. 3, 22, 7, 45, 15,? , 31
 a)91    b)151    c)90    d)5

2. 8 6 17 14 35 31 75 _ 143?

3. Inspired by Fibonacci series Sangeet decided to create his own series which is 1, 2, 3, 7, 7, 22, 15, 67, 31, _, 63?
a)202    b)31    c)76    d)49

 4. 3, 12, 7, 26, 15, ?
a)54    b)27    c)108    d)31

5. 1! + 2! + ……. + 50!=?
a)3.1035*10^64      b)2.1021*10^65      c)3.1035*10^63       d)3.1035*10^62

6. 1, 2, 3, 6, 7, 14, _, 32?

7. 5, 9, 12, 18, 26, 36, 47, 72, _?
a)75     b)135      c)100     d)55

8. 3, 15, x, 51, 53,159,161
a)17     b)34       c)54       d)112

Sunday, 14 October 2012

SQL Basics-1


SQL - What are Subqueries: Advanced Queries
             Subqueries can be performed inside of existing queries. This expands the capabilities of SQL in a number of ways providing a 3rd dimension to the language you might say. Again, we will discuss subqueries in more detail in a later lesson. Feel free to familiarize yourself with what a subquery may look like using the example below.
SQL Code: 
SELECT * FROM table_one WHERE unique_column = (SELECT unique_column FROM table_two WHERE id_column = 1)
Above is a look at where you might cross subqueries. The logic behind the entire query is fairly confusing at this point, try and stay with us and focus on the syntax of the query and subquery.

SQL - Syntax
           SQL follows a general syntax, there are not many quotations or other symbols to throw into your statements. Generally we follow a Do what To what syntax, meaning first we decide what we want to do, then we decide what we want to do it to, and finally we end the whole thing with a semicolon (;).
           A statement begins with a clause. Clauses are commands in the SQL world and the backbone of any script. The first clause of a statement gives a general idea of what type of action a script is taking. A few basic clauses are SELECT, INSERT, or CREATE.
            We will look at each of these clauses a little more in depth on the next few pages but it may be obvious to you already what each of those clauses does. SQL statements end with a semicolon as most with most programming languages. A basic statement might look like this:
SQL Code:
SELECT * FROM table_name;

                Above we have a SELECT clause asking for all columns and values (*) from our database table. As shown above, a good habit is to capitalize your clauses. Later on when we have larger statements and subqueries it will make life much easier to go back and debug your code.
                 Formating your statements in a similar fashion will also aid your debugging efforts. The common formatting technique is to begin each line with a clause or to break up and list columns or tables as needed. More on this in a moment.
SQL Code: 
SELECT * FROM table_name; 

The advantage of this isn't apparent with this example. Each are fairly easy to read. However the example below shows an example where this format shines.
SQL Code: 
SELECT column_one, column_two 
FROM table_name
WHERE ( 
column_one, 
column_two, 
column_three, )
 = (SELECT column_one,
 column_ two
FROM column_ two
WHERE table_one.id = 'table_two.id');

As you can see, when subqueries are thrown into the mix things become a little more complicated. A one line statement will not fit across your screen. Both statements are neither right nor wrong, each are easier to follow. Parentheses generally depict order of operations but it is not an exact science. Quotations are not found until the predicate of the statement.

SQL - Data Types
SQL recognizes 4 general types of data. As the database designer you will be selecting which type of data that can be placed in each table column. Before we look at each type of table column we will elaborate on specific data types and how they are handled in SQL.

Character Strings - ('Words or numbers')
Numbers - (3, 3.423, -17)
Booleans - (True / False)
Nulls - (empty fields)

SQL - NULL Values
A null value may be the most foreign to new programmers. Stating that a value has a null value indicates that nothing exists in that table field. When the table is created you may either allow a table to have a null value or may disallow null values for each table column.
SQL Code:
 CREATE TABLE weekly_payroll (employee_id VARCHAR(10) PRIMARY KEY, total_hours INT NULL, hourly_rate MONEY NOT NULL,);

SQL - Numeric Data
Dates, time stamps, integers, and money are all numeric data types. The advantage of working with numbers is that SQL has built in functions such as the AVG() or SUM() functions that will return the average or the sum of a numeric column.
Numbers:
rate_of_pay
27
26.66
28.40


SQL - Boolean Data
Boolean values are either yes/no (true/false) types of data. Others use a 1/0 (1 for yes 0 for no) approach. Either something is or something is not.

Boolean Values:
admin
1
1
0

SQL - Character Strings
Character strings are sentences, symbols, or a combination of both. Math functions can not be performed with character strings.
Character Strings:
employee_id
TS_0036
TS_0078
CL_1099




SQL Basics


SQL - What's a Database?
A database is nothing more than an empty shell, like a vacant warehouse. It offers no real functionality what so ever, other than holding a name. Tables are the next tier of our tree offering a wide scope of functionality. If you follow our warehouse example, a SQL table would be the physical shelving inside our vacant warehouse. Each SQL table is capable of housing 1024 columns(shelves). Depending on the situation, your goods may require reorganization, reshelving, or removal. SQL tables can be manipulated in this same way or in any fashion the situation calls for.

SQL - Platforms
A SQL platform acts as the stage for building and developing your databases. Several different platforms exist including:
- IBM's DB2
- MySQL
- PostgreSQL
- Oracle
- Microsoft's SQL Server

SQL - MySQL and PostgreSQL
MySQL and PostgreSQL are open source database programs rich in functionality and flexibility. They are often the choice of web developers and small businesses simply because they get the job done for a very reasonable price. Also they will go anywhere and can operate on nearly every operating system available.

SQL - SQL Server
Microsoft's SQL Server is steadily on the rise in the commercial world gaining popularity slowly. This platform has a GUI "Windows" type interface and is also rich with functionality. A free trial version can be downloaded at the Microsoft web site, however it is only available to Windows users.

SQL - DB2 and Oracle
By far the selection of choice for large corporations is either Oracle or DB2. Companies that have large ties to IBM stick to their DB2 software whereas others have made the switch to Oracle. These systems run on personal computers as well as large corporate mainframes.

SQL - Queries
Queries are the backbone of SQL. Query is a loose term that refers to a widely available set of SQL commands called clauses. Each clause (command) performs some sort of function against the database. For instance, the create clause creates tables and databases and the select clause selects rows that have been inserted into your tables. We will dive deeper in detail as this tutorial continues but for now let's take a look at some query structure. Query construction begins with one of the following clauses:
Add
Drop
Create
Insert
Select
Update
Replace
Delete

Queries are loosely typed into your SQL prompt. Spacing and line breaks are not very important as we will discuss further in our SQL Syntax lesson. We now know that a query begins with a clause, what comes next depends on the clause we select and we will be covering all the clauses as the tutorial progresses. For now, let's take a look at some syntax.


SQL - Query Syntax
The syntax of a query is loose, meaning you are free to place line breaks where you please without injuring the code. Few instances require parentheses, including the insert statement listed below. Parentheses will also be covered during our Functions lesson. Be sure to end all query statements with a semicolon (;).

SQL Code: 
                    SELECT * FROM table_name; 

The above code selects every row and every column from a hypothetical table (table_one) and prints it to our prompt. Here's a look at a few more queries that should become second nature to you as the tutorial continues.

SQL Code: 
INSERT INTO table_name (column_one,column_two) VALUES(value_one,value_two);

SQL Code:  
UPDATE table_name SET column_one = value_one, column_two = value_two;

Queries are how you communicate to your database program. Nearly everything typed at a SQL command prompt is a query.


Java Interview Questions-3

Control Statements 

1) What are the programming constructs?
Ans: a) Sequential
         b) Selection -- if and switch statements
         c) Iteration -- for loop, while loop and do-while loop

2) class conditional {
public static void main(String args[]) {
int i = 20;
int j = 55;
int z = 0;
z = i < j ? i : j; // ternary operator
System.out.println("The value assigned is " + z);
}
}
What is output of the above program?
Ans: The value assigned is 20

3) The switch statement does not require a break.
a)True
b)False
Ans: b.
4) The conditional operator is otherwise known as the ternary operator.
a)True
b)False
Ans: a.

5) The while loop repeats a set of code while the condition is false.
a)True
b)False
Ans: b.

6) The do-while loop repeats a set of code atleast once before the condition is tested.
a)True
b)False
Ans: a.

7) What are difference between break and continue?
Ans: The break keyword halts the execution of the current loop and forces control out of the loop.
The continue is similar to break, except that instead of halting the execution of the loop, it starts the next iteration.

8) The for loop repeats a set of statements a certain number of times until a condition is matched.
a)True
b)False
Ans: a.

9) Can a for statement loop indefintely?
Ans : Yes.

10) What is the difference between while statement and a do statement/
Ans : A while statement checks at the beginning of a loop to see whether the next loop iteration should occur.
          A do statement checks at the end of a loop to see whether the next iteration of a loop should occur. The do statement will always execute the body of a loop at least once.

Java Interview Questions-2

Operators 

1) What are operators and what are the various types of operators available in Java?
Ans: Operators are special symbols used in expressions.

The following are the types of operators:

Arithmetic operators,
Assignment operators,
Increment & Decrement operators,
Logical operators,
Biwise operators,
Comparison/Relational operators and
Conditional operators

2) The ++ operator is used for incrementing and the -- operator is used for decrementing.
a)True
b)False
Ans: a.

3) Comparison/Logical operators are used for testing and magnitude.
a)True
b)False
Ans: a.

4) Character literals are stored as unicode characters.
a)True
b)False
Ans: a.

5) What are the Logical operators?
Ans: OR( | ), AND( & ), XOR( ^ ) AND NOT( ~ ).

6) What is the % operator?
Ans : % operator is the modulo operator or reminder operator. It returns the reminder of dividing the first operand by second operand.

7) What is the value of 111 % 13?
a) 3
b) 5
c) 7
d) 9
Ans : c.

8) Is &&= a valid operator?
Ans : No.

9) Can a double value be cast to a byte?
Ans : Yes

10) Can a byte object be cast to a double value ?
Ans : No. An object cannot be cast to a primitive value.

11) What are order of precedence and associativity?
Ans : Order of precedence the order in which operators are evaluated in expressions.
          Associativity determines whether an expression is evaluated left-right or right-left.

12) Which Java operator is right associativity?
Ans : = operator.

13) What is the difference between prefix and postfix of -- and ++ operators?
Ans : The prefix form returns the increment or decrement operation and returns the value of the increment or decrement operation.
The postfix form returns the current value of all of the expression and then  performs the increment or decrement operation on that value.

14) What is the result of expression 5.45 + "3,2"?
a) The double value 8.6
b) The string ""8.6"
c) The long value 8.
d) The String "5.453.2"
Ans : d

15) What are the values of x and y ?
x = 5; y = ++x;
Ans : x = 6; y = 6

16) What are the values of x and z?
x = 5; z = x++;
Ans : x = 6; z = 5

Monday, 8 October 2012

Database Fundamentals


What is a Database?
General:
• A database is any collection of related data.
Restrictive:
• A database is a persistent, logically coherent collection of inherently meaningful data, relevant to some aspects of the real world.

What is a Database Management System?
A database management system (DBMS) is a collection of programs that enables users to create and maintain a database.

What Does a DBMS Do?
Database management systems provide several functions in addition to simple file management:
• allow concurrency
• control security
• maintain data integrity
• provide for backup and recovery
• control redundancy
• allow data independence
• provide non-procedural query language
• perform automatic query optimization

Who Interacts with a DBMS?
Many different individuals are involved with a database management system over its life:
• systems analysts
• database designers
• database administrators
• application developers
• users

Relational Database Model:
What is a relational database?
• a database that treats all of its data as a collection of relations

What is a relation?
• a kind of set
• a subset of a Cartesian product
• an unordered set of ordered tuples




OS Interview Questions-8


1. What is starvation and aging?
Ans :
Starvation: Starvation is a resource management problem where a process does not get the resources it needs for a long time because the resources are being allocated to other processes.
Aging: Aging is a technique to avoid starvation in a scheduling system. It works by adding an aging factor to the priority of each request. The aging factor must increase the request’s priority as time passes and must ensure that a request will eventually be the highest priority request (after it has waited long enough)

2.Different types of Real-Time Scheduling?
Ans :Hard real-time systems – required to complete a critical task within a guaranteed amount of time.
Soft real-time computing – requires that critical processes receive priority over less fortunate ones.

3. What are the Methods for Handling Deadlocks?
Ans :
->Ensure that the system will never enter a deadlock state.
->Allow the system to enter a deadlock state and then recover.
->Ignore the problem and pretend that deadlocks never occur in the system; used by most operating systems, including UNIX.

4. What is a Safe State and its’ use in deadlock avoidance?
Ans :When a process requests an available resource, system must decide if immediate allocation leaves the system in a safe state
->System is in safe state if there exists a safe sequence of all processes.
->Sequence is safe if for each Pi, the resources that Pi can still request can be satisfied by
currently available resources + resources held by all the Pj, with j
If Pi resource needs are not immediately available, then Pi can wait until all Pj have finished.
When Pj is finished, Pi can obtain needed resources, execute, return allocated resources, and terminate.
When Pi terminates, Pi+1 can obtain its needed resources, and so on.
->Deadlock Avoidance Þ ensure that a system will never enter an unsafe state.

5. Recovery from Deadlock?
Ans :Process Termination:
->Abort all deadlocked processes.
->Abort one process at a time until the deadlock cycle is eliminated.
->In which order should we choose to abort?
Priority of the process.
How long process has computed, and how much longer to completion.
Resources the process has used.
Resources process needs to complete.
How many processes will need to be terminated?
Is process interactive or batch?
Resource Preemption:
->Selecting a victim – minimize cost.
->Rollback – return to some safe state, restart process for that state.
->Starvation – same process may always be picked as victim, include number of rollback in cost factor.

6.Difference between Logical and Physical Address Space?
Ans :
->The concept of a logical address space that is bound to a separate physical address space is central to proper memory management.
Logical address – generated by the CPU; also referred to as virtual address.
Physical address – address seen by the memory unit.
->Logical and physical addresses are the same in compile-time and load-time address-binding schemes; logical (virtual) and physical addresses differ in execution-time address-binding scheme

7. Binding of Instructions and Data to Memory?
Ans :Address binding of instructions and data to memory addresses can happen at three different stages
Compile time: If memory location known a priori, absolute code can be generated; must recompile code if starting location changes.
Load time: Must generate relocatable code if memory location is not known at compile time.
Execution time: Binding delayed until run time if the process can be moved during its execution from one memory segment to another. Need hardware support for address maps (e.g., base and limit registers).

8. What is Memory-Management Unit (MMU)?
Ans :Hardware device that maps virtual to physical address.
In MMU scheme, the value in the relocation register is added to every address generated by a user process at the time it is sent to memory.
->The user program deals with logical addresses; it never sees the real physical addresses

9. What are Dynamic Loading, Dynamic Linking and Overlays?
Ans :
Dynamic Loading:
->Routine is not loaded until it is called
->Better memory-space utilization; unused routine is never loaded.
->Useful when large amounts of code are needed to handle infrequently occurring cases.
->No special support from the operating system is required implemented through program design.
Dynamic Linking:
->Linking postponed until execution time.
->Small piece of code, stub, used to locate the appropriate memory-resident library routine.
->Stub replaces itself with the address of the routine, and executes the routine.
->Operating system needed to check if routine is in processes’ memory address.
->Dynamic linking is particularly useful for libraries.
Overlays:
->Keep in memory only those instructions and data that are needed at any given time.
->Needed when process is larger than amount of memory allocated to it.
->Implemented by user, no special support needed from operating system, programming design of overlay structure is complex.

10. What is fragmentation? Different types of fragmentation?
Ans : Fragmentation occurs in a dynamic memory allocation system when many of the free blocks are too small to satisfy any request.
External Fragmentation: External Fragmentation happens when a dynamic memory allocation algorithm allocates some memory and a small piece is left over that cannot be effectively used. If too much external fragmentation occurs, the amount of usable memory is drastically reduced.Total memory space exists to satisfy a request, but it is not contiguous
Internal Fragmentation: Internal fragmentation is the space wasted inside of allocated memory blocks because of restriction on the allowed sizes of allocated blocks.Allocated memory may be slightly larger than requested memory; this size difference is memory internal to a partition, but not being used Reduce external fragmentation by compaction
->Shuffle memory contents to place all free memory together in one large block.
->Compaction is possible only if relocation is dynamic, and is done at execution time.

11. Define Demand Paging, Page fault interrupt, and Trashing?
Ans :
Demand Paging: Demand paging is the paging policy that a page is not read into memory until it is requested, that is, until there is a page fault on the page.
Page fault interrupt: A page fault interrupt occurs when a memory reference is made to a page that is not in memory.The present bit in the page table entry will be found to be off by the virtual memory hardware and it will signal an interrupt.
Trashing: The problem of many page faults occurring in a short time, called “page thrashing,”

12. Explain Segmentation with paging?
Ans : Segments can be of different lengths, so it is harder to find a place for a segment in memory than a page. With segmented virtual memory, we get the benefits of virtual memory but we still have to do dynamic storage allocation of physical memory. In order to avoid this, it is possible to combine segmentation and paging into a two-level virtual memory system. Each segment descriptor points to page table for that segment.This give some of the advantages of paging (easy placement) with some of the advantages of segments (logical division of the program).

13. Under what circumstances do page faults occur? Describe the actions taken by the operating system when a page fault occurs?
Ans : A page fault occurs when an access to a page that has not been brought into main memory takes place. The operating system verifies the memory access, aborting the program if it is invalid. If it is valid, a free frame is located and I/O is requested to read the needed page into the free frame. Upon completion of I/O, the process table and page table are updated and the instruction is restarted

14. What is the cause of thrashing? How does the system detect thrashing? Once it detects thrashing, what can the system do to eliminate this problem?
Ans :
Thrashing is caused by under allocation of the minimum number of pages required by a process, forcing it to continuously page fault. The system can detect thrashing by evaluating the level of CPU utilization as compared to the level of multiprogramming. It can be eliminated by reducing the level of multiprogramming.