0% found this document useful (0 votes)
7 views13 pages

Basic Interview Questions

The document provides an overview of various concepts in C programming, including static variables, pointers, structures, memory allocation, macros, and the differences between arrays and linked lists. It explains the characteristics and usage of these concepts, such as the behavior of static variables, the function of pointers, and the advantages of linked lists over arrays. Additionally, it covers function declarations in header files, memory storage for different variable types, and the use of enumerations in C.

Uploaded by

anjie.l10
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views13 pages

Basic Interview Questions

The document provides an overview of various concepts in C programming, including static variables, pointers, structures, memory allocation, macros, and the differences between arrays and linked lists. It explains the characteristics and usage of these concepts, such as the behavior of static variables, the function of pointers, and the advantages of linked lists over arrays. Additionally, it covers function declarations in header files, memory storage for different variable types, and the use of enumerations in C.

Uploaded by

anjie.l10
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 13

C- Questions

1. What does static variable mean?


--> 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;

Following are some interesting facts about static variables in C.


1) A static int variable remains in memory while the program is running. A normal
or auto variable is destroyed when a function call where the variable was declared
is over.
2) Static variables are allocated memory in data segment, not stack segment.
3) Static variables (like global variables) are initialized as 0 if not initialized
explicitly.
4) In C, static variables can only be initialized using constant literals.
5) Static global variables and functions are also possible in C/C++. The purpose of
these is to limit scope of a variable or function to a file.
--> In C, functions are global by default. The �static� keyword before a
function name makes it static. For example, below function fun() is static. Unlike
global functions in C, access to static functions is restricted to the file where
they are declared. Therefore, when we want to restrict access to functions, we make
them static. Another reason for making functions static can be reuse of the same
function name in other files.

2. What is a pointer?
--> Pointers store address of variables or a memory location.

To use pointers in C, we must understand below two operators:


1. To access address of a variable to a pointer, we use the unary operator &
(ampersand) that returns the address of that variable. For example &x gives us
address of variable x.
2. One more operator is unary * (Astrik) which is used for two things :
a. To declare a pointer variable: When a pointer variable is declared
in C/C++, there must a * before its name.
b. To access the value stored in the address we use the unary operator
(*) that returns the value of the variable located at the address specified by its
operand.

3. What is a structure?
--> A structure is a user defined data type in C/C++. A structure creates a data
type that can be used to group items of possibly different types into a single
type.
a. How to create a structure?
-->�struct� keyword is used to create a structure.
b. How to declare structure variables?
--> A structure variable can either be declared with structure declaration or
as a separate declaration
// A variable declaration with structure declaration.
struct Point
{
int x, y;
} p1; // The variable p1 is declared with 'Point'

// A variable declaration like basic data types


struct Point
{
int x, y;
};

int main()
{
struct Point p1; // The variable p1 is declared like a normal variable
}
Note: In C++, the struct keyword is optional before in declaration of
variable. In C, it is mandatory.
c. How to initialize structure members?
--> Structure members cannot be initialized with declaration.
The reason for above error is simple, when a datatype is declared, no memory
is allocated for it. Memory is allocated only when variables are created.
Structure members can be initialized using curly braces �{}�. -> struct Point
p1 = {0, 1};
d. How to access structure elements?
--> Structure members are accessed using dot (.) operator.
e. What is designated Initialization?
--> Designated Initialization allows structure members to be initialized in
any order.
This feature has been added in C99 standard.

struct Point
{
int x, y, z;
};

int main()
{
// Examples of initializtion using designated initialization
struct Point p1 = {.y = 0, .z = 1, .x = 2};
struct Point p2 = {.x = 20};

printf ("x = %d, y = %d, z = %d\n", p1.x, p1.y, p1.z);


printf ("x = %d", p2.x);
return 0;
}
Output:
x = 2, y = 0, z = 1
x = 20
This feature is not available in C++ and works only in C.
f. What is an array of structures?
--> Like other primitive data types, we can create an array of structures. ->
struct Point arr[10];
g. What is a structure pointer?
--> Like primitive types, we can have pointer to a structure. If we have a
pointer to structure, members are accessed using arrow ( -> ) operator.
struct Point
{
int x, y;
};

