Data Structure Interview Questions: Applications of DSA
Data Structure Interview Questions: Applications of DSA
Data structure is a format for storing data in a structured manner. For example, data
like photos, videos are stored in gallery with the help of a data structure. It is not a
separate programming language. It is just an implementation method and can be
implemented using any one of the programming language like C, C++, Java, etc.
Applications of DSA:-
3. To store dynamically growing data which is accessed very frequently, based upon a key
value.
1. What is a Stack?
Solution:- Stack is a linear data structure that follows a particular order in which the
operations are performed. The order may be LIFO(Last In First Out) or FILO(First In
Last Out). The Stack is a list in which, insertion and deletion can be performed only at
one end that is called the top. It is a recursive data structure having a pointer to its top
element. Last-In-First-Out (LIFO) means the element which is inserted first will be
deleted last from the stack.
Solution:- PUSH and POP are storage and retrieval operations for data in the stack.
• POP: specifies data retrieval. It means that data is being removed from the stack.
Solution:- A linked list is a linear data structure, in which the elements are not stored at
contiguous memory locations. The elements in a linked list are linked using pointers.
This forms a chain-like link for data storage.
Solution:- AB+CD-*
Solution:- Binary search is an efficient algorithm for finding an item from a sorted list
of items. It works by repeatedly dividing in half the portion of the list that could contain
the item until you’ve narrowed down the possible locations to just one. This search
first compares the target value to the mid of the list. If it is not found, then it takes a
decision on whether.
Solution:- Bubble Sort is the simplest sorting algorithm that works by repeatedly
swapping the adjacent elements if they are in the wrong order. Bubble sort is a
comparison-based algorithm in which each pair of adjacent elements is compared and
elements are swapped if they are not in order. It is not suitable for a large set of data
because the time complexity is Ο(n2)
In a stack, the item that is most recently added is removed first. Contrary to this, the
item least recently added is removed first in case of a queue.
Solution:- Aside from being able to store simple structured data types, dynamic
memory allocation can combine separately allocated structured blocks to form
composite structures that expand and contract as needed.
13. How will you insert a new item in a binary search tree?
Solution:- As a binary search tree doesn’t allow for duplicates, the new item to be
inserted must be unique. Assuming it is, we will proceed with checking whether the
tree is empty or not. If it is empty, then the new item will be inserted in the root node.
Solution:- AVL tree is a self-balancing Binary Search Tree (BST) where the difference
between heights of left and right subtrees cannot be more than one for all nodes. The
measure of the balance is given by the difference of the heights of the subtrees from
the root node of the AVL tree.
15. Please explain the Linked List and its various types.
Solution:- Linked lists are of many different types. They are as follows:
• Singly Linked List – Every node stores the address or reference of the next node in the
linked list, leave for the last node that stores NULL
• Doubly Linked List – Every node keeps two references. One point to the next node and
• Circular Linked List – In this type of linked list, all nodes are connected to form a circle.
Hence, there is no NULL at the end. A circular linked list can either be a single circular
Solution:- A data structure is a named location that can be used to store and organize
data. And, an algorithm is a collection of steps to solve a particular problem. Learning
data structures and algorithms allow us to write efficient and optimized computer
programs. For example, we can store a list of items having the same data-type using
the array data structure.
Solution:-
A binary search is an algorithm that is best applied to search a list when the elements
are already in order or sorted. The list is searched starting in the middle, such that if
that middle value is not the target search key, it will check to see if it will continue the
search on the lower half of the list or the higher half. The split and search will then
continue in the same manner.
Solution:- We can reference all the elements in a one-dimension array using an indexed
loop. The counter runs from 0 to the maximum array size, say n, minus one. All
elements of the one-dimension array are referenced in sequence by using the loop
counter as the array subscript.
19. Which data structures are applied when dealing with a recursive function?
Solution:- LIFO is a short form of Last In First Out. It refers to how data is accessed,
stored, and retrieved. A data type that uses LIFO has data that was stored last should
be the one to be extracted first. Thus all the other data that was stored before this first
data must first be retrieved and extracted.
Solution:- Stack is a linear data structure that follows a particular order in which the
operations are performed. The order may be LIFO(Last In First Out) or FILO(First In
Last Out). The Stack is a list in which, insertion and deletion can be performed only at
one end that is called the top. It is a recursive data structure having a pointer to its top
element. Last-In-First-Out (LIFO) means the element which is inserted first will be
deleted last from the stack.
Solution:- FIFO means First-in First-out and is basically a way that defines how the data
within the data structure will be accessed. Mainly followed in QUEUE. Data has been
inserted into the queue list the longest is the one that is removed first.
Solution:- Null means nothing for data types. Void means function returned type have
to be nothing. you also can not return null from a void function. A variable that is given
a Null value simply indicates an empty value.
Solution:- Heap is flexible than stack because memory space for the heap can be
dynamically allocated and de-allocated as per the requirements.
Solution:-
In the case of signed numbers, the first bit is used to indicate whether positive or
negative, which leaves you with one bit short. With unsigned numbers, you have all bits
available for that number. The effect is best seen in the number range (an unsigned 8-
bit number has a range 0-255, while the 8-bit signed number has a range -128 to +127.