Monday, 23 March 2015

C Interview Questions and Answers
1. What does static variable mean?
Ans: Static variables are the variables which retain their values between the function calls. They are initialized only once their scope is within the function in which they are defined.

2. What is a pointer?
Ans: Pointers are variables which stores the address of another variable. That variable may be a scalar (including another pointer), or an aggregate (array or structure). The pointed-to object may be part of a larger object, such as a field of a structure or an element in an array.

3. What are the uses of a pointer?
Ans: Pointer is used in the following cases i) It is used to access array elements ii) It is used for dynamic memory allocation. iii) It is used in Call by reference iv) It is used in data structures like trees, graph, linked list etc.

4. What is a structure?
Ans: Structure constitutes a super data type which represents several different data types in a single unit. A structure can be initialized if it is static or global.

5. What is a union?
Ans: Union is a collection of heterogeneous data type but it uses efficient memory utilization technique by allocating enough memory to hold the largest member. Here a single area of memory contains values of different types at different time. A union can never be initialized.

6. What are the differences between structures and union?
Ans: A structure variable contains each of the named members, and its size is large enough to hold all the members. Structure elements are of same size. A union contains one of the named members at a given time and is large enough to hold the largest member. Union element can be of different sizes.

7. What are the differences between structures and arrays?
Ans: Structure is a collection of heterogeneous data type but array is a collection of homogeneous data types. Array 1-It is a collection of data items of same data type. 2-It has declaration only 3-.There is no keyword. 4- array name represent the address of the starting element. Structure 1-It is a collection of data items of different data type. 2- It has declaration and definition 3- keyword struct is used 4-Structure name is known as tag it is the short hand notation of the declaration.

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

9. What are the differences between malloc () and calloc ()?
Ans: Malloc Calloc 1-Malloc takes one argument Malloc(a);where a number of bytes 2-memory allocated contains garbage values 1-Calloc takes two arguments Calloc(b,c) where b no of object and c size of object 2-It initializes the contains of block of memory to zerosMalloc takes one argument, memory allocated contains garbage values. It allocates contiguous memory locations. Calloc takes two arguments, memory allocated contains all zeros, and the memory allocated is not contiguous.

10. What are macros?
What are its advantages and disadvantages?
Ans: Macros are abbreviations for lengthy and frequently used statements. When a macro is called the entire code is substituted by a single line though the macro definition is of several lines. The advantage of macro is that it reduces the time taken for control transfer as in case of function. The disadvantage of it is here the entire code is substituted so the program becomes lengthy if a macro is called several times.

11. Difference between pass by reference and pass by value?
Ans: Pass by reference passes a pointer to the value. This allows the callee to modify the variable directly.Pass by value gives a copy of the value to the callee. This allows the callee to modify the value without modifying the variable. (In other words, the callee simply cannot modify the variable, since it lacks a reference to it.)

12. What is static identifier?
Ans: A file-scope variable that is declared static is visible only to functions within that file. A function-scope or block-scope variable that is declared as static is visible only within that scope. Furthermore, static variables only have a single instance. In the case of function- or block-scope variables, this means that the variable is not “automatic” and thus retains its value across function invocations.

13. Where is the auto variables stored?
Ans: Auto variables can be stored anywhere, so long as recursion works. Practically, they’re stored on the stack. It is not necessary that always a stack exist. You could theoretically allocate function invocation records from the heap.

14. Where does global, static, and local, register variables, free memory and C Program instructions get stored?
Ans: Global: Wherever the linker puts them. Typically the “BSS segment” on many platforms. Static: Again, wherever the linker puts them. Often, they’re intermixed with the globals. The only difference between globals and statics is whether the linker will resolve the symbols across compilation units.Local: Typically on the stack, unless the variable gets register allocated and never spills.Register: Nowadays, these are equivalent to “Local” variables. They live on the stack unless they get register-allocated.

15. Difference between arrays and linked list?
Ans: An array is a repeated pattern of variables in contiguous storage. A linked list is a set of structures scattered through memory, held together by pointers in each element that point to the next element. With an array, we can (on most architectures) move from one element to the next by adding a fixed constant to the integer value of the pointer. With a linked list, there is a “next” pointer in each structure which says what element comes next.

