0% found this document useful (0 votes)
33 views19 pages

DS Unit-Iii (Nep)

This document covers Unit IV of Data Structures Using C, focusing on linked lists and trees. It explains the definition, types, representation, and operations of linked lists, including singly, doubly, circular, and doubly circular linked lists, as well as the basic concepts of trees and their terminologies. The document highlights the advantages of linked lists and provides insights into tree structures and their hierarchical nature.

Uploaded by

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

DS Unit-Iii (Nep)

This document covers Unit IV of Data Structures Using C, focusing on linked lists and trees. It explains the definition, types, representation, and operations of linked lists, including singly, doubly, circular, and doubly circular linked lists, as well as the basic concepts of trees and their terminologies. The document highlights the advantages of linked lists and provides insights into tree structures and their hierarchical nature.

Uploaded by

ganiy0789
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 19
Data Structures Using C UNIT-IV DATA STRUCTURES USING C NOTES Prepared by Prof, Prabhu Kichadi, y, tech 9880437187 UNIT — IV CONTENTS Linked list: Basic Concepts ~ Definition and Representation of linked list, Types of linked lists - Singly linked list, doubly linked list, Circular linked list Doubly Circular Linked list; Representation of Linked list in Memory; Operations on Singly linked lists ~ ‘Traversing, Searching, Insertion, Deletion; Trees: Definition; Tree terminologies -node, root node, parent node, ancestors of a node, siblings, terminal & non-terminal nodes, degree of a node, level, edge, path, depth; Binary tree: Type of binary trees - strict binary tree, complete binary tree, binary search tree and heap tree; Array representation of binary tree, Traversal of binary tre preorder, in order and post order traversal Prof. Prabhu Kichadi, MTech(9880437187) BCA-II SEM (NEP) 1 Data Structures Using C UNIT-IV el Linked List: Linked List is a linear data structure and it is a collection of objects called nodes that are randomly stored in the memory. A node contains two fields i. 1. Info Field - data stored at that address and 2. Address Field - the pointer which contains the address of the next node in the memory. Example: A linked list is like a train where each bogie is connected with links. Different types of linked lists exist to make lives easier, like an image viewer, music player, or when you navigate through web pages Head data link 12 tt Uses of Linked List: o The list is not required to be contiguously present in the memory. The node can reside anywhere in the memory and linked together to make a list. This achieves optimized utilization of space. © list size is limited to the memory size and does not need to be declared in advance. © Empty node cannot be present in the linked list. © We can store values of primitive types or objects in the singly linked list. CERT Prof. Prabhu Kichadi, MTech(9880437187) BCA-II SEM (NEP) Data Structures Using C UNIT-IV el Representation Of Linked List: A node in the singly linked list consists of two parts: data part and link part. Data part of the node stores actual information that is to be represented by the node while the link part of the node stores the address of its immediate successor. Singly Linked list Head 4800 PP EEE EEE 0 700 000 3000 Types Of Linked Lists: There are 4 types of linked list can be identified. Singly Linked List Doubly Linked List Circular Linked List Doubly Circular Linked List Rune 1. Singly Linked List: A singly linked list is a unidirectional linked list. So, you can only traverse it in one direction, i.e., from head node to tail node. Tall > Boao Prof. Prabhu Kichadi, MTech(9880437187) II SEM (NEP) Data Structures Using C UNIT-IV el There are many applications for singly linked lists. One common application is to store a list of items that need to be processed in order. For example, a singly linked list can be used to store a list of tasks that need to be completed, with the head node representing the first task to be completed and the tail node representing the last task to be completed 2. Doubly Linked List: A doubly linked list is a bi-directional linked list. So, you can traverse it in both directions. Unlike singly linked lists, its nodes contain one extra pointer called the previous pointer. This pointer points to the previous node. cap ER + EIS WE 100 96 ever 104 A doubly linked list of singly linked lists is a data structure that consists of a set of singly linked lists (SLLs), each of which is doubly linked. It is used to store data in a way that allows for fast insertion and deletion of elements. 3. Circular Linked List: A circular Linked list is a unidirectional linked list. So, you can traverse it in only one direction, But this type of linked list has its last node pointing to the head node. So while traversing, you need to be careful and stop traversing when you revisit the head node. CER Prof. Prabhu Kichadi, MTech(9880437187) BCA-II SEM (NEP) Data Structures Using C UNIT-IV Tail exp AS) ES) ES = IE JQ J A circular linked list is a type of data structure that uses linked list technology to store data in a linear, sequential fashion. However, unlike a traditional linked list, a circular linked list has no beginning or end - it is essentially a ring of nodes. This makes circular linked lists ideal for applications where data needs to be processed in a continuous loop, such as in real-time applications or simulations. 4. Doubly Circular Linked List: A circular doubly linked list is a mixture of a doubly linked list and a circular linked list. om> I — 96 100 104 A doubly circular linked list (DCL) is a variation of the standard doubly linked list. In a DCL, the first and last nodes are linked together, forming a circle, This allows for quick and easy traversal of the entire list without the need for special case handling at the beginning or end of the list. Representation Of Linked List in Memory: CO ER Prof. Prabhu Kichadi, MTech(9880437187) BCA-II SEM (NEP) Data Structures Using C UNIT-IV Linked list can be represented as the connection of nodes in which each node points to the next node of the list. The representation of the linked list is shown below - Heed Teil 8 [aao0e}—+{ 5 [as00e}—a[ 4 [soooe]—o{ 2 [Noe ‘700 00 2900 5000 (endorne is) Advantages of Linked list The advantages of using the Linked list are given as follows - © Dynamic data structure - The size of the linked list may vary according to the requirements. Linked list does not have a fixed size. o Insertion and deletion - Unlike arrays, insertion, and deletion in linked list is easier. Array elements are stored in the consecutive location, whereas the elements in the linked list are stored at a random location. To insert or delete an element in an array, we have to shift the elements for creating the space. Whereas, in linked list, instead of shifting, we just have to update the address of the pointer of the node. o Memory efficient - The size of a linked list can grow or shrink according to the requirements, so memory consumption in linked list is efficient. o Implementation - We can implement both stacks and queues using linked list. Operations On Singly Linked Lists - Traversing, Searching, Insertion, Deletion: Self-Referential Structure: struct node { CS ERE Prof. Prabhu Kichadi, MTech(9880437187) BCA-II SEM (NEP) Data Structures Using C UNI el int data; struct node “next; Struct node *head, “temp; In the above declaration, we have defined a structure named as node that contains two variables, one is data that is of integer type, and another one is next that is a pointer which contains the address of next node. 1. Creation of node: Trees: A tree is a nonlinear data structure, is defined as a collection of objects or entities known as nodes that are linked together to represent or simulate hierarchy. Features of Trees: A tree data structure is a non-linear data structure because it does not store in a sequential manner. It is a hierarchical structure as elements in a Tree are arranged in multiple levels. o In the Tree data structure, the topmost node is known as a root node. Each node contains some data, and data can be of any type. In the above tree structure, the node contains the name of the employee, so the type of data would be a string Each node contains some data and the link or reference of other nodes that can be called children Tree Terminologies - CERT Prof. Prabhu Kichadi, MTech(9880437187) BCA-II SEM (NEP) 7 Data Structures Using C UNIT-IV Level 0 Level 1 level child Node @) @) eC fa &) (a) 3 1. Node: Node is an entity of a tree which contains information and reference/link to the children. 2. Root Node: The root node is the topmost node in the tree hierarchy. In other words, the root node is the one that doesn't Prof. Prabhu Kichadi, MTech(9880437187) BCA-II SEM (NEP) 8 Data Structures Using C UNIT-IV el have any parent. In the above structure, node numbered 1 is the root node of the tree. +The first node from where the tree originates is called as a root node. +In any tree, there must be only one root node. +We can never have multiple root nodes in a tree data structure. > Root node ©) cs) fe) Om © © &) Oo ® * jgald to be the parent of that sub-node/children nn L Parent of Band C @) @) Ce) OOM © © &) Prof. Prabhu Kichadi, MTech(9880437187) (CA-I SEM (NEP)

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy