Important 2 Marks and 16 Marks Question Data Stuructures Using C - PUCS3BE01 Unit - 1 to 5-1
Important 2 Marks and 16 Marks Question Data Stuructures Using C - PUCS3BE01 Unit - 1 to 5-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.
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.
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.
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
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
REVIEW QUESTIONS
1. What is sorting? PART A
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