Docsity

Efficient Search Algorithms and Sorting Techniques - Prof. Asamoah, Quizzes of Computer Science

Partial preview of the text

Download Efficient Search Algorithms and Sorting Techniques - Prof. Asamoah and more Quizzes Computer Science in PDF only on Docsity!

KOFORIDUA TECHNICAL UNIVERSITY

BSc INFORMTION TECNOLOGY.

DESIGN AND THEORY OF ALGORITHMS

MID SEMESTER EXAMINATION.

NAME: INDEX:

QUESTION 1

An algorithm can be defined as a set of procedure in solving a problem. Importance

  1. To improve the efficiency of a computer program
  2. Help software developers create efficient and error free programs. **Examples
  3. Google Search.** Even an action as seemingly simple as a Google search is only possible with the help of algorithms. Say, for example, you want to know if an elephant can swim. How you phrase the question to Google is the input you are asking the computer to determine. Google does not even need all the words of the question “can an elephant swim?” For example, try searching for “swimming elephant” and see what you get. You will find that immediately, the output or the results show videos of elephants swimming, followed by more on the subject. Google uses an algorithm to generate these answers without needing the entirety of the question. 2. Traffic Lights Here’s an algorithm we frequently experience; the next time you're in your car stuck at a red light, consider the algorithm the traffic light is executing.” Most traffic lights don’t automatically cycle through green, yellow, and red. Rather, there are sensory inputs that determine the signals’ timing based on the flow of traffic. The algorithm is a well-constructed, step-by-step order that directs the traffic appropriately (although it may not feel like it when you’re sitting at a red light). The traffic light control system using the fuzzy logic algorithm based on the Mandeni method gives the value of the length of time the green light is on depending on the number of arrivals of a path in the first cycle and second cycle of lights QUESTION 2
  4. Big O notation : It is a way to measure an algorithm’s efficiency. It measures the time it takes to run your function as the input grows. In other words, how well does the function scale?
  5. Big omega notation: It is used to define the lower bound of any algorithm or we can say the best case of any algorithm. This always indicates the minimum time required for any algorithm for all input values, therefore the best case of any algorithm.
  6. Big theta notation: It specifies asymptotic bounds (both upper and lower) for a function f(n) and provides the average time complexity of an algorithm QUESTION 3 Data Structures are a specialized means of organizing and storing data in computers in such a way that we can perform operations on the stored data more efficiently. Relevance
  7. Data structure can enhance the efficiency of computer program or algorithm in a better way.
  8. Data structures provide a means to manage large amounts of data efficiently for uses such as large databases and internet indexing services Examples ● Singly Linked List ● Stacks

of dividing the search interval in half, it estimates the position of the target element based on its value and the values of the first and last elements in the search interval. Algorithm: ● Calculate the position of the target element based on its value and the values of the first and last elements in the search interval. ● If the target element matches the element at the estimated position, return its index. ● If the target element is smaller than the element at the estimated position, repeat the search on the lower half of the list. ● If the target element is larger than the element at the estimated position, repeat the search on the upper half of the list. ● If the target element is not found, return -1.

  1. Jump search is a relatively new algorithm for searching an element in a sorted array. The fundamental idea behind this searching technique is to search fewer number of elements compared to linear search algorithm (which scans every element in the array to check if it matches with the element being searched or not). This can be done by skipping some fixed number of array elements or jumping ahead by fixed number of steps in every iteration. Algorithm ● Given a sorted list or array and a target value to search for. ● Set the jump step size as the square root of the length of the list or array. ● Initialize two pointers, left and right, to the beginning and end of the list or array, respectively. ● While the value at the right pointer is greater than the target value and the jump step size is greater than 0: I. Move the left pointer to the current right pointer. II. Set the right pointer as the minimum value between its current position and the jump step size plus the left pointer's position. ● Perform a linear search between the left and right pointers to find the target value. ● If the target value is found, return its index. Otherwise, return - QUESTION 5 I. The linear search algorithm is a simple algorithm used to find an element in a list or an array by sequentially checking each element until a match is found or the end of the list is reached. It is also known as a sequential search algorithm. Algorithm:

