0% found this document useful (0 votes)
27 views29 pages

Important 2 Marks and 16 Marks Question Data Stuructures Using C - PUCS3BE01 Unit - 1 to 5-1

The document provides a comprehensive overview of fundamental concepts in C programming, including primary data types, variables, operators, control structures, functions, arrays, structures, unions, pointers, and file handling. It also includes review questions and explanations of key features, differences between concepts, and programming examples. Additionally, it covers the importance of file handling and the characteristics of arrays and structures.

Uploaded by

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

Important 2 Marks and 16 Marks Question Data Stuructures Using C - PUCS3BE01 Unit - 1 to 5-1

The document provides a comprehensive overview of fundamental concepts in C programming, including primary data types, variables, operators, control structures, functions, arrays, structures, unions, pointers, and file handling. It also includes review questions and explanations of key features, differences between concepts, and programming examples. Additionally, it covers the importance of file handling and the characteristics of arrays and structures.

Uploaded by

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

Unit – 1

REVIEW QUESTIONS
PART-A
1. List down the Primary Data Types in C
• Integer – We use these for storing various whole numbers, such as 5, 8, 67,
2390, etc.
• Character – It refers to all ASCII character sets as well as the single alphabets,
such as ‘x’, ‘Y’, etc.
• Double – These include all large types of numeric values that do not come under
either floating-point data type or integer data type.
• Floating-point – These refer to all the real number values or decimal points,
such as 40.1, 820.673, 5.9, etc.
• Void – This term refers to no values at all. We mostly use this data type when
defining the functions in a program.
2. What is Variable?
✓ Variables are containers for storing data values.
✓ Its value can be changed, and it can be reused many times.
✓ Syntax for creating variables
• type variableName = value;
• Example: int a = 5;
3. What is Operator?
✓ An operator is a special symbol that tells the compiler to perform specific
mathematical or logical operations.
✓ Operators in programming languages are taken from mathematics.
✓ C language supports a rich set of built-in operators.
4. List the types of operators supported in C
✓ Arithmetic operators
✓ Relational operators
✓ Logical operators
✓ Bitwise operators
✓ Assignment operators
✓ Type Information Operators(Special operators)
5. What is Ternary operators or Conditional operators?
✓ Ternary operators is a conditional operator with symbols? and :
✓ Syntax: variable = exp1 ? exp2 : exp3
✓ If the exp1 is true variable takes value of exp2. If the exp2 is false, variable
takes the value of exp3.
6. What is an Operator and Operand?
✓ An operator is a symbol that specifies an operation to be performed on
operands.
✓ Example: *, +, -, / are called arithmetic operators.
✓ The data items that operators act upon are called operands.
7. What is type casting?
✓ Type casting is the process of converting the value of an expression to a
particular data type.
✓ Example: int x,y.
c = (float) x/y; where a and y are defined as integers. Then the result of x/y is
converted into float.
8. What is the difference between while loop and do while loop?
while do while
In the while loop the condition is first In the do…while loop first the statement
executed. is executed and then the condition is
checked.
If the condition is true, then it executes The do…while loop will execute at least
the body of the loop. When the one time even though the condition is
condition is false it comes of the loop. false at the very first time.

9. What is the difference between ++a and a++?