16. What are enumerations?
Ans: They are a list of named integer-valued constants. Example:enum color { black , orange=4, yellow, green, blue, violet };This declaration defines the symbols “black”, “orange”, “yellow”, etc. to have the values “1,” “4,” “5,” … etc. The difference between an enumeration and a macro is that the enum actually declares a type, and therefore can be type checked.

17. Describe about storage allocation and scope of global, extern, static, local and register variables?
Ans: Globals have application-scope. They’re available in any compilation unit that includes an appropriate declaration (usually brought from a header file). They’re stored wherever the linker puts them, usually a place called the “BSS segment.” Extern?
This is essentially “global.” Static: Stored the same place as globals, typically, but only available to the compilation unit that contains them. If they are block-scope global, only available within that block and its subblocks. Local: Stored on the stack, typically. Only available in that block and its subblocks. (Although pointers to locals can be passed to functions invoked from within a scope where that local is valid.) Register: See tirade above on “local” vs. “register.” The only difference is that the C compiler will not let you take the address of something you’ve declared as “register.”

18. What are register variables?
What are the advantages of using register variables?
Ans: If a variable is declared with a register storage class,it is known as register variable.The register variable is stored in the cpu register instead of main memory.Frequently used variables are declared as register variable as it’s access time is faster.

19. What is the use of typedef?
Ans: The typedef help in easier modification when the programs are ported to another machine. A descriptive new name given to the existing data type may be easier to understand the code.

20. Can we specify variable field width in a scanf() format string?
If possible how?
Ans: All field widths are variable with scanf(). You can specify a maximum field width for a given field by placing an integer value between the ‘%’ and the field type specifier. (e.g. %64s). Such a specifier will still accept a narrower field width. The one exception is %#c (where # is an integer). This reads EXACTLY # characters, and it is the only way to specify a fixed field width with scanf().

21. Out of fgets() and gets() which function is safe to use and why?
Ans: fgets() is safer than gets(), because we can specify a maximum input length. Neither one is completely safe, because the compiler can’t prove that programmer won’t overflow the buffer he pass to fgets ().

22. Difference between strdup and strcpy?
Ans: Both copy a string. strcpy wants a buffer to copy into. strdup allocates a buffer using malloc(). Unlike strcpy(), strdup() is not specified by ANSI .

23. What is recursion?
Ans: A recursion function is one which calls itself either directly or indirectly it must halt at a definite point to avoid infinite recursion.

24. Differentiate between for loop and a while loop?
What are it uses?
Ans: For executing a set of statements fixed number of times we use for loop while when the number of iterations to be performed is not known in advance we use while loop.

25. What is storage class?
What are the different storage classes in C?
Ans: Storage class is an attribute that changes the behavior of a variable. It controls the lifetime, scope and linkage. The storage classes in c are auto, register, and extern, static, typedef.

26. What the advantages of using Unions?
Ans: When the C compiler is allocating memory for unions it will always reserve enough room for the largest member.

27. What is the difference between Strings and Arrays?
Ans: String is a sequence of characters ending with NULL .it can be treated as a one dimensional array of characters terminated by a NULL character.

28. What is a far pointer?
Where we use it?
Ans: In large data model (compact, large, huge) the address B0008000 is acceptable because in these model all pointers to data are 32bits long. If we use small data model(tiny, small, medium) the above address won’t work since in these model each pointer is 16bits long. If we are working in a small data model and want to access the address B0008000 then we use far pointer. Far pointer is always treated as a 32bit pointer and contains a segment address and offset address both of 16bits each. Thus the address is represented using segment : offset format B000h:8000h. For any given memory address there are many possible far address segment : offset pair. The segment register contains the address where the segment begins and offset register contains the offset of data/code from where segment begins.

29. What is a huge pointer?
Ans: Huge pointer is 32bit long containing segment address and offset address. Huge pointers are normalized pointers so for any given memory address there is only one possible huge address segment: offset pair. Huge pointer arithmetic is doe with calls to special subroutines so its arithmetic slower than any other pointers.

30. What is a normalized pointer, how do we normalize a pointer?
Ans: It is a 32bit pointer, which has as much of its value in the segment register as possible. Since a segment can start every 16bytes so the offset will have a value from 0 to F. for normalization convert the address into 20bit address then use the 16bit for segment address and 4bit for the offset address. Given a pointer 500D: 9407,we convert it to a 20bitabsolute address 549D7,Which then normalized to 549D:0007.