● Start from the first element of the list. ● Compare the target element with the current element. ● If the target element is found, return its index. ● If the end of the list is reached and the element is not found, return -1. Time Complexity: The worst-case time complexity of the linear search algorithm is O(n), where n is the number of elements in the list. This is because in the worst-case scenario, the target element will not be found until the last element is checked. The best-case time complexity is O(1), which occurs when the target element is found at the first position. Merits: ● The linear search algorithm is simple to implement and understand. ● It works with any type of list or array, regardless of how it is sorted or ordered. ● It is useful for small lists or arrays, as the overhead of sorting or other optimization techniques may not be worth it. Demerits: ● The worst-case time complexity of the linear search algorithm is O(n), which can be slow for large lists or arrays. ● It is not efficient for searching large datasets or databases. ● It can take a long time to search through unsorted lists or arrays. II. The binary search algorithm is a search algorithm used to find an element in a sorted list or array by repeatedly dividing the search interval in half. It is a very efficient algorithm for searching through large datasets. Algorithm: ● Begin with the middle element of the sorted list. ● If the target element matches the middle element, return its index. ● If the target element is smaller than the middle element, repeat the search on the lower half of the list. ● If the target element is larger than the middle element, repeat the search on the upper half of the list. ● If the target element is not found, return -1. Time Complexity: The time complexity of the binary search algorithm is O(log n), where n is the number of elements in the list. This is because in each iteration, the search interval is divided in half, resulting in a logarithmic reduction in the search space.

● The interpolated search algorithm may perform worse than the binary search algorithm for datasets with unevenly distributed values. ● It requires that the list be sorted. ● It is not suitable for dynamic datasets, where elements are frequently added or removed from the list IV. The exponential search algorithm is a search algorithm used to find an element in a sorted list or array by first finding an appropriate range of values using exponential growth, and then performing a binary search on that range. It is an efficient algorithm for searching through large datasets. Algorithm: ● Determine an appropriate range of values by doubling an index starting from 1 until the value at that index is greater than or equal to the target value. ● Perform a binary search on the range determined in step 1 to find the target element. ● If the target element is found, return its index. Otherwise, return -1. Time Complexity: The time complexity of the exponential search algorithm is O(log n), where n is the number of elements in the list. This is because the algorithm first determines an appropriate range of values using exponential growth, which takes O(log n) time. The binary search on that range takes O(log m) time, where m is the size of the range. Merits: ● The exponential search algorithm is efficient for searching through large datasets, where the time complexity can be reduced to O(log n). ● It requires only one binary search, which is faster than multiple binary searches. ● It works best for sorted lists or arrays. Demerits: ● The exponential search algorithm requires the list to be sorted. ● It is not suitable for dynamic datasets, where elements are frequently added or removed from the list. ● It may be slower than other algorithms, such as the binary search algorithm, for datasets with a small number of elements. QUESTION 6 A sorting algorithm is a method for arranging the elements of a list or array in a particular order, such as numerical or alphabetical. Sorting algorithms are commonly used in computer science and many applications, including data analysis, database management, and web searching. Common sorting algorithms and their applications:

  1. Bubble Sort : Bubble sort is a simple sorting algorithm that repeatedly swaps adjacent elements if they are in the wrong order. This algorithm is best suited for small datasets, and it is not very efficient for large datasets. Algorithm: ● Compare the first two elements of the list or array. ● If the first element is greater than the second element, swap them. ● Move to the next pair of adjacent elements and repeat step 2 until the end of the list or array is reached. ● If any swaps were made, repeat steps 1-3 until no more swaps are needed. Applications : Bubble sort is useful for small datasets or where simplicity is important. However, it is not efficient for large datasets or real-time applications.
  2. Selection Sort : Selection sort is another simple sorting algorithm that sorts the list or array by repeatedly finding the minimum element and swapping it with the next element in the sorted part of the list. This algorithm is best suited for small datasets, and it is not very efficient for large datasets. Algorithm : ● Find the minimum element in the unsorted part of the list or array. ● Swap the minimum element with the first element in the unsorted part of the list. ● Move to the next element in the unsorted part of the list and repeat steps 1-2 until the end of the list is reached. Applications : Selection sort is useful for small datasets or where simplicity is important. However, it is not efficient for large datasets or real-time applications.
  3. Merge Sort : Merge sort is a divide-and-conquer sorting algorithm that divides the list or array into smaller sub- lists, sorts them recursively, and then merges the sorted sub-lists back into a single list. This algorithm is efficient for large datasets. Algorithm : ● Divide the list or array into two halves. ● Sort each half recursively using the merge sort algorithm. ● Merge the sorted halves into a single sorted list. Applications : Merge sort is efficient for sorting large datasets or when stability is important. It is often used in sorting large files or in external sorting, where the data cannot fit into memory.
  4. Quick Sort : Quick sort is a divide-and-conquer sorting algorithm that partitions the list or array into two sub-lists based on a pivot element and recursively sorts each sub-list. This algorithm is efficient for large datasets. Algorithm :