✓ ++a means do the increment before the operation (pre increment) a++ means
do the increment after the operation (post increment)
10. What is a Function?
✓ A function is a block of code which only runs when it is called.
✓ It performs a specific task.
11. What is meant by Recursive function?
✓ If a function calls itself again and again, then that function is called Recursive
function.
✓ The syntax for recursive function is:
function recurse() {
// function code
recurse();
// function code
} recurse();
12. Write short notes about main() function in ’C’ program.
Every C program must have main () function.
✓ All functions in C, has to end with ‘( )’ parenthesis.
✓ It is a starting point of all ‘C’ programs.
✓ The program execution starts from the opening brace ‘{‘ and ends with closing
brace ‘}’, within which executable part of the program exists.
13. Give the syntax for the ‘for’ loop statement
for (Initialize counter; Test condition; Increment / Decrement)
{
statements;
}
14. What is an Array?
✓ An array is defined as finite ordered collection of homogenous data, stored in
contiguous memory locations.
➢ finite means data range must be defined.
➢ ordered means data must be stored in continuous memory addresses.
➢ homogenous means data must be of similar data type.
✓ For example: if you want to store marks of 50 students, you can create an array
for it.
• int marks[50];
15. What are the different types of arrays available in C.
✓ One-dimensional arrays
✓ Multidimensional arrays
16. Write short notes on One-dimensional arrays.
✓ A One-Dimensional Array in C programming is a special type of variable that
can store multiple values of only a single data type such as int, float, double, char
etc.
✓ The syntax of declaring Two-dimensional arrays is:
➢ datatype array name [size]
✓ Example
For example, int a[5]
17. Write short notes on Two-dimensional arrays.
✓ A multi-dimensional array can be termed as an array of arrays that stores
homogeneous data in tabular form.
✓ The general form of declaring Two-dimensional arrays is:
➢ data_type array_name[x][y];
✓ Example
int x[10][20];
18. What are the key features in the C programming language?
✓ Portability: It is a platform-independent language.
✓ Modularity: Possibility to break down large programs into small modules.
✓ Flexibility: The possibility of a programmer to control the language.
✓ Speed: C comes with support for system programming and hence it compiles
and executes with high speed when compared with other high-level languages.
✓ Extensibility: Possibility to add new features by the programmer.
19. What is a nested loop?
✓ A loop that runs within another loop is referred to as a nested loop. The first loop
is called the Outer Loop and the inside loop is called the Inner Loop. The inner
loop executes the number of times defined in an outer loop.
20. What are the modifiers available in C programming language?
✓ Short
✓ Long
✓ Signed
✓ Unsigned
✓ long long
21. What is the explanation for prototype function in C?
✓ Prototype function is a declaration of a function with the following information
to the compiler.
• Name of the function.
• The return type of the function.
• Parameters list of the function.
✓ Example
• int sum(int,int);
22. What do you mean by the Scope of the variable?
✓ Scope of the variable can be defined as the part of the code area where the
variables declared in the program can be accessed directly. In C, all identifiers
are lexically (or statically) scoped.
23. Can a C program be compiled or executed in the absence of a main()?
✓ The program will be compiled but will not be executed. To execute any C
program, main() is required.
24. What is the main difference between the Compiler and the Interpreter?
Interpreter Compiler
Translates program one statement at a Scans the entire program and translates
time. it as a whole into machine code.
Interpreters usually take less amount of Compilers usually take a large amount
time to analyze the source code. of time to analyze the source code.
However, the overall execution time is However, the overall execution time is
comparatively slower than compilers. comparatively faster than interpreters.
No Object Code is generated, hence are Generates Object Code which further
memory efficient. requires linking, hence requires more
memory.
Programming languages like Programming languages like C, C++,
JavaScript, Python, Ruby use Java use compilers.
interpreters.
PART-B
1. Explain the different types of operators with neat examples.
2. Illustrate the different conditional statements available in C with syntax and
examples
3. Explain the looping statements with neat examples.
4. What is an Array? Explain Single and Multi-Dimensional arrays with neat examples.
5. Write a C program for Matrix Multiplication with a 3*3 matrix.
6. Create a C program for Matrix Addition.
7. Write a C program to calculate the total, average and grade for 50 Students.
8. Write a C program to calculate the factorial of a given number.
9. Write a C program to check whether a given number is odd or even.
10. Write a C program to check whether a given number is prime or not.
11. Write a C program to check whether a given number is a palindrome or not.
12. Write a C program to check whether a given number is a Armstrong number or not.
UNIT - 2