31. What is near pointer?
Ans: A near pointer is 16 bits long. It uses the current content of the CS (code segment) register (if the pointer is pointing to code) or current contents of DS (data segment) register (if the pointer is pointing to data) for the segment part, the offset part is stored in a 16 bit near pointer. Using near pointer limits the data/code to 64kb segment.

32. In C, why is the void pointer useful?
When would you use it?
Ans: The void pointer is useful because it is a generic pointer that any pointer can be cast into and back again without loss of information.

33. What is a NULL Pointer?
Whether it is same as an uninitialized pointer?
Ans: Null pointer is a pointer which points to nothing but uninitialized pointer may point to anywhere.

34. Are pointers integer?
Ans: No, pointers are not integers. A pointer is an address. It is a positive number.

35. What does the error ‘Null Pointer Assignment’ means and what causes this error?
Ans: As null pointer points to nothing so accessing a uninitialized pointer or invalid location may cause an error.

36. What is generic pointer in C?
Ans: In C void* acts as a generic pointer. When other pointer types are assigned to generic pointer,conversions are applied automatically (implicit conversion).

37. Are the expressions arr and &arr same for an array of integers?
Ans: Yes for array of integers they are same.

38. How pointer variables are initialized?
Ans: Pointer variables are initialized by one of the following ways.

I. Static memory allocation II. Dynamic memory allocation

39. What is static memory allocation?
Ans: Compiler allocates memory space for a declared variable. By using the address of operator, the reserved address is obtained and this address is assigned to a pointer variable. This way of assigning pointer value to a pointer variable at compilation time is known as static memory allocation.

40. What is dynamic memory allocation?
Ans: A dynamic memory allocation uses functions such as malloc() or calloc() to get memory dynamically. If these functions are used to get memory dynamically and the values returned by these function are assigned to pointer variables, such a way of allocating memory at run time is known as dynamic memory allocation.

41. What is the purpose of realloc?
Ans: It increases or decreases the size of dynamically allocated array. The function realloc (ptr,n) uses two arguments. The first argument ptr is a pointer to a block of memory for which the size is to be altered. The second argument specifies the new size. The size may be increased or decreased. If sufficient space is not available to the old region the function may create a new region.

42. What is pointer to a pointer?
Ans: If a pointer variable points another pointer value. Such a situation is known as a pointer to a pointer. Example: int *p1,**p2,v=10; P1=&v; p2=&p1; Here p2 is a pointer to a pointer.

43. What is an array of pointers?
Ans: if the elements of an array are addresses, such an array is called an array of pointers.

44. Difference between linker and linkage?
Ans: Linker converts an object code into an executable code by linking together the necessary built in functions. The form and place of declaration where the variable is declared in a program determine the linkage of variable.

45. Is it possible to have negative index in an array?
Ans: Yes it is possible to index with negative value provided there are data stored in this location. Even if it is illegal to refer to the elements that are out of array bounds, the compiler will not produce error because C has no check on the bounds of an array.

46. Why is it necessary to give the size of an array in an array declaration?
Ans: When an array is declared, the compiler allocates a base address and reserves enough space in memory for all the elements of the array. The size is required to allocate the required space and hence size must be mentioned.

47. What modular programming?
Ans: If a program is large, it is subdivided into a number of smaller programs that are called modules or subprograms. If a complex problem is solved using more modules, this approach is known as modular programming.

48. What is a function?
Ans: A large program is subdivided into a number of smaller programs or subprograms. Each subprogram specifies one or more actions to be performed for the larger program. Such sub programs are called functions.

49. What is an argument?
Ans: An argument is an entity used to pass data from the calling to a called function.

50. What are built in functions?
Ans: The functions that are predefined and supplied along with the compiler are known as built-in functions. They are also known as library functions.

51. What do the ‘c’ and ‘v’ in argc and argv stand for?
Ans: The c in argc(argument count) stands for the number of command line argument the program is invoked with and v in argv(argument vector) is a pointer to an array of character string that contain the arguments.

52. what are C tokens?
Ans: There are six classes of tokens: identifier, keywords, constants, string literals, operators and other separators.

53. What are C identifiers?
Ans: These are names given to various programming element such as variables, function, arrays.It is a combination of letter, digit and underscore.It should begin with letter. Backspace is not allowed.