int main()
{
struct Point p1 = {1, 2};

// p2 is a pointer to structure p1
struct Point *p2 = &p1;
// Accessing structure members using structure pointer
printf("%d %d", p2->x, p2->y);
return 0;
}
Output:
1 2

4. What are the differences between structures and arrays?


--> Array elements are homogeneous. Structure elements are of different data type.
--> Array allocates static memory and uses index / subscript for accessing elements
of the array. Structures allocate dynamic memory and uses (.) operator for
accessing the member of a structure.
--> Array is a pointer to the first element of it. Structure is not a pointer
--> Array element access takes less time in comparison with structures.

5. 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).

6. What are the differences between malloc() and calloc()?


--> The name malloc and calloc() are library functions that allocate memory
dynamically. It means that memory is allocated during runtime(execution of the
program) from heap segment.
Initialization:
malloc() allocates memory block of given size (in bytes) and returns a
pointer to the beginning of the block. malloc() doesn�t initialize the allocated
memory. If we try to acess the content of memory block then we�ll get garbage
values.
void * malloc( size_t size );
calloc() allocates the memory and also initializes the allocates memory
block to zero. If we try to access the content of these blocks then we�ll get 0.
void * calloc( size_t num, size_t size );
Number of arguments:
Unlike malloc(), calloc() takes two arguments:
1) Number of blocks to be allocated.
2) Size of each block.
Return Value:
After successfull allocation in malloc() and calloc(), a pointer to the
block of memory is returned otherwise NULL value is returned which indicates the
failure of allocation.
For instance, If we want to allocate memory for array of 5 integers, see the
following program:-

// C program to demonstrate the use of calloc()


// and malloc()
#include <stdio.h>
#include <stdlib.h>

int main()
{
int *arr;

// malloc() allocate the memory for 5 integers


// containing garbage values
arr = (int *)malloc(5 * sizeof(int)); // 5*4bytes = 5 bytes

// Deallocates memory previously allocated by malloc() function


free( arr );
// calloc() allocate the memory for 5 integers and
// set 0 to all of them
arr = (int *)calloc(5, sizeof(int));

// Deallocates memory previously allocated by calloc() function


free(arr);

return(0);
}
Note: It would be better to use malloc over calloc, unless we want the zero-
initialization because malloc is faster than calloc. So if we just want to copy
some stuff or do something that doesn�t require filling of the blocks with zeros,
then malloc would be a better choice.

7. What are macros? what are its advantages and disadvantages?


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

8. Difference between pass by reference and pass by value?


--> In c we can pass the parameters in a function in two different ways.
(a)Pass by value: In this approach we pass copy of actual variables in
function as a parameter. Hence any modification on parameters inside the function
will not reflect in the actual variable. For example:
#include<stdio.h>
int main(){
int a=5,b=10;
swap(a,b);
printf("%d %d",a,b);
return 0;
}
void swap(int a,int b){
int temp;
temp =a;
a=b;
b=temp;
}
Output: 5 10

(b)Pass by reference: In this approach we pass memory address of actual


variables in function as a parameter. Hence any modification on parameters inside
the function will reflect in the actual variable. For example:
#incude<stdio.h>
int main(){
int a=5,b=10;
swap(&a,&b);
printf("%d %d",a,b);
return 0;
}
void swap(int *a,int *b){
int *temp;
*temp =*a;
*a=*b;
*b=*temp;
}
Output: 10 5
9. What is static identifier?
--> The static identifier is used for initializing only once, and the value retains
during the life time of the program / application. A separate memory is allocated
for �static� variables. This value can be used between function calls.
The default value of an uninitialized static variable is zero. A function can also
be defined as a static function, which has the same scope of the static variable.

10. Where are the auto variables stored?


--> The auto variables are stored in the main memory of the system.
--> The keyword 'auto' is optional.
--> Many of the variables used by the program or application are 'auto' variables,
being the main memory is faster.
--> These variables are stored in the memory runtime stack.
--> It is de-allocated at the completion of its block execution.
--> It is a local variable which is allocated and deallocated automatically when
the program flow enters and leaves the variable's scope.
From GeeksForGeeks (Memory Layout of C Programs)
Stack, where automatic variables are stored, along with information that is
saved each time a function is called. Each time a function is called, the address
of where to return to and certain information about the caller�s environment, such
as some of the machine registers, are saved on the stack. The newly called function
then allocates room on the stack for its automatic and temporary variables. This is
how recursive functions in C can work. Each time a recursive function calls itself,
a new stack frame is used, so one set of variables doesn�t interfere with the
variables from another instance of the function.

