DATA STRUCTURE QUESTIONS WITH
CORRECT ANSWERS
What is the difference between a Singly Linked List and a Doubly Linked List? - Correct
Answers -A singly linked list is a set of nodes where each node has two fields 'data' and
'link'. The 'data' field stores actual piece of information and 'link' field is used to point to
next node. Basically 'link' field is nothing but address only. A DLL contains an extra
pointer, typically called previous pointer, together with next pointer and data which are
there in singly linked list.
What is a Data Structure? - Correct Answers -A data structure is a way of organizing the
data so that the data can be used efficiently. Different kinds of data structures are suited
to different kinds of applications, and some are highly specialized to specific tasks.
What are linear and non linear data Structures? - Correct Answers -Linear: A data
structure is said to be linear if its elements form a sequence or a linear list. Examples:
Array. Linked List, Stacks and Queues
Non-Linear: A data structure is said to be non-linear if traversal of nodes is nonlinear in
nature. Example: Graph and Trees.
What are the various operations that can be performed on different Data Structures? -
Correct Answers -Insertion, Deletion, Traversal, Searching, Sorting.
How is an Array different from Linked List? - Correct Answers -The size of the arrays is
fixed, Linked Lists are Dynamic in size.
Inserting and deleting a new element in an array of elements is expensive, Whereas
both insertion and deletion can easily be done in Linked Lists.
Random access is not allowed in Linked Listed.
Extra memory space for a pointer is required with each element of the Linked list.
Arrays have better cache locality that can make a pretty big difference in performance.
What is Stack and where it can be used? - Correct Answers -Stack is a linear data
structure which the order LIFO(Last In First Out) or FILO(First In Last Out) for accessing
elements. Basic operations of stack are : Push, Pop , Peek
What is Data abstraction? - Correct Answers -Data abstraction is a powerful tool for
breaking down complex data problems into manageable chunks. This is applied by
initially specifying the data objects involved and the operations to be performed on
these data objects without being overly concerned with how the data objects will be
represented and stored in memory.
, How do you insert a new item in a binary search tree? - Correct Answers -Assuming
that the data to be inserted is a unique value (that is, not an existing entry in the tree),
check first if the tree is empty. If it's empty, just insert the new item in the root node. If
it's not empty, refer to the new item's key. If it's smaller than the root's key, insert it into
the root's left subtree, otherwise, insert it into the root's right subtree.
What is the minimum number of nodes that a binary tree can have? - Correct Answers -
A binary tree can have a minimum of zero nodes, which occurs when the nodes have
NULL values. Furthermore, a binary tree can also have 1 or 2 nodes.
What is a Queue, how it is different from stack and how is it implemented? - Correct
Answers -Queue is a linear structure which follows the order is First In First Out (FIFO)
to access elements. Mainly the following are basic operations on queue: Enqueue,
Dequeue, Front, Rear
The difference between stacks and queues is in removing. In a stack we remove the
item the most recently added; in a queue, we remove the item the least recently added.
Both Queues and Stacks can be implemented using Arrays and Linked Lists.
What is Infix notation? - Correct Answers -Infix notation: X + Y - Operators are written
in-between their operands. This is the usual way we write expressions. An expression
such as
A*(B+C)/D
What is prefix notation? - Correct Answers -Prefix notation (also known as "Polish
notation"): + X Y Operators are written before their operands. The expressions given
above are equivalent to
/*A+BCD
What is postfix notation? - Correct Answers -Postfix notation (also known as "Reverse
Polish notation"): X Y + Operators are written after their operands. The infix expression
given above is equivalent to
A B C + * D/
What is a Linked List and What are its types? - Correct Answers -Singly Linked List : In
this type of linked list, every node stores address or reference of next node in list and
the last node has next address or reference as NULL. For example 1->2->3->4->NULL
Doubly Linked List : Here, here are two references associated with each node, One of
the reference points to the next node and one to the previous node. Eg. NULL<-1<->2<-
>3->NULL
Circular Linked List : Circular linked list is a linked list where all nodes are connected to
form a circle. There is no NULL at the end. A circular linked list can be a singly circular
linked list or doubly circular linked list. Eg. 1->2->3->1 [The next pointer of last node is
pointing to the first]
CORRECT ANSWERS
What is the difference between a Singly Linked List and a Doubly Linked List? - Correct
Answers -A singly linked list is a set of nodes where each node has two fields 'data' and
'link'. The 'data' field stores actual piece of information and 'link' field is used to point to
next node. Basically 'link' field is nothing but address only. A DLL contains an extra
pointer, typically called previous pointer, together with next pointer and data which are
there in singly linked list.
What is a Data Structure? - Correct Answers -A data structure is a way of organizing the
data so that the data can be used efficiently. Different kinds of data structures are suited
to different kinds of applications, and some are highly specialized to specific tasks.
What are linear and non linear data Structures? - Correct Answers -Linear: A data
structure is said to be linear if its elements form a sequence or a linear list. Examples:
Array. Linked List, Stacks and Queues
Non-Linear: A data structure is said to be non-linear if traversal of nodes is nonlinear in
nature. Example: Graph and Trees.
What are the various operations that can be performed on different Data Structures? -
Correct Answers -Insertion, Deletion, Traversal, Searching, Sorting.
How is an Array different from Linked List? - Correct Answers -The size of the arrays is
fixed, Linked Lists are Dynamic in size.
Inserting and deleting a new element in an array of elements is expensive, Whereas
both insertion and deletion can easily be done in Linked Lists.
Random access is not allowed in Linked Listed.
Extra memory space for a pointer is required with each element of the Linked list.
Arrays have better cache locality that can make a pretty big difference in performance.
What is Stack and where it can be used? - Correct Answers -Stack is a linear data
structure which the order LIFO(Last In First Out) or FILO(First In Last Out) for accessing
elements. Basic operations of stack are : Push, Pop , Peek
What is Data abstraction? - Correct Answers -Data abstraction is a powerful tool for
breaking down complex data problems into manageable chunks. This is applied by
initially specifying the data objects involved and the operations to be performed on
these data objects without being overly concerned with how the data objects will be
represented and stored in memory.
, How do you insert a new item in a binary search tree? - Correct Answers -Assuming
that the data to be inserted is a unique value (that is, not an existing entry in the tree),
check first if the tree is empty. If it's empty, just insert the new item in the root node. If
it's not empty, refer to the new item's key. If it's smaller than the root's key, insert it into
the root's left subtree, otherwise, insert it into the root's right subtree.
What is the minimum number of nodes that a binary tree can have? - Correct Answers -
A binary tree can have a minimum of zero nodes, which occurs when the nodes have
NULL values. Furthermore, a binary tree can also have 1 or 2 nodes.
What is a Queue, how it is different from stack and how is it implemented? - Correct
Answers -Queue is a linear structure which follows the order is First In First Out (FIFO)
to access elements. Mainly the following are basic operations on queue: Enqueue,
Dequeue, Front, Rear
The difference between stacks and queues is in removing. In a stack we remove the
item the most recently added; in a queue, we remove the item the least recently added.
Both Queues and Stacks can be implemented using Arrays and Linked Lists.
What is Infix notation? - Correct Answers -Infix notation: X + Y - Operators are written
in-between their operands. This is the usual way we write expressions. An expression
such as
A*(B+C)/D
What is prefix notation? - Correct Answers -Prefix notation (also known as "Polish
notation"): + X Y Operators are written before their operands. The expressions given
above are equivalent to
/*A+BCD
What is postfix notation? - Correct Answers -Postfix notation (also known as "Reverse
Polish notation"): X Y + Operators are written after their operands. The infix expression
given above is equivalent to
A B C + * D/
What is a Linked List and What are its types? - Correct Answers -Singly Linked List : In
this type of linked list, every node stores address or reference of next node in list and
the last node has next address or reference as NULL. For example 1->2->3->4->NULL
Doubly Linked List : Here, here are two references associated with each node, One of
the reference points to the next node and one to the previous node. Eg. NULL<-1<->2<-
>3->NULL
Circular Linked List : Circular linked list is a linked list where all nodes are connected to
form a circle. There is no NULL at the end. A circular linked list can be a singly circular
linked list or doubly circular linked list. Eg. 1->2->3->1 [The next pointer of last node is
pointing to the first]