54. Difference between syntax vs logical error?
Ans: Syntax Error 1-These involves validation of syntax of language. 2-compiler prints diagnostic message. Logical Error 1-logical error are caused by an incorrect algorithm or by a statement mistyped in such a way that it doesn’t violet syntax of language. 2-difficult to find.

55. What is preincrement and post increment?
Ans: ++n (pre increment) increments n before its value is used in an assignment operation or any expression containing it. n++ (post increment) does increment after the value of n is used.

56. Write a program to interchange 2 variables without using the third one?. Ans: a ^= b; ie a=a^b b ^= a; ie b=b^a; a ^= b ie a=a^b; here the numbers are converted into binary and then xor operation is performed. You know, you’re just asking “have you seen this overly clever trick that’s not worth applying on modern architectures and only really applies to integer variables”

57. What is the maximum combined length of command line arguments including the space between adjacent arguments?
Ans: It depends on the operating system.

58. What are bit fields?
What is the use of bit fields in a Structure declaration?
Ans: A bit field is a set of adjacent bits within a single implementation based storage unit that we will call a “word”.

The syntax of field definition and access is based on structure. Struct { unsigned int k :1; unsigned int l :1; unsigned int m :1; }flag; the number following the colon represents the field width in bits.flag is a variable that contains three bit fields.

59. What is a preprocessor, what are the advantages of preprocessor?
Ans: A preprocessor processes the source code program before it passes through the compiler. 1- a preprocessor involves the readability of program 2- It facilitates easier modification 3- It helps in writing portable programs 4- It enables easier debugging 5- It enables testing a part of program 6- It helps in developing generalized program

60. What are the facilities provided by preprocessor?
Ans: 1-file inclusion 2-substitution facility 3-conditional compilation

61. What are the two forms of #include directive?
Ans: 1.#include”filename” 2.#include the first form is used to search the directory that contains the source file.If the search fails in the home directory it searches the implementation defined locations.In the second form ,the preprocessor searches the file only in the implementation defined locations.

62. How would you use the functions randomize() and random()?
Ans: Randomize() initiates random number generation with a random value. Random() generates random number between 0 and n-1;

63. What do the functions atoi(), itoa() and gcvt() do?
Ans: atoi() is a macro that converts integer to character. itoa() It converts an integer to string gcvt() It converts a floating point number to string

64. How would you use the functions fseek(), freed(), fwrite() and ftell()?
Ans: fseek(f,1,i) Move the pointer for file f a distance 1 byte from location i. fread(s,i1,i2,f) Enter i2 dataitems,each of size i1 bytes,from file f to string s. fwrite(s,i1,i2,f) send i2 data items,each of size i1 bytes from string s to file f. ftell(f) Return the current pointer position within file f. The data type returned for functions fread,fseek and fwrite is int and ftell is long int.

65. What is the difference between the functions memmove() and memcpy()?
Ans: The arguments of memmove() can overlap in memory. The arguments of memcpy() cannot.

66. What is a file?
Ans: A file is a region of storage in hard disks or in auxiliary storage devices.It contains bytes of information .It is not a data type.

67. what are the types of file?
Ans: Files are of two types 1-high level files (stream oriented files) :These files are accessed using library functions 2-low level files(system oriented files) :These files are accessed using system calls

68. what is a stream?
Ans: A stream is a source of data or destination of data that may be associated with a disk or other I/O device. The source stream provides data to a program and it is known as input stream. The destination stream eceives the output from the program and is known as output stream.

69. What is meant by file opening?
Ans: The action of connecting a program to a file is called opening of a file. This requires creating an I/O stream before reading or writing the data.

70. What is FILE?
Ans: FILE is a predefined data type. It is defined in stdio.h file.

71. What is a file pointer?
Ans: The pointer to a FILE data type is called as a stream pointer or a file pointer. A file pointer points to the block of information of the stream that had just been opened.

72. How is fopen()used ?
Ans: The function fopen() returns a file pointer. Hence a file pointer is declared and it is assigned as FILE *fp; fp= fopen(filename,mode); filename is a string representing the name of the file and the mode represents: “r” for read operation “w” for write operation “a” for append operation “r+”,”w+”,”a+” for update operation