11. Where does global, static, local, register variables, free memory and C Program
instructions get stored?
local variables --> stack
global variable --> data memory
register variable --> register
static variable --> main memory
free memory(dynamic memory allocatios) will be stored in heap memory(i.e in
data segments).
program instrutions will be stored in text segment which will be called
ROM(Read only memory).
const variables also stores in text segments

12. Difference between arrays and linked list?


--> Both Arrays and Linked List can be used to store linear data of similar types,
but they both have some advantages and disadvantages over each other.
Following are the points in favour of Linked Lists.
(1) The size of the arrays is fixed: So we must know the upper limit on the
number of elements in advance. Also, generally, the allocated memory is equal to
the upper limit irrespective of the usage, and in practical uses, upper limit is
rarely reached.
(2) Inserting a new element in an array of elements is expensive, because
room has to be created for the new elements and to create room existing elements
have to shifted.
For example, suppose we maintain a sorted list of IDs in an array id[].
id[] = [1000, 1010, 1050, 2000, 2040, �..].
And if we want to insert a new ID 1005, then to maintain the sorted order, we
have to move all the elements after 1000 (excluding 1000).
Deletion is also expensive with arrays until unless some special techniques
are used. For example, to delete 1010 in id[], everything after 1010 has to be
moved.

So Linked list provides following two advantages over arrays


1) Dynamic size
2) Ease of insertion/deletion

Linked lists have following drawbacks:


1) Random access is not allowed. We have to access elements sequentially
starting from the first node. So we cannot do binary search with linked lists.
2) Extra memory space for a pointer is required with each element of the
list.
3) Arrays have better cache locality that can make a pretty big difference in
performance.

13. What are enumerations?


--> Enumeration (or enum) is a user defined data type in C. It is mainly used to
assign names to integral constants, the names make a program easy to read and
maintain.
enum State {Working = 1, Failed = 0};
Interesting facts about initialization of enum.
1. Two enum names can have same value. For example, in the following C
program both �Failed� and �Freezed� have same value 0.
#include <stdio.h>
enum State {Working = 1, Failed = 0, Freezed = 0};

int main()
{
printf("%d, %d, %d", Working, Failed, Freezed);
return 0;
}
Output:
1, 0, 0

2. If we do not explicitly assign values to enum names, the compiler by


default assigns values starting from 0. For example, in the following C program,
sunday gets value 0, monday gets 1, and so on.
#include <stdio.h>
enum day {sunday, monday, tuesday, wednesday, thursday, friday, saturday};

int main()
{
enum day d = thursday;
printf("The day number stored in d is %d", d);
return 0;
}
Output:
The day number stored in d is 4

3. We can assign values to some name in any order. All unassigned names get
value as value of previous name plus one.
#include <stdio.h>
enum day {sunday = 1, monday, tuesday = 5,
wednesday, thursday = 10, friday, saturday};
int main()
{
printf("%d %d %d %d %d %d %d", sunday, monday, tuesday,
wednesday, thursday, friday, saturday);
return 0;
}
Output:
1 2 5 6 10 11 12

4. The value assigned to enum names must be some integeral constant, i.e.,
the value must be in range from minimum possible integer value to maximum possible
integer value.

5. All enum constants must be unique in their scope. For example, the
following program fails in compilation.
enum state {working, failed};
enum result {failed, passed};
int main() { return 0; }
Output:
Compile Error: 'failed' has a previous declaration as 'state failed'

14. Describe about storage allocation and scope of global, extern, static, local
and register variables?
--> Everybody knows about the scope, but the real thing is for the storage
allocation:-
Memory is devided into four segements namely stack, heap, data, code
segments.
Local Variables are stored in Stack.
The memory created dynamically are stored in Heap
Extern, Global & static variables need to retain their values so are
stored in data segment.
The C program instructions get stored in code segment
Register variables are stored in Register.

