Docsity

Algorithms Data Structures C Ultimate Exam, Exams of Software Engineering

Toggle sidebar
bg1
PrepIQ 19SOFTA1 Algorithms Data Structures C Ultimate Exam
Course: Algorithms and Data Structures / Computer Science
Total Questions: 150
Question Type: Multiple Choice
Description:
This comprehensive examination covers the fundamental principles and
advanced concepts of algorithms and data structures, including complexity
analysis (Big O, Big Theta, Big Omega), fundamental data structures (arrays,
linked lists, stacks, queues, trees, heaps, hash tables, graphs), sorting
algorithms (bubble, insertion, selection, merge, quick, heap, radix),
searching algorithms (linear, binary, interpolation), tree algorithms
(traversals, BST, AVL, B-trees), graph algorithms (DFS, BFS, shortest path,
minimum spanning tree, topological sort), dynamic programming, greedy
algorithms, divide and conquer, recursion, and string matching algorithms.
The exam also explores algorithm design paradigms, complexity classes (P,
NP, NP-Complete), and practical applications. This examination is suitable for
undergraduate and graduate students in computer science, software
engineering, and related fields.
1.,An algorithm is defined as:
A) A programming language
B) A step-by-step procedure for solving a problem
C) A data structure
D) A type of computer hardware
Answer:,B
Explanation:,An algorithm is a finite sequence of well-defined,
unambiguous steps for solving a specific problem or performing a
computation.
2.,The time complexity of an algorithm measures:
A) The amount of memory used
B) The number of operations required as a function of input size
C) The speed of the computer executing it
D) The length of the source code
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

Partial preview of the text

Download Algorithms Data Structures C Ultimate Exam and more Exams Software Engineering in PDF only on Docsity!

PrepIQ 19SOFTA1 Algorithms Data Structures C Ultimate Exam Course: Algorithms and Data Structures / Computer Science Total Questions: 150 Question Type: Multiple Choice Description: This comprehensive examination covers the fundamental principles and advanced concepts of algorithms and data structures, including complexity analysis (Big O, Big Theta, Big Omega), fundamental data structures (arrays, linked lists, stacks, queues, trees, heaps, hash tables, graphs), sorting algorithms (bubble, insertion, selection, merge, quick, heap, radix), searching algorithms (linear, binary, interpolation), tree algorithms (traversals, BST, AVL, B-trees), graph algorithms (DFS, BFS, shortest path, minimum spanning tree, topological sort), dynamic programming, greedy algorithms, divide and conquer, recursion, and string matching algorithms. The exam also explores algorithm design paradigms, complexity classes (P, NP, NP-Complete), and practical applications. This examination is suitable for undergraduate and graduate students in computer science, software engineering, and related fields.

1. An algorithm is defined as: A) A programming language B) A step-by-step procedure for solving a problem C) A data structure D) A type of computer hardware Answer: B Explanation: An algorithm is a finite sequence of well-defined, unambiguous steps for solving a specific problem or performing a computation. 2. The time complexity of an algorithm measures: A) The amount of memory used B) The number of operations required as a function of input size C) The speed of the computer executing it D) The length of the source code

Answer: B Explanation: Time complexity describes how the runtime of an algorithm grows as the input size increases, typically expressed using Big O notation.

3. Big O notation describes: A) The average-case complexity of an algorithm B) The upper bound of the growth rate of an algorithm C) The lower bound of the growth rate of an algorithm D) The exact runtime of an algorithm Answer: B Explanation: Big O notation provides an upper bound on the growth rate of an algorithm's time or space complexity, describing the worst-case scenario. 4. Big Omega (Ω) notation describes: A) The upper bound of the growth rate of an algorithm B) The lower bound of the growth rate of an algorithm C) The exact runtime of an algorithm D) The average-case complexity of an algorithm Answer: B Explanation: Big Omega (Ω) notation provides a lower bound on the growth rate of an algorithm, describing the best-case scenario. 5. Big Theta (Θ) notation describes: A) The upper bound of the growth rate of an algorithm B) The lower bound of the growth rate of an algorithm C) The tight bound of the growth rate of an algorithm (both upper and lower) D) The exact runtime of an algorithm Answer: C Explanation: Big Theta (Θ) notation provides a tight bound, meaning the algorithm grows at the same rate asymptotically (both upper and lower bounds). 6. The time complexity of an algorithm that performs a constant number of operations regardless of input size is: A) O(1) B) O(n) C) O(log n) D) O(n²) Answer: A Explanation: Constant time complexity O(1) means the algorithm takes the same amount of time regardless of the input size.

Answer: C Explanation: Quicksort has O(n²) worst-case complexity when the pivot is the smallest or largest element. Its average case is O(n log n).

