Free Essay

Algorithm

In:

Submitted By zhangiou0
Words 726
Pages 3
Design and Analysis of Computer Algorithm Assignment 2
Name: Boyu Zhang UTD-ID: 2021226566 Email:bxz140830@utdallas.edu

Contents
Problem 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 Problem 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2

Problem 3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

Problem 4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

Problem 5 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

Problem 6 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8

Problem 7 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

Problem 8 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .11

Problem1 This problem can solution by Dial’s algorithm in the lesson six. We can set up W+2 buckets with the labels of 0, 1, …, W, . Then we carry out the following steps: (a). Initial the buckets with node S be in the bucket 0 and all other nodes be in the bucket . (b). then select the node with the minimum temporary distance label. For the first time, it should be the source node S in the bucket 0. (c). Update the buckets information. Then some node should be moved from the bucket  to the corresponding distance bucket. (d). Remove the selected node from the bucket. Then repeat step 2 and 3 until there is no non-empty bucket. Therefore we can compute the shortest paths from source vertexs in O(W|V|+|E|). Because the extract part’s step during the Dijkstra's algorithm takes O(W|V|) time while the decreasing operation still takes O(E) time.

Problem 2 Bottleneck Path Problem algorithm for directed graphs

2

1: INPUT: A directed graph G = (V, E) with m = |E| and edge weights de ∈D for all edge e∈E, source and target vertices s, t ∈V , a number s(m); 2: Initialize i ← 0, E’ ← E, L ← mine∈E de, U = maxe∈E de 3: while i < log s(m) do 4: Determine the median M of {de : e∈E’, de≤U}. 5: T := {e∈E’: de≤M}, F := {e∈E’: de > M} 6: if (V, F) is s–t–connected then 7: E’ ← F, L ← M 8: else 9: E’ ← T, U ← M 10: end if 11: i ← i + 1 12: end while 13: Number the t edges in {e∈E’: de ≤U} according to increasing weights: e1, . . . , et 14: Solve the instance: l(e) =1 if de≤L, or i + 1 if e∈E’, e = ei or t + 2 if ce > U The running time of this algorithm depends on some function s(w), where lines 12 altogether need O(mlog s(m)) steps. As the number of edges in E’

3

with weights at most U is halved in each iteration, we have t = O( m/s(m) ). Thus, if we sort D keys in O(D logD) time, the running time spent in line 13 is O( m/s(m)* log m/s(m) ). Line 14 thus needs O(m) steps. By setting s(m) = logm we obtain an O(mlog logm) algorithm for this problem in directed graphs.

Problem 3 Because in the Faster-All-Pairs-Shortest-Paths, according the lemma 25.2

the multiplication of matrices has already been redefined, then Lk denote the matrix with elements lkij which is the length of the shortest path with at most k edges from i to j. It is obvious that if there is negative-weight cycle in the graph, for example wkj is negative-weight ,so the lki+ wkj always is decrease, the matrix of Ln − 1 and all the matrices with the index greater than n − 1 should be the decrease. So according to this, we can use several ways to check whether there is a negative-weight cycle in the graph,

4

1. Compute Ln, Ln +1. If they are not equal, then there is a negative-weight cycle in the graph. 2. Compute Ln, L 2n. If they are not equal, then there is a negative-weight cycle in the graph.

Problem4

This problem has an optimal structure: The total cost of one labeled tree could always be calculated by the sum cost of the two sub-trees and an additional backup. Using m[i,j] to denote the lowest cost of a subtree with leaves vi, … , vj (i +1 ≤ j). It may seem strange that m[i,i]= 0, contradicts with the fact that one leave i still costs .However, here we only compute about a labeled tree, who has more than one leaf, this definition would keep all the m[i,j] correct (j >= i+1). m[i, j] 0 — —j =i m[i, j] = ai +aj — — j= i +1 m[ i,j ]= mini

Similar Documents

Free Essay

Kolmogorov Algorithm