15. What are register variables? What are the advantage of using register
variables?
--> Registers are faster than memory to access, so the variables which are most
frequently used in a C program can be put in registers using register keyword. The
keyword register hints to compiler that a given variable can be put in a register.
It�s compiler�s choice to put it in a register or not. Generally, compilers
themselves do optimizations and put the variables in register.
1) If you use & operator with a register variable then compiler may give an
error or warning (depending upon the compiler you are using), because when we say a
variable is a register, it may be stored in a register instead of memory and
accessing address of a register is invalid. Try below program.
int main()
{
register int i = 10;
int *a = &i;
printf("%d", *a);
getchar();
return 0;
}

2) register keyword can be used with pointer variables. Obviously, a register


can have address of a memory location. There would not be any problem with the
below program.
int main()
{
int i = 10;
register int *a = &i;
printf("%d", *a);
getchar();
return 0;
}

3) Register is a storage class, and C doesn�t allow multiple storage class


specifiers for a variable. So, register can not be used with static . Try below
program.
int main()
{
int i = 10;
register static int *a = &i;
printf("%d", *a);
getchar();
return 0;
}

4) There is no limit on number of register variables in a C program, but the


point is compiler may put some variables in register and some not.

16. What is the use of typedef?


--> typedef : typedef is used to give data type a new name, for example
// C program to demonstrate typedef
#include <stdio.h>
// After this line BYTE can be used
// in place of unsifned char
typedef unsigned char BYTE;
int main()
{
BYTE b1, b2;
b1 = 'c';
printf("%c ", b1);
return 0;
}
Output:
c

#define : is a C directive which is used to #define alias.


// C program to demonstrate #define
#include <stdio.h>
// After this line HYD is replaced by
// "Hyderabad"
#define HYD "Hyderabad"
int main()
{
printf("%s ", HYD);
return 0;
}
Output :
Hyderabad

typedef is different from #define among the following aspects


1. typedef is limited to giving symbolic names to types only, where as
#define can be used to define alias for values as well, e.g., you can define 1 as
ONE, 3.14 as PI, etc.
2. typedef interpretation is performed by the compiler where #define
statements are performed by preprocessor.
3. #define should not be terminated with semicolon, but typedef should be
terminated with semicolon.
4. #define will just copy-paste the definition values at the point of use,
while typedef is actual definition of a new type.
5. typedef follows the scope rule which means if a new type is defined in a
scope (inside a function), then the new type name will only be visible till the
scope is there. In case of #define, when preprocessor encounters #define, it
replaces all the occurrences, after that (No scope rule is followed).

17. Can we specify variable field width in a scanf() format string? If possible
how?
--> - It is possible to specify variable field width in a scanf() format string
by using %s control string.
- The %s reads a string of variable field width up to the first white space
character.
Example:
scanf("%s", name); // where name is a character array

- The scanf() stores the results away in variables which you provide in the
argument list and reads the data from the console or from a FILE stream and parses
it.

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().

18. Out of fgets() and gets() which function is safe to use and why?
- The fgets() function is safer to use.
- It checks the bounds, i.e., the size of the buffer and does not cause
overflow on the stack to occur.
- The gets() function does not check the bounds.
- The gets() function is an insecure and careless use can lead to errors.

char *fgets(char *str, int n, FILE *stream).


Parameters:
str -- This is the pointer to an array of chars where the string read is
stored.
n -- This is the maximum number of characters to be read (including the final
null-character). Usually, the length of the array passed as str is used.
stream -- This is the pointer to a FILE object that identifies the stream
where characters are read from.

19. Difference between strdup and strcpy?


The function strcpy() will not allocate the memory space to copy. A pointer
to the string to copy and a pointer to place to copy it to should be given.
The function strdup() will occupy / grab itself the memory space for copying
the string to. This memory space needs to be freed up later when it is of no use
anymore.

20. What is recursion?


--> The process in which a function calls itself directly or indirectly is called
recursion and the corresponding function is called as recursive function. Using
recursive algorithm, certain problems can be solved quite easily. Examples of such
problems are Towers of Hanoi (TOH), Inorder/Preorder/Postorder Tree Traversals, DFS
of Graph, etc.