12. The time complexity of quicksort in the average case is: A) O(n) B) O(n log n) C) O(n²) D) O(log n) Answer: B Explanation: Quicksort has O(n log n) average-case time complexity. 13. The time complexity of insertion sort in the worst case is: A) O(n) B) O(n log n) C) O(n²) D) O(log n) Answer: C Explanation: Insertion sort has O(n²) worst-case complexity when the array is reverse sorted. 14. The time complexity of selection sort in the worst case is: A) O(n) B) O(n log n) C) O(n²) D) O(log n) Answer: C Explanation: Selection sort always performs n² comparisons regardless of input order, giving O(n²) complexity. 15. The time complexity of heap sort in the worst case is: A) O(n) B) O(n log n) C) O(n²) D) O(log n) Answer: B Explanation: Heap sort has O(n log n) time complexity in all cases (worst, average, and best). 16. A data structure is: A) A programming language B) A way to organize and store data for efficient access and modification

C) An algorithm for sorting D) A type of computer hardware Answer: B Explanation: A data structure is a specialized format for organizing, processing, retrieving, and storing data to enable efficient operations.

17. An array is a data structure that: A) Stores elements in a linked list B) Stores elements in contiguous memory locations C) Stores elements in a tree structure D) Stores elements in a hash table Answer: B Explanation: An array stores elements in contiguous memory locations, allowing O(1) access time using an index. 18. The time complexity of accessing an element in an array by index is: A) O(1) B) O(log n) C) O(n) D) O(n²) Answer: A Explanation: Array elements are accessed directly by index in constant time O(1). 19. The time complexity of inserting an element at the end of a dynamic array (amortized) is: A) O(1) B) O(log n) C) O(n) D) O(n²) Answer: A Explanation: Appending to a dynamic array has O(1) amortized time complexity (occasional resizing gives O(n) for that operation). 20. A linked list stores elements: A) In contiguous memory locations B) In non-contiguous memory locations with pointers connecting them C) In a tree structure D) In a hash table Answer: B Explanation: A linked list stores elements in nodes with pointers to the next (and previous) node.

C) Random access D) Priority-based access Answer: B Explanation: A stack follows the Last-In-First-Out (LIFO) principle: the last element added is the first one removed.

26. The push operation in a stack: A) Removes the top element B) Adds an element to the top C) Adds an element to the bottom D) Removes an element from the bottom Answer: B Explanation: Push adds an element to the top of the stack. 27. The pop operation in a stack: A) Removes and returns the top element B) Removes and returns the bottom element C) Adds an element to the top D) Adds an element to the bottom Answer: A Explanation: Pop removes and returns the top element from the stack. 28. A queue follows which principle? A) First-In-First-Out (FIFO) B) Last-In-First-Out (LIFO) C) Random access D) Priority-based access Answer: A Explanation: A queue follows the First-In-First-Out (FIFO) principle: the first element added is the first one removed. 29. The enqueue operation in a queue: A) Removes an element from the front B) Adds an element to the rear C) Adds an element to the front D) Removes an element from the rear Answer: B Explanation: Enqueue adds an element to the rear (back) of the queue. 30. The dequeue operation in a queue: A) Removes and returns an element from the front B) Removes and returns an element from the rear

C) Adds an element to the front D) Adds an element to the rear Answer: A Explanation: Dequeue removes and returns the front element from the queue.

31. A deque (double-ended queue) allows: A) Insertion and deletion only at the front B) Insertion and deletion only at the rear C) Insertion and deletion at both ends D) Insertion only at the front Answer: C Explanation: A deque allows insertion and deletion at both the front and rear ends. 32. A priority queue is a data structure where: A) Elements are processed in FIFO order B) Elements are processed in LIFO order C) Elements are processed based on their priority (highest priority first) D) Elements are processed randomly Answer: C Explanation: In a priority queue, each element has a priority, and the element with the highest priority is served first. 33. A heap is a: A) Linear data structure B) Complete binary tree that satisfies the heap property C) Balanced binary search tree D) Hash table Answer: B Explanation: A heap is a complete binary tree where each node's value is either greater than (max-heap) or less than (min-heap) its children. 34. In a max-heap, the root contains: A) The minimum value B) The maximum value C) A random value D) The median value Answer: B Explanation: In a max-heap, the root has the maximum value, and each parent is greater than or equal to its children.

Answer: A Explanation: A collision occurs when two different keys hash to the same index in the hash table.