...CSC 435 DESIGN AND ANALYSIS OF ALGORITHM GROUP THREE(3) ASSIGNMENT THE KOLMOGOROV COMPLEXITY ALGORITHM Computer Science: FMS/0704/11 FMS/0707/11 FMS/0720/11 FMS/0721/11 FMS/0728/11 Computing-with-Accounting: FMS/0818/11 FMS/0643/11 FMS/0749/11 FMS/0722/11 FMS/0729/11 FMS/0741/11 FMS/0829/11 FMS/0784/11 FMS/0812/11 FMS/0652/11 Kolmogorov complexity In algorithmic information theory (a subfield of computer science and mathematics), the Kolmogorov complexity (also known as descriptive complexity, Kolmogorov–Chaitin complexity, algorithmic entropy, or program-size complexity) of an object, such as a piece of text, is a measure of the computability resources needed to specify the object. It is named after Andrey Kolmogorov, who first published on the subject in 1963. For example, consider the following two strings of 32 lowercase letters and digits: abababababababababababababababab 4c1j5b2p0cv4w1x8rx2y39umgw5q85s7 The first string has a short English-language description, namely "ab 16 times", which consists of 11 characters. The second one has no obvious simple description (using the same character set) other than writing down the string itself, which has 32 characters. More formally, the complexity of a string is the length of the shortest possible description of the string in some fixed universal description language (the sensitivity of complexity relative to the choice of description language is discussed below)...

Words: 3373 - Pages: 14

Free Essay

382 Algorithms

...CSC 382, Analysis of Algorithms Group Project For this project you need to make groups of 3-6 people and choose one of the following topics. Most of these topics require you to write a short paper and present it in class (20 points). For those you have the option to just submit a paper and not present for only 10 points. A list of topics: 1. Linear Programming 2. Approximation Algorithms 3. Max-Flow Min-Cut 4. Cryptography: Asymmetric Encryption 5. Complexity Theory 6. Programming Project: Implementing Algorithms, Comparing Running times (10 points, no presentation) For some topics you can find information in the course textbooks (and other textbooks). For the rest, you must research on your own - but I am willing to give suggestions if I have any. You may suggest another topic as well, but I need to approve it. Requirements Each paper is expected to be 3-5 pages long (single-spaced and at 11pt) and it should include references to your sources (which should be more than just Wikipedia). As long as the paper is complete and well-written, the length requirements should not be too important. However, more than 5 pages would be an overkill and less than 3 might not let you give the necessary information and explanations. As for the actual contents of the paper, you should address your classmates, who will receive a copy of the paper in class and before your presentation. You should explain the topic you have selected and give an appropriate 1 2 example. The specifics may differ...

Words: 796 - Pages: 4

Free Essay

Algorithm and Psuedocode

...short answers 5 & 6 pg.71 5. what two things must you normlally specify in a varaible declaration? the variable's name and the varaible data type 6. what value is stored in uninitalized varaibles? unpredictables values algorithm workbench questions 3- 10 3.statements that perform the following operations with the variables a.set b=2+ a b.set a = b*4 c. set b = 3/14/b d. set a = b = 8 4. variables results w,x, y and z all integers w=5 x=4 y=8 z=2 a. x=y = 4+ 8 b. 2*2 = 2*2 c. y/x = 8/4 d. y- 2 = 8-2 5. psuedocode statement declares varaible cost floating= point varaible cost 6.psuedocode that declares the caraible total declare real price= 99.95 display " orginal price" input item orginal price display price 7. pseudocode statement that assign the value 27 count = 27 8. pseudocode statement that assign the value of 10 and 14 declare integar total = 0 set total =10 9. psuedocode statement that subtracts the varaible downpayment declare integar downpayment declare integar total declare integar due set due total 10.puedocode statement that multiplies the variable subtotal declare variable subtotal 0.15 declare integar total declare total fee pg.73 questions 6 & 8 6. design a program that will ask the user to enter the amount of a purchase. program should compute the stat and county tax. state sales tax is 4 % and the county sales tax is 2% ...

