This course has been updated! We now recommend you take the Complete Intro to Computer Science course.

Check out a free preview of the full Four Semesters of Computer Science in 5 Hours, Part 2 course:
The "Tries Exercise" Lesson is part of the full, Four Semesters of Computer Science in 5 Hours, Part 2 course featured in this preview video. Here's what you'd learn in this lesson:

Create a trie to autocomplete search the list of city names in the United States.

Get Unlimited Access Now

Transcript from the "Tries Exercise" Lesson

>> Brian Holt: The basic jist here is I'm going to give you an entire list of all the top cities in the US. Again, if you want to see those, they are kept in this code pen. And it is just a bunch of city names, right? Ordered, I believe in the 2012 census, or something like that.

[00:00:21] So New York was the top one, LA, Chicago. And then if you get down here, it's cities I've never heard of. Actually Spanish Fork is definitely in Utah. I will not talk about it because people from Spanish Fork might be watching.
>> Brian Holt: I can say that, I'm from Utah.

[00:00:42] Okay, so what I'm gonna do here is you can see I'm gonna ask you to create a tree, I'm gonna give you CITY_NAMES, so the first one I give you is just zero to ten so you can start really, really simply. And the nice thing is a lot of the San cities are some of the bigger ones.

[00:01:01] So San Antonio, San Diego and San Jose are gonna actually be the ones that it completes to.
>> Brian Holt: I am not judging you on the order that you return them to me to. So whatever order you return them to, that's fine.
>> Brian Holt: That's why it's doing this _.intersection thing, is it's just making sure everything is in there that it expects to be in there.

>> Brian Holt: Okay
>> Brian Holt: You don't have to use this node data structure. I just gave it to you because I thought this would be a useful way for you to get started.
>> Brian Holt: You'll almost certainly need some sort of constructor. I create the root node here for you. This is going to be all just a list of words.

[00:01:53] And then at the endm you should give me back the list of three things that should go in there.
>> Brian Holt: So again, I'd suggest working on one unit a test at a time, and then from there, kind of getting bigger and bigger.
>> Brian Holt: Okay, I'll give you a bit of time to complete this, and then we'll come back and we'll talk about it.