Free Essay

Algorithm

In:

Submitted By kuntal10
Words 1470
Pages 6
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 | big | row | now | seq | tea | now | box | tab | now | box | fox | tar | fox | fox | rug | tea |

2. Illustrate the insertion of the keys 5, 28, 19, 15, 20, 33, 12, 17, 10 into a hash table with collisions resolved by chaining. Let the table has 9 slots, and let the hash function be h(k) = k mod 9.

ANSWER:

The hash function is h(k)=k mod 9 and the hash functions of the keys are: 1. 5 mod 9 = 5 2. 28 mod 9 = 1 3. 19 mod 9 = 1 4. 15 mod 9 = 6 5. 20 mod 9 = 2 6. 33 mod 9 = 6 7. 12 mod 9 = 3 8. 17 mod 9 = 8 9. 10 mod 9 = 1
Based on the hash values obtained from the hash functions we are going to store them in the hash tables in the following way:

/ | / | / | / | / | . | / | / | / |
0 1 2 3 4 5 6 7 8

5 | / |

. | / | / | / | / | . | / | / | / | 0 1 2 3 4 5 6 7 8 28 | / | 5 | / |

. | / | / | / | / | . | / | / | / | 0 1 2 3 4 5 6 7 8 28 | / | 5 | / |

19 | / |

. | / | / | / | / | . | . | / | / | 0 1 2 3 4 5 6 7 8 15 | / | 28 | / | 5 | / |

19 | / |

. | / | . | / | / | . | . | / | / | 0 1 2 3 4 5 6 7 8 15 | / | 20 | / | 28 | / | 5 | / |

19 | / |

. | / | . | / | / | . | . | / | / | 0 1 2 3 4 5 6 7 8 15 | / | 20 | / | 28 | / | 5 | / |

33 | / | 19 | / |

. | / | . | . | / | . | . | / | / | 0 1 2 3 4 5 6 7 8 15 | / | 20 | / | 12 | / | 28 | / | 5 | / |

33 | / | 19 | / |

. | / | . | . | / | . | . | / | . | 0 1 2 3 4 5 6 7 8 15 | / | 20 | / | 12 | / | 17 | / | 28 | / | 5 | / |

33 | / | 19 | / |

. | / | . | . | / | . | . | / | . | 0 1 2 3 4 5 6 7 8 15 | / | 20 | / | 12 | / | 17 | / | 28 | / | 5 | / |

33 | / | 19 | / |

10 | / |

3. You are given an array of n elements, and you notice that some of these elements are duplicates; that is they appear more than one time in the array. Devise an algorithm to remove all duplicates from the array in time O(n log n). ANSWER: Suppose an array is given with n elements where there are some duplicate values present. To remove all the duplicate elements we will use Merge Sort where we will divide the entire array of n elements into two arrays a and b. Each array must be sorted already in non-decreasing order. As a result a new array is returned containing the same elements merged together into a new array in non-decreasing order. We will use two variables to keep track of where we are in arrays a and b: index_a and index_b. * Set index_a to 0. * Set index_b to 0. * Create an empty array c. * While index_a<the length of array a and index_b<the length of array b, do the following : i) If a[index_a]<=b[index_b], then do the following: * Append a[index_a]on to the end of array c * Add 1 to index_a Otherwise, do the following: * Append b[index_b] on to the end of the array c * Add 1 to index_b Once we have finished adding, we have added all of the elements of either array a or array b to array c. * If a[index_a]= b[index_b], then add 1 to index_b which means the element in the array b will be ignored and the checking will be done with the next element in the array b. In this way, duplicate elements can be ignored and all other elements will be copied in other array c. * If index_a<the length of array a, then: Append all remaining elements of the array a to array c. Similarly, If index_b<the length of array b, then: Append all remaining elements of the array b to array c. * Return the array c with all the sorted elements. In order to analyze Merge Sort we have to go into the details of two processes that is core of the implementation. First, the list is splited into halves. We divide a list in half logn times where n is the length of the list. The second process is the merge. Each item in the list will eventually be processed and placed on the sorted list. So the merge operation which results in a list of size n requires n operations. The result of this analysis is that logn splits, each of which costs n for a total of nlogn operations. Hence we can see that a merge sort is an O(nlogn) algorithm. 4. A sequence of n operations is performed on a data structure. The ith operation costs i if i is an exact power of 2, and 1 otherwise. Use aggregate analysis to determine the amortized cost per operation. ANSWER: Let a sequence of n operations on a data structure is performed in which the ith operation costs i if is an exact power of 2, and 1 otherwise. We will use aggregate analysis to determine the amortized cost per function. OPERATIONS | COST | 1 | 1 | 2 | 2 | 3 | 1 | 4 | 4 | 5 | 1 | 6 | 1 | 7 | 1 | 8 | 8 | 9 | 1 | 10 | 1 | n | n or 1 | In a sequence of n operations there are log2n+1 exact powers of 2, namely 1,2,4,8,…,2log2n . The total cost will be therefore, Total Cost =k=0logn2k + k=0n-logn1 = 1-2logn+11-2+ n-logn = 1-2logn .2-1 + n-logn = 2n + n –logn -1 = 3n – logn -1 <=3n