Words: 256 - Pages: 2

Free Essay

Algorithm

...1. Illustrate the operation of Radix_sort on the following list of English words: cow, dog, seq, rug, row, mob, box tab, bar ear, tar, dig, big, tea, now, fox. ANSWER: It is a sorting algorithm that is used to sort numbers. We sort numbers from least significant digit to most significant digit. In the following array of words, three is the maximum number of digits a word has, hence the number of passes will be three. In pass 1, sort the words alphabetically using first letter from the right. For eg, tea has “a” as the last letter, hence it comes first, similarly mob which has “b” as the last letter comes second. In this way the remaining words are sorted. In pass 2, sort the words alphabetically using second letter from the right. For eg, tab has “a” as its middle letter which comes first, then comes bar and so on. In pass 3, sort the words alphabetically using third letter from the right. For eg, bar has “b” as its first letter from left and since no word starts with “a”, bar will appear first. Similarly, big, box, cow and so on. UNSORTED ARRAY | PASS 1 | PASS 2 | PASS 3(SORTED ARRAY) | cow | tea | tab | bar | dog | mob | bar | big | seq | tab | ear | box | rug | rug | tar | cow | row | dog | tea | dig | mob | dig | seq | dog | box | big | dig | ear | tab | seq | big | fox | bar | bar | mob | mob | ear | ear | dog | now | tar | tar | cow | row | dig | cow | row | rug | ...

Words: 1470 - Pages: 6

Free Essay

Advanced Algorithms

...Approximation Algorithms Springer Berlin Heidelberg NewYork Barcelona Hong Kong London Milan Paris Singapore Tokyo To my parents Preface Although this may seem a paradox, all exact science is dominated by the idea of approximation. Bertrand Russell (1872–1970) Most natural optimization problems, including those arising in important application areas, are NP-hard. Therefore, under the widely believed conjecture that P = NP, their exact solution is prohibitively time consuming. Charting the landscape of approximability of these problems, via polynomial time algorithms, therefore becomes a compelling subject of scientific inquiry in computer science and mathematics. This book presents the theory of approximation algorithms as it stands today. It is reasonable to expect the picture to change with time. The book is divided into three parts. In Part I we cover a combinatorial algorithms for a number of important problems, using a wide variety of algorithm design techniques. The latter may give Part I a non-cohesive appearance. However, this is to be expected – nature is very rich, and we cannot expect a few tricks to help solve the diverse collection of NP-hard problems. Indeed, in this part, we have purposely refrained from tightly categorizing algorithmic techniques so as not to trivialize matters. Instead, we have attempted to capture, as accurately as possible, the individual character of each problem, and point out connections between problems and algorithms for solving them...

Words: 140657 - Pages: 563

Free Essay

Introduction to Algorithm

...4. G REEDY A LGORITHMS I ‣ coin changing ‣ interval scheduling ‣ scheduling to minimize lateness ‣ optimal caching Lecture slides by Kevin Wayne Copyright © 2005 Pearson-Addison Wesley Copyright © 2013 Kevin Wayne http://www.cs.princeton.edu/~wayne/kleinberg-tardos Last updated on Sep 8, 2013 6:30 AM 4. G REEDY A LGORITHMS I ‣ coin changing ‣ interval scheduling ‣ scheduling to minimize lateness ‣ optimal caching Coin changing Goal. Given currency denominations: 1, 5, 10, 25, 100, devise a method to pay amount to customer using fewest number of coins. Ex. 34¢. Cashier's algorithm. At each iteration, add coin of the largest value that does not take us past the amount to be paid. Ex. $2.89. 3 Cashier's algorithm At each iteration, add coin of the largest value that does not take us past the amount to be paid. CASHIERS-ALGORITHM (x, c1, c2, …, cn)...