O(n). This is because the algorithm only needs to make n-1 comparisons in the best case, as each element is already in its proper place. Merits : Insertion sort is a simple algorithm that is easy to understand and implement. It is also efficient for small datasets and has a better performance than bubble sort. It also sorts in place, meaning it does not require additional memory beyond the original list or array. Demerits : Insertion sort is not very efficient for large datasets, as its time complexity is O(n^2), which can make it slow and inefficient. It also has poor performance when the list or array is almost sorted, as it still needs to make the same number of comparisons even if the list is almost sorted. Overall, insertion sort is useful for small datasets or where simplicity is important, but it is not recommended for large datasets or real-time applications.

  1. Merge Sort : Merge sort is a divide-and-conquer sorting algorithm that divides the list or array into smaller sub- lists, sorts them recursively, and then merges the sorted sub-lists back into a single list. This algorithm is efficient for large datasets. Algorithm : ● Divide the list or array into two halves. ● Sort each half recursively using the merge sort algorithm. ● Merge the sorted halves into a single sorted list. Time Complexity : The time complexity of merge sort is O(n log n) in the worst case, where n is the number of elements in the list or array. This is because the algorithm needs to make log n recursive calls to split the list into halves, and each call requires O(n) time to merge the two halves back together. Merits : Merge sort has a consistent time complexity of O(n log n) and is efficient for large datasets. It is also a stable sorting algorithm, meaning that it preserves the order of equal elements in the list. It is also useful in situations where the data to be sorted is stored on external media, as the algorithm minimizes the number of accesses required to the media. Demerits : Merge sort requires additional memory beyond the original list or array, as it needs to create temporary arrays during the merge process. This can make it less efficient in situations where memory is limited. It is also a relatively complex algorithm to understand and implement. Overall, merge sort is a highly efficient sorting algorithm that is well-suited for large datasets, but may not be the best choice in situations where memory is limited or simplicity is preferred
  2. Quick Sort : Quick sort is a divide-and-conquer sorting algorithm that partitions the list or array into two sub-lists based on a pivot element and recursively sorts each sub-list. This algorithm is efficient for large datasets. Algorithm : ● Choose a pivot element from the list or array. ● Partition the list or array into two sub-lists, one with elements smaller than the pivot and one with elements larger than the pivot. ● Sort each sub-list recursively using the quick sort algorithm. ● Merge the sorted sub-lists into a single sorted list.

Time Complexity : The time complexity of quick sort is O(n log n) in the average case, where n is the number of elements in the list or array. However, in the worst case scenario where the pivot is consistently chosen poorly, the time complexity can be O(n^2). In practice, the worst case scenario is rare and quick sort is generally considered one of the fastest sorting algorithms. Merits : Quick sort is highly efficient and well-suited for large datasets. It also has a smaller memory footprint than merge sort, as it sorts the list or array in place without the need for temporary arrays. It is also a highly adaptable algorithm, as it can be optimized for different data distributions and can be easily parallelized. Demerits : Quick sort can be unstable, meaning that the order of equal elements in the list may not be preserved. It can also be sensitive to the choice of pivot element, and poorly chosen pivot elements can lead to worst case scenarios and poor performance. Additionally, quick sort is a relatively complex algorithm to understand and implement. Overall, quick sort is a highly efficient sorting algorithm that is well-suited for large datasets and can be optimized for various scenarios. However, it may not be the best choice in situations where stability is important or where the choice of pivot element is uncertain. QUESTION 8 An array is a data structure that stores a fixed-size sequence of elements of the same data type. Each element in an array is accessed using an index or a subscript, which represents its position in the sequence. An ordered array is an array where the elements are stored in a particular order, such as ascending or descending order based on their values. Examples of ordered arrays include: ● A list of temperatures recorded over a period of time, sorted in chronological order ● A list of student names sorted alphabetically ● A list of stock prices sorted by increasing value An unordered array is an array where the elements are not stored in any particular order. Examples of unordered arrays include: ● A list of customer names and addresses ● A list of emails received in a mailbox ● A list of items in a grocery cart Applications: The choice between using an ordered or unordered array depends on the particular application requirements. Differences Ordered arrays are useful when the data needs to be accessed in a particular order, such as for searching or sorting purposes. For example, if we want to find the highest or lowest temperature recorded in a period of time, an ordered array would make it easier to perform the search. Unordered arrays are useful when the data does not need to be accessed in any particular order, such as for storing a collection of items. For example, a grocery cart can contain a collection of items with no particular ordering requirement.

