Docsity

17-COMP-A4 Program Design and Data Structures Exam B, Exams of Technology

Toggle sidebar
bg1
17-COMP-A4 Program Design and
Data Structures Exam B
Question 1. Which programming paradigm emphasizes the use of objects
encapsulating data and behaviors?
A) Procedural programming
B) Functional programming
C) Object-oriented programming
D) Logic programming
Answer: C
Explanation: Object-oriented programming (OOP) centers around objects
that combine data (attributes) and behaviors (methods), promoting
encapsulation and modularity.
Question 2. Which phase in the program development life cycle involves
translating the design into executable code?
A) Problem understanding
B) Implementation
C) Testing
D) Maintenance
Answer: B
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51
pf52
pf53
pf54
pf55
pf56
pf57
pf58
pf59
pf5a
pf5b
pf5c
pf5d
pf5e
pf5f
pf60
pf61
pf62
pf63
pf64

Partial preview of the text

Download 17-COMP-A4 Program Design and Data Structures Exam B and more Exams Technology in PDF only on Docsity!

Data Structures Exam B

Question 1. Which programming paradigm emphasizes the use of objects encapsulating data and behaviors? A) Procedural programming B) Functional programming C) Object-oriented programming D) Logic programming Answer: C Explanation: Object-oriented programming (OOP) centers around objects that combine data (attributes) and behaviors (methods), promoting encapsulation and modularity. Question 2. Which phase in the program development life cycle involves translating the design into executable code? A) Problem understanding B) Implementation C) Testing D) Maintenance Answer: B

Data Structures Exam B

Explanation: Implementation is the phase where the actual coding occurs based on the design specifications. Question 3. Which characteristic is NOT typical of an efficient algorithm? A) Correctness B) High time complexity in the best case C) Finite steps D) Produces a solution within resource constraints Answer: B Explanation: High time complexity in the best case indicates inefficiency; efficient algorithms aim for low time and space complexity. Question 4. Which of the following is an advantage of using flowcharts to represent algorithms? A) They provide a step-by-step pseudocode description B) They visually depict process flow and decision points C) They automatically generate code D) They are only useful for recursive algorithms Answer: B

Data Structures Exam B

Explanation: Algorithm design often involves balancing speed (execution time) and memory usage, as optimizing one can adversely affect the other. Question 7. Which statement correctly describes structured programming? A) It uses only object-oriented concepts B) It involves breaking programs into sequence, selection, and iteration structures C) It relies solely on recursion D) It requires dynamic memory allocation Answer: B Explanation: Structured programming emphasizes clear control flow using sequence, selection (if/else, switch), and loops, avoiding goto statements. Question 8. Which mechanism allows a function to modify the actual argument passed to it? A) Pass by value B) Pass by reference C) Call by name D) Call by value-result

Data Structures Exam B

Answer: B Explanation: Pass by reference allows the function to directly modify the argument's original memory location, unlike pass by value. Question 9. What is a key disadvantage of recursion? A) It simplifies code B) It can lead to stack overflow if not properly controlled C) It always runs faster than iteration D) It doesn't require a base case Answer: B Explanation: Recursive calls consume stack space; without proper base cases or with excessive recursion depth, it can cause stack overflow. Question 10. Which of the following best describes encapsulation in OOP? A) Deriving classes from a base class B) Hiding internal object data and exposing only necessary parts through public methods C) Overloading functions for different data types D) Creating multiple constructors in a class

Data Structures Exam B

D) Abstraction Answer: C Explanation: Polymorphism allows objects of derived classes to be treated as objects of the base class, supporting method overriding at runtime. Question 13. What is the primary purpose of a constructor in a class? A) To delete objects B) To initialize new objects of the class C) To define class attributes D) To handle exceptions Answer: B Explanation: Constructors initialize an object upon creation, setting initial values for data members. Question 14. Which data structure is best suited for implementing a stack? A) Array or linked list B) Queue C) Tree D) Graph

Data Structures Exam B

Answer: A Explanation: Arrays and linked lists are common implementations for stacks, supporting push and pop operations efficiently. Question 15. Which operation is NOT typically associated with a stack? A) Push B) Pop C) Enqueue D) Peek Answer: C Explanation: Enqueue is associated with queues; stacks use push, pop, and peek for their operations. Question 16. In a queue, which operation removes the element at the front? A) Enqueue B) Dequeue C) Peek D) Insert Answer: B

Data Structures Exam B