40. Chaining is a collision resolution technique that: A) Uses linear probing to find the next available slot B) Uses a linked list to store multiple elements at the same index C) Uses quadratic probing D) Rehashes the key with a different function Answer: B Explanation: Chaining stores all elements that hash to the same index in a linked list (or other data structure) at that index. 41. Open addressing is a collision resolution technique that: A) Uses a linked list at each index B) Finds another empty slot in the hash table (probing) C) Rehashes the key D) Ignores collisions Answer: B Explanation: Open addressing finds the next available slot (using linear, quadratic, or double hashing probing) when a collision occurs. 42. Linear probing is a collision resolution technique where: A) The next slot is found using a quadratic function B) The next slot is found sequentially (index + 1, +2, ...) C) A linked list is used at each index D) A different hash function is used Answer: B Explanation: Linear probing checks the next slot (index + 1, index + 2, ...) sequentially until an empty slot is found. 43. The load factor of a hash table is defined as: A) The number of elements divided by the table size B) The number of collisions divided by the table size C) The number of empty slots divided by the table size D) The number of keys divided by the number of collisions Answer: A Explanation: The load factor α = n / m, where n is the number of elements and m is the table size. 44. A tree is a data structure that: A) Has cycles B) Is a connected acyclic graph

C) Has no root D) Is a linked list Answer: B Explanation: A tree is a connected acyclic graph with a root node and child nodes.

45. A binary tree is a tree where: A) Each node has exactly two children B) Each node has at most two children C) Each node has at most three children D) Nodes have no children Answer: B Explanation: In a binary tree, each node has at most two children: a left child and a right child. 46. A full binary tree is a binary tree where: A) Every node has exactly two children (or none) B) Every node has exactly two children C) All leaves are at the same level D) The tree is complete Answer: A Explanation: In a full binary tree, every node has either 0 or 2 children (no node has exactly one child). 47. A complete binary tree is a binary tree where: A) All levels are completely filled except possibly the last, which is filled from left to right B) Every node has two children C) All leaves are at the same level D) The tree is perfectly balanced Answer: A Explanation: A complete binary tree is filled level by level, and the last level is filled from left to right. 48. A perfect binary tree is a binary tree where: A) All internal nodes have two children and all leaves are at the same level B) All nodes have exactly two children C) All levels are completely filled except the last D) The tree is balanced Answer: A Explanation: A perfect binary tree has all internal nodes with two children and all leaves at the same depth.

Answer: C Explanation: In the worst case (skewed tree), a BST degenerates into a linked list, giving O(n) search time.

54. In-order traversal of a BST visits nodes: A) In sorted order (left, root, right) B) Root, left, right C) Left, right, root D) Root, right, left Answer: A Explanation: In-order traversal (left, root, right) visits nodes in ascending sorted order in a BST. 55. Pre-order traversal visits nodes in the order: A) Left, root, right B) Root, left, right C) Left, right, root D) Root, right, left Answer: B Explanation: Pre-order traversal is: root, left, right. 56. Post-order traversal visits nodes in the order: A) Left, root, right B) Root, left, right C) Left, right, root D) Root, right, left Answer: C Explanation: Post-order traversal is: left, right, root. 57. An AVL tree is a: A) Self-balancing BST where the height difference between left and right subtrees is at most 1 B) Complete binary tree C) Heap D) Hash table Answer: A Explanation: An AVL tree is a self-balancing BST where the balance factor (height left - height right) is -1, 0, or 1 for every node. 58. The time complexity of search, insert, and delete in an AVL tree is: A) O(1) B) O(log n)

C) O(n) D) O(n²) Answer: B Explanation: AVL trees maintain balance, ensuring O(log n) time complexity for search, insert, and delete.

59. A Red-Black tree is a: A) Self-balancing BST with color constraints B) Heap C) Complete binary tree D) Hash table Answer: A Explanation: A Red-Black tree is a self-balancing BST where each node is colored red or black with specific constraints to ensure balance. 60. The time complexity of search, insert, and delete in a Red-Black tree is: A) O(1) B) O(log n) C) O(n) D) O(n²) Answer: B Explanation: Red-Black trees maintain balance, ensuring O(log n) time complexity. 61. A B-tree is a: A) Binary tree B) Self-balancing tree used for external storage (disk) C) Heap D) Hash table Answer: B Explanation: A B-tree is a self-balancing tree data structure that maintains sorted data and allows searches, insertions, deletions in O(log n) time, commonly used in databases and file systems. 62. A B-tree of order m has: A) At most m children per node B) At most 2 children per node C) Exactly m children per node D) At most log m children per node Answer: A Explanation: In a B-tree of order m, each node can have at most m children and at least ceil(m/2) children (except the root).

Answer: B Explanation: A cycle is a path that starts and ends at the same vertex with no other repeated vertices.

