Sunday, January 26, 2020

TCS INTERVIEW QUESTIONS

1)What is data Structure?

     Data structure is the way of collecting and organizing the data in such a way that we can perform various kinds of operations on these data in an effective way.

2)When is a binary search best applied?
 
     A binary search is an algorithm that is best applied to search a list when the elements are already in order or sorted. The list is searched starting in the middle, such that if that middle value is not the target search key, it will check to see if it will continue the search on the lower half of the list or the higher half. The split and search will then continue in the same manner.

3)What is a linked list?(sequential access data structure)
 
     A Linked list is a sequence of nodes in which each node is connected to the node following it .This forms a chain like link for data storage

4)In what areas do data structures are applied?
   
      Data structures are essential in almost every aspect where data is involved. In general, algorithms that involve efficient data structure is applied in the following areas:
       Numerical Analysis, Operating System, A.I., Compiler Design, Database Management, Graphics, and Statistical Analysis, to name a few.

5)What is LIFO?Example?(stack)
     
         LIFO is a short form of Last In First Out. It refers how data is accessed, stored and retrieved. Using this scheme, data that was stored last should be the one to be extracted first. This also means that in order to gain access to the first data, all the other data that was stored before this first data must first be retrieved and extracted.
           A stack is a data structure in which only the top element can be accessed. As data is stored in the stack, each data is pushed downward, leaving the most recently added data on top.
          A good real-life example of a stack is the pile of dinner plates that you encounter when you eat at the local cafeteria: When you remove a plate from the pile, you take the plate on the top of the pile. But this is exactly the plate that was added ("inserted'') most recently to the pile by the dishwasher.

6)What is a queue?Example?(FIFO)

         A queue is a data structure that can simulate a list or stream of data. In this structure, new elements are inserted at one end, and existing elements are removed from the other end.
         FIFO stands for First-in, First-out, and is used to represent how data is accessed in a queue. Data has been inserted into the queue list the longest is the one that is removed first.
         A queue of people at ticket-window: The person who comes first gets the ticket.The person who is coming last is getting the tickets in last.Therefore, it follows first-in-first-out(FIFO) stategy of queue.

7)What are binary trees?(Non Linear Data structure)
          
       1) A binary tree is one type of data structure that has two nodes, a left node, and a right node. In programming, binary trees are an extension of the linked list structures. 
       2)A binary tree is a tree data structure in which each node has at most two children, which are referred to as the left child and the right child. It is implemented mainly using Links.
       3)In a binary tree a node should contain minimum zero subnodes maximum two sub nodes.
       4)A node which has zero subnodes those are called as leaf nodes.

8)Which data structures are applied when dealing with a recursive function?
       
        Recursion, is a function that calls itself based on a terminating condition, makes use of the stack. Using LIFO, a call to a recursive function saves the return address so that it knows how to return to the calling function after the call terminates.

9)Explain Binary Search Tree?
         
        A binary search tree stores data in such a way that they can be retrieved very efficiently. The left subtree contains nodes whose keys are less than the node’s key value, while the right subtree contains nodes whose keys are greater than or equal to the node’s key value. Moreover, both subtrees are also binary search trees.

10)What are multidimensional arrays?
          
       Multidimensional arrays make use of multiple indexes to store data. It is useful when storing data that cannot be represented using single dimensional indexing, such as data representation in a board game, tables with data stored in more than one column.


11)Are linked lists considered linear or non-linear data structures? 
        
       It depends on where you intend to apply linked lists. If you based it on storage, a linked list is considered non-linear. On the other hand, if you based it on access strategies, then a linked list is considered linear.

12)How does dynamic memory allocation help in managing data?
       
      Apart from being able to store simple structured data types, dynamic memory allocation can combine separately allocated structured blocks to form composite structures that expand and contract as needed.

13)What is merge sort?
          
       Merge sort, is a divide-and-conquer approach for sorting the data. In a sequence of data, adjacent ones are merged and sorted to create bigger sorted lists. These sorted lists are then merged again to form an even bigger sorted list, which continues until you have one single sorted list.

14)Differentiate NULL and VOID
          
        Null is a value, whereas Void is a data type identifier. A variable that is given a Null value indicates an empty value. The void is used to identify pointers as having no initial size.

15)What is the primary advantage of a linked list?
          
        A linked list is an ideal data structure because it can be modified easily. This means that editing a linked list works regardless of how many elements are in the list.

16)What is the difference between a PUSH and a POP?
            
         Pushing and popping applies to the way data is stored and retrieved in a stack. A push denotes data being added to it, meaning data is being “pushed” into the stack. On theother hand, a pop denotes data retrieval, and in particular, refers to the topmost data being accessed.

17)What is a linear search?
            
        A linear search refers to the way a target key is being searched in a sequential data structure. In this method, each element in the list is checked and compared against the target key. The process is repeated until found or if the end of the file has been reached.

