Monday, May 4, 2009

Linked Lists?

Hi, currently I'm in a Data Structures and Algorithm class, and I have a question about linked lists. I've read the chapter once and I am about to read it again but I have a few questions.





1) I believe I am failing to see why my description of a linked list is "wrong", an array with each "cell" having 2 parts, 1)First part contains data 2) The Address of the NEXT "cell" except for the last one that contains the address of 0 (NULL)





2)I am having some problems coming up with algorithms for assignments dealing with this, are there any tips, tricks, or advice I could use to get this down faster?





3)I am starting to seriously wonder myself, (from a business stand point) how advanced is the stuff I am doing now, compared to projects out in the field? Is this still "newbie" stuff, or is this more advanced work?

Linked Lists?
1. Your description is not entirely wrong, except that a link list is not an array (ie not the array as you read in data structures). The arrays can contain a fixed-max number of elements, whereas a linked list can grow dynamically. Also, as you might know already, inserting an element anywhere in a link list is very easy as compared to inserting an element in an array (except when the element is inserted at the end).





2. I am not sure how helpful will this be - but you can try it out - Use linked list to store a sorted list of employees. Create methods to add and delete employees - each time an employee is added, you have to ensure that the sorted order is preserved (you can choose any field of employee structure to sort the records on - emp no, name, lastname)





3. Rest assured that data-structure is not even close to being obsolete. With all the advanced languages/products that inundate the markets today - data structure still have their own importance. Agreed, not every type of programming will use data structure, but there are a lot of scenarios, that can be best coded using data structures. Though you can still survive if you don't know this topic well (as there are always more than one way to solve a problem), but then your solution may not be as optimized as it would be with use of data structures.
Reply:1) You're correct, except it is not necessarily an array. The cells are called "nodes", and they do not need to be part of an array (and usually aren't). They can be individual data structures on their own. Each node has data and a pointer to the next node. Otherwise, you're completely right.





2) Your library of routines for linked lists will need a routine to add or remove a link to the list, and to detect if this is the last node. Adding to the end or the beginning of the list is a special consideration. Otherwise, I'll leave it to you to search Google or Yahoo for the terms: linked list example.





3) It is both basic computer science and it is also used at the highest levels. Linked lists are extremely important in many ways. I have been a software engineer for 20 years and I still use them all the time. Some languages have a class called "collection" which handles the linked list for you.


No comments:

Post a Comment