A circular linked list is a special type of linked list in which the last node is linked to the first node, forming a circular sequence. This means that the next pointer of the last node points to the first node, instead of null. Circular linked lists can be either singly linked or doubly linked. The main difference between a doubly linked list and a circular linked list is the way they are linked together. In a doubly linked list, the last node points to null, while in a circular linked list, the last node points to the first node, creating a loop. This means that traversing a circular linked list can be done indefinitely in either direction, while traversing a doubly linked list can only be done until the last node is reached. QUESTION 11 A binary tree is a tree-like data structure in which each node has at most two children, referred to as the left child and the right child. Each node in a binary tree can have either zero, one, or two children. Properties of a binary tree: i. Root: The topmost node of a binary tree is called the root node. It has no parent. ii. Parent and child: Each node in a binary tree can have at most two children, referred to as the left child and the right child. Each child node has a parent node, except for the root node which has no parent. iii. Leaf: A node with no children is called a leaf node or a terminal node. iv. Internal node: A node with at least one child is called an internal node. v. Depth: The depth of a node in a binary tree is the number of edges from the root node to that node. vi. Height: The height of a binary tree is the maximum depth of any node in the tree. vii. Binary search tree: A binary tree can be a binary search tree if it satisfies the following property: for every node, all the nodes in its left subtree have values less than its own value, and all the nodes in its right subtree have values greater than its own value. viii. Balanced tree: A binary tree is balanced if the height of its left and right subtrees differ by at most one. ix. Complete binary tree: A binary tree is complete if all levels of the tree are completely filled, except possibly the last level, which is filled from left to right. x. Full binary tree: A binary tree is full if every node has either zero or two children. xi. QUESTION 12 A binary search tree is a binary tree that satisfies the binary search tree property, which means that for each node in the tree, all the nodes in its left subtree have values less than its own value, and all the nodes in its right subtree have values greater than its own value. Properties of a binary search tree:

  1. Binary tree: A binary search tree is a binary tree, which means that each node can have at most two children.
  2. Binary search property: For each node in a binary search tree, all the nodes in its left subtree have values less than its own value, and all the nodes in its right subtree have values greater than its own value.
  3. Uniqueness property: A binary search tree does not allow duplicate keys. If a key is already present in the tree, a new node with the same key is not inserted.
  4. Height: The height of a binary search tree is the maximum depth of any node in the tree. A balanced binary search tree has a height of O(log n), where n is the number of nodes in the tree.
  5. Search, insert, and delete: The binary search tree supports efficient search, insertion, and deletion of nodes in O(log n) time, where n is the number of nodes in the tree.
  6. In-order traversal: In-order traversal of a binary search tree visits the nodes in sorted order. This property is used in many applications of binary search trees, such as searching for the k-th smallest element in the tree. QUESTION 13

Breadth-first search (BFS) and depth-first search (DFS) are two common algorithms used to traverse or search a graph or a tree. Breadth-first search (BFS): BFS is an algorithm used to traverse or search a graph or a tree data structure. The algorithm starts at the root node and explores all the nodes at the current depth level before moving on to the next depth level. This process is repeated until all nodes have been explored or the desired node has been found. The algorithm uses a queue data structure to keep track of the nodes to be visited. Algorithm for BFS:

  1. Create a queue and add the root node to the queue.
  2. While the queue is not empty: a. Dequeue a node from the queue. b. If the node is the desired node, stop the search. c. Otherwise, add all the unvisited neighbors of the node to the queue.
  3. If the desired node was not found, return "not found". Time complexity of BFS: O(V+E), where V is the number of vertices and E is the number of edges in the graph. Depth-first search (DFS): DFS is an algorithm used to traverse or search a graph or a tree data structure. The algorithm starts at the root node and explores as far as possible along each branch before backtracking. The algorithm uses a stack data structure to keep track of the nodes to be visited. Algorithm for DFS:
  4. Create a stack and add the root node to the stack.
  5. While the stack is not empty: a. Pop a node from the stack. b. If the node is the desired node, stop the search. c. Otherwise, add all the unvisited neighbors of the node to the stack.
  6. If the desired node was not found, return "not found" QUESTION 14 A red-black tree is a self-balancing binary search tree where each node has a color, either red or black. The color of the nodes is used to maintain the balance of the tree, ensuring that the height of the tree is logarithmic in the number of nodes. Properties of a red-black tree:
  7. Every node is either red or black.
  8. The root node is black.
  9. Every leaf node is black.
  10. If a node is red, then both its children are black.
  11. Every path from a node to its descendant leaf nodes contains the same number of black nodes.
  12. The null leaves of the tree are considered black. The red-black tree is important because it is a self-balancing binary search tree that maintains a balance between its height and the number of nodes in the tree. The balanced tree ensures that the worst-case time complexity for searching, inserting, and deleting elements is O(log n), where n is the number of nodes in the tree. QUESTION 15