REVIEW QUESTIONS
PART A
1. What is a Structure in C?
➢ Structure is a user-defined datatype in C language which allows us to combine
data of different types together. Structure helps to construct a complex data type
which is more meaningful.
➢ In structure, data is stored in form of records.
2. How to define a Structure?
➢ struct keyword is used to define a structure. struct defines a new data type which
is a collection of primary and derived data types.
➢ Syntax
struct [structure_tag]
{
//member variable 1
//member variable 2
//member variable 3
...
}[structure_variables];
3. What is Union?
➢ A union is a special data type available in C that allows to store different data
types in the same memory location.
➢ You can define a union with many members, but only one member can contain a
value at any given time. Unions provide an efficient way of using the same
memory location for multiple purpose.
4. Give the syntax for creating a union.
union [union name]
{
member definition;
member definition;
...
member definition;
};
5. Difference between Structure and Union.
Structure Union
The Keyword struct is used to define The Keyword union is used to define
the Structure the Union
Structure allocates storage space for all Union allocates one storage space for
its members seperately. all its members.
Structure occupies high memory space Union occupies low memory space
when compared to Structure
We can access all members of Only one member of union can be
Structure at a time accessed at a time.
Altering the value of a member will Altering the value of a member will
not affect other member of a structure alter other member value in union.

6. What are Enumerated Datatypes?


➢ 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.
7. What is pointer?
➢ A pointer is a variable that stores the memory address of another variable as its
value. A pointer variable points to a data type (like int) of the same type and is
created with the * operator.
8. How addresses are assigned to Pointers?
➢ Example
int* p, a;
a= 8;
p = &a;
➢ Here, 8 is assigned to the variable a and the address of a is assigned to the pointer
p.
9. What are the uses of Pointers?
➢ Pointers are used to return more than one value to the function
➢ Pointers are more efficient in handling the data in arrays
➢ Pointers reduce the length and complexity of the program
➢ They increase the execution speed
➢ The pointers saves data storage space in memory.
10. What is the difference between an array and pointer?
Arrays Pointers
Array allocates space automatically. Pointer is explicitly assigned to point
to an allocated space.
It cannot be resized. It can be resized using realloc ().
It cannot be reassigned. Pointers can be reassigned.
Sizeof(array name) gives the number Sizeof(pointer name) returns the
of bytes occupied by the array. number of bytes used to store the
pointer variable.

11. What is dangling pointer?


➢ In C, a pointer may be used to hold the address of dynamically allocated memory.
After this memory is freed with the free() function, the pointer itself will still
contain the address of the released block. This is referred to as a dangling pointer.
➢ Using the pointer in this state is a serious programming error. Pointer should be
assigned NULL after freeing memory to avoid this bug.
12. What is ‘C’ functions?
➢ A function is a self-contained block (or) a sub-program of one or more statements
that performs a special task when called.
➢ To perform a task repetitively then it is not necessary to re-write the particular
block of the program again and again. The function defined can be used for any
number of times to perform the task.
13. Differentiate library functions and User-defined functions.
Library Functions User-defined Functions
The User-defined functions are the
Library functions are pre-defined set of functions defined by the user according
functions that are defined in C libraries. to his/her requirement.

User can only use the function but User can use this type of function.
cannot change (or) modify this function. User can also modify this function.

14. What are the steps in writing a function in a program?


➢ Function Declaration (Prototype declaration): Every user-defined function has to
be declared before the main().
➢ Function Calling: The user-defined functions can be called inside any functions
like main(), user-defined function, etc.
➢ Function Definition: The function definition block is used to define the user-
defined functions with statements.
15. What is a use of ‘return’ Keyword?
➢ The ‘return’ Keyword is used only when a function returns a value.
16. What is the purpose of the function main()?
➢ The function main () invokes other functions within it. It is the first function to
be called when the program starts execution.
➢ Features of Main method
o It is the starting function.
o It returns an int value to the environment that called the program.
o Recursive call is allowed for main () also.
o It is a user-defined function.
o Program execution ends when the closing brace of the function main() is
reached.
o It has two arguments (a) argument count and (b)argument vector (represents
strings passed.)
17. Compare between Array and Structure
Arrays Structures
An array is a collection of data items A structure is a collection of data items
of same data type. of different data types.
Arrays can only be declared. There is Structures can be declared and defined.
no keyword for arrays. The Keyword for structures is struct.
An array name represents the address A structure name is known as tag. It is a
of the starting element. shorthand notation of the declaration.
An array cannot have bit fields. A structure may contain bit fields.