Words: 3591 - Pages: 15

Premium Essay

Firefly Algorithm Analysis

...Abstract. The speech signal enhancement is needed to obtain clean speech signal from noisy signal. For multimodal optimization we better to use natural-inspired algorithms such as Firefly Algorithm (FA). We compare the firefly algorithm with particle swarm optimization technique. The proposed algorithm contains three module techniques. Those are preprocessing module, optimization module and spectral filtering module. The signals are taken from Loizou’s database and Aurora database for evaluating proposed technique. In this paper we calculate the perceptional evolution of speech quality (PESQ) and signal to noise (SNR) of the enhanced signal. The results of firefly algorithm and PSO are to be compare then we observe that the proposed technique...

Words: 887 - Pages: 4

Free Essay

Algorithms and Programming Languages

...Chapter 2 Algorithms and Programming Languages 1 Algorithms • the central concept underlying all computation is that of the algorithm – an algorithm is a step-by-step sequence of instructions for carrying out some task • programming can be viewed as the process of designing and implementing algorithms that a computer can carry out – a programmer’s job is to: • create an algorithm for accomplishing a given objective, then • translate the individual steps of the algorithm into a programming language that the computer can understand 2 Algorithms in the Real World • the use of algorithms is not limited to the domain of computing – e.g., recipes for baking cookies – e.g., directions to your house • there are many unfamiliar tasks in life that we could not complete without the aid of instructions – in order for an algorithm to be effective, it must be stated in a manner that its intended executor can understand • a recipe written for a master chef will look different than a recipe written for a college student – as you have already experienced, computers are more demanding with regard to algorithm specifics than any human could be 3 Designing & Analyzing Algorithms • 4 steps to solving problems (George Polya) 1. understand the problem 2. devise a plan 3. carry out your plan 4. examine the solution EXAMPLE: finding the oldest person in a room full of people Understanding the problem initial condition, goal and assumptions – room full of people – identify...

Words: 2277 - Pages: 10

Free Essay

Greedy Algorithm

...GREEDY ALGORITHM A greedy algorithm is a mathematical process that looks for simple, easy-to-implement solutions to complex, multi-step problems by deciding which next step will provide the most obvious benefit. Greedy algorithms are similar to dynamic programming algorithms in that the solutions are both efficient and optimal if the problem exhibits some particular sort of substructure. A greedy algorithm builds a solution by going one step at a time through the feasible solutions, applying a heuristic to determine the best choice. A heuristic applies an insight to solving the problem, such as always choose the largest, smallest, etc. Such algorithms are called greedy because while the optimal solution to each smaller instance will provide an immediate output, the algorithm doesn’t consider the larger problem as a whole. Once a decision has been made, it is never reconsidered. Greedy algorithms work by recursively constructing a set of objects from the smallest possible constituent parts. Recursion is an approach to problem solving in which the solution to a particular problem depends on solutions to smaller instances of the same problem. Advantages of greed algorithm * Always taking the best available choice is usually easy. * It usually requires sorting the choices. * Solutions to smaller instances of the problem can be straightforward and easy to understand. * Repeatedly taking the next available best choice is usually linear work. * But don't...

Words: 387 - Pages: 2

Free Essay

Vwap Algorithm

...Competitive Algorithms for VWAP and Limit Order Trading Sham M. Kakade Michael Kearns Computer and Information Science University of Pennsylvania Computer and Information Science University of Pennsylvania kakade@linc.cis.upenn.edu mkearns@cis.upenn.edu Yishay Mansour Luis E. Ortiz Computer Science Tel Aviv University Computer and Information Science University of Pennsylvania mansour@post.tau.ac.il leortiz@linc.cis.upenn.edu ABSTRACT We introduce new online models for two important aspects of modern financial markets: Volume Weighted Average Price trading and limit order books. We provide an extensive study of competitive algorithms in these models and relate them to earlier online algorithms for stock trading. Categories and Subject Descriptors F.2 [Analysis of Algorithms and Problem Complexity]: Miscellaneous; J.4 [Social and Behavioral Sciences]: Economics General Terms Algorithms, Economics Keywords Online Trading, Competitive Analysis, VWAP 1. INTRODUCTION While popular images of Wall Street often depict swashbuckling traders boldly making large gambles on just their market intuitions, the vast majority of trading is actually considerably more technical and constrained. The constraints often derive from a complex combination of business, regulatory and institutional issues, and result in certain kinds of “standard” trading strategies or criteria that invite algorithmic analysis. One of the most common...

