3. Our Prime Concern
• Performance & Efficiency
– In terms of time ;
• faster the execution, better the algorithm
– In terms of space ;
• lesser the space, better the data structure
9/14/2012 DSA - Fall 2012 - SEECS, NUST 3
4. Pros
• Easier to use and access
• Faster access to the
elements
– Takes constant time
– Base + ( item_number *
number_of_bytes)
Cons
• Fixed size
• One block allocation
– Fails if enough contiguous
memory isn’t available
• Complex position based
insertion
9/14/2012
– Expensive to maintain
ordered data OR insertion at
beginning
DSA - Fall 2012 - SEECS, NUST 4
Arrays
Most common data structure to implement
collections or to store data
5. Arrays
• Solution
– Dynamic Memory Allocation
– Faster insertion and deletion of elements without
changing the existing items
• Linked List
9/14/2012 DSA - Fall 2012 - SEECS, NUST 5
6. Linked List
• Linked structure is a collection of
nodes storing data and links to
other nodes
• Dynamic Memory Allocation
– Consequently, nodes can locate
anywhere in the memory and each
node can point to any other node
9/14/2012 DSA - Fall 2012 - SEECS, NUST 6
7. Linked List
• Linked structure is a collection of nodes storing
data and link to other nodes
struct Node {
int data;
Node * next;
};
9/14/2012 DSA - Fall 2012 - SEECS, NUST 7
9. Linked List
Pros
• Dynamic allocation
– the size is not required to be
known in advance
• Flexibility
– insert at (or delete from) any
position in constant time
• No single allocation of
memory needed
Cons
• Complex to use and access
– relatively complex as
compared to arrays
• No constant time access to
the elements
9/14/2012 DSA - Fall 2012 - SEECS, NUST 9