CS 31 MIDTERM/SEMI FINAL EXAM
Fundamentals of Divide & Conquer: Stopping Condition
- Break the problem using divide and conquer strategy - Ensuring it doesn't run indefinitely.
Sorting Techniques: Merge Sorting
- Combining two sorted lists into one-sorted lists. - Splits the array to be sorted into two equal halves and each array is recursively sorted, then merged back together to form the final sorted array.
Sorting Techniques: Bubble Sorting
- Consecutive adjacent pairs of elements in the array are compared with each other. - Comparing and swapping adjacent elements until the largest element "bubbles" to the end.
Two Types of Sorting: External Sorting
- Data is to be sorted cannot be accommodated in the memory at the same time and some has to be kept in the auxiliary memory.
Advantages of Algorithm
- Easy to understand - Step-wise representation of a solution. - Broken down into smaller or pieces
Sorting Techniques: Selection Sorting
- First finds the smallest element in the array and exchanges I will the element in the first position, then finds the second smallest element and exchange it with the element in the second position, and continues in this way until the array is sorted.
Fundamentals of Divide & Conquer: Relational Formula
- Generate from the given technique. - Involving comparisons or logical operations.
Two Types of Sorting: Internal Sorting
- If all the data that is to be sorted can be adjusted at a time in the main memory.
Sequence of four steps: Divide, Sub-Problems
- Main problems are divided into several smaller sub problems.
Applications of Divide & Conquer: Quick Sort
- Most efficient sorting algorithm, also known as partition- exchange sort. - Starts by selecting pivot value from an array followed by dividing the rest of the array elements into two sub-arrays.
Disadvantage
- Necessitates high memory management. - An explicit stack may overuse the space. - May even crash the system.
Applications of Divide & Conquer: Binary Search
- Searching algorithm also called half-interval search or logarithmic search - Works by comparing the target value with the middle element existing in a sorted array.
Dynamic Programming
- Similar to divide-and-conquer technique. - Applicable when the sub-problems are not independent, that is, when sub-problems share sub-problems. - Solves every sub-problem just once and then saves its answer in a table.
Sequence of four steps: Table, Storage
- Solution for each sub-problem is stored in a table, so that it can be used many times whenever required.
Sequence of four steps: Combine, Bottom-Up Computations
- Solutions to main problem is obtained by combing the solutions of smaller sub-problems.
Applications of Divide & Conquer: Merge Sort
- Sorting algorithm that sorts an array by making comparisons. - By dividing an array into sub-array and then recursively sorts each of them. - After the sorting is done, it merges them back.
Advantage
- Successfully solve one of the biggest problems. - Lessened the effort as it works on dividing the main problem into two halves. - Efficiently uses cache memory without occupying much space
Disadvantages of Algorithm
- Takes a long time, it is time-consuming. - Branching and Looping statements are difficult to show in algorithm.
Sequence of four steps: Construct an Optimal Solution
- This step is optional - Required in case if some additional information is required after finding out optimal solution.
Backtracking
- Trying out different sequences of decision until we find one that "works".
Application of Sorting
- Useful in database application for arranging the data in desired order. - Application the data is arranged in sorted order. - Searching the element from the list of elements. - Checking the uniqueness of the element. - Finding the closet pair from the list of elements.
Dynamic Programming Approach
- Various algorithms which make use of Dynamic Programming techniques: o Knapsack Problem o Chain Matrix Multiplication o All pair shortest path o Traveling sales man problem o Tower of Hanoi o Checker Board o Fibonacci Sequence o Assembly Line Scheduling o Optimal Binary Search Trees
Sorting Techniques: Insertion Sorting
- Very simple sorting algorithm in which the sorted array or list is built one element at a time. - Building the sorted list one element at a time by repeatedly taking an unsorted element and inserting it into its correct position.
Algorithms must follow a standard, the mathematical notations use symbols or symbolic expressions, which have a precise semantic meaning.
Mathematical Notation
Lists of two sorted data items can be combined.
Merging
In the real world, programs evolve as a result of new requirements or constraints, so a modification to a program commonly requires a change in one or more of its data structure.
ADVANTAGE OF USING ADT'S
It is a collection of data items together with the operations on the data. An organization of information, usually in the memory, for better algorithm efficiency.
Abstract Data Type
Step-by-step procedure, which defines a set of instruction to be executed in a certain order to get the desired output.
Algorithm
is the process of evaluating and understanding the efficiency and performance characteristics of algorithms. It involves studying how an algorithm behaves in terms of time and space.
Algorithm Analysis
is like measuring how fast a computer program runs or how much memory it needs, depending on how much stuff you're asking it to work on.
Algorithm Complexity
are systematic approaches or strategies used to develop step-by-step instructions.
Algorithm Design Technique
Introduction to Sorting
Arranging the data in ascending or descending order. It is very important from the point of view of our practical life.
- Way to describe how the running time or space requirements of an algorithm.
Asymptotic Notations
Approach to Design an Algorithm: - Starts with designing most basic or primitive components and proceeds to higher level components. - Starting from very bottom, operations that provide layer of abstraction are implemented.
Bottom-Up Approach
- Also known Performance Measurement - Measuring the algorithm's real-world performance, considering all the practical variables.
Characteristics of Algorithm Posterior Analysis
- Also known Performance or Asymptotic Analysis. - Efficiency of an algorithm is measured by assuming that all other factors. - Often focusing on theoretical considerations.
Characteristics of Algorithm Prior Analysis
Characteristics of an Algorithm: Each of its step should be clear in all aspects and must lead to only one meaning
Clear and Unambiguous
Divide and Conquer Approach- Final step, solution obtained by the sub-problems are combined to create.
Combine
Divide and Conquer Approach- Solving them recursively.
Conquer
- Conditions or rules that limit the possible solutions at each step
Constraints
Important Categories of Algorithm that Delete an existing item
Delete
Remove or delete a particular data item from the given collection of data items.
Deleting
Divide and Conquer Approach- Whole problem divided into several sub-problems.
Divide
- Works on breaking the problem into sub-problems.
Divide and Conquer
- Restrict each vector element to be chosen from the set.
Explicit Constraint
Characteristics of an Algorithm: - Simple, generic, and practical, such that it can be executed upon will the available resources.
Feasible
Characteristics of an Algorithm: The algorithm must be finite, i.e. it should not end up in an infinite loops or similar
Finite-ness
Important Categories of Algorithm that Insert item in a data structure
Insert
Add new data items to given list of data items.
Inserting
Characteristics of an Algorithm: It must be just plain instructions that can be implemented in any language.
Language Independent
Data structure operations are the methods used to manipulate the data.
Operations on Data Structure
- Determine which each of the tuples in the solution space.
Quick Sort
Important Categories of Algorithm that Search and item in a data structure
Search
Find the location of one or more data items.
Searching
Important Categories of Algorithm that Sort items in a certain order
Sort
Data items can be arranged in some order.
Sorting
Types of Complexity in Algorithm- Represents the amount of memory space required by the algorithm in its life cycle.
Storage Complexity
Factors in Algorithm- Measured by counting the maximum memory space require by the algorithm.
Storage Factor
Types of Complexity in Algorithm- Represents the amount of time required by the algorithm to run to completion.
Time Complexity
Factors in Algorithm- Measured by counting the number of key operations.
Time Factor
Approach to Design an Algorithm: - Stats with identifying major components of system or program decomposing them into their low-level components. Start with topmost module and incrementally add modules that is calls
Top-Down Approach
Access each data item exactly once.
Traversing
- Provides necessary information about an algorithm's behavior on a typical or random input.
Types of Analysis: Average Case Analysis
- If an algorithm takes the least amount of time to execute. - The algorithm runs the fastest among all the possible inputs of the same size.
Types of Analysis: Best Case Analysis
- Takes maximum amount of time to execute. - The algorithm runs the longest among all the possible inputs of the same size.
Types of Analysis: Worst Case Analysis
Important Categories of Algorithm that Update and existing item
Update
Characteristics of an Algorithm: - Clearly define what output will be yielded and it should be well-defined inputs
Well-Defined Input
Characteristics of an Algorithm: Clearly define what output will be yielded and it should be well-defined as well
Well-Defined Output
Omega Notation
n= 2 f(n) = 2n2 + 5 = 2(2)2 + 5 = 13 g(n) = 7(n) = 7(2) = 14 here, f(n) < g(n)
Theta Notation
n= 3 f(n) = 4n + 3 = 4(3) + 3 = 15 g(n) = 4n = 4(3) = 12 and f(n)= 4n + 3 = 4(3) + 3 = 15 g(n)= 5n = 5(3) = 15 and here, c 1 is 4, c 2 is 5 and n0 is 3
Big - O Notation
n=1 f(n) = 2(n) + 2 = 2(1) + 2 = 4 g(n) = n² = 1² = 1 here, f(n) > g(n)
Principles of Optimality
o Solving the master problem optimally o It should be noted that not all times each sub-problem(s) is solved optimally
Polynomial Breakup
o The total number of sub-problems to be solved should be at-most a polynomial number.