As a teacher (math) who’s trying to learn code, you’re an excellent teacher.
@ispiritus44543 жыл бұрын
A quick correction to when you said that you can’t expect what the output is. Maps are actually ordered by key. In your case, you’ll see that the values were outputted in the lexicographical order of the char keys. There is a concept of maps that doesn’t care about order called unordered_map.
@us072513 жыл бұрын
I noticed that when I use integers as keys. Thanks.
@mohamedmostafak3 жыл бұрын
@iSpiritus I was going to write the same comment, then I found yours. thx for the tip and that doesn't change the fact about this video, it is a very good one.
@saintboimike2 жыл бұрын
My man 👌🏾, thanks for pointing this out
@anty.2 жыл бұрын
in an unordered map, are there still premade indexes for the "beginning" and "end" of them?
@edapb55742 жыл бұрын
When counting the number of times a letter occurs, you can just use "++freq[letter]". The index operator [] automatically inserts a new element if it doesn't exist.
@milomadeagame Жыл бұрын
Thank you!🚗🚗
@didgerihorn3 жыл бұрын
Thank you :) Quick performance tip: Use range based loops insted of iterators for (const auto &c : test) { freq[letter] = (letter.find(c) == freq.end()) ? 0 : freq[letter] + 1; }
@gabriellabrito81342 жыл бұрын
can u explain what did u do there? like, this type of code isnt begginers friendly
@didgerihorn2 жыл бұрын
@@gabriellabrito8134 This is a "range based for" loop. In other languages, similar constructs are often called "foreach". It loops over all elements that are actually contained in the variable "test". In the loop body (thatbeing the part between the opening and closing braces) we use the so-called ternary operator to assign the actual frequency to "freq". The ternary operator can be interpreted as a condensed if-else-bock looks as follows: (condition) ? value_if_true : value_if_false Here, the condition is "letter.find(c) == freq.end()", that means, if the letter c (which comes from "test") doesn't already exist as a key in our map, we set it to zero. Otherwise, if it already exists, we increase its frequency by 1
@arjunganesan9138 Жыл бұрын
Nice One!
@vg44142 жыл бұрын
I always hear Tim's "also" as " else so" like: If (x) {y();} else {so();} Is that a Canadian thing or something? Thanks again Tim, you're out here changing lives bro! 💪
@Nole27012 жыл бұрын
For the letter counter example, I don't think the if statement that checks if a letter is in the map is needed. Since the default value for ints in the map is 0, we can just start adding right away.
@marioprado87892 жыл бұрын
Im thinking the same
@gf4083 жыл бұрын
So people are aware since undefined keys will return a value of 0 in maps you don't actually have to check if the key exists for the practical map example. string test = "Hello world my name is tim! ttthhaaa"; map frequency = {}; for (int i = 0; i < test.length(); ++i) ++frequency[test[i]]; for (auto itr = frequency.begin(); itr != frequency.end(); ++itr) cout first
@vegansynths77572 жыл бұрын
This is the best video on KZbin explaining maps. Great vid.
@tanvirhasanmonir16272 жыл бұрын
Wow! wonderful explanation of map. And the last coding example is really worth it to understand real life use case of map.
@torishi827 ай бұрын
Excellent! So precise and to the point. Thank you.
@waqaspathan33373 жыл бұрын
Tim is grinding right now!!!!!
@ketansonar82993 жыл бұрын
You can use shorthand for loop for iterating on a map for (auto p : mp) { cout
@Shadow-lx9rh3 жыл бұрын
Thank you 👍
@uHasioorr3 жыл бұрын
So map, in other programing languages, is a dictionary.
@Abdullah_hassan_88 Жыл бұрын
Exactly
@abrarmasumabir38093 жыл бұрын
Thanks bro Tim ...for everything.....
@alexchen44422 жыл бұрын
Such a good tutorial.
@shubhrajit2117 Жыл бұрын
An easier way for iterating through map: for (auto i : mp) cout
@jurian86203 жыл бұрын
with the example at the end you don't actualy have to check if it already exists because if it doesnt exist it will equal 0 and (for some reason) if you just say ++ after a nonexistend pair it will make the pair.
@Iffythegreat3 жыл бұрын
I think this happens because the map automatically initializes and adds the pair to itself if you try to access it, the only thing is that its set to its default initialization value 0. The reason as to why it is done this way doesnt really make sense to me, I get returning the default value but it getting added to the map seems like a potential flaw
@samsularefinimon27962 жыл бұрын
Appreciate your hard work ! 🙂
@curiositymaarouf1880 Жыл бұрын
Nice, really nice 👍
@paul-cl3el2 жыл бұрын
algo expert da best !!
@karjun46443 жыл бұрын
Will I ever get a chance to see tim with long hairs before I die ?
@mr.erikchun5863 Жыл бұрын
you can see his long pubic hairs
@mhb12x80 Жыл бұрын
Great job dude
@jorgealfredojaimesteheran3 жыл бұрын
I follow you since I have memory, and I love this channel because in a unequal country like Colombia when I am from i can learn with your channel, Colombia government is KILLING us, SOS
@TheBookOfRon2 жыл бұрын
You have great teaching skills. You explain every detail. Nice video!
@古川範和 Жыл бұрын
I got confused at the last example. The map "freq" was only declared, not initialized. How does it have the keys and values?
@SohanSharad3 жыл бұрын
Hey so, was looking if you were going to go into package installers and how to use them, like pip or npm
@ancientelevator9 Жыл бұрын
When you say that you aren't sure if you need the parentheses are you just saying you are not sure if it is a function/method (getter) or an actual persisted property/value of the object? (as it would be in other languages) or is there a specific C++ syntax that I am missing here?
@cantstandya37612 жыл бұрын
Thanks for the good explanation.
@SunilNerella3 жыл бұрын
Hello Tim, For maps I understand that we can create key and value... But for the line `map`, can we add one more data type to it like `map`?
@memoryLeak-CODE Жыл бұрын
Great video!!!
@clockwerkz3 жыл бұрын
Great explanation of map! Just what I was looking for. I was curious about how it returns the map.end() if the find method doesn't contain the key one is looking for.. does this mean the map iterates through the entire structure to find the key's pointer? I'm guessing no since that would make it O(n)..
@ВикторЕфименко-й1ъ2 жыл бұрын
This lesson really helped me a lot. Thank you very much!
@us072513 жыл бұрын
Instead of using if else statement to cout a string letters frequecny, you can write freq[letter]++
@pamp36572 жыл бұрын
good video thank you
@priyanshusrivastava21452 жыл бұрын
loved it!!
@ayushsingh-gl6wm3 жыл бұрын
From where do you learn these. Like which Udemy(or any) course you took. And which platform you mostly follow for learning, and taking new courses.
@Grepehu3 жыл бұрын
I'm not sure about him but when you're learning the basic syntax of a language it's usually a lot quicker to learn by using documentation itself, some languages even give a quick written tutorial in their websites that cover all of it pretty quickly. But again, I'm not sure if it's how Tim does it.
@nijil18012 жыл бұрын
I cant get the key when i use the value. The out put is 0. There is no syntax error. It only works one way and i dont know what to do?
@anniamatthews68032 жыл бұрын
What should I do if I want to get the max value of the map
@jonnyreh0012 жыл бұрын
Is this equivalent method of checking if the key is present in the map? if (freq.count(letter) == 0)
@manipurihunabopa Жыл бұрын
Some projects that are easy to implement in Python and other programming languages are actually difficult to implement in C++. Can you do your Python projects in C++? If you kindly do that, it will help me a lot.
@elwizko3 жыл бұрын
Great lesson Tim...I have a question...can the maps be used in scenarios such as network log monitoring in incident response? I am not a pro in IR but I feel like it is possible when there are millions of logs and minimal time...I appreciate answers from all commenters.
@psymcdad81512 жыл бұрын
I am trying something like this at the moment (logfile on changes in a file). Sadly map does not like std::tm as a type, so I had to convert that, basicaly making it a map of std::time_t t and std::string report. Works nice just to keep reports, but pulling data out of this is kind of a messy nightmare ^^''' ... And I have no idea how time-efficient that trick is alltogether.
@Someone-uw7je3 жыл бұрын
CLASSES AND OBJECT PLEASE TIM!!
@teprox76902 жыл бұрын
I came to the following solution: int main () { string test = "Hello world my name is tim! ttthhaaa"; map letter_freq; for (int i = 0; i < test.size(); i++) { letter_freq.insert(pair(test[i], letter_freq[test[i]]++)); } for (auto & itr : letter_freq) { cout
@pokeytradetf25823 жыл бұрын
What happened with the private livestream??
@alexander_richter Жыл бұрын
This is plain wrong. std::map is not a hashmap, it’s a RB binary tree and it has O(log n) insertion and lookup time complexity. What you are describing is std::unordered_map.
@jodmatthewaclan58693 жыл бұрын
So that's why i need to dereference my iterator, bc it returns a pointer
@Mr_Escow3 жыл бұрын
WOW! COOL! HI FROM RUSSIA! ))
@MarkosZorzoli2 жыл бұрын
Tnks from argentina bro
@keshav.mishra3 жыл бұрын
Present!
@xFlxrin69 Жыл бұрын
nice
@Jordan4Ibanez3 жыл бұрын
Oh very interesting. This is what I did when you typed out the string and gave the instructions: void MyOutPutTest(){ std::string test = "Hello world my name is time! ttthhaaa"; std::map frequency = {}; for (char const &thisLetter: test){ if (!frequency[thisLetter]){ //create initial value frequency[thisLetter] = 1; } else { frequency[thisLetter]++; } } //output counts std::cout
@makeitsimple72853 жыл бұрын
Please make a video about vector pls
@asadjamsheed97733 жыл бұрын
I have a query?
@techbhanucomputer43893 жыл бұрын
c++ map look like a python dictionary
@mahdavimail8 ай бұрын
Python dictionary looks like C++ maps lol.
@arctan23 жыл бұрын
console.log( ( () => 1)() + ( () => 2)() ); .......can someone explain a execution-trace on this code.
@raghavgupta61863 жыл бұрын
()=> 1 is exactly equal to function returnOne(){ return 1; } rest you can understand
@arctan23 жыл бұрын
@@raghavgupta6186 i know but which function first execute....... like which side does "+" operator see and execute.... the output is 3
@raghavgupta61863 жыл бұрын
@@arctan2 first of all both functions gets executed and 1 is returned from first function and 2 is returned from second then + operator is applied from left to right so 1 + 2 = 3
@arctan23 жыл бұрын
@@raghavgupta6186 yes i also thought the same......thanks for your time
@raghavgupta61863 жыл бұрын
@@arctan2 no problem👍
@radhekrishn7023 жыл бұрын
👍🏼👍🏼👍🏼👍🏼👍🏼
@alexandrucrisan52463 жыл бұрын
razvanon?
@treleamaryus24403 жыл бұрын
Klasna
@cyberspyking330611 ай бұрын
its getting harder 😪😮💨
@kevg35632 жыл бұрын
crap video. All you did was iterate through the map. Your technique is similar to 'the 'Count Sort' algorithm. You did not explain how you can tell instantly if a value exists or not WITHOUT iterating through the map. There is, however, another technique that you could use to achieve this.
@TechWithTim2 жыл бұрын
Well how about you share that technique? I’m always open to criticism and feedback buts it hypocritical to suggest I provided no value when you provide none yourself.
@sumukhjagirdar58603 жыл бұрын
Hello Tim please check discord , I have a question for you.Just like always love the content!!!
@OviMG Жыл бұрын
Bro, your face expressions, your voice tone, and much more besides the appearance is much like iRaphahell (search it on youtube) Idk why but you give me same vibes😂