DS Data Structures
Q1. Consider the following array of integers:
A = [2, 3, 7, 10, 12, 15, 18]
What is the time complexity of the best algorithm to determine whether there exists a pair of elements whose sum is 22?
A. O(n²)
B. O(n log n)
C. O(n)
D. O(log n)
✅ Answer: C
Use two-pointer technique since array is sorted → O(n)
✅ C++ Code:
🧪 Output:
🕒 Time Complexity:
-
O(n) — each element is visited at most once.
-
Space Complexity: O(1)
📚 2. Stacks
Q2. What is the output of the following postfix expression?
Postfix: 6 2 3 + - 3 8 2 / + *
A. 15
B. 24
C. 18
D. 36
✅ Answer: B
Expression:6 - (2 + 3) = 1, and3 + (8 / 2) = 7→1 * 7 = 7
Wait! Let's redo that properly:
Oops! There’s an error in the key.
✅ Correct Answer: 7
✅ Tree Traversal Dry Run – Sample
Given Tree:
Traversals:
-
Inorder:
D B E A C F -
Preorder:
A B D E C F -
Postorder:
D E B F C A -
Level Order (BFS):
A B C D E F
Estate Paramount presenting the The Sky Heights - Enquiry Form, your entryway to upscale Panchkula living, is Estate Paramount. Enter your information to view opulent homes, cutting-edge features, and investment options intended for a sophisticated way of life. Start your path to better life right now. For more visit us!
ReplyDeleteI enjoyed reading your content. Keep doing your best work.
ReplyDeleteHire Python Developer in Chennai