Frequently asked questions

TCS Most Frequently asked Technical Interview Questions

Q) What is Linking in C?

The object code is combined with required supporting code to make an executable program. This step typically involves adding in any libraries that are required.

Q)What is const variable?

Whenever we use const qualifier with variable name, it becomes a read-only variable and get stored in data segment.

Any attempt to modify this read-only variable will then result in a compilation error: “assignment of read-only variable”.

Q) What is pre-processing in C?


  • A Pre-processor is a system software (a computer program that is designed to run on computer’s hardware and application programs).
  • It performs pre-processing of the High Level Language(HLL).
  • Pre-processing is the first step of the language processing system. 
  • Language processing system translates the high level language to machine level language or absolute machine code(i.e. to the form that can be understood by machine).
  • The pre-processor doesn’t know about the scope rules of C.
  • Pre-processor directives like #define come into effect as soon as they are seen and remain in effect until the end of the file that contains them; the program’s block structure is irrelevant


Q) What is Static variables?

Static variables have a property of preserving their value even after they are out of their scope. 
Hence, static variables preserve their previous value in their previous scope and are not initialized again in the new scope.

Syntax:
static data_type var_name = var_value;

Q) Which sort algorithm is best?

The time complexity of Quicksort is 
O(n log n) in the best case,
                                                  
O(n log n) in the average case,
                                                            
and O(n^2) in the worst case.

But because it has the best performance in the average case for most inputs, Quicksort is generally considered the “fastest” sorting algorithm.

Q) What are the types of arrays in c?

a. One dimensional array
b. Multi-dimensional array
• Two dimensional array
• Three dimensional array
• four dimensional array etc…

Q)Write a program to check whether the given string is a palindrome or not?
#include <stdio.h>
#include <string.h>
int main()
{
char string1[20];
int i, length;
int flag = 0;
scanf("%s", string1);
length = strlen(string1);
for(i=0;i < length ;i++)
{
if(string1[i] != string1[length-i-1])
{
flag = 1;
break;
}
}
if (flag) 
printf("%s is not a palindrome", string1);
else
printf("%s is a palindrome", string1);
return 0;
}

Q) Write a program in java to reverse the given String.

import java.util.Scanner;
public class ReverseString
{
public static void main(String[] args)
{
System.out.println("Enter string to reverse:");
Scanner read = new Scanner(System.in);
String str = read.nextLine();
String reverse = "";
for(int i = str.length() - 1; i >= 0; i--)
{
reverse = reverse + str.charAt(i);
}
System.out.println("Reversed string is:");
System.out.println(reverse);
}
}


Q) What is Data Structure?


A data structure is a particular way of organizing data in a computer so that it can be used effectively.


Q) What is binary tree?

A Binary Tree is a type of data structure in which each node has at most two children (left child and right child). Binary trees are used to implement binary search trees and binary heaps, and are used for efficient searching and sorting.


Q) What are the properties of binary search tree?

Binary Search Tree, is a node-based binary tree data structure which has the following properties:
• The left subtree of a node contains only nodes with keys lesser than the node’s key.
• The right subtree of a node contains only nodes with keys greater than the node’s key.
TCS Most Frequently asked Technical Interview Questions
• The left and right subtree each must also be a binary search tree.
• There must be no duplicate nodes.

Q)Draw binary tree for given number 10,20,8,9,2,1

10
/ \
8 20
/\
2 9
/
1


Q)  Explain Heap sort.
  • Heap sort is a comparison based sorting technique based on Binary Heap data structure. 
  • It is similar to selection sort where we first find the maximum element and place the maximum element at the end. 
  • We repeat the same process for remaining element.
  • A complete binary tree is a binary tree in which every level, except possibly the last, is completely filled, and all nodes are as far left as possible.
  • A Binary Heap is a Complete Binary Tree where items are stored in a special order such that value in a parent node is greater(or smaller) than the values in its two children nodes. 
  • The former is called as max heap and the latter is called min heap. 
  • The heap can be represented by binary tree or array.


Q) Difference between c , c++ and Java?

  • C is a general-purpose high-level language that was originally developed by Dennis Ritchie in 1972 for the Unix operating system. 
  • C is a successor of B language which was introduced around 1970. 
  • C is a structured language which is easy to learn and produces efficient programs. 
  • it's a top-down approach. 
  • It can handle low-level activities and can be compiled on a variety of computers. 
  • Today C is the most widely used System Programming Language.

C++ is a general-purpose programming language developed by Bjarne Stroustrup starting in 1979 at Bell Labs, designed to make programming more enjoyable for the serious programmers. 

  • C++ is a superset of the C programming language. 
  • In addition to the facilities provided by C, C++ provides flexible and efficient facilities for defining new types. 
  • The key concept in C++ is class. 
  • A class is a user-defined type.


Java is a programming language created by James Gosling from Sun Microsystems in 1991. 

  • The first publicly available version of Java (Java 1.0) was released in 1995. 
  • The Old name of Java was Oak. 
  • Java is now taken by Oracle Corporation. 
  • The acquisition of Sun Microsystems by Oracle Corporation was completed by Oracle in January 2010. 
  • The current version of Java is Java 1.8 ( Java 8 ). 
  • Java is a Programming language as well as a Platform itself.

Q) Explain oops concepts.
• Object
• Class
• Inheritance
• Polymorphism
• Abstraction

• Encapsulation