the source code in a way that minimizes the total length of the encoded message. The tree is constructed by starting with the two least frequent symbols and repeatedly combining the two nodes with the lowest frequency until a single root node is created.

  1. Dijkstra's shortest path algorithm : Dijkstra's algorithm is used to find the shortest path between two nodes in a graph. The algorithm works by maintaining a set of visited nodes and a set of unvisited nodes. It starts by setting the distance of the source node to 0 and the distance of all other nodes to infinity. Then, it repeatedly selects the unvisited node with the smallest distance and relaxes its neighboring nodes by updating their distances if a shorter path is found. QUESTION 18 Phase 1 a) 15, 24, 11, 25, 16, 12, 18, 21, 25, 10, 33, 36, 19, 22, 31 b) 24, 15, 11, 25, 16, 12, 18, 21, 25, 10, 33, 36, 19, 22, 31 c) 24, 15, 11, 25, 16, 12, 18, 21, 25, 10, 33, 36, 19, 22, 31 d) 24, 15, 25, 11, 16, 12, 18, 21, 25, 10, 33, 36, 19, 22, 31 e) 24, 15, 25, 16, 11, 12, 18, 21, 25, 10, 33, 36, 19, 22, 31 f) 24, 15, 25, 16, 12, 11, 18, 21, 25, 10, 33, 36, 19, 22, 31 g) 24, 15, 25, 16, 12, 18, 11, 21, 25, 10, 33, 36, 19, 22, 31 h) 24, 15, 25, 16, 12, 18, 21, 11, 25, 10, 33, 36, 19, 22, 31 i) 24, 15, 25, 16, 12, 18, 21, 25, 11, 10, 33, 36, 19, 22, 31 j) 24, 15, 25, 16, 12, 18, 21, 25, 11, 10, 33, 36, 19, 22, 31 k) 24, 15, 25, 16, 12, 18, 21, 25, 11, 33, 10, 36, 19, 22, 31 l) 24, 15, 25, 16, 12, 18, 21, 25, 11, 33, 36, 10, 19, 22, 31 m) 24, 15, 25, 16, 12, 18, 21, 25, 11, 33, 36, 19, 10, 22, 31 n) 24, 15, 25, 16, 12, 18, 21, 25, 11, 33, 36, 19, 22, 10, 31 o) 24, 15, 25, 16, 12, 18, 21, 25, 11, 33, 36, 19, 22, 31, 10 Phase 2 a) 24, 15, 25, 16, 12, 18, 21, 25, 11, 33, 36, 19, 22, 31, 10 b) 24, 25, 15, 16, 12, 18, 21, 25, 11, 33, 36, 19, 22, 31, 10 c) 24, 25, 16, 15, 12, 18, 21, 25, 11, 33, 36, 19, 22, 31, 10 d) 24, 25, 16, 15, 12, 18, 21, 25, 11, 33, 36, 19, 22, 31, 10 e) 24, 25, 16, 15, 18, 12, 21, 25, 11, 33, 36, 19, 22, 31, 10 f) 24, 25, 16, 15, 18, 21, 12, 25, 11, 33, 36, 19, 22, 31, 10 g) 24, 25, 16, 15, 18, 21, 25, 12, 11, 33, 36, 19, 22, 31, 10 h) 24, 25, 16, 15, 18, 21, 25, 12, 11, 33, 36, 19, 22, 31, 10 i) 24, 25, 16, 15, 18, 21, 25, 12, 33, 11, 36, 19, 22, 31, 10 j) 24, 25, 16, 15, 18, 21, 25, 12, 33, 36, 11, 19, 22, 31, 10 k) 24, 25, 16, 15, 18, 21, 25, 12, 33, 36, 19, 11, 22, 31, 10 l) 24, 25, 16, 15, 18, 21, 25, 12, 33, 36, 19, 22, 11, 31, 10 m) 24, 25, 16, 15, 18, 21, 25, 12, 33, 36, 19, 22, 31, 11, 10 n) 24, 25, 16, 15, 18, 21, 25, 12, 33, 36, 19, 22, 31, 11, 10 o) 24, 25, 16, 15, 18, 21, 25, 12, 33, 36, 19, 22, 31, 11, 10 Phase 3 a) 24, 25, 16, 15, 18, 21, 25, 12, 33, 36, 19, 22, 31, 11, 10 b) 25, 24, 16, 15, 18, 21, 25, 12, 33, 36, 19, 22, 31, 11, 10 c) 25, 24, 16, 15, 18, 21, 25, 12, 33, 36, 19, 22, 31, 11, 10 d) 25, 24, 16, 15, 18, 21, 25, 12, 33, 36, 19, 22, 31, 11, 10 e) 25, 24, 16, 18, 15, 21, 25, 12, 33, 36, 19, 22, 31, 11, 10 f) 25, 24, 16, 18, 21, 15, 25, 12, 33, 36, 19, 22, 31, 11, 10

