0% found this document useful (0 votes)
7 views12 pages

1.4.2 Linked Lists, Trees and Graphs

The document covers data structures, specifically linked lists, trees, and graphs, emphasizing their interconnected nodes and traversal operations. It details linked lists, including their operations such as insertion, deletion, and traversal, along with step-by-step processes for adding and removing nodes. Additionally, it challenges the reader to explore and document algorithms for various data structures, including graphs and trees.

Uploaded by

tmgbarnard
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views12 pages

1.4.2 Linked Lists, Trees and Graphs

The document covers data structures, specifically linked lists, trees, and graphs, emphasizing their interconnected nodes and traversal operations. It details linked lists, including their operations such as insertion, deletion, and traversal, along with step-by-step processes for adding and removing nodes. Additionally, it challenges the reader to explore and document algorithms for various data structures, including graphs and trees.

Uploaded by

tmgbarnard
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 12

A Level Computer

Science
1.4.2. Data Structures
Linked-Lists, Trees and Graphs
Specification
Recap

 A data structure is a group of related data items organised in the computer.


 A data structure allows a large number of pieces of data to be managed as
a single set.
 Each type of data structure is designed to be processed in a particular way.
 Arrays and lists are linear sets of data that are typically processed in a
serial or sequential manner.
 Records and tuples are aggregate data structures (can be referenced as a
single entity, and yet consists of more than one piece of data.). They are
typically used to look up or return database queries and are often
associated with permanently stored databases or files.
 Stacks and queues are linear structures where processing is determined by
the order data is added. Stacks are LIFO while queues are FIFO.
Linked lists, trees and graphs

 Linked lists, trees and graphs are data structures characterised by


interconnected nodes.
 Nodes are data items that contain links to other data items.
 The manner of interconnection is the defining characteristic of each
data structure and determines how it is typically processed.
 Traversal of the data structure is often the important processing
operation associated with these types of structures.
Linked Lists

 A linked list is a list of data items where each item contains data
together with a pointer to the next item in the list.
 Linked lists are typically used to access data in a particular order
even if they are not stored in order or even in adjacent memory
spaces.
 Linked lists can be doubly linked, i.e. they can link to the previous
item in the list too.
 A linked list needs a pointer to indicate the head or first item in the
list.
(Terminator)
 An unconnected link is called a null pointer or terminator.
Hea
d
Linked Lists Operations

 The typical linked list operations are insertion, deletion, display and
find.
 Insertion is the adding of a data item into the list into a position that
maintains the defining order of the list.
 Deletion is the removal of a data item from a list, maintain its
defining order.
 Display the complete list.
 Find or search looks for a specific element using a given key.
 Display and find are traversal operations.
Liked list insertion

 Adding a new node in linked list is a more than one step activity.
 Step 1, create a node using the same structure and find the location
where it has to be inserted.
 Imagine we are inserting a new node B between node A and node C.
Linked list insertion
 Step 2, make the new node B point to node C.

 Step 3, make node A point to node B .


Linked list deletion

 Deletion is also a multi-step operation.


 Step 1, find the data item you are looking to delete. (We will look at
the find operation later – see traversal)

 In searching for the data item it is important to retain the location of


the previous node (lets call it the left node) as well as the current or
target node.
 Leftnode.next points to the target node.
Linked list deletion
 Step 2, make leftnode.next = targetnode.next.

 Step 3, set targetnode.next = null.

 The list is now effectively:


Traversing a linked list

 To traverse a linked list, “follow the pointers”.


 To display the complete list.
1. Set current node to the head node.
2. Output the node.
3. Make current node = current.next
4. Output the node.
5. Repeat steps 3 and 4 until current.next = null.
 To search for an item in the list using a given key traverse in a similar
way (without outputting all the nodes), until the current node
matches the search key (then output node) or the current node is
greater than the given key (then stop and report unfound)
Challenge
 You have now studied several data structures and seen that we need to be
able to describe the structure and the how it is typically processed.
 For each data structure you should be able to draw an abstract
representation of the data structure.
 For each data structure you should be able to describe an algorithm to add
new or remove specified data items to the data structure. If the data items
are held in a specific order then each operation should maintain that order.
 For each data structure you should be able to describe how to traverse the
data structure to display all the data, where appropriate in a specified order.
 Where helpful, you should be able to illustrate the operations you describe
with abstract diagrams.
 Your challenge is now to research and make notes covering the above
information about graph (directed and undirected) and tree data structures.
 (Incidentally a tree is a special form of a graph, and a linked list is a trivial
tree where each node has only one branch.)

You might also like