data_structures_part-A
data_structures_part-A
PART A–––––-
Order Functions
• Use binary search for array A[1]<A[2]<...<A[N]A[1] < A[2] < ... < A[N]A[1]<A[2]<...<A[N].
def is_prime(N):
if N % i == 0: return False
return True
def fibonacci(n):
if n <= 1: return n
result = 1
if exp % 2 == 1:
result *= base
base *= base
exp //= 2
return result
while n != 0:
m, n = n, m % n
return m
def circle_geometry(radius):
if x > 10:
print("Big") # O(1)
else:
print("Small") # O(1)
UNIT 2
PART A
7. Advantages of ADT:
UNIT 3
PART A
2. Applications of stacks:
• Expression evaluation.
• Syntax parsing.
6. ENQUEUE vs DEQUEUE:
8. Prefix to postfix:
• ++A*BCD: AB∗CD++AB*CD++AB∗CD++.
• +*AB*CD: AB∗CD∗+AB*CD*+AB∗CD∗+.
• Parentheses matching.
• Depth-First Search.
• Process scheduling.
• Printing tasks.
• Message queues.
UNIT 4
PART A
markdown
Copy code
/\
2 5
/\
4 3
(*)
/ \
(+) (^)
/\ /\
2x y (-) 3
/\
5 b
3. Full binary trees among 8, 15, 13, 14 nodes:
Only 15 nodes can form a full binary tree because a full binary tree always has 2h−12^h -
12h−1 nodes (e.g., 15 for h=4h = 4h=4).
mathematica
Copy code
/\
B C
/\ \
D E G
7. Hashing:
Hashing maps keys to values using a hash function for efficient data retrieval, often used in
hash tables.
• Open addressing.
• Separate chaining.
• Quadratic probing.
• Double hashing.
• Best-case: O(1)O(1)O(1).
1. Array: Index-based.
• Insertion.
• Deletion.
• Search.
UNIT 5
PART A
2. Types of Searching:
1. Linear search.
2. Binary search.
3. Interpolation search.
4. Exponential search.
5. Hash-based search.
Copy code
arr[j + 1] = arr[j--];
arr[j + 1] = key;
• Data size.
• Memory availability.
• Stability requirement.
• Complexity constraints.
• Data pre-sorting.
Data Requirement Suitable for large data. Efficient for small data.
4o