Uploaded by MARK JOSEPH GULMATICO

Design and Analysis of Algorithm-Reviewer

advertisement
Design and Analysis of Algorithm –Midterm Reviewer
Bubble Sort: an 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.
Divide and Conquer: a type of algorithmic paradigm involves breaking down a problem into
smaller subproblems, solving each subproblem, and combining the solutions.
Merge Sort: a sorting algorithm has an average and worst-case time complexity of O(n log n)
and is based on the divide-and-conquer strategy.
Binary Search: a searching algorithm works by repeatedly dividing the search range in half.
Recursion: an algorithmic approach involves solving a problem by solving smaller instances of
the same problem and combining their solutions
Stack: a data structure operates on a Last In, First Out (LIFO) principle.
Insertion Sort: an algorithm is known for its efficiency in sorting small data sets and is an inplace, comparison- based sorting algorithm
selection sort: a sorting algorithm repeatedly selects the maximum element and puts it at the
end of the list in each iteration
algorithm: It is a step-by-step procedure or a set of rules designed for solving a specific
problem or accomplishing a particular task.
data structure: It is a way of organizing and storing data to perform operations efficiently.
❖ Linear search is a simple search algorithm that sequentially checks each element of the list
until it finds the desired element.
❖ Binary search requires the array to be sorted in order to efficiently search for an element by
repeatedly dividing the search interval in half.
❖ DFS does not necessarily find the shortest path in a graph. It explores as far as possible along
each branch before backtracking.
❖ 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.
❖ Graph traversal algorithms, such as DFS and BFS, are used to systematically visit every
vertex and edge in a graph, typically starting from a specified vertex.
❖ When evaluating an algorithm's performance about the size of the input data it processes,
which concept are you primarily concerned with?
Algorithm Complexity
❖ Which concept measures how the running time of an algorithm grows with the size of the
input?
Time Complexity
❖ What term refers to the memory requirements of an algorithm as a function of the input
size?
Space Complexity
❖ Which term describes step-by-step procedures or formulas for solving problems?
Algorithms
❖ What programming technique involves a function calling itself to solve smaller instances
of the same problem?
Recursion
❖ Which strategy involves breaking a problem into smaller subproblems, solving them
independently, and then combining their solutions to solve the original problem?
Divide and Conquer
❖ Which approach makes locally optimal choices at each step in the hope that the overall
solution will be globally optimal?
Greedy Algorithm
❖ What technique breaks a problem into overlapping subproblems, solves each subproblem
only once, and stores the solutions to subproblems in a table to avoid redundant
computations?
dynamic programming
❖ Which method exhaustively searches through all possible solutions and selects the one
that satisfies the problem constraints?
Brute Force
❖ What approach systematically searches through all possible solutions by making choices
and backtracking when a choice leads to a dead end?
Backtracking
❖ In a scenario where you want to implement an algorithm that offers a degree of
unpredictability while ensuring good performance, which option would you most likely
consider?
Randomized Algorithm
❖ You're tasked with solving problems related to graphs. Which type of algorithm would you
choose for this purpose?
Graph Algorithms
❖ Imagine you need to address issues concerning flow in networks, such as identifying
maximum flow or minimum cut. Which algorithm category would you explore?
Network Flow Algorithms
❖ When describing how a function behaves as its input approaches infinity, which notation
would you use?
Asymptotic Notation
❖ In determining the maximum amount of resources an algorithm requires for any input of a
given size, what complexity concept would you examine?
Worse- case Complexity
❖ When discussing the average amount of resources an algorithm necessitates over all
possible inputs of a given size, which complexity term would you refer to?
Average - case Complexity
❖ In a system where elements can only be inserted or deleted at one end, what data
structure would you employ?
Stack
❖ If you need a structure where items are inserted at one end and deleted at the other, what
type of list would you utilize?
Queues
❖ When representing each element of a data object in a cell or node, what list structure
would you use?
Linked List
❖ In the context of arranging records in a particular order, what process would you employ?
Sorting
❖ Which sorting algorithm compares adjacent elements and swaps them if they're in the
wrong order?
Bubble sort
❖ What algorithm repeatedly selects the minimum element from an unsorted region and
swaps it with the first element of the unsorted region?
Selection sort
❖ Which algorithm builds a sorted array one element at a time by inserting each element
into its correct position within the sorted region?
Insertion sort
❖ Which divide-and-conquer algorithm divides the array into two halves, recursively sorts
them, and then merges the sorted halves?
Merge sort
❖ Which divide-and-conquer algorithm selects a pivot element, partitions the array into two
sub-arrays, and recursively sorts the sub-arrays?
Quick sort
❖ What non-linear data structure organizes data in a hierarchical structure?
Trees
❖ Which search algorithm finds the position of a target value within a sorted array or list?
Binary Search
❖ What term defines a particular way of organizing and storing data efficiently?
Data structure
❖ What is a collection of elements, each identified by an index or a key?
Arrays
❖ What term refers to the process of repeating a set of instructions or steps in a systematic
way?
Iteration
Arrays and dynamic arrays:
❖ Question: Dynamic arrays have a fixed size that cannot be changed after initialization.
Answer: False
Linked lists (Singly, Doubly, Circular):
❖ Question: In a singly linked list, each node contains a reference to both the next and previous
nodes.
Answer: False
Stacks and Queues:
❖ Question: Stacks follow the First In, First Out (FIFO) principle.
Answer: False
Trees (Binary, Binary Search, AVL):
❖ Question: In a binary search tree, the left child of a node contains a value less than or equal
to the node's value.
Answer: True
Hash tables and Hash maps:
❖ Question: Hash tables use a collision resolution technique to handle cases where multiple
keys hash to the same index.
Answer: True
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.
Two types of data structure
●
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 real-world
entities and operations.
Four popular linear data structures
●
Arrays: A contiguous block of memory elements, each element is identified by an array
index.
●
Linked Lists: Elements are stored in nodes, each node pointing to the next node in the
sequence.
●
Stacks: A Last In, First Out (LIFO) data structure where elements are inserted and
removed from the same end.
●
Queues: A First In, First Out (FIFO) data structure where elements are inserted at the rear
and removed from the front.
Three types of Asymptotic notations
●
Big O notation (O): It provides an upper bound on the growth rate of a function.
●
Omega notation (Ω): It provides a lower bound on the growth rate of a function.
●
Theta notation (Θ): It provides both upper and lower bounds, indicating tight bounds on
the growth rate of a function.
Four Non-Linear data structures
●
Trees: Hierarchical data structures with a root node and subtrees of children nodes.
●
Graphs: A collection of nodes (vertices) and edges that connect pairs of nodes.
●
Hash Tables: A data structure that implements an associative array abstract data type,
where keys are mapped to values.
●
Heaps: A specialized tree-based data structure that satisfies the heap property.
Two-Algorithm Complexity Analysis
●
Time Complexity: It measures the amount of time an algorithm takes to run as a function
of the length of the input.
●
Space Complexity: It measures the amount of memory space an algorithm requires as a
function of the length of the input.
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.
Disjoint Set/Union Find: This is a data structure used to keep track of a set of elements
partitioned into a number of disjoint (non-overlapping) subsets. It supports two main operations:
finding which set a particular element belongs to and merging two sets.
Trie (Prefix Tree): A trie, also known as a prefix tree, is a tree-like data structure used to store
a dynamic set of strings where the keys are usually strings. It supports efficient prefix-based
searching and insertion operations.
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. It's
particularly useful when dealing with cumulative frequency tables.
Suffix Array and Suffix Tree: These are data structures used for efficiently storing and
querying the suffixes of a string. Suffix arrays are arrays of the starting positions of suffixes
sorted lexicographically, while suffix trees are trees that represent all suffixes of a string in a
compressed form.
Divide and Conquer: Breaks a problem into smaller subproblems, solves them recursively, and
combines their solutions.
Greedy Algorithms: Makes locally optimal choices at each step to find an overall optimal
solution.
Dynamic Programming: Efficiently solves problems by breaking them into simpler
subproblems and storing results to avoid redundant computations.
Backtracking: Systematically searches for a solution by exploring all possible paths and
backtracking when necessary.
Branch and Bound: Systematically searches for an optimal solution by exploring the entire
search space and pruning branches using bounding functions.
using System;
class Program
{
static void Main(string[] args)
{
int[] numbers = { 10, 5, 20, 8, 15 };
// Initialize max and min with the first element of the array
int max = numbers[0];
int min = numbers[0];
// Loop through the array to find the maximum and minimum values
foreach (int num in numbers)
{
if (num > max)
{
max = num; // Update max if current number is greater
}
if (num < min)
{
min = num; // Update min if current number is smaller
}
}
Console.WriteLine("Maximum value: " + max);
Console.WriteLine("Minimum value: " + min);
}
}
using System;
using System.Collections.Generic;
class Program
{
static void Main(string[] args)
{
int[] arr = { 2, 4, 5, 6, 7, 4, 8, 10, 8, 10 };
// Create a HashSet to store unique elements
HashSet<int> set = new HashSet<int>();
// Iterate through the array
foreach (int num in arr)
{
// If the element is already in the set, it's a duplicate
if (!set.Add(num))
{
Console.WriteLine("Duplicate number found: " + num);
break; // If you want to find multiple duplicates, remove this break statement
}
}
}
}
Download