Explanation: Doubly linked lists have pointers to both previous and next nodes, enabling bidirectional traversal. Question 19. Which operation is characteristic of a doubly linked list but not a singly linked list? A) Insertion at the beginning B) Deletion from the end C) Traversal in both directions D) Searching for a value Answer: C Explanation: Doubly linked lists support traversal in both forward and backward directions due to two pointers per node. Question 20. Which is an advantage of using a linked list over an array? A) Constant-time access to any element by index B) Dynamic memory allocation allows flexible size growth C) Easier to implement binary search D) Better cache performance Answer: B

Data Structures Exam B

Explanation: Linked lists can grow dynamically without reallocation, unlike arrays that require resizing. Question 21. Which traversal method visits nodes in the order: root, left subtree, right subtree? A) Inorder B) Preorder C) Postorder D) Level order Answer: B Explanation: Preorder traversal visits root first, then left subtree, then right subtree. Question 22. Which binary tree traversal is best suited for copying the tree structure? A) Inorder B) Preorder C) Postorder D) Level order

Data Structures Exam B

D) Traversing the tree Answer: A Explanation: Deletion of a node with two children requires replacement with the inorder successor (minimum in right subtree), which involves additional steps. Question 25. Which property does a min-heap satisfy? A) Parent node is always less than or equal to its children B) Parent node is always greater than or equal to its children C) All levels are fully filled D) It is a complete binary tree with no specific heap property Answer: A Explanation: In a min-heap, each parent is less than or equal to its children, ensuring the minimum element is at the root. Question 26. Which operation maintains the heap property after insertion? A) Heapify-up (percolate up) B) Heapify-down (percolate down) C) Bubble sort

Data Structures Exam B

D) Binary search Answer: A Explanation: Heapify-up restores the heap property after inserting a new element at the bottom. Question 27. Which graph representation uses a two-dimensional matrix? A) Adjacency list B) Incidence matrix C) Adjacency matrix D) Edge list Answer: C Explanation: An adjacency matrix uses a 2D array to represent edges between vertices. Question 28. Which graph traversal algorithm is suitable for finding the shortest path in an unweighted graph? A) Depth-First Search (DFS) B) Breadth-First Search (BFS) C) Dijkstra's algorithm

Data Structures Exam B

C) Linked list D) Stack Answer: B Explanation: Heaps efficiently implement priority queues, allowing quick access to the highest or lowest priority element. Question 31. Which search algorithm requires the data to be sorted beforehand? A) Linear search B) Binary search C) Hashing D) Sequential search Answer: B Explanation: Binary search operates efficiently only on sorted data, dividing the search interval each step. Question 32. What is the worst-case time complexity of binary search? A) O(1) B) O(log n)

Data Structures Exam B

C) O(n) D) O(n log n) Answer: B Explanation: Binary search halves the search space each iteration, resulting in O(log n) time complexity. Question 33. Which sorting algorithm is based on repeatedly swapping adjacent elements to sort the list? A) Bubble Sort B) Merge Sort C) Quick Sort D) Heap Sort Answer: A Explanation: Bubble Sort compares and swaps adjacent elements, bubbling the largest to the end each pass. Question 34. Which sorting algorithm is considered the most efficient in average cases for large datasets? A) Bubble Sort

Data Structures Exam B

B) Indexed sequential organization C) Direct access organization D) Hash organization Answer: A Explanation: Sequential file organization stores records one after another, suitable for batch processing. Question 37. Which external sorting technique is used when data exceeds the main memory size? A) Bubble sort B) Merge sort (external variant) C) Selection sort D) Radix sort Answer: B Explanation: External merge sort efficiently sorts large datasets by dividing into manageable chunks and merging sorted runs. Question 38. Which algorithmic technique involves breaking a problem into smaller subproblems, solving them independently, and combining solutions?

Data Structures Exam B

A) Divide and Conquer B) Greedy C) Dynamic Programming D) Backtracking Answer: A Explanation: Divide and Conquer splits the problem, solves subproblems recursively, and combines results to form a solution. Question 39. Which approach is characteristic of greedy algorithms? A) Always finding the global optimum by making locally optimal choices B) Considering all possible solutions before choosing C) Solving subproblems recursively with overlapping substructures D) Exhaustively searching the solution space Answer: A Explanation: Greedy algorithms make the best local choice at each step with the hope of finding a global optimum. Question 40. Which dynamic programming technique is used to solve problems with overlapping subproblems efficiently?