18)How does variable declaration affect memory allocation?
            
           The amount of memory to be allocated or reserved would depend on the data type of the variable being declared. For example, if a variable is declared to be of integer type, then 32 bits of memory storage will be reserved for that variable.


19)What is the advantage of the heap over a stack?

          The heap is more flexible than the stack. That’s because memory space for the heap can be dynamically allocated and de-allocated as needed. However, the memory of the heap can at times be slower when compared to that stack.

20)How do signed and unsigned numbers affect memory?

         In the case of signed numbers, the first bit is used to indicate whether positive or negative, which leaves you with one bit short. With unsigned numbers, you have all bits available for that number. The effect is best seen in the number range an unsigned 8-bit number has a range 0-255, while the 8-bit signed number has a range -128 to +127.        


21)Do all declaration statements result in a fixed reservation in memory?

       Most declarations do, with the exemption of pointers. Pointer declaration does not allocate memory for data, but for the address of the pointer variable. Actual memory allocation for the data comes during run-time.

22)What are ARRAYs?
        
        1)When dealing with arrays, data is stored and retrieved using an index that refers to the element number in the data sequence. This means that data can be accessed in any order. In programming, an array is declared as a variable having a number of indexed elements.
       2)Array is one of the derived data type which is a collection of similar datatypes of elements and
which  are in contiguous memory locations.

23)Differentiate STACK from ARRAY.
       
            Stack follows a LIFO pattern. It means that data access follows a sequence wherein the last data to be stored when the first one to be extracted. Arrays, on the other hand, does not follow a particular order and instead can be accessed by referring to the indexed element within the array.

24)What is a bubble sort and how do you perform it?

            A bubble sort is one sorting technique that can be applied to data structures such as an array.
 It works by comparing adjacent elements and exchanges their values if they are out of order. This method lets the smaller values “bubble” to the top of the list, while the larger value sinks to the bottom.

25)Differentiate between Compiler and Interpreter?
           
           An interpreter reads one instruction at a time and carries out the actions  implied by that instruction. It does not perform any translation. But a compiler translates the entire instructions.

26)What is a file?

          A file is a named location which stores data or information permanently. A file is always stored inside a storage device using file name (e.g. STUDENT.MARKS). A file name normally has primary and secondary name separated by a “.”(DOT).

27)What are command line arguments?
            
        1)The argument passed to the main() function while executing the program is known as command line argument.
        2)Command line arguments is the mechanism where we can supply the input at load time.

28)What is a token ?
     
         1)The Token is an identifier. It can be constant, keyword, string literal, etc. A token is the smallest individual unit in a program.
          2)C has the following tokens:
                Identifiers: Identifiers refer to the name of the variables.
                Keywords: Keywords are the predefined words that are explained by the compiler.
                Constants: Constants are the fixed values that cannot be changed during the execution of a                                     program.
                Operators: An operator is a symbol that performs the particular operation.
     Special characters: All the characters except alphabets and digits are treated as special                                                        characters.

29)What is an auto keyword in C ?

        In C, every local variable of a function is known as an automatic (auto) variable. Variables which are declared inside the function block are known as a local variable. The local variables are also known as an auto variable. It is optional to use an auto keyword before the data type of a variable. If no value is stored in the local variable, then it consists of a garbage value.

30)What is a union ?
     1)Union is one of the userdefined datatype which is a collection of different types of data which are in same memory location.
     2)However, it doesn't occupy the sum of the memory of all members. It holds the memory of the largest member only.
     3)In union, we can access only one variable at a time as it allocates one common space for all the members of a union.

31)What is a structure ?

       1)Structure is one of the userdefined datatypes which is a collection of different types of data which are in contiguous memory locations.
      2)It occupies the sum of the memory of all members.
      3)The structure members can be accessed only through structure variables.
      4)Structure variables accessing the same structure but the memory allocated for each variable will be different.

32)What is Dynamic Memory Allocation ?

      1)In case of dynamic memory allocation, memory is allocated at runtime and memory can be increased while executing the program. It is used in the linked list.
      2) The malloc() or calloc() function is required to allocate the memory at the runtime.
      3)An allocation or deallocation of memory is done at the execution time of a program.
      4)No dynamic pointers are required to access the memory.
      5)The dynamic memory is implemented using data segments.
      6)Less memory space is required to store the variable.

33)What is Static Memory Allocation ?

    1)In case of static memory allocation, memory is allocated at compile time, and memory can't be increased while executing the program. It is used in the array.
    2)The lifetime of a variable in static memory is the lifetime of a program.
    3)The static memory is allocated using static keyword.
    4)The static memory is implemented using stacks or heap.
    5)The pointer is required to access the variable present in the static memory.
    6)The static memory is faster than dynamic memory.
    7)In static memory, more memory space is required to store the variable.