73. How is a file closed ?
Ans: A file is closed using fclose() function Eg. fclose(fp); Where fp is a file pointer.

74. What is a random access file?
Ans: A file can be accessed at random using fseek() function fseek(fp,position,origin); fp file pointer position number of bytes offset from origin origin 0,1 or 2 denote the beginning ,current position or end of file respectively.

75. What is the purpose of ftell ?
Ans: The function ftell() is used to get the current file represented by the file pointer. ftell(fp); returns a long integer value representing the current file position of the file pointed by the file pointer fp.If an error occurs ,-1 is returned.

76. What is the purpose of rewind() ?
Ans: The function rewind is used to bring the file pointer to the beginning of the file. Rewind(fp); Where fp is a file pointer.Also we can get the same effect by feek(fp,0,0);

77. Difference between a array name and a pointer variable?
Ans: A pointer variable is a variable where as an array name is a fixed address and is not a variable. A pointer variable must be initialized but an array name cannot be initialized. An array name being a constant value , ++ and — operators cannot be applied to it.

78. Represent a two-dimensional array using pointer?
Ans: Address of a[I][j] Value of a[I][j] &a[I][j] or a[I] + j or *(a+I) + j *&a[I][j] or a[I][j] or *(a[I] + j ) or *( * ( a+I) +j )

79. Difference between an array of pointers and a pointer to an array?
Ans: Array of pointers 1- Declaration is: data_type *array_name[size]; 2-Size represents the row size. 3- The space for columns may be dynamically Pointers to an array 1-Declaration is data_type ( *array_name)[size]; 2-Size represents the column size.

80. Can we use any name in place of argv and argc as command line arguments ?
Ans: yes we can use any user defined name in place of argc and argv;

81. What are the pointer declarations used in C?
Ans: 1- Array of pointers, e.g , int *a[10]; Array of pointers to integer 2-Pointers to an array,e.g , int (*a)[10]; Pointer to an array of into 3-Function returning a pointer,e.g, float *f( ) ; Function returning a pointer to float 4-Pointer to a pointer ,e.g, int **x; Pointer to apointer to int 5-pointer to a data type ,e.g, char *p; pointer to char

82. Differentiate between a constant pointer and pointer to a constant?
Ans: const char *p; //pointer to a const character. char const *p; //pointer to a const character. char * const p; //const pointer to a char variable. const char * const p; // const pointer to a const character.

83. Is the allocated space within a function automatically deallocated when the function returns?
Ans: No pointer is different from what it points to .Local variables including local pointers variables in a function are deallocated automatically when function returns.,But in case of a local pointer variable ,deallocation means that the pointer is deallocated and not the block of memory allocated to it. Memory dynamically allocated always persists until the allocation is freed or the program terminates.

84. Discuss on pointer arithmetic?
Ans: 1- Assignment of pointers to the same type of pointers. 2- Adding or subtracting a pointer and an integer. 3-subtracting or comparing two pointer. 4-incrementing or decrementing the pointers pointing to the elements of an array. When a pointer to an integer is incremented by one , the address is incremented by two. It is done automatically by the compiler. 5-Assigning the value 0 to the pointer variable and comparing 0 with the pointer. The pointer having address 0 points to nowhere at all.

85. What is the invalid pointer arithmetic?
Ans: i) adding ,multiplying and dividing two pointers. ii) Shifting or masking pointer. iii) Addition of float or double to pointer. iv) Assignment of a pointer of one type to a pointer of another type

v) 86. What are the advantages of using array of pointers to string instead of an array of strings?
Ans: i) Efficient use of memory. ii) Easier to exchange the strings by moving their pointers while sorting.

87. Are the expressions *ptr ++ and ++ *ptr same?
Ans: No,*ptr ++ increments pointer and not the value pointed by it. Whereas ++ *ptr increments the value being pointed to by ptr.

88. What would be the equivalent pointer expression foe referring the same element as a[p][q][r][s] ?
Ans : *( * ( * ( * (a+p) + q ) + r ) + s)

89. Are the variables argc and argv are always local to main?
Ans: Yes they are local to main.

90. Can main () be called recursively?
Ans: Yes any function including main () can be called recursively.
Data Structure

91. What is data structure?
Ans: The logical and mathematical model of a particular organization of data is called data structure. There are two types of data structure i) Linear ii) Nonlinear