Words: 9064 - Pages: 37

Free Essay

Algorithms Notes

...3PART ONE * Lecture 1 (01/09) Posted on: Monday, January 28, 2013 Topics: Stable Matching Reading: class handout * Lecture 2 (01/14) Posted on: Thursday, January 24, 2013 Topics: Graph Representation, BFS, DFS Reading: CLRS (Sections 22.1, 22.2, 22.3), KT (3.2, 3.3) Notes: 2 possible representations of a graph 1. Adjacency Matrix-used for dense graphs (V2 memory space) a. Aij=1 if edge exists between I and J but 0 if not 2. Adjacency List- Used for sparse graphs (V+E memory space or V+2E for undirected) b. Array adj of |V| lists, one for each vertex. c. Adj[u] contains all vertices adjacent (or reachable by one edge) to u Breadth First Search(G,s) BFS.G; s/ 1 for each vertex u in G.V –{s} 2 u.color = WHITE 3 u.disc =∞ 4 u.parent= NIL 5 s.color = GRAY 6 s.disc = 0 7 s.parent= NIL 8 Q = ∅; 9 ENQUEUE(Q,s) 10 while Q ≠ ∅ 11 u = DEQUEUE(Q) 12 for each v in G.Adj[u] 13 if v.color == WHITE 14 v.color = GRAY 15 v.disc = u.disc + 1 16 v.parent = u 17 ENQUEUE(Q,v) 18 u.color = BLACK White means not discovered yet, grey mean discovered but not finished, black means finished. Run time O(V+E) BFS gives shortest path from s to every vertex Lemma: x in Li and Y in Lj and edge (x,y) exists Then |i-j| less than or equal to 1 Depth First search Properties: 1) v is a descendenant of u iff v if discovered when u is gray 2) Parenthesis theorem, u and v in V. either discovery and finish times are...

Words: 5019 - Pages: 21

Free Essay

Gnetic Algorithms

...Genetic Algorithms Basic Genetic Algorithm – Flow Chart 1. Initial Population 1. Initial Population ON ON | | GENERATE RANDOM POPULATION (POSSIBLE SOLUTIONS) | 2. Fitness Evaluation 2. Fitness Evaluation 3. Selection 3. Selection | | EVALUATE THE FITNESS OF EACH (BASED ON THE FITNESS FUNCTION) | | | CHOOSE PARENT FACTORS (BETTER FITNESS = BETTER CHANCE) | 4. Crossover 4. Crossover 5. Mutation 5. Mutation | | CROSSOVER THE PARENT TRAITS TO FORM NEW CHILDREN. (PROBABILITY) | | | MUTATION PROBABILITY APPLIED (MAINTAINS GENETIC DIVERSITY) | Acceptable? Acceptable? | | IF OPTIMIZATION CONDITIONS ARE NOT MET(REPEAT STEPS 2-5) * OR | Yes Yes End Process End Process | | IF THE MAXIMUM GENERATIONS ARE MET (TERMINATE) * OR | | | IF SATISFACTORY FITNESS LEVEL IS REACHED (END THE PROCESS) | KEY TERMS * INDIVIDUAL Any possible solution to the problem at hand, usually expressed in binary code * POPULATION Group of all individuals * CHROMOSOME Blueprint for an individual usually expressed in binary code. (Ex: 011011) * GENE An individual value in a chromosome, usually expressed as a “1” or “0” * PARENTS An original “individual” solution in the GA process that has passed the fitness function * CHILDREN A new solution to the problem formed through crossover and mutation from the parent solutions * SEARCH SPACE All possible solutions to the problem...

