Since sets ignore duplicates, attempting to add the same word more than once does nothing. In this case, the book would be parsed and all words would be inserted into the set. Another great scenario for a set that comes to mind is determining the number of unique words in a book. The point is that we put all items on our list into our cart exactly one time. We can add items to the shopping list and we can remove them, but we don't really care about the order of items on our list. One example that implements a set is a shopping list. Sets, similar to other data structures mentioned, have specific cases where their use is ideal. The difference, however, is in the order in which elements are enqueued (pushed) and dequeued (popped) enqueuing an element places it at the back and dequeuing removes the element at the front. The fundamental operations of a queue are pretty similar to those of a stack You can push to a queue, you can pop from a queue, and you can check both the frontmost and rearmost elements of a queue. The order of a queue is then known as "FIFO", or the first item that goes in is the first item that comes out. At the movie theater, people are served in the order in which they get in line the first person that gets in line is the first person who gets their ticket. The compiler checks for matching braces by implementing the stack data structure.Ī queue is another data structure that is a lot like the line at a grocery store or movie theater. ![]() Another area where stacks find use is in the balancing of braces and parentheses in a program. When you press CMD+Z (or CTRL+Z for my windows friends), the most recent action gets "popped" from the stack. Every time a change is made to a document, that change gets added to a stack. One of the most popular is the undo feature that is used in word processors. Stacks are useful in an abundance of applications. When you "pop" from a stack, you remove the top item.Įnter fullscreen mode Exit fullscreen mode When you "push" an item to a stack, you place it at the top. Calling "top" on a stack allows you to examine the top item but does not remove it. In a stack, the three fundamental operations are top, push, and pop. Similarly, if you grade another new paper and place it in the pile, it is now at the top of the pile. When you get up and look at those papers, the first one you will see is the last you finished grading. Imagine you are grading papers, every time you finish one you place the paper into a neat pile on your desk. The order of a stack is known as "LIFO", or the last item that goes in is the first item that comes out. ![]() Like the name implies, a stack is simply a stack of things In this structure, items can only be added or removed from the top. Here, I will briefly discuss the theory and applications of stacks, queues, sets, and maps implemented in C++. So why would you want to learn about data structures? Well, just as there are many tools that serve unique purposes in the construction of a house, there are various data structures that are useful in solving different kinds of problems in computer science. The course does an excellent job at transforming you from someone who knows how to code into someone who knows how to use computers to solve problems. For the past few months now, I have been following the old Stanford CS106B lectures available through YouTube. However, I lacked the theory necessary to be confident that I was writing the best code.Įnter my introduction to data structures. Sure I was learning to write code heck, I even got out of "tutorial hell" and was quickly building projects on my own. Recently, however, I have been faced with this lingering question: are my programs optimized for performance?Ĭuriosity has led me to dive deeper into some of the computer science fundamentals, something that I feel was missing from the previous stage of my learning. I love to code and this journey has allowed me to seamlessly integrate the technical and creative sides of my brain. ![]() I've been programming seriously now for about a year in that time I've brushed up on my python skills, completed a few YouTube courses on HTML/CSS, studied JavaScript, and built a few React apps.
0 Comments
Leave a Reply. |