I have finished reading LinkedList. How to use it in projects? I never saw Node in projects. Thanks!
@mike LinkedLists are a type of a collection, similar to an Array. The difference of course is that an array by default has indices which allow you to reference the objects that they hold in that position. This is an advantage over LinkedLists since in order to find a particular object in the list, you have to iterate the list every time. The advantage of a LinkedList are:
They are dynamic in size (they don’t have a fixed size, so they can increase according to your needs). An array on the other hand USUALLY, but not always has a fixed size.
The other benefit of a LinkedList is that one can insert/remove an object from the middle of the collection fairly easily. With an array, this is not so straight forward, as you typically cannot have an empty index in between objects, which means you have to move all after the insertion/removal point up or down.
Arrays are much easier to traverse, since the objects in the collection have indices that can be referenced, and because each object in the Aray does not have a reference connecting to the previous/next object in the collection, binary search can be performed on the array.
I hope this helps!
All the best.
@syedfa Thanks for your answer, which is very helpful. My another questions is, when I am using an array, I can put any type in it, but it seems that LinkedList can only hold Node? I never saw Node in a project and specifically, is Node also a type? Can I use it in iOS projects?
Thanks again for your time!
@mike A “Node” is just a name for the object in the list. Each “Node” typically contains two properties:
- A “value” of some type which could be a number, String, or whatever object type you want
- A “next” property of type “Node” which would reference the object that comes after it in the list, and if the list is a doubly linked list, a “previous” reference also of type “Node” which would point to the object that comes before it in the list.
So to answer your question, “Node” is a type that you create, to hold or contain the actual value type you wish the LinkedList to have.
With respect to working with LinkedLists and using it professionally, believe it or not, it is very rare to actually work with LinkedLists in a job situation. Neither myself, nor other senior iOS developers I know have actually used them on the job. The unfortunate reality is, while these are important concepts to know for the application or job interview process for finding work as an iOS developer (or any software developer job in general), rarely are these concepts ever used in an actual role. I spoke with one recruiter for a very large company and he pointed something interesting out to me about this:
He said it is much easier for a company to test a candidate on these topics because the candidate can simply focus on learning the data structures and algorithms which are static, as opposed to trying to learn the entire iOS API, which is also dynamic (i.e. changes from year to year with each new release).
I will point out that knowing these concepts definitely improve a developers problem solving skills, and while some of the data structures like LinkedLists may not be as relevant in most jobs, other data structures are (e.g. Queues). Queues in iOS are indeed used, specifically in multi threading. If you know how queues work, then knowing the Operations API becomes much easier. It’s called OperationQueue for a reason
Search and Sort algorithms can also be useful in your work, since almost always, you’re working with a collection of objects, and efficiently using them is key. Keep in mind as well that if you’re working on a project that is used by a large number of users, and/or uses a lot of memory/cpu/data, then having a firm understanding of data structures and algorithms becomes crucial to make sure that your app is as efficient as possible.
I hope this helps!
All the best!
@syedfa Thanks for the detailed information. This is really very helpful for studying this book. I was not good at whiteboard interviews before and so far I could see this book helps a lot.
@mike No problem! I’m happy to help.