The total cost to compute n operations is therefore O(n). The average cost of each operation calculated in the worst case is then O(n) /n = O(1). Therefore, the amortized cost per function is O(1).

5. A sequence of stack operations is performed on a stack whose size never exceeds k. After every k operations, a copy of the entire stack is made for backup purposes. Show that the cost of n stack operations, including copying the stack, is O(n) by assigning suitable amortized costs to the various stack operations. ANSWER: Amortized cost is assigned to the operations in the following way:

OPERATION | AMORTTIZED COST | PUSH | 3 | POP | 0 | MULTIPOP | 0 | COPY | 0 | Here the PUSH operation is assigned a cost of 3 to pay for the item to be pushed. From 3, $1 is saved in the credit for the future POP and remaining $1 is saved for future copy. POP cannot be performed if the stack is empty. POP does not need to pay for itself since each item on the stack is reserving 1 credit for it. Similarly MULTIPOP also does not need to pay as it is same as the cost of the POPs. The COPY also does not need to pay as the PUSH has saved a credit for this also. Thus we can see that in the worst case, the amortized cost for n operations (n pushes) is O(3n)=O(n).Furthermore, credit will always be greater than 0 because POPs and MULTIPOPs cannot occur if items have not been pushed and COPY does not incur any cost if the stack is empty.

6. Suppose we wish not only to increment a counter but also to reset it to zero (i.e., make all bits in it 0). Show how to implement a counter as an array of bits so that any sequence of increment or reset operations takes time O(n) on an initially zero counter.

ANSWER:

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

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

Free Essay

Euclid's Algorithm

...Assignment #2 A. Algorithm to calculate Easter day for the year 2013: X = 2013 1. Divide X by 19 to obtain a quotient (which will be ignored) and a remainder A. 2013/19 = quotient 105 and remainder 18. A = 18 2. Divide X by 100 to obtain a quotient B and a remainder C. 2013/100 = quotient 20 and remainder 13. B =20; C = 13. 3. Divide B by 4 to obtain a quotient D and a remainder E 20/4 = quotient 5 and remainder 0. D = 5; E = 0. 4. Divide (8*B + 13) by 25 to obtain a quotient G and remainder (which will be ignored). (8*20 + 13)/25 = quotient 6 and remainder 23 G = 6. 5. Divide (19*A+B-D-G+15) by 30 to obtain a quotient which will be ignored and a remainder L. (19*18+20-5–6+15)/30 = quotient 12 and remainder 6 H = 6. 6. Divide (A+11*H) by 310 to obtain a quotient M and a remainder (which will be ignored). (18+11*6)/310 = quotient 0 and remainder 174. M = 0 7. Divide C by 4 to obtain a quotient J and a remainder K. 13/4 => quotient 3; remainder 1 J = 3 and K = 1 8. Divide (2*E + 2*J - K – H + M + 32) by 7 to obtain a quotient (which will be ignored) and a remainder L. (2*0 + 2*3 – 1 – 6 + 0 + 32)/7 = quotient 4 and remainder 3. L = 3. 9. Divide (H - M + L + 90) by 25 to obtain a quotient N and a remainder (which will be ignored). (6 – 0 + 3 + 90)/25 = quotient 3 and remainder 24. N = 3. 10. Divide (H – M + L + N + 19)/32 to obtain a quotient (which will be ignored and a remainder P. (6 – 0 +3+3+19)/32 = remainder...

Words: 477 - Pages: 2