g) 25, 24, 16, 18, 21, 25, 15, 12, 33, 36, 19, 22, 31, 11, 10 h) 25, 24, 16, 18, 21, 25, 15, 12, 33, 36, 19, 22, 31, 11, 10 i) 25, 24, 16, 18, 21, 25, 15, 33, 12, 36, 19, 22, 31, 11, 10 j) 25, 24, 16, 18, 21, 25, 15, 33, 36, 12, 19, 22, 31, 11, 10 k) 25, 24, 16, 18, 21, 25, 15, 33, 36, 19, 12, 22, 31, 11, 10 l) 25, 24, 16, 18, 21, 25, 15, 33, 36, 19, 22, 12, 31, 11, 10 m) 25, 24, 16, 18, 21, 25, 15, 33, 36, 19, 22, 31, 12, 11, 10 n) 25, 24, 16, 18, 21, 25, 15, 33, 36, 19, 22, 31, 12, 11, 10 o) 25, 24, 16, 18, 21, 25, 15, 33, 36, 19, 22, 31, 12, 11, 10 Phase 4 a) 25, 24, 16, 18, 21, 25, 15, 33, 36, 19, 22, 31, 12, 11, 10 b) 25, 24, 16, 18, 21, 25, 15, 33, 36, 19, 22, 31, 12, 11, 10 c) 25, 24, 16, 18, 21, 25, 15, 33, 36, 19, 22, 31, 12, 11, 10 d) 25, 24, 18, 16, 21, 25, 15, 33, 36, 19, 22, 31, 12, 11, 10 e) 25, 24, 18, 21, 16, 25, 15, 33, 36, 19, 22, 31, 12, 11, 10 f) 25, 24, 18, 21, 25, 16, 15, 33, 36, 19, 22, 31, 12, 11, 10 g) 25, 24, 18, 21, 25, 16, 15, 33, 36, 19, 22, 31, 12, 11, 10 h) 25, 24, 18, 21, 25, 16, 33, 15, 36, 19, 22, 31, 12, 11, 10 i) 25, 24, 18, 21, 25, 16, 33, 36, 15, 19, 22, 31, 12, 11, 10 j) 25, 24, 18, 21, 25, 16, 33, 36, 19, 15, 22, 31, 12, 11, 10 k) 25, 24, 18, 21, 25, 16, 33, 36, 19, 22, 15, 31, 12, 11, 10 l) 25, 24, 18, 21, 25, 16, 33, 36, 19, 22, 31, 15, 12, 11, 10 m) 25, 24, 18, 21, 25, 16, 33, 36, 19, 22, 31, 15, 12, 11, 10 n) 25, 24, 18, 21, 25, 16, 33, 36, 19, 22, 31, 15, 12, 11, 10 o) 25, 24, 18, 21, 25, 16, 33, 36, 19, 22, 31, 15, 12, 11, 10 Phase 5 a) 25, 24, 18, 21, 25, 16, 33, 36, 19, 22, 31, 15, 12, 11, 10 b) 25, 24, 18, 21, 25, 16, 33, 36, 19, 22, 31, 15, 12, 11, 10 c) 25, 24, 21, 18, 25, 16, 33, 36, 19, 22, 31, 15, 12, 11, 10 d) 25, 24, 21, 25, 18, 16, 33, 36, 19, 22, 31, 15, 12, 11, 10 e) 25, 24, 21, 25, 18, 16, 33, 36, 19, 22, 31, 15, 12, 11, 10 f) 25, 24, 21, 25, 18, 33, 16, 36, 19, 22, 31, 15, 12, 11, 10 g) 25, 24, 21, 25, 18, 33, 36, 16, 19, 22, 31, 15, 12, 11, 10 h) 25, 24, 21, 25, 18, 33, 36, 19, 16, 22, 31, 15, 12, 11, 10 i) 25, 24, 21, 25, 18, 33, 36, 19, 22, 16, 31, 15, 12, 11, 10 j) 25, 24, 21, 25, 18, 33, 36, 19, 22, 31, 16, 15, 12, 11, 10 k) 25, 24, 21, 25, 18, 33, 36, 19, 22, 31, 16, 15, 12, 11, 10 l) 25, 24, 21, 25, 18, 33, 36, 19, 22, 31, 16, 15, 12, 11, 10 m) 25, 24, 21, 25, 18, 33, 36, 19, 22, 31, 16, 15, 12, 11, 10 n) 25, 24, 21, 25, 18, 33, 36, 19, 22, 31, 16, 15, 12, 11, 10 o) 25, 24, 21, 25, 18, 33, 36, 19, 22, 31, 16, 15, 12, 11, 10 Phase 6 a) 25, 24, 21, 25, 18, 33, 36, 19, 22, 31, 16, 15, 12, 11, 10 b) 25, 24, 21, 25, 18, 33, 36, 19, 22, 31, 16, 15, 12, 11, 10 c) 25, 24, 21, 25, 18, 33, 36, 19, 22, 31, 16, 15, 12, 11, 10 d) 25, 24, 25, 21, 18, 33, 36, 19, 22, 31, 16, 15, 12, 11, 10 e) 25, 24, 25, 21, 18, 33, 36, 19, 22, 31, 16, 15, 12, 11, 10