18. Is it better to use a macro or a function?


➢ Macros are more efficient (and faster) than function because their corresponding
code is inserted directly at the point where the macro is called. There is no
overhead involved in using a macro like there is in placing a call to a function.
➢ However, macros are generally small and cannot handle large, complex coding
constructs. In cases where large, complex constructs are to handled, functions are
more suited, additionally; macros are expanded inline, which means that the code
is replicated for each occurrence of a macro.
19. List the characteristics of Arrays.
➢ All elements of an array share the same name, and they are distinguished form one
another with help of an element number.
➢ Any element of an array can be modified separately without disturbing other
elements.
20. What are the types of Arrays?
➢ One-Dimensional Array
➢ Two-Dimensional Array
➢ Multi-Dimensional Array
21. What is File Handling in C?
➢ A file is nothing but a source of storing information permanently in the form of a
sequence of bytes on a disk. The contents of a file are not volatile like the C
compiler memory. The various operations available like creating a file, opening
a file, reading a file, or manipulating data inside a file is referred to as file
handling.
22. What is the need for File Handling in C?
➢ Reusability: It helps in preserving the data or information generated after
running the program.
➢ Large storage capacity: Using files, you need not worry about the problem of
storing data in bulk.
➢ Saves time: There are certain programs that require a lot of input from the user.
You can easily access any part of the code with the help of certain commands.
➢ Portability: You can easily transfer the contents of a file from one computer
system to another without having to worry about the loss of data.
23. List some of C File Handling Operations.
➢ Creating a new file: fopen()
➢ Opening an existing file in your system: fopen()
➢ Closing a file: fclose()
➢ Reading characters from a line: getc()
➢ Writing characters in a file: putc()
➢ Reading a set of data from a file: fscanf()
➢ Writing a set of data in a file: fprintf()
➢ Reading an integral value from a file: getw()
24. Give the syntax for Opening a Text File in C.
Syntax
*fpointer = FILE *fopen(const char *file_name, const char *mode);
• *fpointer is the pointer to the file that establishes a connection between the
file and the program.
• *file_name is the name of the file.
• *mode is the mode in which we want to open our file.
25. How to Read and Write a Text File in C?
➢ The input/output operations in a file help you read and write in a file.
➢ The simplest functions used while performing operations on reading and writing
characters in a file are getc() and putc() respectively.
➢ In order to read and write a set of data in a file, we use the fscanf() and fprintf()
operators.
26. Write short notes on Preprocessor Directives.
➢ The C preprocessor is a macro processor that is used automatically by the C
compiler to transform your program before actual compilation (Preprocessor
directives are executed before compilation.).
➢ It is called a macro processor because it allows you to define macros, which are
brief abbreviations for longer constructs.
27. What is macro?
➢ A macro is a segment of code which is replaced by the value of macro. Macro is
defined by #define directive.
28. List few preprocessor directives in C.
➢ #include
➢ Macro's (#define)
➢ #undef
➢ #ifdef
➢ #ifndef
➢ #if
➢ #else
PART-B

1. Explain Structure in C with neat program.


2. Write short notes on Union with example program.
3. What is a function? Explain with neat program.
4. Explain call by value and call by reference with example programs.
5. Explain the file handling mechanism in C with programs.
6. Explain preprocessor directives with its types and examples.
7. Explain the concept of pointers with neat programs.
8. Write shorts notes on Arrays.
9. How to write Data into a text file and Read Data from the file? Discuss.
10. How to read and write data to the binary file in a program? Explain.
Unit – 3