Words: 261 - Pages: 2

Free Essay

Algorithms and Logic for Computer Programming

...Personal Learning Management University of Phoenix Algorithms and Logic for Computer Programming PRG 211 Professor Sam March 07, 2013 Personal Learning Management Being able to develop a management tool that would allow a user or student to review course material would be very beneficial. With a course such as programming that has so much information, it is important to be able to recall information in order to properly understand how programming works. I for example, do not have any prior knowledge of so I would have to continuously refresh the information that I have learn in the reading as well as in the class room environment. I will be discussing some topics that are important to the development of such a program. In order to properly develop an application, we must first address and analyze the problem that has caused this need. In this situation, we want to design an application that will allow students to be able to review reading assignments as well as task or anything that would be beneficial to retain. Some subjects are a harder to remember than others such as programming. Modular programming would be the best fit because we would want everyone to read the material in the same order. We would set up the program so everyone’s view is the same. If we allow people to “jump around” in the programming, some learning material is going to be skipped over and that would defeat the purpose of the development of this application. Submodules would be added...

Words: 480 - Pages: 2

Free Essay

Sorting Algorithms

...REVIEW ON SORTING ALGORITHMS A comparative study on two sorting algorithms By Pooja Adhikari A Term Paper Submitted to the Faculty of Dr. Gene Boggess Mississippi State University In the Department of Computer Science & Engineering Mississippi State, Mississippi 04 20072 ABSTRACT Any number of practical applications in computing requires things to be in order. The performance of any computation depends upon the performance of sorting algorithms. Like all complicated problems, there are many solutions that can achieve the same results. One sort algorithm can do sorting of data faster than another. A lot of sorting algorithms has been developed to enhance the performance in terms of computational complexity, memory and other factors. This paper choose two of the sorting algorithms among them selection sort and shell sort and compares the various performance factor among them. 1. INTRODUCTION Sorting is the rearrangement of things in a list into their correct lexicographic order. A number of sorting algorithms have been developed like include heap sort , merge sort, quick sort, selection sort all of which are comparison based sort .There is another class of sorting algorithms which are non comparison based sort. This paper gives the brief introduction about sorting algorithms [2] where it discuss about the class of sorting algorithms and their running times. It mainly analyses the performance between two...

Words: 841 - Pages: 4

Free Essay

Genetic Algorithms

...Genetic Algorithm Approach to Solve the Shortest Path Problem for Road Maps Sachith Abeysundara*, Baladasan Giritharan+, Saluka Kodithuwakku◊ *Department of Statistics and Computer Science, Faculty of Science, University of Peradeniya, Sri Lanka Email: sachith@email.com Telephone: (+94) 81 2374652 + Department of Statistics and Computer Science, Faculty of Science, University of Peradeniya, Sri Lanka Email: bgiri@pdn.ac.lk ◊ Department of Statistics and Computer Science, Faculty of Science, University of Peradeniya, Sri Lanka Email: salukak@pdn.ac.lk Telephone: (+94) 81 2394260 Abstract—This paper presents a new genetic algorithm approach to solve the shortest path problem for road maps. This is based on the analogy of finding the shortest possible distance between two towns or cities in a graph or a map with potential connection, which means that the path distances are always positive. Typically this is represented by a graph with each node representing a city and each edge being a path between two cities and there exist some traditional algorithms that produce solutions for the problem. A new method is found to solve the shortest path problem using GAs. The algorithm has been tested for a road map containing more than 125 cities and the experimental results guarantee to provide acceptably good solutions for the given search space. HE shortest path problem is typical in the world of combinatorial systems. This research will attempt to apply a Genetic algorithm to solve...

Words: 2513 - Pages: 11