Hashes 4 Hash Functions for Strings

  Рет қаралды 71,684

RobEdwards

RobEdwards

Күн бұрын

Пікірлер: 133
@sontiyo7113
@sontiyo7113 5 жыл бұрын
His jokes are killing me man I love this guy
@xerxius5446
@xerxius5446 6 жыл бұрын
what if i have shi.. never mind..
@audreyjensen666
@audreyjensen666 3 жыл бұрын
06:05
@mmahal
@mmahal 3 жыл бұрын
@Harper Malcolm yea you guessed it right mate. No one cares.
@Doctor_Hams_Dingus_Jam
@Doctor_Hams_Dingus_Jam 3 жыл бұрын
Writing on the glass whiteboard while it's in front of you is the best shit I've ever seen. I wish all my professors had this Edit: wait, how does that work? It's edited in, right?
@andrewwaggoner8797
@andrewwaggoner8797 3 жыл бұрын
video is flipped, if you saw it live from this angle letters would be backwards. nice how it makes it so easy to see
@pepa007
@pepa007 4 жыл бұрын
He started writing and I was like wait... how… holy smoke that’s genius! 😍
@superuser8636
@superuser8636 4 жыл бұрын
“...returns all permutations of the string and [assigns a unique value according to order] ...” ... wow. Great explanation of finding all anagrams assigned a unique Val. These videos are incredible
@justinlee6075
@justinlee6075 5 жыл бұрын
I noticed a few things, and correct me if my thoughts are wrong. Hell, I may have completely interpreted the lecture wrong. 1) 116 + g(104 + g(105 + g(115 + g))) doesn't translate to 116 + 104g + 105g^2 + 115g^3. He may have meant to write 116 + g(104 + g(105 + g(115))). 2) That hashCode function at the end doesn't represent 116 + 104g + 105g^2 + 115g^3. I think it represents 116g^3 + 104g^2 + 105g + 115. (Although, that may have been intentional, in which that case, I apologize for pointing out the obvious).
@markrayne5382
@markrayne5382 4 жыл бұрын
this comment right here! you hit the nail in the head a fair few and confusing mistakes by the professor that needed clearing up
@Funnybone_FB
@Funnybone_FB 3 жыл бұрын
I noticed the same things! Thanks for posting so I know I'm not going nutty
@MrYourMedia
@MrYourMedia 5 жыл бұрын
The character at index 6 is e; hehe
@laneroberts8747
@laneroberts8747 4 жыл бұрын
@@abhishekavr1848 You are an idiot, you have had 8 months to respond and you respond with the wrong answer lmao
@saineshnakra6045
@saineshnakra6045 4 жыл бұрын
@@abhishekavr1848 Yeah , you probably want to count that again
@moisesacero4995
@moisesacero4995 4 жыл бұрын
@@laneroberts8747 gawd dam ur pissy
@laneroberts8747
@laneroberts8747 4 жыл бұрын
@@moisesacero4995 ya maybe... But the point is that he literally did not count. However, I do realize that what I said might be out of line. But @Abhishek avr is still an idiot
@thepurpleone7153
@thepurpleone7153 4 жыл бұрын
He IS right, its e. My name 0123456
@a1988ditya
@a1988ditya 4 жыл бұрын
6:05 THAT EPIC MOMENT :)
@edrtjiud7752
@edrtjiud7752 7 жыл бұрын
I think the correct "formula" of what you are writing (at min 7:30) is: s[0]*g^(n-1) + s[1]*g^(n-2) + ...+s[n-1]*g^0. (where s is our string and n = s.length()) The power you have to rise g starts from (s.length - 1). ex: s[i] * g^(n - i - 1) Using this formula you can do like this: for (int i = 0; i < s.length(); i++){ hash += Math.pow(31, s.length() - i - 1) * s.charAt(i); }
@任安明
@任安明 7 жыл бұрын
edrt jiud does it matters?i think there is no big difference
@syedasadalizaidi55
@syedasadalizaidi55 6 жыл бұрын
why are we taking g as 31?
@NourAli-hl4ih
@NourAli-hl4ih 6 жыл бұрын
this is correct. his is g^0 then g^1... while yours is g^1 then g^0..
@MammadovAdil
@MammadovAdil 5 жыл бұрын
I also noticed that, there should not be much difference but what he explained and what he coded are different. I think instead of using Math.pow, we can also just invert the loop to start from last element and to go down to first
@seitarion4538
@seitarion4538 4 жыл бұрын
Your iterating through indices, there's no need to calculate the descending index to raise the constant to that instead of just raising to the power of the index your currently on. They have the exact same effect.
@user-og6hl6lv7p
@user-og6hl6lv7p 7 жыл бұрын
Beautiful explanation of basic string hashing, thanks!
@songsmania1681
@songsmania1681 6 жыл бұрын
why are we taking g as 31?
@pressgreen
@pressgreen 6 жыл бұрын
It is a prime number which reduces the chances of collisions. I think lol
@goutham24693
@goutham24693 3 жыл бұрын
From the explanation he gave, I think the code should be for (i = 0 ; i < size; i ++) { hash += s.charAt(i) * (pow (g,i)); } Not sure how he came up with, 116 + g(104 + g(105 + g(115 + g))) at 7:56. if I expand this I get, 116 + 104g + 105(g^2) + 115 (g^3) + (g^4) can someone explain this and the specific use of 31 ? Thanks.
@Zach-cv4gu
@Zach-cv4gu 2 жыл бұрын
31 is optimal for computing hashing results
@imanelamnaoir590
@imanelamnaoir590 Жыл бұрын
Both methods are correct , the video used what we call the Horner method ; Horner's method is a technique used to efficiently evaluate a polynomial at a particular value ( the value is the famous g=31)
@mayaayaviri1493
@mayaayaviri1493 Жыл бұрын
im testing it right now and i get two different numbers using the two different methods@@imanelamnaoir590
@karlloveridge8818
@karlloveridge8818 2 жыл бұрын
Loved his explanation. If Hollywood ever needs to do a biopic about Donald Pleasence, this is the guy! He even sounds like him!
@ZerofeverOfficial
@ZerofeverOfficial 3 жыл бұрын
This video made me get it. Thank you for making it.
@ashuvssut
@ashuvssut 2 жыл бұрын
He applied Horner's Rule at 07:33 Applying this rule reduces the number of mathematical operations required to solve a polynomial. I came by this rule today morning only! See this vid kzbin.info/www/bejne/j2W1kHxvg8-fgqs
@kirktelia
@kirktelia 3 жыл бұрын
Thanks a mill this made sense out of nonsense for me
@goldenotis9703
@goldenotis9703 4 жыл бұрын
Thanks for that end part information. The strings get really big in the program where I’m trying to implement this function and I need to optimize it for speed.
@_paralaks_
@_paralaks_ 4 жыл бұрын
I am autoliking these lectures. Like literally new video starts from the playlist, I hit like so I don't have to pause or go back to like.
@code3design
@code3design 5 жыл бұрын
g = 31 is salting the hash? If 31 is for the purpose of a prime number, why 31 specifically? Nonetheless, one of the best lectures in explaining hashes. Thank you professor Edwards!
@CapiEtheriel
@CapiEtheriel 4 жыл бұрын
nope, it's not. you just needed to pick a G, any G would work as long as you used the same G everytime. 31 is a prime though, I know that helps avoiding collisions but I'm not 100% sure why.
@OneStopMusic.
@OneStopMusic. Жыл бұрын
there are a few reasons to use 31. 1. 31 being a prime number, it makes the distribution of hashes more uniform in comparison to a non prime number. The reason for this is that there is a high chance that prime number will be coprime with your table size (We are talking in terms of probability here, so it is not a 100% thing that it will be coprime). And thus it will reduce any patterns or cluttering of hashes to same value as there would be no common factors. 2. we don't want to use a larger prime number to avoid more time consuming arithmetic calculations. Feel free to add more reasons.
@omparikh4426
@omparikh4426 4 жыл бұрын
excatly what i was looking for!
@Tin98Tin
@Tin98Tin 5 жыл бұрын
You solved my homework, thanks!
@danielrnuttall
@danielrnuttall 5 жыл бұрын
@6:04 hahaha!
@srijaljoshi3421
@srijaljoshi3421 5 жыл бұрын
Glad I'm not the only one who noticed lmao
@justindoane7482
@justindoane7482 6 жыл бұрын
Is he writing backwards?????
@kamoroso94
@kamoroso94 6 жыл бұрын
No they flipped the video in post.
@uhmmcool2862
@uhmmcool2862 6 жыл бұрын
no he is writing backwards
@brandonlovatt
@brandonlovatt 5 жыл бұрын
look up The Learning Glass (he gives credit at the end of the video)
@vaisuliafu3342
@vaisuliafu3342 5 жыл бұрын
he actually wrote it upside down but they flipped it post
@catteixeira18
@catteixeira18 4 жыл бұрын
@ops t170 I spat my tea reading this
@nadimkazi2038
@nadimkazi2038 4 ай бұрын
Nice explained.
@EvgenyAleshin
@EvgenyAleshin 7 жыл бұрын
Amazing explanation and presentation
@syedasadalizaidi55
@syedasadalizaidi55 6 жыл бұрын
why are we taking g as 31?
@Skraticks
@Skraticks 2 жыл бұрын
Won't the hash number get really big for a large string? Would the hash number not pass the maximum allowed int?
@Warrior33016
@Warrior33016 2 жыл бұрын
After you get the hash number, modulo it by a prime number
@diogodionisio8924
@diogodionisio8924 4 жыл бұрын
Great job!
@julianrivadera1224
@julianrivadera1224 5 жыл бұрын
Grande pelado!!! me vas a hacer aprobar!!
@nicolabombace2004
@nicolabombace2004 Жыл бұрын
2:15 is going to compile because of implicit Typecasting. There is no overload by return type!
@robertt8748
@robertt8748 3 жыл бұрын
Thanks, this was very helpful!
@shivendrasaxena2199
@shivendrasaxena2199 6 жыл бұрын
which software is being used to make this. M curious
@sliderBro
@sliderBro 6 жыл бұрын
I don't think you need any special software. Use a transparent slab of glass as your whiteboard, film from the other side (not the side the professor is writing on) and then use the mirror image of the frames.
@xerxius5446
@xerxius5446 6 жыл бұрын
they just flipped the image on horizontal axis and then they are showing it on the projector to the students ( and us )
@kariabraham2998
@kariabraham2998 3 жыл бұрын
Great video
@anudeepb5400
@anudeepb5400 4 жыл бұрын
Correct me if I'm wrong but charAt method is not overloaded and you cannot overload a method in java just based on its return type. It works because char is a subset of integer type.
@gadirrustamli6216
@gadirrustamli6216 3 жыл бұрын
That’s correct. Int is 32 bits and char is 16 bits. So, smaller size types can be casted to bigger ones but not vice-versa. This is the increasing order: byte < short, char < int, float < long, double
@switchwithSagar
@switchwithSagar 4 жыл бұрын
Hi, Thanks for the explanation, really appreciate the lectures. But I have some doubts. 1. Shouldn't the hash function @7:59 be -> 116 + g*(104 + g*(105 + 115*g)). 2. The code explained @10:15 generates the hash function -> ((116*g+104)*g+105)*g+115, This is not similar to the hash generated by the method we have discussed in the lecture. Below is the hash generator which I wrote -> I have pasted my hash generator just for reference (C++) int hashCode(const string& str, int g) { int index = str.size() - 1; // Take the last char of the string. int hash = 0; while (index >= 0) { hash = (hash * g) + str[index]; --index; } return hash; } Can someone help me out, on the doubts, or please correct me if I am going wrong somewhere?
@Elxnicorojas
@Elxnicorojas 4 жыл бұрын
His mistake was the way he visited all the positions of the array. His for() function should be like the next: (int i = str.size() - 1 ; i >= 0; i - -) Your solution is right bc it goes through the array in the same way tho. Sorry for my bad english and for answering this 4 weeks later
@mattp6460
@mattp6460 4 ай бұрын
thank you
@rahulbawa6864
@rahulbawa6864 6 ай бұрын
heavy breathing! I hope the professor is keeping well. But such an amazing teacher.
@bw2619
@bw2619 2 жыл бұрын
very helpful, thanks
@j1952d
@j1952d 2 жыл бұрын
A bit late to the party, but IIRC (I'm old) origiinal ASCII was only 7 bits ( 0 - 127), leaving 1 bit in an 8-bit byte for parity.
@miroslavsavel7560
@miroslavsavel7560 3 жыл бұрын
In which string can by hash value negative? Can you please give me example where the hashCode() return negative value? Thank you
@SKeeetcher
@SKeeetcher 3 жыл бұрын
Never. Unicode is always positive
@pleasethink4789
@pleasethink4789 2 жыл бұрын
1:25 m is incorrect for parameter 6. class Main { public static void main(String[] args) { String s = "my name is Rob."; char c = s.charAt(6); System.out.println("c is " + c); } } OUTPUT: c is e
@robimez
@robimez 2 жыл бұрын
lost it at the Sh*t joke , never met many teachers with a sense of humor , take my like and subscribe even if you probably don't need it.
@mernaiskander4607
@mernaiskander4607 3 жыл бұрын
Are you right handed or left handed?
@cristianmoldovan1429
@cristianmoldovan1429 7 жыл бұрын
Got a like from me for the shit joke :))
@TheCaffeinatedDrive
@TheCaffeinatedDrive 7 жыл бұрын
6:05
@simrandotdev
@simrandotdev 6 жыл бұрын
He indeed is a funny teacher. I took one of his courses at SDSU.
@DavidMwangikamau
@DavidMwangikamau 3 жыл бұрын
6:08 🤣🤣🤣
@Capitalust
@Capitalust 6 жыл бұрын
Amazing
@Alkis05
@Alkis05 Жыл бұрын
Why aren't we counting from 0? I'm confused.
@vamsisaivenkat
@vamsisaivenkat 3 жыл бұрын
man how its even possibile writing in backword ???
@syedasadalizaidi55
@syedasadalizaidi55 6 жыл бұрын
Perfect! but why are we taking g as 31?
@qapoo5438
@qapoo5438 6 жыл бұрын
I guess it's random thing. I picked g as 2 and it's working fine.
@syedasadalizaidi55
@syedasadalizaidi55 6 жыл бұрын
Isn't it a prime number thing?
@htxdy
@htxdy 6 жыл бұрын
the collision rate for bigger numbers are small when g is prime
@amirnia47
@amirnia47 3 жыл бұрын
because characters in the ASCII chart starts from 32
@daniyaniazics
@daniyaniazics 4 жыл бұрын
LOVE IT
@pranavprabhu698
@pranavprabhu698 5 жыл бұрын
Can you restore the string from this
@fahimhuq2768
@fahimhuq2768 4 жыл бұрын
AFAIK hashes are one way ; so, no.
@markrayne5382
@markrayne5382 4 жыл бұрын
this is wrong the hashcode produced should match by 116*31^0 + 104*31^1 + 105*31^2 + 115*31^3 = 3,425,965 the algorithm should give this hashcode also but does not the algorithm gives the hashcode - 3,559,070 *edit the reason for this was the professor represented the wrong expression as another comment said the expression is (116g^3 + 104g^2 + 105g + 115) and not (116 + 104g + 105g^2 + 115g^3)
@altf4thc
@altf4thc 4 жыл бұрын
is this guy writing backwards though?
@MammadovAdil
@MammadovAdil 5 жыл бұрын
Character at 6th index is not m, but not important )
@大王-b1k
@大王-b1k 5 жыл бұрын
Adil Mammadov should be e
@aysenur3057
@aysenur3057 5 жыл бұрын
space is also a character. so 6th is m. it's correct. not starting at 0.
@phil5053
@phil5053 4 жыл бұрын
He was about to write shit at 6:07
@gngn2973
@gngn2973 3 жыл бұрын
how do they do this see through glass sorcery? my brain hurts every time i see it. I figured it might be a mirror but then his head should block text that hes written, but it doesnt. then thought it might be a see through white board. but then he would have to write everything backwards for it to be forward for us. i guess the only explanation is some type of hollywood movie magic? I dont know anything about cinematography though. Great video, wish it was longer. Cheers.
@mohammadshahin4922
@mohammadshahin4922 2 жыл бұрын
they simply flip the video around and show it backwards
@rukna3775
@rukna3775 3 жыл бұрын
6:05 - shit 😂
@hazemyahea1588
@hazemyahea1588 7 ай бұрын
why 31 ?
@yanivsh
@yanivsh 3 жыл бұрын
Actually CharAt works by starting at index 0 so his example is a bit wrong ('m')
@tamdnf3214
@tamdnf3214 5 жыл бұрын
Wouldn’t g * hash always result in 0 since hash’s value starts at 0?
@Lyser11
@Lyser11 5 жыл бұрын
No, you are adding s.charAt(i) to hash, so the first value of hash (after 0) will be the value of the first char of the string.
@davidgeismar6531
@davidgeismar6531 5 жыл бұрын
@@Lyser11 yes but that s different from the explanation he gave before when he was raisong g to the power related to the position of the char... so that confused me also
@woofelator
@woofelator 4 жыл бұрын
You should have used "sith" as one of the anagrams of this haha
@ericlongteaches
@ericlongteaches 5 ай бұрын
Position 6 should be e. Strings as char are 0 indexed
@aminemaghous
@aminemaghous 3 жыл бұрын
The problem with this technique is that if we have a long string, 1000 character for instance then in that case g^1000 can't fit in any number or lets it will be inefficient if it fits like in python
@miladzamanzadeh2881
@miladzamanzadeh2881 4 жыл бұрын
I think he should return hash%31
@abhishekavr1848
@abhishekavr1848 4 жыл бұрын
I have a doubt . The logic he used in the for loop is different from what he explained. Is it??
@JimmyCroissant69
@JimmyCroissant69 3 жыл бұрын
Can you please wear a black balaclava next time for better readability?
@soniaxrp7353
@soniaxrp7353 3 жыл бұрын
Didn't anyone else notice his charAt example was wrong? charAt starts at 0 index so should be 'e'! 2 minutes in, and it pissed me off.
@MaxiLR_
@MaxiLR_ 2 жыл бұрын
U r right
@z08840
@z08840 3 жыл бұрын
kinda BS - you can't overload method by return type in java - code will compile because of implicit conversion char to int
@JCiverJPonest
@JCiverJPonest 5 жыл бұрын
Like
@ericlongteaches
@ericlongteaches 5 ай бұрын
Bro you worry too much about the math. We just wanna learn the concept man
@WaseemHuweih-ql8bw
@WaseemHuweih-ql8bw 5 жыл бұрын
my name is Jeff
@laneroberts8747
@laneroberts8747 4 жыл бұрын
charAt() is not overloaded. Overloading a method can only allow it to have multiple input types, it does not allow it to have multiple outputs. This video is mediocre at best.
@ohaRega
@ohaRega 4 жыл бұрын
Oh, you must be a genius XD We all know that what he *meant* was: the constructor for an Integer is overloaded, meaning, it has a version that takes in a character.
@laneroberts8747
@laneroberts8747 4 жыл бұрын
@@ohaRega That is not true, I assume that you are saying, like any constructor there can be many ways to instantiate. That is the idea of overloading. However in this case, he is creating int i. int is primitive(which means that it is not a class) and as such has NO constructor... So no, he is still wrong, and ig now I can add you to the "Wrong list." lmao nice try though
@ohaRega
@ohaRega 4 жыл бұрын
@@laneroberts8747 Actually, yes, you're right. That's my bad.
@cybermindable
@cybermindable 3 жыл бұрын
way too much unnecessary personality and so very dumb writing actual code on the blackboard, especially semicolons ever heard about pseudo-code doc?
@rocknroooollllll
@rocknroooollllll 5 жыл бұрын
Robert! Please speak like a proper Englishman! It sounds so odd when you say "zee"! Can't you just say "zed" and let the students adapt?
@reecebuckle397
@reecebuckle397 5 жыл бұрын
Are you kidding... with the amount of Indian tutorials with thick accents on youtube (not that I have a problem with that) and you're complaining about a rare white guy who's not only extremely easy to understand, but also goes at a slow detailed pace
@markrayne5382
@markrayne5382 4 жыл бұрын
he's not a proper Englishman though if he was he would be a professor in an English uni
@kenanthompsonkilledmydog4753
@kenanthompsonkilledmydog4753 3 жыл бұрын
What was g? the hash table size?
Hashes 5  Compressing numbers to fit the size of the array
3:36
RobEdwards
Рет қаралды 14 М.
Hashes 1 Introduction
15:36
RobEdwards
Рет қаралды 40 М.
小丑女COCO的审判。#天使 #小丑 #超人不会飞
00:53
超人不会飞
Рет қаралды 16 МЛН
UFC 310 : Рахмонов VS Мачадо Гэрри
05:00
Setanta Sports UFC
Рет қаралды 1,2 МЛН
Hash Tables and Hash Functions
13:56
Computer Science Lessons
Рет қаралды 1,6 МЛН
Understanding and implementing a Hash Table (in C)
24:54
Jacob Sorber
Рет қаралды 373 М.
SHA: Secure Hashing Algorithm - Computerphile
10:21
Computerphile
Рет қаралды 1,2 МЛН
Hashes 8 Open Addressing
10:46
RobEdwards
Рет қаралды 31 М.
Hash Tables - Data Structures and Algorithms
20:16
Caleb Curry
Рет қаралды 39 М.
Hashing Algorithms and Security - Computerphile
8:12
Computerphile
Рет қаралды 1,5 МЛН
Red Black Trees 2 Example of building a tree
17:45
RobEdwards
Рет қаралды 107 М.
Fast Inverse Square Root - A Quake III Algorithm
20:08
Nemean
Рет қаралды 5 МЛН
4. Hashing
52:55
MIT OpenCourseWare
Рет қаралды 347 М.
What is a Cryptographic Hashing Function? (Example + Purpose)
7:08
Whiteboard Crypto
Рет қаралды 104 М.
小丑女COCO的审判。#天使 #小丑 #超人不会飞
00:53
超人不会飞
Рет қаралды 16 МЛН