21. Differentiate between a for loop and a while loop? What are it uses?
22. What are the different storage classes in C?
23. Write down the equivalent pointer _expression for referring the same element
a[i][j][k][l]?
24. What is difference between Structure and Unions?
25. What the advantages of using Unions?
26. What are the advantages of using pointers in a program?
27. What is the difference between Strings and Arrays?
28. In a header file whether functions are declared or defined?
29. What is a far pointer? where we use it?
30. How will you declare an array of three function pointers where each function
receives two ints and returns a float?
31. what is a NULL Pointer? Whether it is same as an uninitialized pointer?
32. What is a NULL Macro? What is the difference between a NULL Pointer and a NULL
Macro?
33. What does the error 'Null Pointer Assignment' mean and what causes this error?
34. What is near, far and huge pointers? How many bytes are occupied by them?
35. How would you obtain segment and offset addresses from a far address of a
memory location?
36. Are the expressions arr and &arr same for an array of integers?
37. Does mentioning the array name gives the base address in all the contexts?
38. Explain one method to process an entire string as one unit?
39. What is the similarity between a Structure, Union and enumeration?
40. Can a Structure contain a Pointer to itself?
41. How can we check whether the contents of two structure variables are same or
not?
42. How are Structure passing and returning implemented by the complier?
43. How can we read/write Structures from/to data files?
44. What is the difference between an enumeration and a set of pre-processor #
defines?
45. what do the 'c' and 'v' in argc and argv stand for?
46. Are the variables argc and argv are local to main?
47. What is the maximum combined length of command line arguments including the
space between adjacent arguments?
48. If we want that any wildcard characters in the command line arguments should be
appropriately expanded, are we required to make any special provision? If yes,
which?
49. Does there exist any way to make the command line arguments available to other
functions without passing them as arguments to the function?
50. What are bit fields? What is the use of bit fields in a Structure declaration?
51. To which numbering system can the binary number 1101100100111100 be easily
converted to?
52. Which bit wise operator is suitable for checking whether a particular bit is on
or off?
53. Which bit wise operator is suitable for turning off a particular bit in a
number?
54. Which bit wise operator is suitable for putting on a particular bit in a
number?
55. Which bit wise operator is suitable for checking whether a particular bit is on
or off?
56. which one is equivalent to multiplying by 2:Left shifting a number by 1 or Left
shifting an unsigned int or char by 1?
57. Write a program to compare two strings without using the strcmp() function.
58. Write a program to concatenate two strings.
59. Write a program to interchange 2 variables without using the third one.
60. Write programs for String Reversal & Palindrome check
61. Write a program to find the Factorial of a number
62. Write a program to generate the Fibinocci Series
63. Write a program which employs Recursion
64. Write a program which uses Command Line Arguments
65. Write a program which uses functions like strcmp(), strcpy()? etc
66. What are the advantages of using typedef in a program?
67. How would you dynamically allocate a one-dimensional and two-dimensional array
of integers?
68. How can you increase the size of a dynamically allocated array?
69. How can you increase the size of a statically allocated array?
70. When reallocating memory if any other pointers point into the same piece of
memory do you have to readjust these other pointers or do they get readjusted
automatically?
71. Which function should be used to free the memory allocated by calloc()?
72. How much maximum can you allocate in a single call to malloc()?
73. Can you dynamically allocate arrays in expanded memory?
74. What is object file? How can you access object file?
75. Which header file should you include if you are to develop a function which can
accept variable number of arguments?
76. Can you write a function similar to printf()?
77. How can a called function determine the number of arguments that have been
passed to it?
78. Can there be at least some solution to determine the number of arguments passed
to a variable argument list function?
79. How do you declare the following:
* An array of three pointers to chars
* An array of three char pointers
* A pointer to array of three chars
* A pointer to function which receives an int pointer and returns a float pointer
* A pointer to a function which receives nothing and returns nothing
80. What do the functions atoi(), itoa() and gcvt() do?
81. Does there exist any other function which can be used to convert an integer or
a float to a string?
82. How would you use qsort() function to sort an array of structures?
83. How would you use qsort() function to sort the name stored in an array of
pointers to string?
84. How would you use bsearch() function to search a name stored in array of
pointers to string?
85. How would you use the functions sin(), pow(), sqrt()?
86. How would you use the functions memcpy(), memset(), memmove()?
87. How would you use the functions fseek(), freed(), fwrite() and ftell()?
88. How would you obtain the current time and difference between two times?
89. How would you use the functions randomize() and random()?
90. How would you implement a substr() function that extracts a sub string from a
given string?
91. What is the difference between the functions rand(), random(), srand() and
randomize()?
92. What is the difference between the functions memmove() and memcpy()?
93. How do you print a string on the printer?
94. Can you use the function fprintf() to display the output on the screen?

