@Harper Malcolm yea you guessed it right mate. No one cares.
@Doctor_Hams_Dingus_Jam3 жыл бұрын
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?
@andrewwaggoner87973 жыл бұрын
video is flipped, if you saw it live from this angle letters would be backwards. nice how it makes it so easy to see
@pepa0074 жыл бұрын
He started writing and I was like wait... how… holy smoke that’s genius! 😍
@superuser86364 жыл бұрын
“...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
@justinlee60755 жыл бұрын
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).
@markrayne53824 жыл бұрын
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_FB3 жыл бұрын
I noticed the same things! Thanks for posting so I know I'm not going nutty
@MrYourMedia5 жыл бұрын
The character at index 6 is e; hehe
@laneroberts87474 жыл бұрын
@@abhishekavr1848 You are an idiot, you have had 8 months to respond and you respond with the wrong answer lmao
@saineshnakra60454 жыл бұрын
@@abhishekavr1848 Yeah , you probably want to count that again
@moisesacero49954 жыл бұрын
@@laneroberts8747 gawd dam ur pissy
@laneroberts87474 жыл бұрын
@@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
@thepurpleone71534 жыл бұрын
He IS right, its e. My name 0123456
@a1988ditya4 жыл бұрын
6:05 THAT EPIC MOMENT :)
@edrtjiud77527 жыл бұрын
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
@syedasadalizaidi556 жыл бұрын
why are we taking g as 31?
@NourAli-hl4ih6 жыл бұрын
this is correct. his is g^0 then g^1... while yours is g^1 then g^0..
@MammadovAdil5 жыл бұрын
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
@seitarion45384 жыл бұрын
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-og6hl6lv7p7 жыл бұрын
Beautiful explanation of basic string hashing, thanks!
@songsmania16816 жыл бұрын
why are we taking g as 31?
@pressgreen6 жыл бұрын
It is a prime number which reduces the chances of collisions. I think lol
@goutham246933 жыл бұрын
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-cv4gu2 жыл бұрын
31 is optimal for computing hashing results
@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 Жыл бұрын
im testing it right now and i get two different numbers using the two different methods@@imanelamnaoir590
@karlloveridge88182 жыл бұрын
Loved his explanation. If Hollywood ever needs to do a biopic about Donald Pleasence, this is the guy! He even sounds like him!
@ZerofeverOfficial3 жыл бұрын
This video made me get it. Thank you for making it.
@ashuvssut2 жыл бұрын
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
@kirktelia3 жыл бұрын
Thanks a mill this made sense out of nonsense for me
@goldenotis97034 жыл бұрын
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_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.
@code3design5 жыл бұрын
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!
@CapiEtheriel4 жыл бұрын
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. Жыл бұрын
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.
@omparikh44264 жыл бұрын
excatly what i was looking for!
@Tin98Tin5 жыл бұрын
You solved my homework, thanks!
@danielrnuttall5 жыл бұрын
@6:04 hahaha!
@srijaljoshi34215 жыл бұрын
Glad I'm not the only one who noticed lmao
@justindoane74826 жыл бұрын
Is he writing backwards?????
@kamoroso946 жыл бұрын
No they flipped the video in post.
@uhmmcool28626 жыл бұрын
no he is writing backwards
@brandonlovatt5 жыл бұрын
look up The Learning Glass (he gives credit at the end of the video)
@vaisuliafu33425 жыл бұрын
he actually wrote it upside down but they flipped it post
@catteixeira184 жыл бұрын
@ops t170 I spat my tea reading this
@nadimkazi20384 ай бұрын
Nice explained.
@EvgenyAleshin7 жыл бұрын
Amazing explanation and presentation
@syedasadalizaidi556 жыл бұрын
why are we taking g as 31?
@Skraticks2 жыл бұрын
Won't the hash number get really big for a large string? Would the hash number not pass the maximum allowed int?
@Warrior330162 жыл бұрын
After you get the hash number, modulo it by a prime number
@diogodionisio89244 жыл бұрын
Great job!
@julianrivadera12245 жыл бұрын
Grande pelado!!! me vas a hacer aprobar!!
@nicolabombace2004 Жыл бұрын
2:15 is going to compile because of implicit Typecasting. There is no overload by return type!
@robertt87483 жыл бұрын
Thanks, this was very helpful!
@shivendrasaxena21996 жыл бұрын
which software is being used to make this. M curious
@sliderBro6 жыл бұрын
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.
@xerxius54466 жыл бұрын
they just flipped the image on horizontal axis and then they are showing it on the projector to the students ( and us )
@kariabraham29983 жыл бұрын
Great video
@anudeepb54004 жыл бұрын
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.
@gadirrustamli62163 жыл бұрын
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
@switchwithSagar4 жыл бұрын
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?
@Elxnicorojas4 жыл бұрын
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
@mattp64604 ай бұрын
thank you
@rahulbawa68646 ай бұрын
heavy breathing! I hope the professor is keeping well. But such an amazing teacher.
@bw26192 жыл бұрын
very helpful, thanks
@j1952d2 жыл бұрын
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.
@miroslavsavel75603 жыл бұрын
In which string can by hash value negative? Can you please give me example where the hashCode() return negative value? Thank you
@SKeeetcher3 жыл бұрын
Never. Unicode is always positive
@pleasethink47892 жыл бұрын
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
@robimez2 жыл бұрын
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.
@mernaiskander46073 жыл бұрын
Are you right handed or left handed?
@cristianmoldovan14297 жыл бұрын
Got a like from me for the shit joke :))
@TheCaffeinatedDrive7 жыл бұрын
6:05
@simrandotdev6 жыл бұрын
He indeed is a funny teacher. I took one of his courses at SDSU.
@DavidMwangikamau3 жыл бұрын
6:08 🤣🤣🤣
@Capitalust6 жыл бұрын
Amazing
@Alkis05 Жыл бұрын
Why aren't we counting from 0? I'm confused.
@vamsisaivenkat3 жыл бұрын
man how its even possibile writing in backword ???
@syedasadalizaidi556 жыл бұрын
Perfect! but why are we taking g as 31?
@qapoo54386 жыл бұрын
I guess it's random thing. I picked g as 2 and it's working fine.
@syedasadalizaidi556 жыл бұрын
Isn't it a prime number thing?
@htxdy6 жыл бұрын
the collision rate for bigger numbers are small when g is prime
@amirnia473 жыл бұрын
because characters in the ASCII chart starts from 32
@daniyaniazics4 жыл бұрын
LOVE IT
@pranavprabhu6985 жыл бұрын
Can you restore the string from this
@fahimhuq27684 жыл бұрын
AFAIK hashes are one way ; so, no.
@markrayne53824 жыл бұрын
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)
@altf4thc4 жыл бұрын
is this guy writing backwards though?
@MammadovAdil5 жыл бұрын
Character at 6th index is not m, but not important )
@大王-b1k5 жыл бұрын
Adil Mammadov should be e
@aysenur30575 жыл бұрын
space is also a character. so 6th is m. it's correct. not starting at 0.
@phil50534 жыл бұрын
He was about to write shit at 6:07
@gngn29733 жыл бұрын
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.
@mohammadshahin49222 жыл бұрын
they simply flip the video around and show it backwards
@rukna37753 жыл бұрын
6:05 - shit 😂
@hazemyahea15887 ай бұрын
why 31 ?
@yanivsh3 жыл бұрын
Actually CharAt works by starting at index 0 so his example is a bit wrong ('m')
@tamdnf32145 жыл бұрын
Wouldn’t g * hash always result in 0 since hash’s value starts at 0?
@Lyser115 жыл бұрын
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.
@davidgeismar65315 жыл бұрын
@@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
@woofelator4 жыл бұрын
You should have used "sith" as one of the anagrams of this haha
@ericlongteaches5 ай бұрын
Position 6 should be e. Strings as char are 0 indexed
@aminemaghous3 жыл бұрын
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
@miladzamanzadeh28814 жыл бұрын
I think he should return hash%31
@abhishekavr18484 жыл бұрын
I have a doubt . The logic he used in the for loop is different from what he explained. Is it??
@JimmyCroissant693 жыл бұрын
Can you please wear a black balaclava next time for better readability?
@soniaxrp73533 жыл бұрын
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_2 жыл бұрын
U r right
@z088403 жыл бұрын
kinda BS - you can't overload method by return type in java - code will compile because of implicit conversion char to int
@JCiverJPonest5 жыл бұрын
Like
@ericlongteaches5 ай бұрын
Bro you worry too much about the math. We just wanna learn the concept man
@WaseemHuweih-ql8bw5 жыл бұрын
my name is Jeff
@laneroberts87474 жыл бұрын
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.
@ohaRega4 жыл бұрын
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.
@laneroberts87474 жыл бұрын
@@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
@ohaRega4 жыл бұрын
@@laneroberts8747 Actually, yes, you're right. That's my bad.
@cybermindable3 жыл бұрын
way too much unnecessary personality and so very dumb writing actual code on the blackboard, especially semicolons ever heard about pseudo-code doc?
@rocknroooollllll5 жыл бұрын
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?
@reecebuckle3975 жыл бұрын
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
@markrayne53824 жыл бұрын
he's not a proper Englishman though if he was he would be a professor in an English uni