Professional Documents
Culture Documents
-> A data structure is a particular way of storing and organizing data in a computer so that it
can be used efficiently.
Data management concept includes, data collection or organization of data in proper
structure.
2. Can you explain the difference between file structure and storage structure?
-> The main difference between file structure and storage structure is based on memory area
that is being accessed.
Storage structure: It is the representation of the data structure in the computer memory.
File structure: It is the representation of the storage structure in the auxiliary memory.
3. Can you tell how linear data structures differ from non-linear data structures?
->
Linear data structure Nonlinear data structure
Elements are stored sequentially Not stored in sequential order
We can traverse either forward or Branches to more than one node
backward
Example : array, stacks, queues, Can’t be traversed in a single run
linked list
Example : tree, graphs
4. What is an array?
-> An array is a data structure consisting of a collection of similar data elements, each
identified by one array index.
The elements in array are stored in consecutive memory locations.
Fixed size.
Data elements are stored in continuous memory locations which may not be available
always.
Adding and removing of elements is tough because of shifting the elements from their
positions.
Better method :
int x[3][4] = {{0,1,2,3}, {4,5,6,7}, {8,9,10,11}};
A linked list whose nodes contain two fields: an integer value and a link to the next node.
The last node is linked to a terminator (NULL pointer) used to signify the end of the list.
Advantage: Provides quick insert and delete operations
Disadvantage: Slow search operations and requires more memory space.(Why?)
Need to traverse one by one element as they are not having Index.
Example : Chain(Hand to hand)
9. Explain the scenarios where you can use linked lists and arrays.
-> The scenarios where we use linked list over array:
When we do not know the exact number of elements beforehand.
When we know that there would be large number of add or remove operations.
Less number of random access operations.
Where we use arrays over the linked list:
When we need to index or randomly access elements more frequently.
When we need speed while iterating over the elements in the sequence.
Due to the nature of arrays and linked list, it is safe to say that filled arrays use less memory
than linked lists.
22. What is the difference between tree and graph data structure?
->
Graph Tree
Graph is a non-linear data structure. Tree is a non-linear data structure.
Tree is a non-linear data structure. It is a collection of nodes and edges.
Each node can have any number of edges. General trees consist of the nodes having any
number of child nodes. But in case of binary
trees every node can have at the most two
child nodes.
There is no unique node called root in graph. There is a unique node called root in trees.
A cycle can be formed. There will not be any cycle.
Applications: For finding shortest path in Applications: For game trees, decision trees,
networking graph is used. the tree is used.
23. What is the difference between the Breadth-First Search (BFS) and Depth First Search
(DFS)?
->
BFS DFS
BFS stands for Breadth First Search. DFS stands for Depth First Search.
BFS(Breadth First Search) uses Queue data DFS(Depth First Search) uses Stack data
structure for finding the shortest path. structure.
BFS can be used to find single source In DFS, we might traverse through more
shortest path in an unweighted graph, edges to reach a destination vertex from a
because in BFS, we reach a vertex with source.
minimum number of edges from a source
vertex.
BFS is more suitable for searching vertices DFS is more suitable when there are
which are closer to the given source. solutions away from source.
BFS considers all neighbors first and DFS is more suitable for game or puzzle
therefore not suitable for decision making problems. We make a decision, then explore
trees used in games or puzzles. all paths through this decision. And if this
decision leads to win situation, we stop.
The Time complexity of BFS is O(V + E) when The Time complexity of DFS is also O(V + E)
Adjacency List is used and O(V^2) when when Adjacency List is used and O(V^2)
Adjacency Matrix is used, where V stands for when Adjacency Matrix is used, where V
vertices and E stands for edges. stands for vertices and E stands for edges.
Here, siblings are visited before the children Here, children are visited before the siblings