pseudocode

Randomly Generate Letters According to their Frequency of Use?

白昼怎懂夜的黑 提交于 2019-11-27 08:44:01
How can I randomly generate letters according to their frequency of use in common speech? Any pseudo-code appreciated, but an implementation in Java would be fantastic. Otherwise just a poke in the right direction would be helpful. Note: I don't need to generate the frequencies of usage - I'm sure I can look that up easily enough. I am assuming that you store the frequencies as floating point numbers between 0 and 1 that total to make 1. First you should prepare a table of cumulative frequencies, i.e. the sum of the frequency of that letter and all letters before it. To simplify, if you start

Algorithm for generating a random number

青春壹個敷衍的年華 提交于 2019-11-27 04:53:57
I'm looking to generate a random number and issue it to a table in a database for a particular user_id. The catch is, the same number can't be used twice. There's a million ways to do this, but I'm hoping someone very keen on algorithms has a clever way of solving the problem in an elegant solution in that the following criteria is met: 1) The least amount of queries to the database are made. 2) The least amount of crawling through a data structure in memory is made. Essentially the idea is to do the following 1) Create a random number from 0 to 9999999 2) Check the database to see if the

transitive reduction algorithm: pseudocode?

蹲街弑〆低调 提交于 2019-11-27 04:17:41
问题 I have been looking for an algorithm to perform a transitive reduction on a graph, but without success. There's nothing in my algorithms bible (Introduction To Algorithms by Cormen et al) and whilst I've seen plenty of transitive closure pseudocode, I haven't been able to track down anything for a reduction. The closest I've got is that there is one in "Algorithmische Graphentheorie" by Volker Turau (ISBN:978-3-486-59057-9), but unfortunately I don't have access to this book! Wikipedia is

Feasible implementation of a Prime Counting Function [closed]

我怕爱的太早我们不能终老 提交于 2019-11-27 02:51:47
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 years ago . Can anyone provide computationally feasible pseudocode of any prime-counting function implementation? I initially attempted coding the Hardy-Wright algorithm, but its factorials began generating miserable overflow, and many others appear bound to yield similar problems. I've scoured Google for practical

How to find the units digit of a certain power in a simplest way

a 夏天 提交于 2019-11-27 02:20:02
问题 How to find out the units digit of a certain number (e.g. 3 power 2011 ). What logic should I use to find the answer to this problem? 回答1: For base 3: 3^1 = 3 3^2 = 9 3^3 = 27 3^4 = 81 3^5 = 243 3^6 = 729 3^7 = 2187 ... That is the units digit has only 4 possibilities and then it repeats in ever the same cycle. With the help of Euler's theorem we can show that this holds for any integer n, meaning their units digit will repeat after at most 4 consecutive exponents. Looking only at the units

help in the Donalds B. Johnson's algorithm, i cannot understand the pseudo code (PART II)

雨燕双飞 提交于 2019-11-27 02:15:38
i cannot understand a certain part of the paper published by Donald Johnson about finding cycles (Circuits) in a graph. More specific i cannot understand what is the matrix Ak which is mentioned in the following line of the pseudo code : Ak:=adjacency structure of strong component K with least vertex in subgraph of G induced by {s,s+1,....n}; to make things worse some lines after is mentins " for i in Vk do " without declaring what the Vk is... As far i have understand we have the following: 1) in general, a strong component is a sub-graph of a graph, in which for every node of this sub-graph

Java balanced expressions check {[()]}

不想你离开。 提交于 2019-11-27 00:31:35
问题 I am trying to create a program that takes a string as an argument into its constructor. I need a method that checks whether the string is a balanced parenthesized expression. It needs to handle ( { [ ] } ) each open needs to balance with its corresponding closing bracket. For example a user could input [({})] which would be balanced and }{ would be unbalanced. This doesn't need to handle letters or numbers. I need to use a stack to do this. I was given this pseudocode but can not figure how

From milliseconds to hour, minutes, seconds and milliseconds

自闭症网瘾萝莉.ら 提交于 2019-11-27 00:27:27
问题 I need to go from milliseconds to a tuple of (hour, minutes, seconds, milliseconds) representing the same amount of time. E.g.: 10799999ms = 2h 59m 59s 999ms The following pseudo-code is the only thing I could come up with: # The division operator below returns the result as a rounded down integer function to_tuple(x): h = x / (60*60*1000) x = x - h*(60*60*1000) m = x / (60*1000) x = x - m*(60*1000) s = x / 1000 x = x - s*1000 return (h,m,s,x) I'm sure it must be possible to do it smarter

Interview puzzle: Jump Game

喜夏-厌秋 提交于 2019-11-27 00:15:21
问题 Jump Game: Given an array, start from the first element and reach the last by jumping. The jump length can be at most the value at the current position in the array. The optimum result is when you reach the goal in minimum number of jumps. What is an algorithm for finding the optimum result? An example: given array A = {2,3,1,1,4} the possible ways to reach the end (index list) are 0,2,3,4 (jump 2 to index 2, then jump 1 to index 3 then 1 to index 4) 0,1,4 (jump 1 to index 1, then jump 3 to

Find the paths between two given nodes?

痴心易碎 提交于 2019-11-26 21:31:41
Say I have nodes connected in the below fashion, how do I arrive at the number of paths that exist between given points, and path details? 1,2 //node 1 and 2 are connected 2,3 2,5 4,2 5,11 11,12 6,7 5,6 3,6 6,8 8,10 8,9 Find the paths from 1 to 7: Answer: 2 paths found and they are 1,2,3,6,7 1,2,5,6,7 implementation found here is nice I am going to use the same Here is the snippet from the above link in python # a sample graph graph = {'A': ['B', 'C','E'], 'B': ['A','C', 'D'], 'C': ['D'], 'D': ['C'], 'E': ['F','D'], 'F': ['C']} class MyQUEUE: # just an implementation of a queue def __init__