C++- Questions
1. What is a class?
2. What is an object?
3. What is the difference between an object and a class?
4. What is the difference between class and structure?
5. What is public, protected, private?
6. What are virtual functions?
7. What is friend function?
8. What is a scope resolution operator?
9. What do you mean by inheritance?
10. What is abstraction?
11. What is polymorphism? Explain with an example.
12. What is encapsulation?
13. What do you mean by binding of data and functions?
14. What is function overloading and operator overloading?
15. What is virtual class and friend class?
16. What do you mean by inline function?
17. What do you mean by public, private, protected and friendly?
18. When is an object created and what is its lifetime?
19. What do you mean by multiple inheritance and multilevel inheritance?
Differentiate between them.
20. Difference between realloc() and free?
21. What is a template?
22. What are the main differences between procedure oriented languages and object
oriented languages?
23. What is R T T I ?
24. What are generic functions and generic classes?
25. What is namespace?
26. What is the difference between pass by reference and pass by value?
27. Why do we use virtual functions?
28. What do you mean by pure virtual functions?
29. What are virtual classes?
30. Does c++ support multilevel and multiple inheritance?
31. What are the advantages of inheritance?
32. When is a memory allocated to a class?
33. What is the difference between declaration and definition?
34. What is virtual constructors/destructors?
35. In c++ there is only virtual destructors, no constructors. Why?
36. What is late bound function call and early bound function call? Differentiate.
37. How is exception handling carried out in c++?
38. When will a constructor executed?
39. What is Dynamic Polymorphism?
40. Write a macro for swapping integers.

DATA STRUCTURE QUESTIONS

1. What is a data structure?


2. What does abstract data type means?
3. Evaluate the following prefix _expression " ++ 26 + - 1324" (Similar types can
be asked)
4. Convert the following infix _expression to post fix notation ((a+2)*(b+4)) -1
(Similar types can be asked)
5. How is it possible to insert different type of elements in stack?
6. Stack can be described as a pointer. Explain.
7. Write a Binary Search program
8. Write programs for Bubble Sort, Quick sort
9. Explain about the types of linked lists
10. How would you sort a linked list?
11. Write the programs for Linked List (Insertion and Deletion) operations
12. What data structure would you mostly likely see in a non recursive
implementation of a recursive algorithm?
13. What do you mean by Base case, Recursive case, Binding Time, Run-Time Stack and
Tail Recursion?
14. Explain quick sort and merge sort algorithms and derive the time-constraint
relation for these.
15. Explain binary searching, Fibinocci search.
16. What is the maximum total number of nodes in a tree that has N levels? Note
that the root is level (zero)
17. How many different binary trees and binary search trees can be made from three
nodes that contain the key values 1, 2 & 3?
18. A list is ordered from smaller to largest when a sort is called. Which sort
would take the longest time to execute?
19. A list is ordered from smaller to largest when a sort is called. Which sort
would take the shortest time to execute?
20. When will you sort an array of pointers to list elements, rather than sorting
the elements themselves?
21. The element being searched for is not found in an array of 100 elements. What
is the average number of comparisons needed in a sequential search to determine
that the element is not there, if the elements are completely unordered?
22. What is the average number of comparisons needed in a sequential search to
determine the position of an element in an array of 100 elements, if the elements
are ordered from largest to smallest?
23. Which sort show the best average behavior?
24. What is the average number of comparisons in a sequential search?
25. Which data structure is needed to convert infix notations to post fix
notations?
26. What do you mean by:
* Syntax Error
* Logical Error
* Runtime Error
How can you correct these errors?
27. In which data structure, elements can be added or removed at either end, but
not in the middle?
28. How will inorder, preorder and postorder traversals print the elements of a
tree?
29. Parenthesis are never needed in prefix or postfix expressions. Why?
30. Which one is faster? A binary search of an orderd set of elements in an array
or a sequential search of the elements.

You might also like