




























































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Exam A introduces basic programming concepts and fundamental data structures such as arrays, linked lists, stacks, and queues. Candidates learn algorithm design, complexity analysis, and implementation techniques essential for software development and problem solving.
Typology: Exams
1 / 126
This page cannot be seen from the preview
Don't miss anything!





























































































Question 1. Which of the following best describes a variable in programming? A) A fixed value that cannot change during execution B) A reserved keyword in the programming language C) A storage location identified by a name that can hold data D) A function that returns a value Answer: C Explanation: A variable is a named storage location in memory that can hold data which can be changed during program execution. Question 2. Which data type is most appropriate for storing whole numbers in a typical programming language? A) float B) string C) int D) boolean Answer: C
Explanation: The 'int' data type is used to store integer (whole number) values. Question 3. Which operator is used for logical AND in most programming languages? A) & B) && C) | D) || Answer: B Explanation: '&&' is the logical AND operator, which evaluates to true if both operands are true. Question 4. What is the primary purpose of the 'if' statement? A) To execute a block of code repeatedly B) To select one block of code to execute based on a condition C) To define a function D) To declare a variable Answer: B
Explanation: Passing by reference allows the function to modify the original variable because it operates on its memory address. Question 7. Which recursive function is commonly used to compute factorial? A) factorial(n) = n + factorial(n-1) B) factorial(n) = 1 if n=0, else n * factorial(n-1) C) factorial(n) = factorial(n-1) / n D) factorial(n) = n^2 + factorial(n-1) Answer: B Explanation: The recursive factorial function multiplies n by the factorial of n- 1, with 0! defined as 1, which is the base case. Question 8. Which principle states that program flow should follow a clear, logical sequence? A) Modular programming B) Structured programming C) Object-oriented programming D) Event-driven programming
Answer: B Explanation: Structured programming emphasizes using sequence, selection, and iteration to make code clear and logical. Question 9. Which of the following is a benefit of modular programming? A) Increased code duplication B) Reduced code readability C) Reusability of code blocks D) Difficulty in debugging Answer: C Explanation: Modular programming promotes reusability, maintainability, and easier debugging by breaking down complex problems into smaller modules. Question 10. Which core OOP concept involves hiding complex implementation details? A) Encapsulation B) Inheritance C) Polymorphism
D) Flexibility through polymorphism Answer: C Explanation: Increased coupling is generally a negative aspect; OOP aims to reduce coupling to improve modularity. Question 13. Which phase involves understanding the problem and defining requirements before coding? A) Implementation phase B) Testing phase C) Problem analysis D) Deployment phase Answer: C Explanation: Problem analysis involves understanding requirements and planning before implementation. Question 14. Which diagram is useful for representing the flow of control in an algorithm? A) Data flow diagram B) Entity-relationship diagram
C) Flowchart D) Class diagram Answer: C Explanation: Flowcharts visually depict the sequence of operations in an algorithm, illustrating control flow. Question 15. Which coding convention improves code readability? A) Using meaningful variable names B) Omitting comments C) Writing all code in a single line D) Avoiding indentation Answer: A Explanation: Using meaningful variable names enhances understandability, making code easier to read and maintain. Question 16. Which debugging technique involves systematically checking code to locate errors? A) Rubber duck debugging B) Breakpoint debugging
B) Omega (Ω) C) Theta (Θ) D) Delta (Δ) Answer: A Explanation: Big O notation describes the upper bound or worst-case time complexity of an algorithm. Question 19. Which data type is most suitable for storing a sequence of characters? A) int B) float C) string D) boolean Answer: C Explanation: Strings are sequences of characters used for text data. Question 20. Which operation is NOT typically associated with arrays? A) Traversal B) Insertion at arbitrary position with shifting
C) Dynamic resizing without reallocation D) Binary search on sorted array Answer: C Explanation: Arrays have a fixed size; dynamic resizing requires creating a new array and copying data. Question 21. Which string operation compares two strings for equality? A) copy() B) concatenate() C) strcmp() D) length() Answer: C Explanation: 'strcmp()' compares two strings lexicographically, returning 0 if they are equal. Question 22. What is the main characteristic of a stack? A) FIFO (First-In, First-Out) B) LIFO (Last-In, First-Out) C) Random access
D) Linked list Answer: B Explanation: A stack supports last-in, first-out operations ideal for backtracking algorithms. Question 25. In a queue, which operation removes the element at the front? A) enqueue() B) dequeue() C) peek() D) push() Answer: B Explanation: 'dequeue()' removes and returns the element at the front of the queue. Question 26. Which data structure is best suited for implementing a printer queue? A) Stack B) Queue C) Array
D) Linked list Answer: B Explanation: Queues follow FIFO order, suitable for scheduling print jobs. Question 27. Which type of linked list allows traversal in both directions? A) Singly linked list B) Doubly linked list C) Circular linked list D) Array Answer: B Explanation: Doubly linked lists have pointers to both next and previous nodes, enabling bidirectional traversal. Question 28. Which is an advantage of doubly linked lists over singly linked lists? A) Simpler implementation B) Easier traversal in both directions C) Uses less memory per node D) No need for pointers
Answer: B Explanation: Trees naturally represent hierarchical data, with parent-child relationships. Question 31. In a binary tree, what is the maximum number of children a node can have? A) 1 B) 2 C) 3 D) Unlimited Answer: B Explanation: By definition, a binary tree node can have at most two children. Question 32. Which traversal 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 the root first, then left and right subtrees. Question 33. In a binary search tree (BST), where are smaller values stored relative to a node? A) Left subtree B) Right subtree C) Both subtrees equally D) In the parent node Answer: A Explanation: In BSTs, nodes with smaller values are stored in the left subtree, larger in the right. Question 34. Which operation in a BST can be used to find the minimum value? A) Search B) Insertion C) Min()
C) Dijkstra's algorithm D) Prim's algorithm Answer: B Explanation: DFS explores as deep as possible along each branch, backtracking when necessary. Question 37. Which algorithm is used to find the shortest path in a weighted graph with non-negative weights? A) Dijkstra’s algorithm B) BFS C) Kruskal’s algorithm D) Bellman-Ford algorithm Answer: A Explanation: Dijkstra’s algorithm efficiently computes the shortest path in graphs with non-negative edge weights. Question 38. Which sorting algorithm repeatedly swaps adjacent elements if they are in the wrong order? A) Selection Sort
B) Bubble Sort C) Merge Sort D) Quick Sort Answer: B Explanation: Bubble Sort compares and swaps adjacent elements to sort the array. Question 39. Which sorting algorithm has the best average-case time complexity among the listed options? A) Bubble Sort B) Selection Sort C) Insertion Sort D) Quick Sort Answer: D Explanation: Quick Sort has an average-case time complexity of O(n log n), making it faster on average. Question 40. Which sorting algorithm is stable and in-place? A) Merge Sort