92. What are the goals of Data Structure?
Ans: It must rich enough in structure to reflect the actual relationship of data in real world. The structure should be simple enough for efficient processing of data.

93. What does abstract Data Type Mean?
Ans: Data type is a collection of values and a set of operations on these values. Abstract data type refer to the mathematical concept that define the data type. It is a useful tool for specifying the logical properties of a data type. ADT consists of two parts 1) Values definition 2) Operation definition Example:-The value definition for the ADT RATIONAL states that RATIONAL value consists of two integers, second doesn’t equal to zero. The operator definition for ADT RATIONAL includes the operation of creation (make rational) addition, multiplication and test for equality.

94. What is the difference between a Stack and an Array?
Ans: i) Stack is a ordered collection of items ii) Stack is a dynamic object whose size is constantly changing as items are pushed and popped . iii) Stack may contain different data types iv) Stack is declared as a structure containing an array to hold the element of the stack, and an integer to indicate the current stack top within the array. ARRAY v) Array is an ordered collection of items vi) Array is a static object i.e. no of item is fixed and is assigned by the declaration of the array vii) It contains same data types. viii) Array can be home of a stack i.e. array can be declared large enough for maximum size of the stack.

95. What do you mean by recursive definition?
Ans: The definition which defines an object in terms of simpler cases of itself is called recursive definition.

96. What is sequential search?
Ans: In sequential search each item in the array is compared with the item being searched until a match occurs. It is applicable to a table organized either as an array or as a linked list.

97. What actions are performed when a function is called?
Ans: When a function is called i) arguments are passed ii) local variables are allocated and initialized iii) transferring control to the function

98. What actions are performed when a function returns?
Ans: i) Return address is retrieved ii) Function’s data area is freed iii) Branch is taken to the return address

99. What is a linked list?
Ans: A linked list is a linear collection of data elements, called nodes, where the linear order is given by pointers. Each node has two parts first part contain the information of the element second part contains the address of the next node in the list.

100. What are the advantages of linked list over array (static data structure)?
Ans: The disadvantages of array are i) unlike linked list it is expensive to insert and delete elements in the array ii) One can’t double or triple the size of array as it occupies block of memory space. In linked list iii) each element in list contains a field, called a link or pointer which contains the address of the next element iv) Successive element’s need not occupy adjacent space in memory.

101. What are the disadvantages of linear list?
Ans: i) We cannot reach any of the nodes that precede node (p) ii) If a list is traversed, the external pointer to the list must be persevered in order to reference the list again

102. Define circular list?
Ans: In linear list the next field of the last node contain a null pointer, when a next field in the last node contain a pointer back to the first node it is called circular list. Advantages – From any point in the list it is possible to reach at any other point

103. What are the disadvantages of circular list?
Ans: i) We can’t traverse the list backward ii) If a pointer to a node is given we cannot delete the node

104. Define double linked list?
Ans: It is a collection of data elements called nodes, where each node is divided into three parts i) An info field that contains the information stored in the node ii) Left field that contain pointer to node on left side iii) Right field that contain pointer to node on right side

105. Is it necessary to sort a file before searching a particular item ?
Ans: If less work is involved in searching a element than to sort and then extract, then we don’t go for sort If frequent use of the file is required for the purpose of retrieving specific element, it is more efficient to sort the file. Thus it depends on situation.

106. What are the issues that hamper the efficiency in sorting a file?
Ans: The issues are i) Length of time required by the programmer in coding a particular sorting program ii) Amount of machine time necessary for running the particular program iii)The amount of space necessary for the particular program.

107. Calculate the efficiency of sequential search?
Ans: The number of comparisons depends on where the record with the argument key appears in the table If it appears at first position then one comparison If it appears at last position then n comparisons Average=(n+1)/2 comparisons Unsuccessful search n comparisons Number of comparisons in any case is O (n).

108. Is any implicit arguments are passed to a function when it is called?
Ans: Yes there is a set of implicit arguments that contain information necessary for the function to execute and return correctly. One of them is return address which is stored within the function’s data area, at the time of returning to calling program the address is retrieved and the function branches to that location.

109. Parenthesis is never required in Postfix or Prefix expressions, why?
Ans: Parenthesis is not required because the order of the operators in the postfix /prefix expressions determines the actual order of operations in evaluating the expression

