Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

This is a reviewer for Algorithm, Summaries of Mathematics

Definition of Algorithm, Different Sorting

Typology: Summaries

2017/2018

Uploaded on 12/03/2023

bienvenida-morco
bienvenida-morco 🇵🇭

1 document

1 / 24

Toggle sidebar

Partial preview of the text

Download This is a reviewer for Algorithm and more Summaries Mathematics in PDF only on Docsity! ALCOM REVIEWER • Practical – Web Developer, Mobile Developer, System Developer, Game Developer, Database Administrator, Networking Administrator, Penetration Tester • Theoretical – Computer Scientist, Artificial Intelligence Researcher, Mathematician, Cybersecurity Researcher Algorithmics is the study of algorithms. It is the cornerstone of computer science. • A book, named Algorithmics : the Spirit of Computing, by David Harel: • “Algorithmics is more than a branch of computer science. It is the core of computer science, and in all fairness, can be said to be relevant to most of science, business, and technology” WHAT IS AN ALGORITHM? Algorithm - Is a sequence of unambiguous instructions for solving a problem, i.e. for obtaining a required output for any legitimate input in a finite amount of time. Every algorithm development starts with a problem. 1. Problem: an inquiry starting from given conditions to investigate or demonstrate a fact, result, or law. 2. Algorithm: is a set of instructions in solving a problem 3. Computer: is a device where the algorithm is fed and follows it’s instruction 4. Input: To test the algorithm we need inputs 5. Output: Is the result of processing the inputs into the computer. Example: Create an algorithm that accepts 1 integer input and 1Boolean output. The algorithm determine whether the integer input is a odd or even number. Odd is represented by false Boolean value while even is represented by true Boolean value. Condition: No modulo operation x = integer input y = Boolean output For x >= 0 if x == 0 { y = true end program } else { y = false x = x - 2 if x < 0 { end program Example: Create an algorithm that get the GCD(Greatest common divisor) of two positive integer inputs and produce an positive integer output. Getting the GCD has many different algorithms to solve the problem: • Middle-school procedure • Consecutive integer checking • Euclid’s Algorithm Middle-school procedure • Remember the “Factor Tree” Fundamentals of algorithmic problem solving • It is very important to specify exactly the set of instances the algorithm needs to handle. This what is called an “instance”, means defining the set of inputs. ➢ The vast majority of algorithms in use today are still destined to be programmed for a computer closely resembling the von Neumann machine—a computer architecture outlined by the prominent. ➢ Hungarian-American mathematician John von Neumann (1903–1957), in collaboration with A. Burks and H. Goldstine, in 1946. There are a lots of techniques in designing algorithms. Most of our lesson will be focusing on those techniques. Here are some techniques: ➢ Exhaustive Search and Brute Force ➢ Decrease and Conquer ➢ Divide and Conquer ➢ Transform and Conquer ➢ Space and Time Trade off These are the two options that are most widely used nowadays for specifying algorithms. • Pseudocode • Flowchart Pseudocode - is a mixture of a natural language and programming language-like constructs. Flowchart - a method of expressing an algorithm by a collection of connected geometric shapes containing descriptions of the algorithm’s steps. Efficiency – we measure algorithms through mathematical formulas, which can be give us exact numbers of the algorithms efficiency. There are two kinds of algorithm efficiency: • Time Efficiency - indicating how fast the algorithm runs, a measure of amount of time for an algorithm to execute. • Space Efficiency - a measure of the amount of memory needed for an algorithm to execute. • Simplicity – It is a characteristic of an algorithms that is easily to understand, more concise and clear. And it is easy to implement to our programs. (Example GCD algorithms, Euclids, Middle-school, consecutive integer) • Generality – It is a characteristic of an algorithms that defined that an algorithms has limitation, it is identified which inputs it takes. Coding the Algorithm - The last fundamentals of algorithm problem solving --------------------------------------------------------------------------------------------------------------------- The Von Neumann Computer Architecture It looks like the graphical representation of an algorithm Random Access Memory (RAM) – is the essence of the architecture. RAM - works as the central assumption is that instructions are executed one after another one operation at a time. Algorithms that execute one after another one is called sequential algorithms. There’s also an algorithm that execute concurrent or parallel to one another. This is what you called a parallel algorithms. RAM follow the concept of instruction tables in which the algorithm is executed. To demonstrate how algorithms are translated into assembly, or we can use instruction table to represent in the Von Neumann Architecture. 0x00001 0x00002 0x00003 Closest-pair problem is finding the closest pair among n points. Convex-hull problem is finding the smallest convex polygon that would include all the points of a given set. Numerical problems are problems that involve mathematical objects of continuous nature: solving equations and systems of equations, computing definite integrals, evaluating function and so on. Fundamentals of data structures • Data structures plays a critical role in design and analysis of algorithms. • Data structures tells how the data are organized in the memory. • Data structure can be defined as a particular scheme of organizing related data items. There are different kinds of data structure: • Linear Data Structure • Graph • Trees Linear Data Structure – is a data structure that the data are aligned in linear to the memory. There two most important linear data structure: • Arrays is a sequence of n items of the same data type that are stored contiguously in computer memory and made accessible by specifying a value of the array’s index. • Arrays is a well-known data structure since this one of the basic foundation of learning programming. • Linked list is a sequence of zero or more elements called nodes, each containing two kinds of information: some data and one or more links called pointers to other nodes of the linked list. • Linked List – are different in memory in the RAM. It uses pointers to direct the next memory address it follows. There are two type of linked list: singly linked list and doubly linked list. • Singly Linked List - each node, except the last one, contains a single pointer to the next element. • Doubly Linked List - in which every node, except the first and the last, contains pointers to both its successor and its predecessor Graphs Informal Definition : a collection of points in the plane called “vertices” or “nodes,” some of them connected by line segments called “edges” or “arcs.” Formal Definition : a graph G=〈V,E〉is defined by a pair of two sets: a finite non empty set V of items called vertices and a set E of pairs of these items called edges. Trees tree is an undirected graph in which any two vertices are connected by exactly one path, or equivalently a connected acyclic undirected graph. --------------------------------------------------------------------------------------------------------------------- Definition of analysis Analysis is breaking an information into different parts for individual study and examination. In algorithm’s analysis, there are two important parts: • Memory space (How much space does it need?) • Time consumption (How long does it take to provide an output?) There’s a framework, we will be using in analyzing an algorithms. The Analysis Framework In analysis framework, there are two kinds of efficiency we conduct when we analyze an algorithms. Time Complexity – indicates how fast an algorithm in question runs. Space Complexity – refers to the amount of memory units required by the algorithm in addition to the space needed for it’s input and output. - During half century, time and space are regards as premium stuffs in a computer system. Since they play vital role in solving computational problems. 1GB = 1000MB Computer scientists rather than depending on time unit when measuring time complexity, they use operation counting. It is number of operation executed on an algorithm. What operators the algorithms consumed: • Arithmetic Operator (+, -, /, *, mod) • Comparison Operator (==, !=) • Logical Operators (&&, ||) • Equality Operator (=) • We represent time complexity by using the function as of t(n) Formally: 𝑡(𝑛) = 𝐶𝑜𝑝𝐶(𝑛) 𝐶𝑜𝑝 = Computer capability (number of operation / time unit) 𝐶(𝑛) = Counting function Using counting function: 𝐶(𝑛) Problem: How much longer an algorithm runs if the number of input is doubled? If our number of operation is 2𝑛 (𝑛 − 1), while our computer runs at 1. First we need to find our 𝐶(𝑛), which is 2𝑛 (𝑛 − 1), unfortunately we need to simplify it first. 𝐶(𝑛) = 2𝑛 (𝑛 − 1) 𝐶(𝑛) = 2𝑛2 − 2𝑛 Problem: How much longer an algorithm runs if the number of input is doubled? If our number of operation is 2𝑛 (𝑛 − 1), while our computer runs at 1. 𝐶(𝑛) = 2𝑛2 − 2𝑛 𝐶𝑜𝑝 = 1 Now our problem is asking how much longer an algorithm runs if the number of input is double? Which means we need to compare two algorithm, one that runs if the input is doubled and one that runs if the input is not doubled. Which can be represented: Two parts in the analysis framework: First, we use the Input’s Size to determine how much space and time the algorithm will consume. Second, Operation Counting, we determined how many operations that the algorithm will execute, since using time unit is not efficient! Now lastly, the Order of Growth Order of Growth - is determining the algorithm’s operation count as input goes larger and larger until infinity. It is also a way of computer scientist in categorize where the growth of algorithms grows. Order of Growth: Basic asymptotic efficiency classes: Algorithms running at logarithmic time runs at when the algorithm total operation count gets smaller by dividing them to halves. Example: Binary Tree search algorithms 1 constant log 𝑛 logarithmic 𝑛 linear 𝑛 log 𝑛 linearithmic 𝑛2 quadratic 𝑛3 cubic 2𝑛 exponential 𝑛! factorial SEICIEIES CICIESEIED Bor min value at index 2 min value at index 2 min value at index 2 IEEE min value at index 2 min value at index 2 Code: class SelectionSort { void selectionSort(int array[]) { int size = array.length; for (int step = 0; step < size - 1; step++) { int min_idx = step; for (int i = step + 1; i < size; i++) { if (array[i] < array[min_idx]) { min_idx = i; } } int temp = array[step]; array[step] = array[min_idx]; array[min_idx] = temp; } } public static void main(String args[]) { int[] data = { 20, 12, 10, 15, 2 }; SelectionSort ss = new SelectionSort(); ss.selectionSort(data); System.out.println("Sorted Array in Ascending Order: "); System.out.println(Arrays.toString(data)); } Bubble sort - Brute-force application to the sorting problem is to compare adjacent elements of the list and exchange them if they are out of order. - By doing it repeatedly, we end up “bubbling up” the largest element to the last position on the list. - The next pass bubbles up the second largest element, and so on, until after n − 1 passes the list is sorted. Bubble sort - is an algorithm that compares the adjacent elements and swaps their positions if they are not in the intended order. The order can be ascending or descending.