Uploaded by MARK JOSEPH GULMATICO

COSC90 Reviewer

advertisement
Types of Sorting
Sorting - arranging records in a particular order
1. Bubble Sort: algorithm known for its sorting method that repeatedly steps through
the list, compares adjacent elements, and swaps them if they are in the wrong
order.
- Algorithm that repeatedly selects the minimum element from an unsorted region
and swaps it with the first element of the unsorted region.
2. Merge Sort: sorting algorithm that has an average and worst-case time complexity
of O(n log n) and is based on the divide-and-conquer strategy.
- A divide-and-conquer algorithm that selects a pivot element, partitions the
array into two sub-arrays, and recursively sorts the sub-arrays
3. Insertion Sort: an algorithm is known for its efficiency in sorting small data
sets and is an in-place, comparison- based sorting algorithm.
- A divide-and-conquer algorithm that divides the array into two halves,
recursively sorts them, and then merges the sorted halves
4. Selection Sort: a sorting algorithm repeatedly selects the maximum element and
puts it at the end of the list in each iteration.
- An algorithm that builds a sorted array one element at a time by inserting each
element into its correct position within the sorted region
5. Quick Sort: A non-linear data structure that organizes data in a hierarchical
structure.
Types of Searching
1. Binary Search: a searching algorithm works by repeatedly dividing the search range
in half.
- requires the array to be sorted in order to efficiently search for an element
by repeatedly dividing the search interval in half.
2. Linear Search: a simple search algorithm that sequentially checks each element of
the list until it finds the desired element.
Two-Algorithm Complexity Analysis


Time Complexity - measures how the running time of an algorithm grows with the
size of the input
Space Complexity - refers to the memory requirements of an algorithm as a function
of the input size
Algorithm Techniques
1. Divide and Conquer - Makes locally optimal choices at each step to find an overall
optimal solution.
- a type of algorithmic paradigm involves breaking down a problem into smaller
subproblems, solving each subproblem, and combining the solutions.
2. Greedy Algorithm - makes locally optimal choices at each step in the hope that
the overall solution will be globally optimal
3. Dynamic Programming - Efficiently solves problems by breaking them into simpler
subproblems and storing results to avoid redundant computations.
4. Backtracking - Systematically searches for a solution by exploring all possible
paths and backtracking when necessary
5. Branch and Bound - Systematically searches for an optimal solution by exploring
the entire search space and pruning branches using bounding functions
Data Structures
- a way of organizing and storing data to perform operations efficiently.
- defines a particular way of organizing and storing data efficiently
1. Linear
a. Arrays: A contiguous block of memory elements, each element is identified
by an array index.
b. Linked Lists: Elements are stored in nodes, each node pointing to the next
node in the sequence.
c. Stacks: A Last In, First Out (LIFO) data structure where elements are
inserted and removed from the same end.
d. Queues: A First In, First Out (FIFO) data structure where elements are
inserted at the rear and removed from the front.
2. Non-Linear
a. Trees: Hierarchical data structures with a root node and subtrees of children
nodes.
 Trie (Prefix Tree): A trie, also known as a prefix tree, is a treelike data structure used to store a dynamic set of strings where the
keys are usually strings.
 Segment Tree: This is a tree data structure used for storing intervals
or segments of data. It allows querying and updating the segments
efficiently, often used in problems involving range queries and
updates.
 Fenwick Tree (Binary Indexed Tree): A Fenwick tree, or binary indexed
tree, is a data structure that supports efficient prefix sum queries
and updates over an array of numbers.
 B-trees and B+ trees: These are self-balancing tree data structures
that maintain sorted data and are commonly used in databases and file
systems for efficient insertion, deletion, and searching operations.
b. Graphs: A collection of nodes (vertices) and edges that connect pairs of
nodes.
c. Hash Tables: A data structure that implements an associative array abstract
data type, where keys are mapped to values.
d. Heaps: A specialized tree-based data structure that satisfies the heap
property.
Types of Data Structures


Primitive data structures: These are basic data structures that directly operate
upon the machine instructions.
Abstract data structures: These are high-level data structures that model realworld entities and operations.
Five Characteristics of an Algorithm



Finiteness: An algorithm must terminate after a finite number of steps.
Definiteness: Each step of the algorithm must be precisely defined.
Input: An algorithm should have zero or more inputs.


Output: An algorithm should produce one or more outputs.
Effectiveness: Every step in an algorithm should be doable using basic operations.
Three Types of Asymptotic Notations
Asymptotic Notations - Used to describe how a function behaves as its input approaches
infinity
1. Big O notation (O): It provides an upper bound on the growth rate of a function.
2. Omega notation (Ω): It provides a lower bound on the growth rate of a function.
3. Theta notation (Θ): It provides both upper and lower bounds, indicating tight
bounds on the growth rate of a function.
Graph Traversal Algorithms
Used to systematically visit every vertex and edge in a graph, typically starting from
a specified vertex.
1. DFS does not necessarily find the shortest path in a graph. It explores as far as
possible along each branch before backtracking.
2. BFS uses a queue data structure for traversal, not a stack. This ensures that
nodes are visited in the order of their distance from the starting node.
Terms












Algorithm: It is a step-by-step procedure or a set of rules designed for solving
a specific problem or accomplishing a particular task.
Linked List: represents each element of a data object in a cell or node
Arrays: a collection of elements, each identified by an index or a key
Recursion: a programming technique that involves a function calling itself to
solve smaller instances of the same problem
Iteration: process of repeating a set of instructions or steps in a systematic
way
Algorithm Complexity: concerned with evaluating an algorithm's performance about
the size of the input data it processes
Brute Force: method that exhaustively searches through all possible solutions and
selects the one that satisfies the problem constraints
Randomized Algorithm: Used to implement an algorithm that offers a degree of
unpredictability while ensuring good performance
Graph Algorithms: for solving problems related to graphs
Network Flow Algorithms: used to address issues concerning flow in networks, such
as identifying maximum flow or minimum cut
Worse- case Complexity: to determine the maximum amount of resources an algorithm
requires for any input of a given size
Average - case Complexity: discusses the average amount of resources an algorithm
necessitates over all possible inputs of a given size
Download