REVIEW QUESTIONS
PART-A
1. What do you mean by non-linear data structure? Give example.
➢ The non-linear data structure is the kind of data structure in which the data may
be arranged in hierarchical fashion. For example- Trees and graphs.
2. List the various operations that can be performed on data structure.
➢ Various operations that can be performed on the data structure are
• Create
• Insertion of element
• Deletion of element
• Searching for the desired element
• Sorting the elements in the data structure
• Reversing the list of elements.
3. What is abstract data type
➢ The abstract datatype is special kind of datatype, whose behavior is defined by
a set of values and set of operations.
4. What is list ADT in data structure?
➢ The list ADT is a collection of elements that have a linear relationship with each
other. A linear relationship means that each element of the list has a unique
successor.
5. What Are Arrays in Data Structures?
➢ An array is a linear data structure that collects elements of the same data type
and stores them in contiguous and adjacent memory locations. Arrays work on
an index system starting from 0 to (n-1), where n is the size of the array.
6. What is a linked list?
➢ A linked list is a set of nodes where each node has two fields ‘data’ and ‘link’.
The data field is used to store actual piece of information and link field is used
to store address of next node.
7. What are the pitfall encountered in singly linked list?
➢ The singly linked list has only forward pointer and no backward link is provided.
Hence the traversing of the list is possible only in one direction. Backward
traversing is not possible.
➢ Insertion and deletion operations are less efficient because for inserting the
element at desired position the list needs to be traversed. Similarly, traversing of
the list is required for locating the element which needs to be deleted.
8. What is Singly Linked List?
➢ A singly linked list is a type of linked list that is unidirectional, that is, it can be
traversed in only one direction from head to the last node (tail).
9. Define doubly linked list.
➢ Doubly linked list is a kind of linked list in which each node has two link fields.
One link field stores the address of previous node and the other link field stores
the address of the next node.
10. Write down the steps to modify a node in linked lists.
o Enter the position of the node which is to be modified.
o Enter the new value for the node to be modified.
o Search the corresponding node in the linked list.
o Replace the original value of that node by a new value.
o Display the messages as “The node is modified”.
11. Difference between arrays and lists.
➢ In arrays any element can be accessed randomly with the help of index of array,
whereas in lists any element can be accessed by sequential access only.
➢ Insertion and deletion of data is difficult in arrays on the other hand insertion
and deletion of data is easy in lists.
12. State the properties of LIST abstract data type with suitable example.
➢ It is linear data structure in which the elements are arranged adjacent to each
other.
➢ It allows to store single variable polynomial.
➢ If the LIST is implemented using dynamic memory, then it is called linked list.
Example of LIST are- stacks, queues, linked list.
13. State the advantages of circular lists over doubly linked list.
➢ In circular list the next pointer of last node points to head node, whereas in
doubly linked list each node has two pointers: one previous pointer and another
is next pointer.
➢ The main advantage of circular list over doubly linked list is that with the help
of single pointer field we can access head node quickly. Hence some amount of
memory get saved because in circular list only one pointer is reserved.
14. What are the advantages of doubly linked list over singly linked list?
➢ The doubly linked list has two pointer fields. One field is previous link field, and
another is next link field. Because of these two pointer fields we can access any
node efficiently whereas in singly linked list only one pointer field is there which
stores forward pointer.
15. Why is the linked list used for polynomial arithmetic?
➢ We can have separate coefficient and exponent fields for representing each term
of polynomial. Hence there is no limit for exponent. We can have any number
as an exponent.
16. What is the advantage of linked list over arrays?
➢ The linked list makes use of the dynamic memory allocation. Hence the user can
allocate or de allocate the memory as per his requirements. On the other hand,
the array makes use of the static memory location. Hence there are chances of
wastage of the memory or shortage of memory for allocation.
17. What is the circular linked list?
➢ The circular linked list is a kind of linked list in which the last node is connected
to the first node or head node of the linked list.
18. What is the basic purpose of header of the linked list?
➢ The header node is the very first node of the linked list. Sometimes a dummy
value such - 999 is stored in the data field of header node.
➢ This node is useful for getting the starting address of the linked list.
19. What is the advantage of an ADT?
➢ Change: the implementation of the ADT can be changed without makingchanges
in the client program that uses the ADT.
➢ Understandability: ADT specifies what is to be done and does not specify the
implementation details. Hence code becomes easy to understand due to ADT.
➢ Reusability: the ADT can be reused by some program in future.
20. What is queue ADT?
➢ Queue is an abstract data structure, somewhat like Stacks. Unlike stacks, a queue
is open at both its ends. One end is always used to insert data (enqueue) and the
other is used to remove data (dequeue). Queue follows First-In-First-Out
methodology, i.e., the data item stored first will be accessed first.
21. What is priority queue
➢ A priority queue is a special type of queue in which each element is associated
with a priority value. Elements are served on the basis of their priority. That is,
higher priority elements are served first. However, if elements with the same
priority occur, they are served according to their order in the queue.
22. What is stack?
➢ Stack is an abstract data type that serves as a collection of elements, with two
main operations: Push, which adds an element to the collection, and Pop, which
removes the most recently added element that was not yet removed.
23. How is Stack represented in Data Structure?
➢ A stack may be represented in the memory in various ways. There are two main
ways: using a one-dimensional array and a single linked list.
24. List some applications of queue data structure.
➢ Managing requests on a single shared resource such as CPU scheduling and disk
scheduling.
➢ Handling hardware or real-time systems interrupts.
➢ Handling website traffic.
➢ Routers and switches in networking.
➢ Maintaining the playlist in media players.
25. List some applications of stack data structure.
➢ A Stack can be used for evaluating expressions consisting of operands and
operators.
➢ Stacks can be used for Backtracking, i.e., to check parenthesis matching in an
expression.
➢ It can also be used to convert one form of expression to another form. It can be
used for systematic Memory Management.

