CS163_Week4_topic1 - CS163: Data structures Week 4 topic 1:...

Info iconThis preview shows pages 1–10. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CS163: Data structures Week 4 topic 1: Other types of linked lists 6/2008 dbtien Data structures What will be discussed today? discuss algorithms to manage circular and doubly linked lists should we use a dummy head node? What are the advantages and disadvantages what about arrays of linked lists, or linked lists of arrays? evaluate the benefits/drawbacks of a doubly threaded list dbtien Data structures Dynamic Linked Lists Wisely controlled dynamic memory can save considerable memory that may be wasted by other implementations We are not limited to fixed size restrictions Certain operations are simpler with linked structures (inserting into a linked list consists of only 2 assignment statements, once we have found the location)...no shifting! dbtien Data structures Dynamic Linked Lists Of course, algorithms may be more complex, harder to read, and harder to debug than similar algorithms with statically allocated structures Think: How would have an array changed the debugging process? Would it have provided all of the necessary functionality? dbtien Data structures Dynamic Linked Lists And, dont forget that in some cases dynamic linked lists can waste memory. It is possible to store many pointers compared to the quantity of data. This pointer space must be considered as overhead, which is accentuated when the nodes contain a small amount of data (like a LLL of single characters!) dbtien Data structures Dynamic Linked Lists For example, a list with a single character data member (one byte) may require a 4-byte pointer as its link resulting in 80% overhead (4 bytes out of 5) in each list node Lastly, allocating and deallocating memory at run-time is overhead and can overshadow the time saved by simple list-processing algorithms. ** no hard and fast rules! ** dbtien Data structures Doubly Linked Lists We have already discussed the benefits and drawbacks of doubly linked lists in relation to various position oriented ADTs avoids the need to manage a previous pointer when we traverse think about this: when you traverse a singly linked list to remove a node -- what happens? yes! two pointers must be managed (current, previous) or a look-ahead approach is used which requires 2 dereferences! dbtien Data structures Traversing...singly LLL Lets examine this further: node * current=head; node * previous= NULL; while (current && current->data != match) { previous = current; current = current->next; } Count the number of operations, fetches... dbtien Data structures Traversing...singly LLL With the look ahead approach: node * current=head; if (current) while (current->next && current->next->data != match) { current = current->next; } Count the number of operations, fetches......
View Full Document

This note was uploaded on 11/03/2010 for the course CS 16x taught by Professor Tang during the Spring '10 term at Aachen University of Applied Sciences.

Page1 / 39

CS163_Week4_topic1 - CS163: Data structures Week 4 topic 1:...

This preview shows document pages 1 - 10. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online