Jump to content

khaled

Senior Members
  • Posts

    594
  • Joined

  • Last visited

Everything posted by khaled

  1. TIMER in Algorithm is the local clock, in Machine level it's the hardware clock.
  2. this happen always with me, but we have the key "try something different" ! and since you are looking for Optimality, I think you should use a Binary Tree instead of a Linked List since Keys are numeric and can be ordered ! If you change your LinkedList into a BinaryTree, Insertion Time and Search Time will be reduced from O(n) to O(log n), it's like the Optimal solution in an NP-complete problem ... I usually give a course to my college's students called "Create My Own Data Structure", We show that creating your own data structure is fun, and makes you feel like building a Castle ! Anyway, the algorithm of your program is simple as you stated: 1. generate whatever you need to store 2. define a new MyHashTable, which will implicitly define new K MyBinaryTree(s) 3. Iterate over your buckets\array\matrix\..etc and add them to the MyHashTable using for(int i=0; i<bucket.length; i++){ MyHashTable.add(bucket); } Good luck .. one more thing, i found out what is your problem, you try to solve everything at once, that will make you lose everything, .. so take things one by one, and them take your time to organize your work,
  3. That seem like you are using the final byte of 128-bit number, by masking &0x000000FF000000FF and shifting to retrieve that bytes ... but it's a waste of time, you can use a 1-byte number from the begining, but if for example you are using 128-bit numbers, you can hash it down into the 1-byte number, because if you do masking then all entries with same digits on the F-masked parts are considered to be the same, and that is a main leak in the hash function ... good luck, don't be sad, sometimes it's easier to implement everything from scratch, if your project doesn't depend on some library that does something you cannot implement by yourself. so why not designing your own hash table, your own data structure, and your own hash function ... If standard methods makes your work complex with their constraints, then make your own version with your own constraints ...
  4. So, you are working with an array, you should've told me that it was an array from the beginning, This is a complex hash function for a given array of 8-bit array, // this means hash() return values from 0 ~ 1000 const unsigned long MAX_PARAMETER = 1000; // hash function i wrote for you Xittenn size_t hash(unsigned char[] key, size_t size) { unsigned long t = 0; size_t h = 0; // step 1: summation for(int i=0; i<size; i++) t += key[i]; // step 2: reduction while(t > MAX_PARAMETER) t = t MOD (t % (10 * ( t % 10))); h = t; return h; } Good luck,
  5. I was afraid of misunderstanding, what I meant simply is ... If the UUID is an unsigned long, then simply convert it to unsigned long to be a valid input to the Hash function ... UUID u; unsigned long n = Convert_UUID_to_unsigned_long(u); size_t h = hash(n); and If the UUID is a structure that contain the unsigned number, then just take it off the structure ... UUID MyUUID(); unsigned long n = MyUUID.get(); size_t h = hash(n); This shouldn't be that difficult ...
  6. listen cutie, when we talk about Algorithms, we talk about simplicity, So, how can we represent a 128bit unsigned integer, that would unsigned long so, you simple put your hash function code in here unordered_map m = new unordered_map<unsigned long,MyDataStructure,MyHash<unsigned long>>(); with, template <class t> class MyHash { MyHash(){} size_t operator()(const t& x) { size_t h = 0; // calculate hash as if X is unsigned long return h; } }; about your hash function, it can anything ... it can be MD5, SHA1, or anything you can make up, I once wrote a simple hash function: size_t sum_digits(size_t a) { size_t b = 0; while(a > 0) { b += a % 10; a = a / 10; } return b; } // this hash function is based on digits sum loop // author: khaled khunaifer, 2008 size_t hash(unsigned long n) { size_t h = n; while(h > 9) h = sum_digits(h); return h; } Good luck, .. note that my real name is written in the code
  7. The unordered_map Class: template < class Key, class Ty, class Hash = std::hash<Key>, class Pred = std::equal_to<Key>, class Alloc = std::allocator< std::pair<const Key, Ty> > > class unordered_map; where: + Key: The key type + Ty: The mapped type + Hash: The hash function object type + Pred: The equality comparison function object type. + Alloc: The allocator class. .. So, to Create a Standard unordered_map, that works with your hash function: unordered_map m = new unordered_map<long,MyDataStructure,MyHash<long>>(); where template <class t> class MyHash { MyHash(){} size_t operator()(const t& x) { size_t h = 0; // calculate hash return h; } }; good luck ... hmm, I know a good formal way of having a discussion ;]
  8. in mathematics, a quadratic equation have two solutions when [latex]\Delta[/latex] is positive, one solution if [latex]\Delta[/latex] is Zero, and No real solution if [latex]\Delta[/latex] is negative !
  9. hashing functions are based on what you will use them for, if you use them for security, then you can use MD5, or MD6 hashing which is already implemented and can be found on the web ... but if you use them for a Hash Table, then you need to work out one for yourself, or lookup the internet for an implemented one, Hash Table is a 1Dimensional Array Of K Pointers To Data Structures, example: Array of K Binary-Tree Pointers, initially empty Hash Function is a function that maps any input to one of the K Data Structures, by returning an output (the index) from 1 to K ... The hash function have to be: 1. secure: given the same input, it returns the same index 2. distributed: given H entries, it should balance H over K Data Structures where the average of every Data Structure Size becomes H/K .. it's then normalized .. Good luck on writing a good hash function and by the way, you look cute,
  10. 1. A PRNG is Safe If and only If, the PRNG ,given the same input, gives the same output If for the same input it give different output, It is Not Safe ... 2. A PRNG is Secure, given a serious of K outputs from an initial State S, If using K, one can't get S .. If one can use K to get S then it is Not Secure ... there are other things, you can lookup in Wikipedia too ... Good luck, I have worked a Random Number Generator myself too, but, it's not pseudo-random .. it's a total randomness ... I'm going to publish my design after 4 months approximately, I took a look into your algorithm, I think this is the algorithm: LOCAL m AS QUAD LOCAL n AS LONG LOCAL a, b, x AS EXT x=TIMER MOD 1 b=x^2 FOR m=2 TO 8193 DO a=b+1/m FOR n=1 TO 16384 DO a+=x x=(a*x+a) MOD 1 NEXT NEXT Your algorithm have some issues: 1. Performance: This algorithm takes more than (8192+16384) = (24576) Steps, just to generate 1 bit ! so saying you want to generate a K-bit Integer, you need (24576)*K .. which is not good ! Because you are basing your algorithm on binary .. with alot of operations ... you can optimize this loop: FOR n=1 TO 16384 DO a+=x into a single assignment: a += x * 16384 and optimize this loop: FOR m=2 TO 8193 DO a=b+1/m into a single assignment: a = SUM OF b+1 * 1/m FOR m = (1..8192)+1 and since: aZ + bZ + cZ = Z * (a + b + c) which gives: a = (b+1) * HARMONIC_SUM(1/m,1..8192)+1 you can define harmonic sum, look at this: http://mathworld.wolfram.com/HarmonicSeriesofPrimes.html ------------------------------------------------- 2. Safety: This algorithm is not safe, because you are doing alot of addictive mathematical operations, on a 32-bit and 64-bit Integers, Where you will have tens of Overflows .. so, if you want to manage this you have to as following: LOCAL m AS LONG LOCAL a AS LONG FOR a = 1 TO 100000 DO m += a MOD LONG_MAX in here, we jump the the border of overflow, but this will make you work only on positive integers only !.. since: A MOD A = 0 also, it's not safe because of using the TIMER, because the random output should be based on the input, not the current TIME\CLOCK, but if you mean using a TIMER like a STOP-WATCH then that's still based on the input, this includes using an input-based CLOCK ... -------------------------------------------------- Good luck
  11. NFA is a graph where vertices define connection between alphabets that can come in order to form a word in a dictionary ... NFA can be formed from a Regular Expression ... NFA can be transformed into Lexical Analyzer, directly or throught DFA ... Good luck,
  12. It is logic, which is what systems are built over ... Even Chaos and Noise are systems, "God does not play dice" --Einstein
  13. I think Moore's Law is like a Linear O(n) Progression of his assumption ... but I think with going into the future, Moore's Law is more like a Logarithm O(log n) Progression, where the amount of advancement in computing power during his assumed time period, is dynamic and slowly increase !
  14. lol, I think I know how it is possible, If one human can get his mind into Subconscious State ! The inner brain will take any input without assertion, that's when we can use a pulse generator connected to the brain, the pulse generator will be used to generate scenes, sounds, motion, and feelings which will be like a dream, but more powerful ! which will seem like a normal life ... Crazy, isn't it .. well, that's my guess, if it becomes real, you can have just-like-real imaginary sex .. without using your body at all !
  15. the first thing comes to a developer's mind, when talking about Optimization & Data Structure is Hashing Table ! another point is, even Data Structures are logical when a program is running, but you can create a virtual cache on use ... Graph frequency of use on the memory levels, or balance your priority-based AVL trees. Anyway, good luck
  16. Mac's new operating systems are something different ... take a look at their Machine's Instruction Set, www.stat.uchicago.edu/~thisted/Distribute/comparch.pdf also, apple company have a full division of experts for one thing, .. can you guess without looking at the spoiler ? SEE
  17. You need to show you attempts first, then we will help you ... I won't offer anything, but I will give you a hint ... on Q1: you can use Linked-Lists and Counters ... on Q2: you can define a graph using 2D Matrix ...
  18. As a Programming Assistance, I can tell you this, use C, if you need to program an Algorithm, because C is the fastest ! use C++, if you are working under Windows, or C under Linux ... use Java, if you don't care about "how fast", and on the other hand it gives you alot of benefits: - automated memory management - full Object-Oriented - portability (same code works on all Operating Systems) - support (has alot of standard libraries for many things such as Complex Cryptography) - Thread-ability, Parallelism, Distribute-ability, Security, Safety, Fault-Tolerability ..etc
  19. If we take things based on the basic definition of what is the power, since power is multiplicity of self, its definition was made recursive, [latex]a^{-p} = \frac{1}{a^p} = { \left( \frac{1}{a} \right) }^{p}[/latex] [latex]a^p = a^{p-1} \times a[/latex] and [latex]a^p = \frac{a^{p+1}}{a}[/latex] with base case is for: [latex]a^{0} = 1[/latex], [latex]{0}^x = 0[/latex], and [latex]0^{0} = [/latex] undefined OR 1, [latex]0^{+\infty} = [/latex] undefined OR 0, [latex]0^{-\infty} = [/latex] undefined OR 0 where undefined might be 1 for [latex]0^{0}[/latex] and 0 for [latex]-\infty[/latex] [latex]+\infty[/latex] according to some mathematicians that's all I know ...
  20. A quick guess gives me ... but this might be wrong !
  21. My suggestion is that you start by Mathematical Logic, because it's the basis of computer sciences ... Here is a Free book on everything in Mathematical Logic .. HERE good luck !
  22. Modulo Arithmetic would be fine to mess with that, but all of that on top of assuming a formula for some values ... In the end, it will end by generating random set of notes that none would like to hear, not to mention that even a random given formula would generate noise on sound output ... If you want to map Music from Mathematics, that's a not easy thing, you have to understand Music and Harmony then the work of writing a music sheet, which requires knowledge at the Neural Studies and the Artificial Intelligence, and then to create a model that maps this system in Mathematics ... I once had such project, but it was paused until I get free time ...
  23. I feel like listening to the explanation of the path I'm walking nowdays, besides that I've chosen to become a teacher, to teach Mathematical Logic, Mathematical Modelling and Programming on the Computer, and Algorithms ... But, since I'm still a Batchelor student, then I'm not late at this point.
  24. One more thing, I have made a drawing, related to Navier-Stokes Equation Problem The formal context about the problem was: The drawing is related to Water and Boat Engines ... .. so can I post the drawing on here .. to help other scientists get more ideas about this problem ? yes, and not a real progress, but it was a progress well, after a time it might need alot of help from specialists and a life-time ... I wrote some papers, but they are based on basic ideas, not much in mathematics.
  25. first you calculate how many copies of a given/average human can lie on the continents at the same time, denoting that as H where, H = Area Of the Continents / Area of a given/average human then we calculate time needed for that human to move the radius of a circle that concise his given area, denoting that as T in seconds for instance, given time one can lie on the ground, stay for a while, and stand up again denoted as L, then the total needed time for him to do all that is denoted by TOTAL, TOTAL = L*H + (T-1)*H = (L+T-1)*H
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.