PART B

1. Explain Singly Link List with algorithm and examples.


2. How insertion and deletion are performed on a singly linked list? Explain with
pseudocode and examples
3. Explain Doubly Linked List with examples and algorithms.
4. Explain Array based implementation of List ADT with examples and pseudocode.
5. Explain Array based implementation of Stack ADT with examples.
6. Demonstrate the implementation of circular linked list with examples.
7. Explain the applications of stack with examples.
8. Write short notes on queue ADT.
9. How are insertion and deletion operations performed in a queue? Explain with
examples and pseudocode.
10. Explain the implementation of priority queue with examples and pseudocode.
11. Explain queue implementation using linked list with pseudocode and examples.
12. Explain queue implementation using stack with pseudocode and examples.
Unit – 4

REVIEW QUESTIONS
PART A
1. Define binary tree?

➢ A binary tree is a tree data structure composed of nodes, each of which has
utmost, two children, referred to as left and right nodes. The tree starts off with
a single node known as the root.
2. What are the two methods of binary tree implementation?
➢ Linear representation.
➢ Linked representation
3. What are the applications of binary tree?
➢ Binary tree is used in data processing.
o File index schemes
o Hierarchical database management system
4. List out few of the Application of tree data-structure?
➢ The manipulation of Arithmetic expression
➢ Used for Searching Operation
➢ Used to implement the file system of several popular operating systems
➢ Symbol Table construction
➢ Syntax analysis
5. Define expression tree?
➢ Expression tree is also a binary tree in which the leaf’s terminal nodes or
operands and non-terminal intermediate nodes are operators used for traversal.
6. Define tree– traversal and mention the type of traversals?
➢ Three types of tree traversal
• Inorder traversal
• Preoder traversal
• Postorder traversal.
7. Define in -order traversal?
➢ In-order traversal entails the following steps;
➢ Traverse the left subtree
➢ Visit the root node
➢ Traverse the right subtree
8. What is pre-order traversal?
➢ In preorder traversal, first, root node is visited, then left sub-tree and after that
right sub-tree is visited. The process of preorder traversal can be represented as:
root → left → right
9. Define threaded binary tree.
➢ A binary tree is threaded by making all right child pointers that would normally
be null point to the in order successor of the node, and all left child pointers that
would normally be null point to the in-order predecessor of the node.
10. What are the types of threaded binary tree?
➢ Right-in threaded binary tree
➢ Left-in threaded binary tree
➢ Fully-in threaded binary tree
11. Define Binary Search Tree.
➢ Binary search tree is a binary tree in which for every node X in the tree, the
values of all the keys in its left subtree are smaller than the key value in X and
the values of all the keys in its right subtree are larger than the key value in X.
12. What is AVL Tree?
➢ AVL stands for Adelson-Velskii and Landis. An AVL tree is a binary search tree
which has the following properties:
• The sub-trees of every node differ in height by at most one.
• Every sub-tree is an AVL tree.
13. List out the steps involved in deleting a node from a binary search tree.
➢ Deleting a node is a leaf node (ie) No children
➢ Deleting a node with one child.
➢ Deleting a node with two Childs.
14. Define complete binary tree.
➢ If all its levels, possible except the last, have maximum number of nodes and if
all the nodes in the last level appear as far left as possible
15. Write short notes on Expression Trees.
➢ A binary expression tree is a specific kind of a binary tree used to represent
expressions.
➢ Two common types of expressions that a binary expression tree can represent
are algebraic and boolean. These trees can represent expressions that contain
both unary and binary operators.
16. What is Hashing?
➢ Hashing is a technique of mapping a large chunk of data into small tables using
a hashing function. It is also known as the message digest function. It is a
technique that uniquely identifies a specific item from a collection of similar
items.
17. What is Hash Function?
➢ A hash function is a function that takes a set of inputs of any arbitrary size and
fits them into a table or other data structure that contains fixed-size elements.
18. List the advantages of hashing in data structure
➢ Hash provides better synchronization than other data structures. Hash tables are
more efficient than search trees or other data structures. Hash provides constant
time for searching, insertion and deletion operations on average.
19. What is separate chaining?
➢ Separate Chaining is one of the techniques that is used to resolve the collision.
It is implemented using linked lists.
➢ This method combines a linked list with a hash table in order to resolve the
collision. In this method, we put all the elements that hash to the same slot in the
linked list.
20. What is open addressing in hashing?
➢ In open addressing,
• Unlike separate chaining, all the keys are stored inside the hash table.
• No key is stored outside the hash table.
21. List the techniques used in open addressing.
➢ Linear Probing
➢ Quadratic Probing