h) 25, 33, 36, 25, 24, 31, 22, 21, 19, 18, 16, 15, 12, 11, 10 i) 25, 33, 36, 25, 24, 31, 22, 21, 19, 18, 16, 15, 12, 11, 10 j) 25, 33, 36, 25, 24, 31, 22, 21, 19, 18, 16, 15, 12, 11, 10 k) 25, 33, 36, 25, 24, 31, 22, 21, 19, 18, 16, 15, 12, 11, 10 l) 25, 33, 36, 25, 24, 31, 22, 21, 19, 18, 16, 15, 12, 11, 10 m) 25, 33, 36, 25, 24, 31, 22, 21, 19, 18, 16, 15, 12, 11, 10 n) 25, 33, 36, 25, 24, 31, 22, 21, 19, 18, 16, 15, 12, 11, 10 o) 25, 33, 36, 25, 24, 31, 22, 21, 19, 18, 16, 15, 12, 11, 10 Phase 10 a) 25, 33, 36, 25, 24, 31, 22, 21, 19, 18, 16, 15, 12, 11, 10 b) 33, 25, 36, 25, 24, 31, 22, 21, 19, 18, 16, 15, 12, 11, 10 c) 33, 36, 25, 25, 24, 31, 22, 21, 19, 18, 16, 15, 12, 11, 10 d) 33, 36, 25, 25, 24, 31, 22, 21, 19, 18, 16, 15, 12, 11, 10 e) 33, 36, 25, 25, 24, 31, 22, 21, 19, 18, 16, 15, 12, 11, 10 f) 33, 36, 25, 25, 24, 31, 22, 21, 19, 18, 16, 15, 12, 11, 10 g) 33, 36, 25, 25, 31, 24, 22, 21, 19, 18, 16, 15, 12, 11, 10 h) 33, 36, 25, 25, 31, 24, 22, 21, 19, 18, 16, 15, 12, 11, 10 i) 33, 36, 25, 25, 31, 24, 22, 21, 19, 18, 16, 15, 12, 11, 10 j) 33, 36, 25, 25, 31, 24, 22, 21, 19, 18, 16, 15, 12, 11, 10 k) 33, 36, 25, 25, 31, 24, 22, 21, 19, 18, 16, 15, 12, 11, 10 l) 33, 36, 25, 25, 31, 24, 22, 21, 19, 18, 16, 15, 12, 11, 10 m) 33, 36, 25, 25, 31, 24, 22, 21, 19, 18, 16, 15, 12, 11, 10 n) 33, 36, 25, 25, 31, 24, 22, 21, 19, 18, 16, 15, 12, 11, 10 o) 33, 36, 25, 25, 31, 24, 22, 21, 19, 18, 16, 15, 12, 11, 10 Phase 11 a) 33, 36, 25, 25, 31, 24, 22, 21, 19, 18, 16, 15, 12, 11, 10 b) 36, 33, 25, 25, 31, 24, 22, 21, 19, 18, 16, 15, 12, 11, 10 c) 36, 33, 25, 25, 31, 24, 22, 21, 19, 18, 16, 15, 12, 11, 10 d) 36, 33, 25, 31, 25, 24, 22, 21, 19, 18, 16, 15, 12, 11, 10 e) 36, 33, 25, 31, 25, 24, 22, 21, 19, 18, 16, 15, 12, 11, 10 f) 36, 33, 25, 31, 25, 24, 22, 21, 19, 18, 16, 15, 12, 11, 10 g) 36, 33, 25, 31, 25, 24, 22, 21, 19, 18, 16, 15, 12, 11, 10 h) 36, 33, 25, 31, 25, 24, 22, 21, 19, 18, 16, 15, 12, 11, 10 i) 36, 33, 25, 31, 25, 24, 22, 21, 19, 18, 16, 15, 12, 11, 10 j) 36, 33, 25, 31, 25, 24, 22, 21, 19, 18, 16, 15, 12, 11, 10 k) 36, 33, 25, 31, 25, 24, 22, 21, 19, 18, 16, 15, 12, 11, 10 l) 36, 33, 25, 31, 25, 24, 22, 21, 19, 18, 16, 15, 12, 11, 10 m) 36, 33, 25, 31, 25, 24, 22, 21, 19, 18, 16, 15, 12, 11, 10 n) 36, 33, 25, 31, 25, 24, 22, 21, 19, 18, 16, 15, 12, 11, 10 o) 36, 33, 25, 31, 25, 24, 22, 21, 19, 18, 16, 15, 12, 11, 10 Phase 12 a) 36, 33, 25, 31, 25, 24, 22, 21, 19, 18, 16, 15, 12, 11, 10 b) 36, 33, 25, 31, 25, 24, 22, 21, 19, 18, 16, 15, 12, 11, 10 c) 36, 33, 25, 31, 25, 24, 22, 21, 19, 18, 16, 15, 12, 11, 10 d) 36, 33, 31, 25, 25, 24, 22, 21, 19, 18, 16, 15, 12, 11, 10 e) 36, 33, 31, 25, 25, 24, 22, 21, 19, 18, 16, 15, 12, 11, 10 f) 36, 33, 31, 25, 25, 24, 22, 21, 19, 18, 16, 15, 12, 11, 10 g) 36, 33, 31, 25, 25, 24, 22, 21, 19, 18, 16, 15, 12, 11, 10