68. A connected graph is a graph where: A) There is a path between every pair of vertices B) There are no edges C) All vertices have degree 1 D) The graph is acyclic Answer: A Explanation: A graph is connected if there is a path between every pair of vertices. 69. A tree is: A) A connected acyclic graph B) A connected graph with cycles C) A disconnected graph D) A graph with no vertices Answer: A Explanation: A tree is a connected graph with no cycles (acyclic). 70. The degree of a vertex in a graph is: A) The number of edges incident to the vertex B) The number of vertices in the graph C) The number of connected components D) The distance to the farthest vertex Answer: A Explanation: The degree of a vertex is the number of edges connected to it. 71. Depth-First Search (DFS) uses which data structure? A) Queue B) Stack (or recursion) C) Priority queue D) Hash table Answer: B Explanation: DFS uses a stack (or recursion) to traverse as deep as possible before backtracking. 72. Breadth-First Search (BFS) uses which data structure? A) Stack B) Queue C) Priority queue D) Hash table

Answer: B Explanation: BFS uses a queue to explore all vertices at the present depth before moving to the next depth.

73. The time complexity of DFS and BFS on a graph with V vertices and E edges is: A) O(V) B) O(E) C) O(V + E) D) O(V²) Answer: C Explanation: DFS and BFS both have O(V + E) time complexity. 74. Topological sort is applicable to: A) Undirected graphs B) Directed acyclic graphs (DAGs) C) Graphs with cycles D) Unweighted graphs Answer: B Explanation: Topological sort is only applicable to Directed Acyclic Graphs (DAGs), ordering vertices linearly. 75. Dijkstra's algorithm finds: A) The shortest path in an unweighted graph B) The shortest path in a weighted graph with non-negative weights C) The minimum spanning tree of a graph D) The topological order of a graph Answer: B Explanation: Dijkstra's algorithm finds the shortest path from a source vertex to all other vertices in a weighted graph with non-negative edge weights. 76. The time complexity of Dijkstra's algorithm with a binary heap is: A) O(V²) B) O(E log V) C) O(V log V) D) O(E + V log V) Answer: D Explanation: With a binary heap, Dijkstra's algorithm runs in O((E + V) log V) ≈ O(E + V log V). 77. Bellman-Ford algorithm finds: A) The shortest path in a graph with negative weights (no negative cycles)

82. Prim's algorithm finds: A) The shortest path B) The minimum spanning tree (MST) C) The topological order D) The maximum flow Answer: B Explanation: Prim's algorithm finds the MST by growing the tree from a starting vertex, adding the smallest edge that connects a new vertex. 83. The time complexity of Kruskal's algorithm with a union-find data structure is: A) O(V) B) O(E log E) C) O(V + E) D) O(V²) Answer: B Explanation: Kruskal's algorithm sorts E edges (O(E log E)) and uses union- find operations. 84. The time complexity of Prim's algorithm with a binary heap is: A) O(V²) B) O(E log V) C) O(V log V) D) O(E + V log V) Answer: D Explanation: With a binary heap, Prim's algorithm runs in O(E + V log V). 85. A greedy algorithm makes: A) The globally optimal decision at each step B) The locally optimal decision at each step C) Random decisions D) Decisions based on backtracking Answer: B Explanation: A greedy algorithm makes the locally optimal choice at each step, hoping to find the globally optimal solution. 86. The fractional knapsack problem can be solved optimally using: A) Dynamic programming B) Greedy algorithm C) Divide and conquer D) Backtracking

Answer: B Explanation: The fractional knapsack problem (where items can be divided) is solved optimally with a greedy algorithm (sort by value/weight ratio).

87. The 0/1 knapsack problem is solved optimally using: A) Greedy algorithm B) Dynamic programming C) Divide and conquer D) Backtracking Answer: B Explanation: The 0/1 knapsack problem (items cannot be divided) is solved optimally with dynamic programming. 88. The time complexity of the 0/1 knapsack dynamic programming solution is: A) O(n) B) O(W) C) O(n × W) D) O(2^n) Answer: C Explanation: The 0/1 knapsack DP solution has O(n × W) time complexity, where n is the number of items and W is the capacity. 89. The longest common subsequence (LCS) problem is solved using: A) Greedy algorithm B) Dynamic programming C) Divide and conquer D) Backtracking Answer: B Explanation: The LCS problem is solved optimally using dynamic programming, with O(m × n) time complexity. 90. The time complexity of the LCS dynamic programming solution is: A) O(m) B) O(n) C) O(m × n) D) O(m + n) Answer: C Explanation: LCS DP has O(m × n) time complexity, where m and n are the lengths of the two sequences. 91. The edit distance (Levenshtein distance) problem is solved using: A) Greedy algorithm