CSC 210 Exam: Algorithms & Complexity
CSC 210 Exam: Algorithms & Complexity
Heap sort has a worst-case, average-case, and best-case time complexity of O(n log n). This consistency across different cases is due to the nature of the heap data structure, which maintains an efficient logarithmic time complexity during sorting operations .
A good algorithm is one that is correct, efficient (with optimal time and space complexity), well-defined, maintainable, and scalable. These criteria ensure that an algorithm is reliable, executes efficiently across varying inputs, and can be adapted or improved as needed .
A mini-Heap and a max-Heap differ in their priority of element arrangement. In a mini-Heap, the smallest element has the highest priority and is root, whereas in a max-Heap, the largest element is the root. Both maintain heap properties to facilitate efficient retrieval .
Sequential search offers advantages in scenarios where data is unsorted or when no index is available. Its advantages include simplicity, no additional storage requirement, and suitability for small datasets where its linear nature is less of a drawback .
A sorting algorithm arranges data in a particular order, either ascending or descending. Examples include quicksort, mergesort, and heapsort, used in scenarios like organizing data for efficient searches and simplifying data manipulations .
The complexity of an algorithm refers to the computational resources required for running it, primarily time and space. It is crucial for assessing an algorithm's efficiency, predicting performance, and identifying bottlenecks in resource usage .
An algorithm is defined by characteristics including finiteness, definiteness, input, output, and effectiveness. These properties ensure the algorithm completes after a finite number of steps, is clearly defined, can receive inputs and produce outputs, and is feasible for practical execution .
Linear probing handles collisions by placing the collided element in the next available slot in the hash table. When a hash collision occurs, the algorithm checks subsequent indices sequentially until an open spot is found .
The two essential properties of asymptotic notations are transitivity and non-negativity. Transitivity helps in simplifying complexity expressions, while non-negativity ensures that asymptotic comparisons remain meaningful and valid .
The primary operations in hash tables are insertion, deletion, and searching. Insertion involves adding a key-value pair, deletion removes the pair, and searching retrieves a value using the key. These operations depend on the hash function to compute the index in the table .