h) 36, 33, 31, 25, 25, 24, 22, 21, 19, 18, 16, 15, 12, 11, 10 i) 36, 33, 31, 25, 25, 24, 22, 21, 19, 18, 16, 15, 12, 11, 10 j) 36, 33, 31, 25, 25, 24, 22, 21, 19, 18, 16, 15, 12, 11, 10 k) 36, 33, 31, 25, 25, 24, 22, 21, 19, 18, 16, 15, 12, 11, 10 l) 36, 33, 31, 25, 25, 24, 22, 21, 19, 18, 16, 15, 12, 11, 10 m) 36, 33, 31, 25, 25, 24, 22, 21, 19, 18, 16, 15, 12, 11, 10 n) 36, 33, 31, 25, 25, 24, 22, 21, 19, 18, 16, 15, 12, 11, 10 o) 36, 33, 31, 25, 25, 24, 22, 21, 19, 18, 16, 15, 12, 11, 10 Therefore, the sorted list in descending order using bubble sort is : 36,33,31,25,25,24,22,21,19,18,16,15,12,11,10. Binary Tree Max-Heap QUESTION 19 (i) Depth First Search 45, 41, 37, 26, 25, 20, 35, 38, 32, 29 (ii) Breadth First Search 45, 41, 38, 37, 35, 32, 29, 26, 25, 20 QUESTION 20 A heap is a specialized tree-based data structure that satisfies the heap property. The heap property can either be the max- heap property or the min-heap property, which specifies the relationship between parent and child nodes. In a max-heap, the value of each parent node is greater than or equal to the values of its children nodes, and in a min-heap, the value of each parent node is less than or equal to the values of its children nodes. 10 (^1011) 11 (^15 12 15 ) (^21 19 181621 ) (^25 25 242225 ) 33 31 33 31 (^3636)