110. List out the areas in which data structures are applied extensively?
Ans: Compiler Design, Operating System, Database Management System, Statistical analysis package, Numerical Analysis, Graphics, Artificial Intelligence, Simulation

111. What are the major data structures used in the following areas : network data model & Hierarchical data model?.
Ans: RDBMS – Array (i.e. Array of structures) Network data model – Graph Hierarchical data model – Trees

112. If you are using C language to implement the heterogeneous linked list, what pointer type will you use?
Ans: The heterogeneous linked list contains different data types in its nodes and we need a link, pointer to connect them. It is not possible to use ordinary pointers for this. So we go for void pointer. Void pointer is capable of storing pointer to any type as it is a generic pointer type.

113. Minimum number of queues needed to implement the priority queue?
Ans: Two. One queue is used for actual storing of data and another for storing priorities.

114. What is the data structures used to perform recursion?
Ans: Stack. Because of its LIFO (Last In First Out) property it remembers its ‘caller’ so knows whom to return when the function has to return. Recursion makes use of system stack for storing the return addresses of the function calls. Every recursive function has its equivalent iterative (non-recursive) function. Even when such equivalent iterative procedures are written, explicit stack is to be used.

115. What are the notations used in Evaluation of Arithmetic Expressions using prefix and postfix forms?
Ans: Polish and Reverse Polish notations.

Convert the expression ((A + B) * C – (D – E) ^ (F + G)) to equivalent Prefix and Postfix notations. Ans: Prefix Notation: ^ – * +ABC – DE + FG Postfix Notation: AB + C * DE – – FG + ^

116. Sorting is not possible by using which of the following methods?
i) Insertion ii) Selection iii) Exchange iv) Deletion Ans: (d) Deletion. Using insertion we can perform insertion sort, using selection we can perform selection sort, using exchange we can perform the bubble sort (and other similar sorting methods). But no sorting method can be done just using deletion.

117. List out few of the Application of tree data-structure?
Ans: The manipulation of Arithmetic expression, Symbol Table construction, Syntax analysis.

118. List out few of the applications that make use of Multilinked Structures?
Ans: Sparse matrix, Index generation.

119. in tree construction which is the suitable efficient data structure?
I. Array (b) Linked list (c) Stack (d) Queue (e) none Ans: (b) Linked list

120. What is the type of the algorithm used in solving the 8 Queens problem?
Ans: Backtracking

121. In an AVL tree, at what condition the balancing is to be done?
Ans: If the ‘pivotal value’ (or the ‘Height factor’) is greater than 1 or less than –1.

122. There are 8, 15, 13, 14 nodes were there in 4 different trees. Which of them could have formed a full binary tree?
Ans: 15 In general: There are 2n-1 nodes in a full binary tree. By the method of elimination: Full binary trees contain odd number of nodes. So there cannot be full binary trees with 8 or 14 nodes, so rejected. With 13 nodes you can form a complete binary tree but not a full binary tree. So the correct answer is 15. Note: Full and Complete binary trees are different. All full binary trees are complete binary trees but not vice versa.

123. In RDBMS, what is the efficient data structure used in the internal storage representation?
Ans: B+ tree. Because in B+ tree, all the data is stored only in leaf nodes, that makes searching easier. This corresponds to the records that shall be stored in leaf nodes.

124. One of the following tree structures, which is, efficient considering space and time complexities?
1- Incomplete Binary Tree. 2- Complete Binary Tree. 3- Full Binary Tree. Ans: b) Complete Binary Tree. By the method of elimination: Full binary tree loses its nature when operations of insertions and deletions are done. For incomplete binary trees, extra property of complete binary tree is maintained even after operations like additions and deletions are done on it.

125. What is a spanning Tree?
Ans: A spanning tree is a tree associated with a network. All the nodes of the graph appear on the tree once. A minimum spanning tree is a spanning tree organized so that the total edge weight between nodes is minimized.

126. Does the minimum spanning tree of a graph give the shortest distance between any 2 specified nodes?
Ans: No. Minimal spanning tree assures that the total weight of the tree is kept at its minimum. But it doesn’t mean that the distance between any two nodes involved in the minimum-spanning tree is minimum.

127. Whether Linked List is linear or Non-linear data structure?
Ans: According to Storage Linked List is a Non-linear one.

No comments: