Data Structures QA Answers
Data Structures QA Answers
A data structure is a way of organizing and storing data so that it can be accessed and modified efficiently.
Common data structures include arrays, linked lists, stacks, queues, trees, and graphs.
An Abstract Data Type (ADT) is a data type where only behavior (operations) is defined but not
implementation. Examples include Stack, Queue, List, etc. The implementation is hidden from the user.
Time Complexity refers to the amount of time an algorithm takes to run as a function of the size of its input.
Space Complexity refers to the amount of memory space an algorithm uses as a function of the size of the
input.
Sparse matrices are used when most of the elements in a matrix are zero. Applications include:
- Image compression
5. Write any two built in functions of strings with syntax and example.
Example:
s = "Hello"
print(len(s)) # Output: 5
Example:
s = "hello"
- No memory wastage
8. Define Recursion.
Recursion is a technique where a function calls itself to solve smaller instances of the same problem.
Example:
def factorial(n):
if n == 0:
return 1
else:
return n * factorial(n-1)
Tree:
Binary Tree:
A graph is a collection of nodes (vertices) and edges that connect pairs of nodes.
Example:
Vertices: A, B, C
Hashing is a technique to convert a given key into an index using a hash function. This index determines