Q)What is overloading & overriding?


  • The real object type in the run-time, not the reference variable's type, determines which overridden method is used at run time. 
  • In contrast, reference type determines which overloaded method will be used at compile time.
  • Polymorphism applies to overriding, not to overloading.
  • Overriding is a run-time concept while overloading is a compile-time concept.

 Q)What is inheritance and abstraction?


  • One of the most fundamental concept of OOPs is Abstraction. 
  • Abstraction is a process where you show only “relevant” data and “hide” unnecessary details of an object from the user. 
  • For example, when you login to your Amazon account online, you enter your user_id and password and press login, what happens when you press login, how the input data sent to amazon server, how it gets verified is all abstracted away from the you.
  • Inheritance is the mechanism by which an object acquires the some/all properties of another object.
  • It supports the concept of hierarchical classification.

Q) Write small program to display information in java?

public class AddTwoNumbers 
{
public static void main(String[] args) 
{
int num1 = 5, num2 = 15, sum;
sum = num1 + num2;
System.out.println("Sum of these numbers: "+sum);
}

}


Q) What is copy constructor?

A copy constructor is a member function which initializes an object using another object of the same class. A copy constructor has the following general function prototype:
ClassName (const ClassName &old_obj);

Q) Example of Function Overloading.

public class Sum {
// Overloaded sum(). This sum takes two int parameters
public int sum(int x, int y)
{
return (x + y);
}
// Overloaded sum(). This sum takes three int parameters
public int sum(int x, int y, int z)
{
return (x + y + z);
}
// Overloaded sum(). This sum takes two double parameters
public double sum(double x, double y)
{
return (x + y);
}
// Driver code
public static void main(String args[])
{
Sum s = new Sum();
System.out.println(s.sum(10, 20));
System.out.println(s.sum(10, 20, 30));
System.out.println(s.sum(10.5, 20.5));
}
}

Q) What is Polymorphism?

Polymorphism in Java is a concept by which we can perform a single action in different ways. Polymorphism is derived from 2 Greek words: poly and morphs. The word "poly" means many and "morphs" means forms. So polymorphism means many forms.
TCS Most Frequently asked Technical Interview Questions
There are two types of polymorphism in Java:
• compile-time polymorphism
• runtime polymorphism.
We can perform polymorphism in java by method overloading and method overriding.
If you overload a static method in Java, it is the example of compile time polymorphism.

Q) Explain Inheritance.

• Inheritance in Java is a mechanism in which one object acquires all the properties and behaviours of a parent object.
• It is an important part of OOPs (Object Oriented programming system).
• The idea behind inheritance in Java is that you can create new classes that are built upon existing classes.
• When you inherit from an existing class, you can reuse methods and fields of the parent class. Moreover, you can add new methods and fields in your current class also.
Inheritance represents the IS-A relationship which is also known as a parent-child relationship.

Q) Explain exception handling.

The Exception Handling in Java is one of the powerful mechanism to handle the runtime errors so that normal flow of the application can be maintained.

Q) What is Interface in Java?

• Like a class, an interface can have methods and variables, but the methods declared in interface are by default abstract (only method signature, no body).
• Interfaces specify what a class must do and not how. It is the blueprint of the class.
• An Interface is about capabilities like a Player may be an interface and any class implementing Player must be able to (or must implement) move(). So it specifies a set of methods that the class has to implement.
• If a class implements an interface and does not provide method bodies for all functions specified in the interface, then class must be declared abstract.

• A Java library example is, Comparator Interface. If a class implements this interface, then it can be used to sort a collection.

Q) Difference between DBMS and RDBMS with example.

• A DBMS is a software used to store and manage data.
• Relational Database Management System (RDBMS) is an advanced version of a DBMS system
• DBMS system, stores data in either a navigational or hierarchical form
• RDBMS uses a tabular structure where the headers are the column names, and the rows contain corresponding values
• DBMS does not support the integrity constants
• RDBMS supports the integrity constraints at the schema level
• Examples of DBMS are a file system, XML, Windows Registry, etc.
• Example of RDBMS is MySQL, Oracle, SQL Server, etc.

Q) What is cloud computing?


  • cloud computing is the delivery of computing services—including servers, storage, databases, networking, software, analytics, and intelligence—over the Internet (“the cloud”) to offer faster innovation, flexible resources, and economies of scale. 
  • You typically pay only for cloud services you use, helping lower your operating costs, run your infrastructure more efficiently and scale as your business needs change.

Q) What is bigdata?


  • Big data is a term that describes the large volume of data – both structured and unstructured – that inundates a business on a day-to-day basis. 
  • But it’s not the amount of data that’s important. 
  • It’s what organizations do with the data that matters. 
  • Big data can be analysed for insights that lead to better decisions and strategic business moves.


Q) Explain Kruskal’s algorithm.

  •  Sort all the edges in non-decreasing order of their weight.
  •  Pick the smallest edge. Check if it forms a cycle with the spanning tree formed so far. 
  • If cycle is not formed, include this edge. Else, discard it.
  •  Repeat step#2 until there are (V-1) edges in the spanning tree.

Q)Explain Prim’s algorithm.

  • Prim's algorithm is a minimum spanning tree algorithm that takes a graph as input and finds the subset of the edges of that graph which form a tree that includes every vertex has the minimum sum of weights among all the trees that can be formed from the graph.

Working:
• It falls under a class of algorithms called greedy algorithms which find the local optimum in the hopes of finding a global optimum.
• We start from one vertex and keep adding edges with the lowest weight until we reach our goal.
The steps for implementing Prim's algorithm are as follows:
• Initialize the minimum spanning tree with a vertex chosen at random.
• Find all the edges that connect the tree to new vertices, find the minimum and add it to the tree
• Keep repeating step 2 until we get a minimum spanning tree.

No comments:

Post a Comment

CTS Written test results of Vijayawada, Guntur, Ongole, Godarvari Districts were out.  Tentative dates of TR and HR are 24th and 25th Nov...