34)What is the usage of Pointer in C ?
 
  1)Accessing array elements: Pointers are used in traversing through an array of integers and                Strings.The string is an array of characters which is terminated by a null character '\0'.
  2)Dynamic memory allocation: Pointers are used in allocation and deallocation of memory during       the execution of a program.
  3)Call by Reference:The pointers are used to pass a reference of a variable to other function.
  4)Data Structures like a tree, graph, linked list, etc.: The pointers are used to construct different        data structures like tree, graph, linked list, etc.

35)What is a dangling pointer in C ?
     
   1)If a pointer is pointing any memory location, but meanwhile another pointer deletes the memory         occupied by the first pointer while the first pointer still points to that memory location, the first           pointer will be known as a dangling pointer.
  2)Dangling pointer arises when an object is deleted without modifying the value of the pointer. The        pointer points to the deallocated memory.

36)What is a NULL pointer ?

      A pointer that doesn't refer to any address of value but NULL is known as a NULL pointer. When we assign a '0' value to a pointer of any type, then it becomes a Null pointer.

37)What is a pointer in C?
   
     A pointer is a variable that refers to the address of a value. It makes the code optimized and makes the performance fast. Whenever a variable is declared inside a program, then the system allocates some memory to a variable. The memory contains some address number. The variables that hold this address number is known as the pointer variable.

38)What is recursion in C ?

     When a function calls itself, and this process is known as recursion. The function that calls itself is known as a recursive function.
Recursive function comes in two phases:
Winding phase: When the recursive function calls itself, and this phase ends when the condition is reached.
Unwinding phase: Unwinding phase starts when the condition is reached, and the control returns to the original call.

39)What is the difference between Call By Value and Call By Reference?

  1)When a copy of the value is passed to the function, then the original value is not modified.
     When a copy of the value is passed to the function, then the original value is modified.
 2)Actual arguments and formal arguments are created in separate memory locations.
    Actual arguments and formal arguments are created in the same memory location.
 3)In this case, actual arguments remain safe as they cannot be modified.
     In this case, actual arguments are not reliable, as they are modified.
 4)The copies of the actual arguments are passed to the formal arguments.
    The addresses of actual arguments are passed to their respective formal arguments.

40)What is the use of writing a function in C Programming Language?

  1)C functions are used to avoid the rewriting the same code again and again in our program.
  2)C functions can be called any number of times from any place of our program.
  3)When a program is divided into functions, then any part of our program can easily be tracked.
  4)C functions provide the reusability concept, i.e., it breaks the big task into smaller tasks so that it        makes the C program more understandable.

41)What are the differences between Local Variables and Global Variables?

  1)A variable which is declared inside function or block is known as a local variable.
     A variable which is declared outside function or block is known as a global variable.
 2)The scope of a variable is available within a function in which they are declared.
    The scope of a variable is available throughout the program.
 3)Variables can be accessed only by those statements inside a function in which they are declared.
    Any statement in the entire program can access variables
 4)Life of a variable is created when the function block is entered and destroyed on its exit.
    Life of a variable exists until the program is executing.
 5)Variables are stored in a stack unless specified
    The compiler decides the storage location of a variable.

42)Why is C known as the Mother Language ?

   C is known as a mother language because most of the compilers and JVMs are written in C language. Most of the languages which are developed after C language has borrowed heavily
from it like C++, Python, Rust, JavaScript, etc. It introduces new core concepts like arrays, functions, file handling which are used in these languages.

43)What does the format %10.2 mean when included in a printf statement?

               This format is used for two things: to set the number of spaces allotted for the output number and to set the number of decimal places. The number before the decimal point is for the allotted space, in this case it would allot 10 spaces for the output number. If the number of space occupied by the output number is less than 10, addition space characters will be inserted before the actual output number. The number after the decimal point sets the number of decimal places, in
this case, it’s 2 decimal spaces.


44)What are macros? What are its advantages and disadvantages?

            1)Macros are processor directive which will be replaced at compile time.
            2)The disadvantage with macros is that they just replace the code they are not
                function calls.
            3)Similarly the advantage is they can reduce time for replacing the
                same values.

45)What is the difference between an array and a list?
       
           1)Array is collection of homogeneous elements.
              List is is collection of heterogeneous elements.
           2)For Array memory allocated is static and continuous.
              For List memory allocated is  dynamic and random.
           3)User need not have to keep in track of next memory allocation.
              User has to keep in Track of next location where memory is allocated.
           4)Array uses direct access of stored members
              list uses sequential access for  members.     
 
46)What is debugger?

         A debugger or debugging tool is a computer program that is used to test and debug other programs


47)What is an interrupt?
 
       Interrupt is an asynchronous signal informing a program that an event has occurred. When a program receives an interrupt signal, it takes a specified action.

48)What are enumerations?
     
        1)An enumeration is a data type, used to declare variable that store list of names. It is act like a database, which will store list of items in the variable.
        2)enum is one of the userdefined data type which is useful for providing a name to constants
 so,that understanding the program becomes easy.

49)In header files whether functions are declared or defined?
   
      Functions are declared within header file. That is function prototypes exist in a header file,not function bodies. They are defined in library (lib).