➢ Double Hashing
22. What is Linear Probing?
➢ Linear probing is a scheme in computer programming for resolving collisions in
hash tables, data structures for maintaining a collection of key–value pairs and
looking up the value associated with a given key.
23. Write short notes on Quadratic Probing?
➢ Quadratic probing is an open addressing scheme in computer programming for
resolving hash collisions in hash tables.
➢ Quadratic probing operates by taking the original hash index and adding
successive values of an arbitrary quadratic polynomial until an open slot is
found.
24. Explain about Double Hashing.
➢ Double hashing is a collision resolving technique in Open Addressed Hash
tables. Double hashing uses the idea of applying a second hash function to key
when a collision occurs.
25. What is rehashing in data structure?
➢ Rehashing is a technique in which the table is resized, i.e., the size of table is
doubled by creating a new table.
26. List the advantages of Double hashing
➢ The advantage of Double hashing is that it is one of the best form of probing,
producing a uniform distribution of records throughout a hash table.
➢ This technique does not yield any clusters.
➢ It is one of effective method for resolving collisions.
PART-B

1. Explain the tree traversal techniques with an example.


2. Construct an expression tree for the expression (a+b*c) + ((d*e+f)*g). Give the
outputs when you apply inorder, preorder and postorder traversals.
3. How to insert and delete an element into a binary search tree and write down the code
for the insertion routine with an example.
4. Create a binary search tree for the following numbers start from an empty binary
search tree. 45,26,10,60,70,30,40 Delete keys 10, 60 and 45 one after the other and
show the trees at each stage.
5. Explain Open Addressing techniques in detail.
6. Find the In-order, Pre-order, and Post-order for the given tree below
UNIT – 5

REVIEW QUESTIONS
1. What is sorting? PART A

➢ Sorting refers to arranging data in a particular format. Sorting algorithm specifies


the way to arrange data in a particular order.
2. Define insertion sort?
➢ Successive element in the array to be sorted and inserted into its proper place
with respect to the other already sorted element. We start with second element
and put it in its correct place, so that the first and second elements of the array
are in order.
3. Write short notes on quick sort.
➢ Quicksort is a divide-and-conquer algorithm. It works by selecting a 'pivot'
element from the array and partitioning the other elements into two sub-arrays,
according to whether they are less than or greater than the pivot. For this reason,
it is sometimes called partition-exchange sort.
4. What is Time Complexity for Quick Sort?

5. What is Merge sort?


➢ The Merge Sort function repeatedly divides the array into two halves until we
reach a stage where we try to perform Merge Sort on a subarray of size 1
6. What is Time Complexity for Merge Sort?
➢ Merge Sort is an efficient, stable sorting algorithm with an average, best-case,
and worst-case time complexity of O(n log n).
7. What is Linear Search?
➢ The Linear search algorithm works by sequentially iterating through the whole
array or list from one end until the target element is found.
➢ If the element is found, it returns its index, else -1.
8. What is binary Search?
➢ Binary search follows the divide and conquer approach in which the list is
divided into two halves, and the item is compared with the middle element of the
list. If the match is found then, the location of the middle element is returned.
Otherwise, we search into either of the halves depending upon the result
produced through the match.
➢ Binary search can be implemented only on a sorted list of items. If the elements
are not sorted already, we need to sort them first.
9. What is Heap Sort?
➢ Heap sort is a comparison-based sorting technique based on Binary Heap data
structure.
➢ It is like the selection sort where we first find the minimum element and place
the minimum element at the beginning. Repeat the same process for the
remaining elements.
10. What is Time Complexity for Heap Sort?
➢ The time complexity for Heap sort in average, best-case, and worst-case
time complexity of O(n log n).
11. What is Time Complexity for Insertion Sort?
Algorithm Best Case Average Case Worst Case
Insertion Sort O(n) O(n2) O(n2)

12. Why quick sort is preferred for arrays and merge sort for linked lists?
➢ Quick sort is an in-place sorting algorithm, i.e. which means it does not require
any additional space, whereas Merge sort does, which can be rather costly. In
merge sort, the allocation and deallocation of the excess space increase the
execution time of the algorithm.
➢ Unlike arrays, in linked lists, we can insert elements in the middle in O(1) extra
space and O(1) time complexities if we are given a reference/pointer to the
previous node. As a result, we can implement the merge operation in the merge
sort without using any additional space.
13. In which case insertion sort is used?
➢ Insertion sort has a fast best-case running time and is a good sorting algorithm
to use if the input list is already mostly sorted.
14. What is the advantage of using Quick sort algorithm?
➢ Quick sort reduces unnecessary swaps and moves an item to a greater distance,
in one move.
15. Mention the various types of searching techniques in C.
➢ Linear search
➢ Binary search
16. Define Searching.
➢ Searching in data structure refers to the process of finding the required
information from a collection of items stored as elements in the computer
memory.
➢ These sets of items are in different forms, such as an array, linked list, graph, or
tree.
17. Compare Quick sort and Merge Sort.
Basis for comparison Quick Sort Merge Sort
Efficiency Inefficient for larger arrays More efficient
Sorting method Internal External
Stability Not Stable Stable
Preferred for for Arrays for Linked Lists

18. Mention the different ways to select a pivot element.


o Pick the first element as pivot
o Pick the last element as pivot
o Pick the Middle element as pivot
o Median-of-three elements
o Pick three elements, and find the median x of these elements
o Use that median as the pivot.
o Randomly pick an element as pivot.
19. What is divide-and-conquer strategy?
➢ Divide a problem into two or more sub problems
➢ Solve the sub problems recursively
➢ Obtain solution to original problem by combining these solutions
PART B

1. Explain Insertion sort with algorithm and examples.


2. Sort the sequence 13,11,74,37,85,39,22,56,25 using insertion sort.
3. Explain the operation and implementation of merge sort.
4. Write quick sort algorithm and explain with an example.
5. Trace the quick sort algorithm for the following list of numbers.
90,77,60,99,55,88,66
6. Explain linear search algorithm with an example.
7. Explain Binary search algorithm with an example.
8. Write down the merge sort algorithm and give its worst case, best case and average
case analysis.
9. Explain Heap Sort algorithm with an example

You might also like