The document discusses linked lists and their implementation in C++. It contains the following key points:
1) A linked list stores data non-contiguously in memory by chaining together nodes that contain a data element and a pointer to the next node. The head pointer points to the first node.
2) To create a new node, the Node class constructor is called and passed the data element. This allocates memory and returns a pointer to the new node.
3) To insert a new node, its next pointer is set to the next node of the current node. The current node's next pointer is then set to the new node.
4) The List class manages the linked list by
This document discusses methods of linked lists, including the start, remove, length, and analysis methods. It provides code examples for initializing the start of a linked list and removing a node. It also analyzes the time and memory efficiency of different linked list operations like add, remove, find, and back compared to arrays. Finally, it introduces doubly linked lists, showing how they allow moving forward and backward easily using next and prev pointers in each node.
Static memory allocation assigns memory at compile time using arrays, while dynamic allocation assigns memory at runtime using pointers. Dynamic allocation overcomes issues with static allocation like wasted memory and unknown memory needs. The malloc() function dynamically allocates memory, returning a void pointer. The free() function deallocates memory to avoid memory leaks. Linked lists use dynamic allocation through malloc() and free() to overcome array limitations like unknown sizes and complex insertions/deletions. Linked lists have nodes with data and next pointer, allowing flexible memory usage through various operations like creation, insertion, deletion, traversal and searching.
The document discusses list data structures and their implementation using arrays and linked memory. It describes common list operations like insertion, removal, searching, and provides examples of how to implement them with arrays and linked lists. Key list operations include adding and removing elements from different positions, accessing elements by index or pointer, and traversing the list forward and backward. Linked lists offer more flexibility than arrays by not requiring predefined memory allocation.
Linked lists are linear data structures where each node points to the next. Each node contains a data field and a pointer to the next node. There are three types: singly, doubly, and circular linked lists. Linked lists allow for constant-time insertions and deletions and do not require fixed size allocation. Common operations on linked lists include insertion, deletion, searching, and traversal. Linked lists are useful for implementations like stacks, queues, and dynamic data structures.
Python has many built-in data types including numbers, strings, lists, tuples, and dictionaries. It also supports user-defined data structures like classes. Data types store values without semantics while data structures organize data to allow efficient operations. Python uses dynamic typing so variables can reference values of any type. Some key differences between mutable and immutable objects are that mutable objects like lists can be modified after creation while immutable objects like strings and tuples cannot be changed once set.
The document discusses arrays and their use in programming. It defines an array as a data storage structure built into most languages. Arrays allow storing multiple items of the same type under a single name. The document covers creating, accessing, initializing, and manipulating array elements through examples. It also discusses dividing a program into classes for an object-oriented approach to using arrays. Key operations covered include insertion, searching, and deletion of array elements.
This document contains a programming exam paper with 5 questions related to object-oriented programming concepts in Java. The questions cover topics like binary search trees, message boards, exceptions, threads, and generics. Students are asked to provide implementations and specifications for various data structures and algorithms, and explain concepts like method call stacks, exceptions, synchronization, and generics.
This document discusses methods of linked lists, including the start, remove, length, and analysis methods. It provides code examples for initializing the start of a linked list and removing a node. It also analyzes the time and memory efficiency of different linked list operations like add, remove, find, and back compared to arrays. Finally, it introduces doubly linked lists, showing how they allow moving forward and backward easily using next and prev pointers in each node.
Static memory allocation assigns memory at compile time using arrays, while dynamic allocation assigns memory at runtime using pointers. Dynamic allocation overcomes issues with static allocation like wasted memory and unknown memory needs. The malloc() function dynamically allocates memory, returning a void pointer. The free() function deallocates memory to avoid memory leaks. Linked lists use dynamic allocation through malloc() and free() to overcome array limitations like unknown sizes and complex insertions/deletions. Linked lists have nodes with data and next pointer, allowing flexible memory usage through various operations like creation, insertion, deletion, traversal and searching.
The document discusses list data structures and their implementation using arrays and linked memory. It describes common list operations like insertion, removal, searching, and provides examples of how to implement them with arrays and linked lists. Key list operations include adding and removing elements from different positions, accessing elements by index or pointer, and traversing the list forward and backward. Linked lists offer more flexibility than arrays by not requiring predefined memory allocation.
Linked lists are linear data structures where each node points to the next. Each node contains a data field and a pointer to the next node. There are three types: singly, doubly, and circular linked lists. Linked lists allow for constant-time insertions and deletions and do not require fixed size allocation. Common operations on linked lists include insertion, deletion, searching, and traversal. Linked lists are useful for implementations like stacks, queues, and dynamic data structures.
Python has many built-in data types including numbers, strings, lists, tuples, and dictionaries. It also supports user-defined data structures like classes. Data types store values without semantics while data structures organize data to allow efficient operations. Python uses dynamic typing so variables can reference values of any type. Some key differences between mutable and immutable objects are that mutable objects like lists can be modified after creation while immutable objects like strings and tuples cannot be changed once set.
The document discusses arrays and their use in programming. It defines an array as a data storage structure built into most languages. Arrays allow storing multiple items of the same type under a single name. The document covers creating, accessing, initializing, and manipulating array elements through examples. It also discusses dividing a program into classes for an object-oriented approach to using arrays. Key operations covered include insertion, searching, and deletion of array elements.
This document contains a programming exam paper with 5 questions related to object-oriented programming concepts in Java. The questions cover topics like binary search trees, message boards, exceptions, threads, and generics. Students are asked to provide implementations and specifications for various data structures and algorithms, and explain concepts like method call stacks, exceptions, synchronization, and generics.
1) The document discusses various data structures and algorithms including arrays, stacks, queues, pointers, and linked lists.
2) It provides details on common data structure operations like insertion, deletion, sorting, and searching. Linear and non-linear data structures are described.
3) Examples of how each data structure works are given, such as the push and pop operations for stacks, and insertion and deletion for queues. Applications like arithmetic expressions and recursion are discussed.
Insertion in a singly linked list can be done at the beginning, middle, or end of the list. To insert a node, a new node is first created and its data and link fields are initialized. For insertion at the beginning, the new node's link is set to the current head node and the head is updated to the new node. For middle insertion, the link of the new node is set to the link of the previous node and the previous node's link is updated to the new node. For end insertion, the link of the last existing node is updated to the new node and the new node's link is set to null. Traversal may be needed to reach the insertion point, with conditions to stop at
The document provides an overview and syllabus for a course on fundamentals of data structures. It covers topics such as linear and non-linear data structures including arrays, stacks, queues, linked lists, trees and graphs. It describes various data types in C like integers, floating-point numbers, characters and enumerated types. It also discusses operations on different data structures and analyzing algorithm complexity.
Computer science solution - programming - big c plus plusPraveen Tyagi
The program implements a telephone lookup that allows searching by name or number. It defines functions to search, sort, and traverse a data structure containing names and phone numbers. The main() function displays a menu, takes user input, calls the appropriate functions to lookup and return the matching name or number, and repeats until the user exits. Binary search functions are implemented recursively to efficiently search the sorted data structure.
This document discusses stacks and queues as data structures. It begins by explaining what a stack is, noting that a stack follows last-in, first-out ordering. It then provides an analogy using mail delivery to explain the stack concept. The document goes on to provide Java code examples for implementing a stack. It also gives examples of using a stack to reverse a word and check balanced parentheses. Next, the document defines queues as first-in, first-out data structures and provides Java code for implementing a queue. It concludes by explaining how stacks can be used to parse arithmetic expressions by first converting them to postfix notation.
This document discusses files and streams in .NET framework 4.5. It covers navigating the file system using classes like FileInfo, DirectoryInfo, and DriveInfo. It also discusses reading and writing files using streams, including FileStream for binary data and StreamReader/StreamWriter for text. Key points covered include getting information on files and directories, creating/deleting files and folders, and reading/writing files using streams in a simple way compared to FileStream.
Linked lists are linear data structures where elements are linked using pointers. Unlike arrays, the elements of a linked list are not stored at contiguous memory locations. Linked lists allow for dynamic sizes and easier insertion/deletion of elements compared to arrays but have disadvantages like non-sequential access of elements and extra memory usage for pointers. A linked list node contains a data field and a pointer to the next node. A doubly linked list node also contains a pointer to the previous node, allowing traversal in both directions.
The document discusses arrays and data structures in Java. It explains that wrapping an array in a class hides implementation details and provides an interface for users. This abstraction makes the code easier to design. It also describes how ordered arrays allow faster searching through binary search but slower insertion compared to unordered arrays. The document provides code examples for an ordered array class that implements binary search and shows how to store objects like Person data in an array.
1. Recursion is a programming technique where a method calls itself to solve smaller instances of the same problem. This document discusses examples of using recursion to calculate triangular numbers, factorials, binary search, and the Towers of Hanoi puzzle.
2. Mergesort is presented as a recursive algorithm for sorting an array. It works by recursively splitting the array in half and merging the sorted halves.
3. Various examples of Java programs are provided that implement recursive solutions to problems like calculating triangular numbers, factorials, binary search, Towers of Hanoi, and mergesort.
This document discusses linked lists and polynomials represented as linked lists. It provides details on singly linked lists, including how to implement insertion and deletion of nodes. It also describes how to represent stacks and queues as dynamically linked lists. Finally, it discusses representing polynomials using arrays or linked lists, and how to perform addition and multiplication of polynomials in each representation.
The document discusses stacks and queues as abstract data types (ADTs). It describes stacks as LIFO (last-in first-out) data structures and queues as FIFO (first-in first-out) data structures. It provides implementations of stacks using arrays and discusses various stack operations like push, pop, peek, etc. It also discusses applications of stacks like expression evaluation, conversion between infix, postfix and prefix notations. Similarly, it describes the basic representation and operations of queues.
In computer science, a linked list is a linear collection of data elements, whose order is not given by their physical placement in memory. Instead, each element points to the next. It is a data structure consisting of a collection of nodes which together represent a sequence.
This document provides an introduction to data structures. It discusses key concepts like abstract data types, different types of data structures including primitive and non-primitive, and common operations on data structures like traversing, searching, inserting, deleting, sorting and merging. It also covers algorithm analysis including time and space complexity and asymptotic notations. Specific data structures like arrays, linked lists, stacks, queues, trees and graphs are mentioned. The document concludes with discussions on pointers and structures in C/C++.
Introduction to Data Structure : PointerS P Sajjan
This document discusses pointers to structures and arrays in C programming. It explains how to declare a pointer to a structure, access members of a structure using pointer operators like -> and *, and define pointers to arrays of strings. It also covers pointers to pointers, opening and closing files, reading from and writing to files, and how to create and manage files in C.
This document outlines the syllabus for Computer Science (41) taught by Prof. K. Adisesha. It covers 4 units: Unit A discusses computer hardware components and data structures; Unit B covers object-oriented programming in C++; Unit C focuses on databases, queries, and large data; Unit D examines advanced communication technology concepts like networking and web design. Key topics include motherboards, Boolean algebra, arrays, stacks, queues, classes, inheritance, pointers, files, SQL, networks, and HTML.
This document discusses the implementation of a single linked list data structure. It describes the nodes that make up a linked list, which have an info field to store data and a next field pointing to the next node. The document outlines different ways to represent linked lists, including static arrays and dynamic pointers. It also provides algorithms for common linked list operations like traversing, inserting, and deleting nodes from the beginning, end, or a specified position within the list.
The document provides information about the Data Structures course offered by S. Durga Devi from CSE department of CBIT. It includes the course objectives, outcomes, units and topics covered in the course. The 5 units cover introduction to data structures, linked lists, stacks and queues, trees, hashing and balanced search trees. Commonly used data structures like arrays, linked lists, stacks, queues, trees and graphs are part of the course. Sorting algorithms like quicksort and mergesort are also included. The performance of algorithms is analyzed in terms of time and space complexity. Asymptotic notations like Big-O, Omega and Theta are discussed for analyzing algorithms. Recursion and its applications are explained.
This document discusses linked lists and their implementation. It covers singly linked lists, doubly linked lists, and generic linked lists. Key points include:
- Linked lists store data in nodes that point to the next node.
- Singly linked lists use a head node and each node's next pointer to link the nodes in a linear fashion.
- Doubly linked lists add a previous pointer to each node to allow traversal in both directions.
- Generic linked lists use type parameters to make the list elements any type.
Algorithms like insertion, removal, and searching are described along with code examples in various Java classes. Exercises are provided to add methods to the generic linked list implementation.
A list is a sequential data structure that allows additions and removals at any position, unlike stacks and queues. Common list operations include adding and removing nodes, updating node contents, checking if the list is empty/full, and initializing/destroying the list. Lists can be implemented using arrays (for static storage) or linked nodes (for dynamic storage). Array lists allow constant-time access but linear-time insertion/removal. Linked lists have linear-time access but constant-time insertion/removal. Both use probes and previous references to traverse the list during operations.
- The document discusses implementing a stack data structure using a linked list to overcome the fixed size limitation of an array.
- When using a linked list, elements can be inserted at the start or end in constant time, but removing from the start is more efficient than the end.
- Therefore, the stack implementation inserts new nodes at the start of the linked list for the push() operation and removes nodes from the start for the pop() operation.
- Code examples are provided for the push() and pop() methods to demonstrate how elements are added and removed from the start of the linked list.
Abstract Data Types (a) Explain briefly what is meant by the ter.pdfkarymadelaneyrenne19
Abstract Data Types
(a) Explain briefly what is meant by the term abstract data type (ADT). Give two
reasons why use of ADTs is good programming practice.
(b) Write out a signature, or interface, that defines the operations of a stack ADT.
(c) Consider a string of characters of the form
... (.( ... ).) ...
where ... indicates an arbitrary sequence of characters (except for parentheses),
(.( indicates an arbitrary number (one or more) of opening parentheses, and
similarly ).) indicates an arbitrary number of closing parentheses.
Using only the stack abstraction operations defined above, write pseudocode for
an algorithm that determines, using a stack, whether or not the number of closing
parentheses is the same as the number of opening parentheses.
You may assume the existence of a function read(str,ch) that reads the next character
of string str into ch.
You may also assume that you can invoke a function reportFail, that will cause
termination with failure, and similarly, reportSuccess causes termination with a
success indication.
Further, you may also assume that you can call a function newStack(S) to create
a new empty stack S, and eos(str) that returns false when you reach the end of
the string.
Solution
(a) Explain briefly what is meant by the term abstract data type (ADT). Give two
reasons why use of ADTs is good programming practice.
A data type is a collection of values and a set of operations on those values. That collection and
these operations form a mathematical construct that may be implemented with the use of a
particular hardware or software data structure. The term abstract data type (ADT) refers to the
basic mathematical concept that defines the data type. We have discussed four different
implementations of the list data structure.
In case of implementation of the list with the use of an array, the size of the array gives difficulty
if increased.
To avoid this, we allocate memory dynamically for nodes before connecting these nodes with the
help of pointers.
For this purpose, we made a singly linked list and connected it with the next pointer to make a
chain.
Moving forward is easy but going back is a difficult task.
To overcome this problem, we made a doubly linked list using prev andnext pointers. With the
help of these pointers, we can move forward and backward very easily. Now we face another
problem that the prev pointer of first node and the next pointer of the last node are NULL.
Therefore, we have to be careful in case of NULL pointers. To remove the NULL pointers, we
made the circular link list by connecting the first and last node.
The program employing the list data structure is not concerned with its implementation.
We do not care how the list is being implemented whether through an array, singly linked list,
doubly linked list or circular linked list. It has been witnessed that in these four implementations
of the list, the interface remained the same i.e. it implements the same methods like add, get,
next, start a.
1) The document discusses various data structures and algorithms including arrays, stacks, queues, pointers, and linked lists.
2) It provides details on common data structure operations like insertion, deletion, sorting, and searching. Linear and non-linear data structures are described.
3) Examples of how each data structure works are given, such as the push and pop operations for stacks, and insertion and deletion for queues. Applications like arithmetic expressions and recursion are discussed.
Insertion in a singly linked list can be done at the beginning, middle, or end of the list. To insert a node, a new node is first created and its data and link fields are initialized. For insertion at the beginning, the new node's link is set to the current head node and the head is updated to the new node. For middle insertion, the link of the new node is set to the link of the previous node and the previous node's link is updated to the new node. For end insertion, the link of the last existing node is updated to the new node and the new node's link is set to null. Traversal may be needed to reach the insertion point, with conditions to stop at
The document provides an overview and syllabus for a course on fundamentals of data structures. It covers topics such as linear and non-linear data structures including arrays, stacks, queues, linked lists, trees and graphs. It describes various data types in C like integers, floating-point numbers, characters and enumerated types. It also discusses operations on different data structures and analyzing algorithm complexity.
Computer science solution - programming - big c plus plusPraveen Tyagi
The program implements a telephone lookup that allows searching by name or number. It defines functions to search, sort, and traverse a data structure containing names and phone numbers. The main() function displays a menu, takes user input, calls the appropriate functions to lookup and return the matching name or number, and repeats until the user exits. Binary search functions are implemented recursively to efficiently search the sorted data structure.
This document discusses stacks and queues as data structures. It begins by explaining what a stack is, noting that a stack follows last-in, first-out ordering. It then provides an analogy using mail delivery to explain the stack concept. The document goes on to provide Java code examples for implementing a stack. It also gives examples of using a stack to reverse a word and check balanced parentheses. Next, the document defines queues as first-in, first-out data structures and provides Java code for implementing a queue. It concludes by explaining how stacks can be used to parse arithmetic expressions by first converting them to postfix notation.
This document discusses files and streams in .NET framework 4.5. It covers navigating the file system using classes like FileInfo, DirectoryInfo, and DriveInfo. It also discusses reading and writing files using streams, including FileStream for binary data and StreamReader/StreamWriter for text. Key points covered include getting information on files and directories, creating/deleting files and folders, and reading/writing files using streams in a simple way compared to FileStream.
Linked lists are linear data structures where elements are linked using pointers. Unlike arrays, the elements of a linked list are not stored at contiguous memory locations. Linked lists allow for dynamic sizes and easier insertion/deletion of elements compared to arrays but have disadvantages like non-sequential access of elements and extra memory usage for pointers. A linked list node contains a data field and a pointer to the next node. A doubly linked list node also contains a pointer to the previous node, allowing traversal in both directions.
The document discusses arrays and data structures in Java. It explains that wrapping an array in a class hides implementation details and provides an interface for users. This abstraction makes the code easier to design. It also describes how ordered arrays allow faster searching through binary search but slower insertion compared to unordered arrays. The document provides code examples for an ordered array class that implements binary search and shows how to store objects like Person data in an array.
1. Recursion is a programming technique where a method calls itself to solve smaller instances of the same problem. This document discusses examples of using recursion to calculate triangular numbers, factorials, binary search, and the Towers of Hanoi puzzle.
2. Mergesort is presented as a recursive algorithm for sorting an array. It works by recursively splitting the array in half and merging the sorted halves.
3. Various examples of Java programs are provided that implement recursive solutions to problems like calculating triangular numbers, factorials, binary search, Towers of Hanoi, and mergesort.
This document discusses linked lists and polynomials represented as linked lists. It provides details on singly linked lists, including how to implement insertion and deletion of nodes. It also describes how to represent stacks and queues as dynamically linked lists. Finally, it discusses representing polynomials using arrays or linked lists, and how to perform addition and multiplication of polynomials in each representation.
The document discusses stacks and queues as abstract data types (ADTs). It describes stacks as LIFO (last-in first-out) data structures and queues as FIFO (first-in first-out) data structures. It provides implementations of stacks using arrays and discusses various stack operations like push, pop, peek, etc. It also discusses applications of stacks like expression evaluation, conversion between infix, postfix and prefix notations. Similarly, it describes the basic representation and operations of queues.
In computer science, a linked list is a linear collection of data elements, whose order is not given by their physical placement in memory. Instead, each element points to the next. It is a data structure consisting of a collection of nodes which together represent a sequence.
This document provides an introduction to data structures. It discusses key concepts like abstract data types, different types of data structures including primitive and non-primitive, and common operations on data structures like traversing, searching, inserting, deleting, sorting and merging. It also covers algorithm analysis including time and space complexity and asymptotic notations. Specific data structures like arrays, linked lists, stacks, queues, trees and graphs are mentioned. The document concludes with discussions on pointers and structures in C/C++.
Introduction to Data Structure : PointerS P Sajjan
This document discusses pointers to structures and arrays in C programming. It explains how to declare a pointer to a structure, access members of a structure using pointer operators like -> and *, and define pointers to arrays of strings. It also covers pointers to pointers, opening and closing files, reading from and writing to files, and how to create and manage files in C.
This document outlines the syllabus for Computer Science (41) taught by Prof. K. Adisesha. It covers 4 units: Unit A discusses computer hardware components and data structures; Unit B covers object-oriented programming in C++; Unit C focuses on databases, queries, and large data; Unit D examines advanced communication technology concepts like networking and web design. Key topics include motherboards, Boolean algebra, arrays, stacks, queues, classes, inheritance, pointers, files, SQL, networks, and HTML.
This document discusses the implementation of a single linked list data structure. It describes the nodes that make up a linked list, which have an info field to store data and a next field pointing to the next node. The document outlines different ways to represent linked lists, including static arrays and dynamic pointers. It also provides algorithms for common linked list operations like traversing, inserting, and deleting nodes from the beginning, end, or a specified position within the list.
The document provides information about the Data Structures course offered by S. Durga Devi from CSE department of CBIT. It includes the course objectives, outcomes, units and topics covered in the course. The 5 units cover introduction to data structures, linked lists, stacks and queues, trees, hashing and balanced search trees. Commonly used data structures like arrays, linked lists, stacks, queues, trees and graphs are part of the course. Sorting algorithms like quicksort and mergesort are also included. The performance of algorithms is analyzed in terms of time and space complexity. Asymptotic notations like Big-O, Omega and Theta are discussed for analyzing algorithms. Recursion and its applications are explained.
This document discusses linked lists and their implementation. It covers singly linked lists, doubly linked lists, and generic linked lists. Key points include:
- Linked lists store data in nodes that point to the next node.
- Singly linked lists use a head node and each node's next pointer to link the nodes in a linear fashion.
- Doubly linked lists add a previous pointer to each node to allow traversal in both directions.
- Generic linked lists use type parameters to make the list elements any type.
Algorithms like insertion, removal, and searching are described along with code examples in various Java classes. Exercises are provided to add methods to the generic linked list implementation.
A list is a sequential data structure that allows additions and removals at any position, unlike stacks and queues. Common list operations include adding and removing nodes, updating node contents, checking if the list is empty/full, and initializing/destroying the list. Lists can be implemented using arrays (for static storage) or linked nodes (for dynamic storage). Array lists allow constant-time access but linear-time insertion/removal. Linked lists have linear-time access but constant-time insertion/removal. Both use probes and previous references to traverse the list during operations.
- The document discusses implementing a stack data structure using a linked list to overcome the fixed size limitation of an array.
- When using a linked list, elements can be inserted at the start or end in constant time, but removing from the start is more efficient than the end.
- Therefore, the stack implementation inserts new nodes at the start of the linked list for the push() operation and removes nodes from the start for the pop() operation.
- Code examples are provided for the push() and pop() methods to demonstrate how elements are added and removed from the start of the linked list.
Abstract Data Types (a) Explain briefly what is meant by the ter.pdfkarymadelaneyrenne19
Abstract Data Types
(a) Explain briefly what is meant by the term abstract data type (ADT). Give two
reasons why use of ADTs is good programming practice.
(b) Write out a signature, or interface, that defines the operations of a stack ADT.
(c) Consider a string of characters of the form
... (.( ... ).) ...
where ... indicates an arbitrary sequence of characters (except for parentheses),
(.( indicates an arbitrary number (one or more) of opening parentheses, and
similarly ).) indicates an arbitrary number of closing parentheses.
Using only the stack abstraction operations defined above, write pseudocode for
an algorithm that determines, using a stack, whether or not the number of closing
parentheses is the same as the number of opening parentheses.
You may assume the existence of a function read(str,ch) that reads the next character
of string str into ch.
You may also assume that you can invoke a function reportFail, that will cause
termination with failure, and similarly, reportSuccess causes termination with a
success indication.
Further, you may also assume that you can call a function newStack(S) to create
a new empty stack S, and eos(str) that returns false when you reach the end of
the string.
Solution
(a) Explain briefly what is meant by the term abstract data type (ADT). Give two
reasons why use of ADTs is good programming practice.
A data type is a collection of values and a set of operations on those values. That collection and
these operations form a mathematical construct that may be implemented with the use of a
particular hardware or software data structure. The term abstract data type (ADT) refers to the
basic mathematical concept that defines the data type. We have discussed four different
implementations of the list data structure.
In case of implementation of the list with the use of an array, the size of the array gives difficulty
if increased.
To avoid this, we allocate memory dynamically for nodes before connecting these nodes with the
help of pointers.
For this purpose, we made a singly linked list and connected it with the next pointer to make a
chain.
Moving forward is easy but going back is a difficult task.
To overcome this problem, we made a doubly linked list using prev andnext pointers. With the
help of these pointers, we can move forward and backward very easily. Now we face another
problem that the prev pointer of first node and the next pointer of the last node are NULL.
Therefore, we have to be careful in case of NULL pointers. To remove the NULL pointers, we
made the circular link list by connecting the first and last node.
The program employing the list data structure is not concerned with its implementation.
We do not care how the list is being implemented whether through an array, singly linked list,
doubly linked list or circular linked list. It has been witnessed that in these four implementations
of the list, the interface remained the same i.e. it implements the same methods like add, get,
next, start a.
Data structure and algorithms chapter three LINKED LISTbinakasehun2026
The document discusses linked lists and their implementation in C++. It defines a linked list as a data structure containing nodes that are connected by pointers, with each node containing a data element and a pointer to the next node. It describes creating a struct containing data fields and a pointer to define the nodes, and using pointers to dynamically allocate memory for new nodes and link them together to form a linked list. It also compares linked lists to arrays and covers different types of linked lists such as singly linked lists and doubly linked lists.
SIT221 Data Structures and Algorithms Trimester 2, 2019 .docxedgar6wallace88877
SIT221 Data Structures and Algorithms Trimester 2, 2019
1
Practical Task 5.1
(Pass Task)
Submission deadline: 10:00am Monday, August 26
Discussion deadline: 10:00am Saturday, September 14
General Instructions
The objective of this task is to study implementation of a Doubly Linked List, a generic data structure capable
to maintain an arbitrary number of data elements and support various standard operations to read, write,
and delete data. Compared to other popular data structures, linked list like data structures offer a number
of advantages with respect to time complexity and practical application. For example, where an array‐based
data structure, such as a simple list (or a vector), requires a contiguous memory location to store data, a
linked list may record new data elements anywhere in the memory. This is achievable by encapsulation of a
payload (the user’s data record) into a node, then connecting nodes into a sequence via memory references
(also known as links). Because of this, a linked list is not restricted in size and new nodes can be added
increasing the size of the list to any extent. Furthermore, it is allowed to use the first free and available
memory location with only a single overhead step of storing the address of memory location in the previous
node of a linked list. This makes insertion and removal operations in a linked list of a constant 1 time;
that is, as fast as possible. Remember that these operations generally run in a linear n time in an array
since memory locations are consecutive and fixed.
A doubly linked list outperforms a singly linked list achieving better runtime for deletion of a given data node
as it enables traversing the sequence of nodes in both directions, i.e. from starting to end and as well as from
end to starting. For a given a node, it is always possible to reach the previous node; this is what a singly linked
list does not permit. However, these benefits come at the cost of extra memory consumption since one
additional variable is required to implement a link to previous node. In the case of a simpler singly linked list,
just one link is used to refer to the next node. However, traversing is then possible in one direction only, from
the head of a linked list to its end.
1. To start, follow the link below and explore the functionality of the LinkedList<T> generic class available
within the Microsoft .NET Framework.
https://msdn.microsoft.com/en‐au/library/he2s3bh7(v=vs.110).aspx.
Because some operations that you are asked to develop in this task are similar to those in the
LinkedList<T>, you may refer to the existing description of the class to get more insights about how your
own code should work.
2. Explore the source code attached to this task. Create a new Microsoft Visual Studio project and import
the DoublyLinkedList.cs file. This file contains a template of the DoublyLinkedList<T> class. The objective
of the task i.
The document discusses data structures including linked lists and trees. It describes linked lists, their implementations and operations. Specifically, it covers single, double and circular linked lists. It also covers different types of trees like binary trees, binary search trees, AVL trees, B-trees and heaps. It discusses their representations, implementations and traversal algorithms. Finally, it provides information on dynamic memory allocation in C using functions like malloc(), calloc(), free() and realloc().
C++ is an object-oriented programming language created by Bjarne Stroustrup in 1985 that maintains aspects of C while adding object-oriented features like classes. C++ can be used to create everything from small programs to large applications and is a powerful general-purpose language. Inheritance allows code reusability by creating new classes from existing classes or base classes, where derived classes inherit capabilities from base classes but can add their own features and refinements. Polymorphism enables objects to react differently to the same function call through virtual functions, allowing different classes that inherit from a base class to provide their own implementation of a function.
Must use the c-> syntax because we get a pointer from the queue. The object is still alive because it was created in the heap. One should be careful about transient objects that are stored by reference in data structures.computer notes
This document provides information on various data types, variables, and structures in Visual Basic, including:
- The differences between information and data, with data being information formatted for computer software.
- Common variable types like Integer, String, and Date that can be declared and initialized.
- Mathematical and string methods that can be used to manipulate variable values.
- Control structures like If/Then/Else statements, loops, and Select Case that allow conditional execution of code.
- Collections like arrays and ArrayLists that can store and manage multiple values.
The document covers many fundamental concepts in Visual Basic programming for representing and manipulating data.
The document discusses data structures and provides an example program that uses a circular linked list to solve the Josephus problem. It explains how the program includes the CList class, which defines methods like add, remove, next, and get for manipulating the list. The program is able to efficiently solve the problem by using these pre-defined methods rather than implementing the logic directly. The document also discusses benefits of abstract data types and how they allow changing the underlying implementation without affecting programs, and introduces stacks as another important data structure.
ECE 263/264 Fall 2016
Final Project
Due Date – Sunday, December 11, 2016, 11:59pm
This semester’s final project involves implementing a simple Hospital Patient Management System that
will allow the user to read, store, and manipulate patient data through a friendly text‐based interface.
During execution, the program stores all patient data in a linked list, and upon termination this data is
automatically writes/saves into a text file. Note that this project requires knowledge of some material
from Chapters 12, 13, and 17, which will be covered during the week of Nov. 28.
1) OVERVIEW OF THE PROJECT
You will be provided with the following 6 files that contain the initial source code for this project:
proj_main.c, structs.h, proj1.c, proj1.h, proj2.c and proj2.h. You will need all 6 of these files to build the
program for this project (See Section 2).
Below is a detailed description of the contents of each of each file.
‐ File proj_main.c contains the “main” function.
‐ File structs.h contains all the structure definitions for the project.
‐ File proj1.c contains empty/shell function definitions, which you will need to fill in with
appropriate code, according to the function description given below.
‐ File proj1.h contains prototypes for the functions defined in proj1.c
‐ File proj2.c contains function definitions that have already been implemented.
‐ File proj2.h contains prototypes for the functions defined in proj2.c.
When the program is executed, it repeatedly displays a menu asking the user to enter a command. Each
item in the menu corresponds to a specific operation on patient data, and each operation is performed
by calling one of the functions that you will be implementing (see Section 6). The menu items are:
D Display List
A Add patient
R Remove patient
U Update patient checkup history
C Show patient checkup history
S Sort list either by patient name or by ward number
Q Terminate program
2) YOUR TASK AND WHAT YOU NEED TO SUBMIT
Your main task in this project is to complete the function definitions in proj1.c as described in Section 6.
You must not change any of the other 5 files.
You may only submit file proj1.c.
3) HOW TO GET STARTED WITH THE PROJECT
1. Download the above mentioned 6 files from Canvas.
2. Create a new solution in Visual studio, add all files to the solution.
3. Build the solution then run the program. The program should run correctly but does not do
anything useful; specifically, nothing is displayed on the screen when you select any menu item.
4. Read the project description carefully, and try to understand which functions are called for each
menu item and what each function is supposed to do.
5. You may want to start by implementing function displayList. It is conceptually simple and will
test your basic understanding of linked lists.
6. You will notice that when you initially ...
This document provides a practical manual on data structures for computer science students. It was prepared by Mr. Naveen Choudhary and Dr. Dharm Singh of the Computer Science and Engineering department at Maharana Pratap University of Agriculture and Technology in Udaipur. The 138-page manual contains exercises and solutions to help students understand data structures from an applied perspective. It covers topics like stacks, queues, linked lists, trees, and sorting and searching algorithms.
Data structures and algorithms short note (version 14).pdNimmi Weeraddana
The document provides an introduction to data structures and algorithms. It discusses why data structures are needed, common measurements of efficiency, and the costs of algorithms. It defines abstract and concrete data structures, and provides examples of stacks and queues as abstract data types that can be implemented using concrete data structures like arrays. It also discusses algorithms for operations like sorting, searching, insertion and removal. Overall, the document serves as an introductory overview of key concepts in data structures and algorithms.
C++ (pronounced "see plus plus") is a computer programming language based on C. It was created for writing programs for many different purposes. In the 1990s, C++ became one of the most used programming languages in the world.
The C++ programming language was developed by Bjarne Stroustrup at Bell Labs in the 1980s, and was originally named "C with classes". The language was planned as an improvement on the C programming language, adding features based on object-oriented programming. Step by step, a lot of advanced features were added to the language, like operator overloading, exception handling and templates.
C++ is an object-oriented programming language created by Bjarne Stroustrup in 1985 that maintains aspects of C while adding object-oriented features like classes. C++ can be used to create small programs or large applications across many domains. Key concepts covered include functions, classes, inheritance, polymorphism, and memory management techniques like realloc() and free().
The “&” indicates a parameter that is a reference variable. Because it is the value that is passed. We can always pass a literal or even an expression in call-by-value computer notes
This document summarizes key aspects of reference variables in C++. It discusses how reference variables are declared using an ampersand (&) symbol and how they differ from regular variables and pointer variables. It provides an example comparing three functions - one that passes a regular variable, one that passes a pointer, and one that passes a reference. When the reference variable function is called, the reference acts like an alias to the original variable, so changes made to the reference inside the function also change the original variable. This allows passing large objects to functions without incurring copying overhead.
The document discusses object-oriented programming concepts in Python including classes, objects, methods, and class definitions. Some key points:
- Python supports object-oriented programming with classes that define new data types and objects that are instances of those classes.
- A class defines attributes and methods that are common to all objects of that class. Methods are functions defined inside classes that operate on object instances.
- Objects are instantiated from classes and can have instance-specific attribute values. Dot notation accesses attributes and methods of an object.
- Initialization methods like __init__() set up new object instances. Special methods starting with double underscores have predefined meanings.
- Methods allow passing the object instance as the first
This document provides information about C++ classes and objects. It discusses arrays of class objects, static members and variables, const member functions, and string objects. It also includes examples of catching bugs in C++ code snippets and implementing classes for points, polygons, and rectangles.
Similar to computer notes - Linked list inside computer memory (20)
The document discusses different techniques for improving the efficiency of union-find algorithms, including union-by-size, path compression, and union-by-height. Union-by-size works by making the root of the smaller tree the child of the larger tree during a union operation, keeping tree heights small. Path compression further optimizes find operations by updating the parent pointers along the search path. Together these optimizations allow union-find algorithms to run in almost linear time for practical purposes.
The document discusses divide and conquer algorithms for sorting, specifically mergesort and quicksort. It explains that mergesort works by recursively splitting a list in half, sorting the halves, and then merging the sorted halves together. Quicksort works by picking a pivot value and partitioning the list into elements less than and greater than the pivot, before recursively sorting the sublists. Both algorithms run in O(n log n) time.
The document discusses different types of tree data structures, focusing on binary trees. It defines a binary tree recursively as a finite set of elements that is either empty or partitioned into three disjoint subsets containing a single root element and left and right subtrees. The document outlines common binary tree terminology like nodes, parents, descendants, and levels. It also describes complete binary trees where all levels are fully filled except the lowest, which has nodes filled from left to right.
The document discusses AVL trees and balanced binary search trees. It provides the following key points:
1) An AVL tree is a self-balancing binary search tree where the height of the two child subtrees of every node differ by at most one.
2) A balanced binary search tree is one where the height of the left and right subtrees of each node differ by no more than one.
3) Inserting new nodes can cause the tree to become unbalanced if the insertion breaks the height balance property. Rotations may be needed to rebalance the tree.
The document discusses level-order traversal of binary trees. Level-order traversal visits all nodes at each level from left to right before moving to the next level. This can be implemented by using a queue, where the left and right children of each dequeued node are enqueued. The code provided traverses a binary tree using this level-order technique.
The document discusses equivalence relations and the union-find algorithm. It defines what makes a binary relation an equivalence relation by having the properties of reflexivity, symmetry, and transitivity. It gives examples like electrical connectivity being an equivalence relation. The union-find algorithm can be used to dynamically determine if elements are in the same equivalence class based on the given relations, by performing find and union operations in time proportional to m+n for m finds and n-1 unions.
The document discusses various aspects of balanced binary search trees, including:
1) Const keyword can be used to mark parameters and return values as constant to prevent unintended modification.
2) AVL trees are binary search trees where the heights of left and right subtrees differ by at most 1.
3) For a binary search tree to be balanced, the heights of left and right subtrees should be close to equal to avoid a skewed or degenerate tree structure.
Union-find data structures can be used to efficiently generate random mazes. A maze can be represented as a grid of cells where each cell is initially isolated by walls. Removing walls corresponds to union operations, joining the cells' sets. A maze is generated by randomly performing unions until the entrance and exit cells are in the same set, connected by a path through the maze.
The document discusses different types of linked lists, including singly linked lists, doubly linked lists, and circularly linked lists. It provides code examples for implementing linked lists in C++ and compares the time complexity of different linked list operations. It also describes how a circularly linked list can be used to solve the Josephus problem of eliminating people seated in a circle.
The document discusses binary search trees and different ways to traverse them. It explains that traversing a binary search tree can be done in preorder, inorder, or postorder fashion by recursively visiting the left child, then the node, then the right child in different orders. Searching for a value in a balanced binary search tree takes O(log n) time, while searching an unsorted linked list takes O(n) time.
The document discusses deleting nodes from a binary search tree (BST). There are three cases to consider when deleting a node: 1) if the node is a leaf, it can be deleted immediately, 2) if the node has one child, its parent pointer is redirected to the child node, 3) if the node has two children, it is replaced with its inorder successor. The algorithm and C++ code for deleting nodes from a BST is presented.
The document discusses deletion in AVL trees and outlines 5 cases to consider when deleting nodes from an AVL tree. It also discusses expression trees and parse trees, providing examples of an expression tree for a mathematical expression and a parse tree for an SQL query. Other uses of binary trees mentioned include their use in compilers for expression trees, parse trees, and abstract syntax trees.
The document discusses various data structures including skip lists, AVL trees, and hashing. It explains that skip lists allow for logarithmic-time operations and are simple to implement. Hashing provides constant-time operations by mapping keys to array indices via a hash function, but collisions must be handled. Common hash functions discussed include summing character codes or converting to a number in a prime base.
The document discusses different methods for handling collisions in hash tables, which occur when two keys hash to the same slot. It describes linear probing, where the next empty slot is used to store the colliding key; quadratic probing which uses a quadratic function to determine subsequent slots; and chaining, where each slot contains a linked list of colliding keys. It notes the advantages and disadvantages of each approach.
In the rapidly evolving landscape of technologies, XML continues to play a vital role in structuring, storing, and transporting data across diverse systems. The recent advancements in artificial intelligence (AI) present new methodologies for enhancing XML development workflows, introducing efficiency, automation, and intelligent capabilities. This presentation will outline the scope and perspective of utilizing AI in XML development. The potential benefits and the possible pitfalls will be highlighted, providing a balanced view of the subject.
We will explore the capabilities of AI in understanding XML markup languages and autonomously creating structured XML content. Additionally, we will examine the capacity of AI to enrich plain text with appropriate XML markup. Practical examples and methodological guidelines will be provided to elucidate how AI can be effectively prompted to interpret and generate accurate XML markup.
Further emphasis will be placed on the role of AI in developing XSLT, or schemas such as XSD and Schematron. We will address the techniques and strategies adopted to create prompts for generating code, explaining code, or refactoring the code, and the results achieved.
The discussion will extend to how AI can be used to transform XML content. In particular, the focus will be on the use of AI XPath extension functions in XSLT, Schematron, Schematron Quick Fixes, or for XML content refactoring.
The presentation aims to deliver a comprehensive overview of AI usage in XML development, providing attendees with the necessary knowledge to make informed decisions. Whether you’re at the early stages of adopting AI or considering integrating it in advanced XML development, this presentation will cover all levels of expertise.
By highlighting the potential advantages and challenges of integrating AI with XML development tools and languages, the presentation seeks to inspire thoughtful conversation around the future of XML development. We’ll not only delve into the technical aspects of AI-powered XML development but also discuss practical implications and possible future directions.
Removing Uninteresting Bytes in Software FuzzingAftab Hussain
Imagine a world where software fuzzing, the process of mutating bytes in test seeds to uncover hidden and erroneous program behaviors, becomes faster and more effective. A lot depends on the initial seeds, which can significantly dictate the trajectory of a fuzzing campaign, particularly in terms of how long it takes to uncover interesting behaviour in your code. We introduce DIAR, a technique designed to speedup fuzzing campaigns by pinpointing and eliminating those uninteresting bytes in the seeds. Picture this: instead of wasting valuable resources on meaningless mutations in large, bloated seeds, DIAR removes the unnecessary bytes, streamlining the entire process.
In this work, we equipped AFL, a popular fuzzer, with DIAR and examined two critical Linux libraries -- Libxml's xmllint, a tool for parsing xml documents, and Binutil's readelf, an essential debugging and security analysis command-line tool used to display detailed information about ELF (Executable and Linkable Format). Our preliminary results show that AFL+DIAR does not only discover new paths more quickly but also achieves higher coverage overall. This work thus showcases how starting with lean and optimized seeds can lead to faster, more comprehensive fuzzing campaigns -- and DIAR helps you find such seeds.
- These are slides of the talk given at IEEE International Conference on Software Testing Verification and Validation Workshop, ICSTW 2022.
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...SOFTTECHHUB
The choice of an operating system plays a pivotal role in shaping our computing experience. For decades, Microsoft's Windows has dominated the market, offering a familiar and widely adopted platform for personal and professional use. However, as technological advancements continue to push the boundaries of innovation, alternative operating systems have emerged, challenging the status quo and offering users a fresh perspective on computing.
One such alternative that has garnered significant attention and acclaim is Nitrux Linux 3.5.0, a sleek, powerful, and user-friendly Linux distribution that promises to redefine the way we interact with our devices. With its focus on performance, security, and customization, Nitrux Linux presents a compelling case for those seeking to break free from the constraints of proprietary software and embrace the freedom and flexibility of open-source computing.
Threats to mobile devices are more prevalent and increasing in scope and complexity. Users of mobile devices desire to take full advantage of the features
available on those devices, but many of the features provide convenience and capability but sacrifice security. This best practices guide outlines steps the users can take to better protect personal devices and information.
Sudheer Mechineni, Head of Application Frameworks, Standard Chartered Bank
Discover how Standard Chartered Bank harnessed the power of Neo4j to transform complex data access challenges into a dynamic, scalable graph database solution. This keynote will cover their journey from initial adoption to deploying a fully automated, enterprise-grade causal cluster, highlighting key strategies for modelling organisational changes and ensuring robust disaster recovery. Learn how these innovations have not only enhanced Standard Chartered Bank’s data infrastructure but also positioned them as pioneers in the banking sector’s adoption of graph technology.
Climate Impact of Software Testing at Nordic Testing DaysKari Kakkonen
My slides at Nordic Testing Days 6.6.2024
Climate impact / sustainability of software testing discussed on the talk. ICT and testing must carry their part of global responsibility to help with the climat warming. We can minimize the carbon footprint but we can also have a carbon handprint, a positive impact on the climate. Quality characteristics can be added with sustainability, and then measured continuously. Test environments can be used less, and in smaller scale and on demand. Test techniques can be used in optimizing or minimizing number of tests. Test automation can be used to speed up testing.
Essentials of Automations: The Art of Triggers and Actions in FMESafe Software
In this second installment of our Essentials of Automations webinar series, we’ll explore the landscape of triggers and actions, guiding you through the nuances of authoring and adapting workspaces for seamless automations. Gain an understanding of the full spectrum of triggers and actions available in FME, empowering you to enhance your workspaces for efficient automation.
We’ll kick things off by showcasing the most commonly used event-based triggers, introducing you to various automation workflows like manual triggers, schedules, directory watchers, and more. Plus, see how these elements play out in real scenarios.
Whether you’re tweaking your current setup or building from the ground up, this session will arm you with the tools and insights needed to transform your FME usage into a powerhouse of productivity. Join us to discover effective strategies that simplify complex processes, enhancing your productivity and transforming your data management practices with FME. Let’s turn complexity into clarity and make your workspaces work wonders!
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionAggregage
Join Maher Hanafi, VP of Engineering at Betterworks, in this new session where he'll share a practical framework to transform Gen AI prototypes into impactful products! He'll delve into the complexities of data collection and management, model selection and optimization, and ensuring security, scalability, and responsible use.
“An Outlook of the Ongoing and Future Relationship between Blockchain Technologies and Process-aware Information Systems.” Invited talk at the joint workshop on Blockchain for Information Systems (BC4IS) and Blockchain for Trusted Data Sharing (B4TDS), co-located with with the 36th International Conference on Advanced Information Systems Engineering (CAiSE), 3 June 2024, Limassol, Cyprus.
20 Comprehensive Checklist of Designing and Developing a WebsitePixlogix Infotech
Dive into the world of Website Designing and Developing with Pixlogix! Looking to create a stunning online presence? Look no further! Our comprehensive checklist covers everything you need to know to craft a website that stands out. From user-friendly design to seamless functionality, we've got you covered. Don't miss out on this invaluable resource! Check out our checklist now at Pixlogix and start your journey towards a captivating online presence today.
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc
How does your privacy program stack up against your peers? What challenges are privacy teams tackling and prioritizing in 2024?
In the fifth annual Global Privacy Benchmarks Survey, we asked over 1,800 global privacy professionals and business executives to share their perspectives on the current state of privacy inside and outside of their organizations. This year’s report focused on emerging areas of importance for privacy and compliance professionals, including considerations and implications of Artificial Intelligence (AI) technologies, building brand trust, and different approaches for achieving higher privacy competence scores.
See how organizational priorities and strategic approaches to data security and privacy are evolving around the globe.
This webinar will review:
- The top 10 privacy insights from the fifth annual Global Privacy Benchmarks Survey
- The top challenges for privacy leaders, practitioners, and organizations in 2024
- Key themes to consider in developing and maintaining your privacy program
Pushing the limits of ePRTC: 100ns holdover for 100 daysAdtran
At WSTS 2024, Alon Stern explored the topic of parametric holdover and explained how recent research findings can be implemented in real-world PNT networks to achieve 100 nanoseconds of accuracy for up to 100 days.
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfMalak Abu Hammad
Discover how MongoDB Atlas and vector search technology can revolutionize your application's search capabilities. This comprehensive presentation covers:
* What is Vector Search?
* Importance and benefits of vector search
* Practical use cases across various industries
* Step-by-step implementation guide
* Live demos with code snippets
* Enhancing LLM capabilities with vector search
* Best practices and optimization strategies
Perfect for developers, AI enthusiasts, and tech leaders. Learn how to leverage MongoDB Atlas to deliver highly relevant, context-aware search results, transforming your data retrieval process. Stay ahead in tech innovation and maximize the potential of your applications.
#MongoDB #VectorSearch #AI #SemanticSearch #TechInnovation #DataScience #LLM #MachineLearning #SearchTechnology
Unlocking Productivity: Leveraging the Potential of Copilot in Microsoft 365, a presentation by Christoforos Vlachos, Senior Solutions Manager – Modern Workplace, Uni Systems
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...James Anderson
Effective Application Security in Software Delivery lifecycle using Deployment Firewall and DBOM
The modern software delivery process (or the CI/CD process) includes many tools, distributed teams, open-source code, and cloud platforms. Constant focus on speed to release software to market, along with the traditional slow and manual security checks has caused gaps in continuous security as an important piece in the software supply chain. Today organizations feel more susceptible to external and internal cyber threats due to the vast attack surface in their applications supply chain and the lack of end-to-end governance and risk management.
The software team must secure its software delivery process to avoid vulnerability and security breaches. This needs to be achieved with existing tool chains and without extensive rework of the delivery processes. This talk will present strategies and techniques for providing visibility into the true risk of the existing vulnerabilities, preventing the introduction of security issues in the software, resolving vulnerabilities in production environments quickly, and capturing the deployment bill of materials (DBOM).
Speakers:
Bob Boule
Robert Boule is a technology enthusiast with PASSION for technology and making things work along with a knack for helping others understand how things work. He comes with around 20 years of solution engineering experience in application security, software continuous delivery, and SaaS platforms. He is known for his dynamic presentations in CI/CD and application security integrated in software delivery lifecycle.
Gopinath Rebala
Gopinath Rebala is the CTO of OpsMx, where he has overall responsibility for the machine learning and data processing architectures for Secure Software Delivery. Gopi also has a strong connection with our customers, leading design and architecture for strategic implementations. Gopi is a frequent speaker and well-known leader in continuous delivery and integrating security into software delivery.
20240609 QFM020 Irresponsible AI Reading List May 2024
computer notes - Linked list inside computer memory
1. ecomputernotes.com Data Structures Lecture No. 03
___________________________________________________________________
Page 1 of 12
Data Structures
Lecture No. 03
2. ecomputernotes.com Data Structures Lecture No. 03
___________________________________________________________________
Page 2 of 12
Linked List inside Computer Memory
Fig 1. Linked list in memory
There are two parts of this figure. On the left is the linked list chain that is actually the
conceptual view of the linked list and on the right is the linked list inside the computer
memory. Right part is a snapshot of the computer memory with memory addresses
from 1051 to 1065. The head pointer is pointing to the first element in the linked list.
Note that head itself is present in the memory at address 1062. It is actually a pointer
containing the memory address 1054. Each node in the above linked list has two parts
i.e. the data part of the node and the pointer to the next node. The first node of the
linked list pointed by the head pointer is stored at memory address 1054. We can see
the data element 2 present at that address. The second part of the first node contains
the memory address 1051. So the second linked list s node starts at memory address
1051. We can use its pointer part to reach the third node of the list and in this way, we
can traverse the whole list. The last node contains 1 in its data part and 0 in its pointer
part. 0 indicates that it is not pointing to any node and it is the last node of the linked
list.
Linked List Operations
The linked list data structure provides operations to work on the nodes inside the list.
The first operation we are going to discuss here is to create a new node in the
memory. The Add(9) is used to create a new node in the memory at the current
61051
10631052
10631053
21054
10511055
1056
71057
10601058
1059
11060
01061
10541062
81063
10571064
1065
currentent
headent
head
2 6 8 7 1
3. ecomputernotes.com Data Structures Lecture No. 03
___________________________________________________________________
Page 3 of 12
position to hold 9 . You must remember while working with arrays, to add an
element at the current position that all the elements after the current position were
shifted to the right and then the element was added to the empty slot.
Here, we are talking about the internal representation of the list using linked list. Its
interface will remain the same as in case of arrays.
We can create a new node in the following manner in the add() operation of the linked
list with code in C++:
Node * newNode = new Node(9);
The first part of the statement that is on the left of the assignment is declaring a
variable pointer of type Node. It may also be written as Node * newNode. On the
right of this statement, the new operator is used to create a new Node object as new
Node(9). This is one way in C++ to create objects of classes. The name of the class is
provided with the new operator that causes the constructor of the class to be called.
The constructor of a class has the same name as the class and as this a function,
parameters can also be passed to it. In this case, the constructor of the Node class is
called and 9 is passed to it as an int parameter.
Hence, the whole statement means:
Call the constructor of the Node class and pass it 9 as a parameter. After
constructing the object in memory, give me the starting memory address of the object.
That address will be stored in the pointer variable newNode.
To create an object of int type in the same manner, we can write as:
int * i = new int ;
Previously, we used the same technique to allocate memory for an array of ints as:
int * i = new int [10] ;
Now after the node has been created, how the node is fit into the chain of the linked
list.
Fig 2. Insertion of new Node into the linked list
In the above figure, there is a linked list that contains five nodes with data elements as
2, 6, 8, 7 and 1. The current pointer is pointing to the node with element as 8. We
want to insert a new node with data element 9. This new node will be inserted at the
current position (the position where the current pointer is pointing to). This insertion
2 6 8 7 1
9
1current
newNode
e
2
3
4. ecomputernotes.com Data Structures Lecture No. 03
___________________________________________________________________
Page 4 of 12
operation is performed in a step by step fashion.
- The first step is to point next pointer of the new node (with data element as 9) to
the node with data element as 7.
- The second step is to point the next pointer of the node with data element 8 to the
node the new node with data element 9.
- The third step is to change the current pointer to point to the new node.
Now, the updated linked list has nodes with data elements as 2, 6, 8, 9, 7 and 1. The
list size has become 6.
Linked List Using C++
/* The Node class */
class Node
{
public:
int get() { return object; };
void set(int object) { this->object = object; };
Node * getNext() { return nextNode; };
void setNext(Node * nextNode) { this->nextNode = nextNode; };
private:
int object;
Node * nextNode;
};
Whenever, we write a class, it begins with the word class followed by the class-name
and the body of the class enclosed within curly braces. In the body, we write its public
variables, methods and then private variables and methods, this is normally the
sequence.
If there is no code to write inside the constructor function of a class, we need not to
declare it ourselves as the compiler automatically creates a default constructor for us.
Similarly, if there is nothing to be done by the destructor of the class, it will be better
not to write it explicitly. Rather, the compiler writes it automatically. Remember, the
default constructor and destructor do nothing as these are the function without any
code statements inside.
Let s start with the data members first. These are given at the bottom of the class body
with the scope mentioned as private. These data members are actually two parts of a
linked list s node. First variable is object of type int, present there to store the data
part of the node. The second variable is nextNode, which is a pointer to an object of
type Node. It has the address of the next element of the linked list.
The very first public function given at the top is get(). We have written its code within
the class Node. It returns back the value of the variable object i.e. of the type of int.
When we write class in C++, normally, we make two files (.h and .cpp) for a class.
The .h file contains the declarations of public and private members of that class. The
public methods are essentially the interface of the class to be employed by the users of
5. ecomputernotes.com Data Structures Lecture No. 03
___________________________________________________________________
Page 5 of 12
this class. The .cpp file contains the implementation for the class methods that has the
actual code. This is usually the way that we write two files for one class. But this is
not mandatory. In the code given above, we have only one file .cpp, instead of
separating into two files. As the class methods are very small, so their code is written
within the body of the class. This facilitates us in carrying on discussion. Thus instead
of talking about two files, we will only refer to one file. On the other hand, compiler
takes these functions differently that are called inline functions. The compiler replaces
the code of these inline functions wherever the call to them is made.
The second method in the above-mentioned class is set() that accepts a parameter of
type int while returning back nothing. The accepted parameter is assigned to the
internal data member object. Notice the use of this pointer while assigning the value
to the internal data member. It is used whenever an object wants to talk to its own
members.
The next method is getNext() which returns a pointer to an object of type Node lying
somewhere in the memory. It returns nextNode i.e. a pointer to an object of type
Node. As discussed above, nextNode contains the address of next node in the linked
list.
The last method of the class is setNext() that accepts a pointer of type Node, further
assigned to nextNode data member of the object. This method is used to connect the
next node of the linked list with the current object. It is passed an address of the next
node in the linked list.
Let s discuss a little bit about classes. A very good analogy of a class is a factory.
Think about a car factory. On the placement of order, it provides us with the number
of vehicles we ordered for. Similarly, you can see number of other factories in your
daily-life that manufacture the specific products.
Let s take this analogy in C++ language. Suppose, we want to make a factory in C++.
By the way, what is our Node class? It is actually a factory that creates nodes. When
we want to make a new node, a new operator is used. By using new operator with the
Node class, actually, we send an order to Node factory, to make as many as nodes for
us.
So we have a good analogy, to think about a class as a factory. The products that are
made by the factory have their own characteristics. For example, a car made by an
automobile factory has an engine, wheels, steering and seats etc. These variables
inside a class are called state variables. Now the kinds of operations this car can do
are the methods of its class. A car can be driven, engine can be started, gears can be
shifted and an accelerator can be pressed to run it faster.
Similarly, the Node class creates nodes, where every node has two-state variables i.e.
object and nextNode. We have already seen its operations in the above code. We use
new to create new object or an array of new objects, stored in memory.
Let s see the code below.
/* List class */
#include <stdlib.h>
#include "Node.cpp"
class List
6. ecomputernotes.com Data Structures Lecture No. 03
___________________________________________________________________
Page 6 of 12
{
public:
// Constructor
List() {
headNode = new Node();
headNode->setNext(NULL);
currentNode = NULL;
size = 0;
}
We are creating a list factory here employed to create list objects. Remember the list
operations; add, remove, next, back and start etc. Let s see the above class declaration
code in detail.
There are two include statements at the start. The first line is to include a standard
library stdlib.h while the second line includes the Node class file Node.cpp. This Node
class is used to create nodes that form a List object. So this List factory will order
Node class to create new nodes. The List class itself carries out the chain management
of these Node objects.
We have written our own constructor of List class as the default constructor is not
sufficient enough to serve the purpose. The List constructor is parameterless. The very
first step it is doing internally is that it is asking Node class to create a new node and
assigning the starting address of the new Node s object to the headNode data member.
In the second statement, we are calling setNext() method of the Node class for the
object pointed to by the headNode pointer. This call is to set the nextNode data
member to NULL, i.e. Node s object pointed to by the headNode pointer is not
pointing to any further Node. The next statement is to set the currentNode pointer to
NULL. So at the moment, we have initialized the currentNode pointer to NULL that is
not pointing to any Node object. The next statement is to initialize the size data
member to 0 indicating that there is no node present in the list. All this processing is
done inside the constructor of List class, as we want all this done when a list object is
created. Considering the analogy of car factory, the constructor function can perform
certain tasks: The oil is poured into the engine, the tyres are filled-in with air etc.
Let s see the add method of the List class:
/* add() class method */
void add (int addObject)
{
1. Node * newNode = new Node();
2. newNode->set(addObject);
3. if( currentNode != NULL )
4. {
5. newNode->setNext(currentNode->getNext());
6. currentNode->setNext( newNode );
7. lastCurrentNode = currentNode;
8. currentNode = newNode;
9. }
10. else
7. ecomputernotes.com Data Structures Lecture No. 03
___________________________________________________________________
Page 7 of 12
11. {
12. newNode->setNext(NULL);
13. headNode->setNext(newNode);
14. lastCurrentNode = headNode;
15. currentNode = newNode;
16. }
17. size ++;
}
The interface or signatures of add() method is similar to the one discussed in case of
an array. This method takes the object to be added as a parameter. The
implementation of this add() method is a bit longer as the method is being
implemented for linked list. In the first statement, a new Node object is created with
its address stored in the newNode pointer variable. The second statement is to call
set() method of the Node object pointed to by the newNode pointer. You can note the
way the method is called. A pointer variable is at the left most side then an arrow sign
(->), then the name of the method with appropriate arguments within parenthesis. It is
followed by the if-statement that checks the currentNode is not NULL to perform
certain operations inside the if-code block. Inside the if-statement, at line 5, the
nextNode pointer of the new node is being set to the nextNode of the object pointed to
by the currentNode pointer. In order to understand the statements given in this code
properly, consider the fig 2 above, where we added a node in the linked list. We have
done step 1 at line5. At line 6, we are performing the second step by setting the
newNode in the nextNode pointer of the object pointed to by the currentNode. At line
7, we are saving the current position (address) of the currentNode pointer in the
pointer variable lastCurrentNode, which might be useful for backward traversing.
Although, the fig 1 (left part) indicates movement in one direction from left to right
but the lastCurrentNode pointer node can be used by the back() member function to
traverse one position back from right to left. At line 8, the currentNode pointer is
assigned the address of the object pointed to by newNode. This way, a new node is
added in already existent linked list.
Line 10 is start of the else part of if-statement. This is executed if the currentNode is
NULL. It means that there is no node present in the list previously and first node is
going to be added. At line 12, we are setting the nextNode pointer of the object
pointed to by newNode pointer. The nextNode is being set to NULL by calling the
setNext() method. Then at line 13, we point the head pointer (headNode) to this new
node pointed to by newNode pointer. Note that headNode is pointing to a node that is
there despite the fact that the size of the linked list is 0. Actually, we have allocated a
Node object for headNode pointer. Although, we don t need a Node object here, yet it
will be helpful when we perform other operations like remove() and find().
At line 14, the headNode address is being assigned to lastCurrentNode. At line 15,
currentNode pointer is assigned the address of newNode. At the end i.e. at line 17, the
size of the list is incremented by 1.
8. ecomputernotes.com Data Structures Lecture No. 03
___________________________________________________________________
Page 8 of 12
Fig 3. Add operation of linked list
Following is the crux of this add() operation :
Firstly, it will make a new node by calling Node class constructor. Insert the value
e.g. 2. of the node into the node by calling the set method. Now if the list already
exists (has some elements inside or its size is non-zero), it will insert the node after
the current position. If the list does not already exist, this node is added as the first
element inside the list.
Let s try to add few more elements into the above linked list in the figure. The
following are the lines of code to be executed to add nodes with values 8, 7 and 1 into
the linked list.
list.add(8); list.add(7); list.add(1);
Fig 4. More Nodes added into linked list
Now we will see the remaining methods of the linked list. The get() method of the
List class is given below
headNode size = 0List list;
headNode
currentNode
size = 1
lastCurrentNode
2headNodee
currentNode
size = 2
lastCurrentNode
list.add(2);
list.add(6);
2
6
2 6 8 7 1
headNode lastCurrentNode
currentNode
size = 5
9. ecomputernotes.com Data Structures Lecture No. 03
___________________________________________________________________
Page 9 of 12
/* get() class method */
int get()
{
if (currentNode != NULL)
return currentNode->get();
}
This method firstly confirms that the currentNode pointer is not NULL. If it is not
NULL, then it must be pointing to some Node object as inside the constructor of the
List class, we have initialized this pointer variable to NULL. That indicates that the
currentNode is NULL when there is no element inside the list. However, when a Node
object is added into it, it starts pointing to it. So, this get() returns the address of the
node pointed to by the currentNode pointer.
Further, we have another method given below:
/* next() class method */
bool next()
{
1. if (currentNode == NULL) return false;
2.
3. lastCurrentNode = currentNode;
4. currentNode = currentNode->getNext();
5. return true;
};
This is next() method, used to advance the currentNode pointer to the next node inside
the linked list. At line 1, the currentNode is being checked to confirm that there are
some elements present in the list to advance further. At line 1, the method is returning
false if there is no element present in the list. At line 3, it is storing the value of the
currentNode pointer into the lastCurrentNode. At line 4, currentNode is calling the
getNext() method to get the address of next node to be stored in the currentNode
pointer to advance the currentNode pointer to the next element. At line 5, it returns
true indicating the method is successful in moving to the next node.
Example Program
Given below is the full source code of the example program. You can copy, paste and
compile it right away. In order to understand the linked list concept fully, it is highly
desirable that you understand and practice with the below code.
#include <iostream.h>
#include <stdlib.h>
/* The Node class */
class Node
{
public:
int get() { return object; };
void set(int object) { this->object = object; };
10. ecomputernotes.com Data Structures Lecture No. 03
___________________________________________________________________
Page 10 of 12
Node * getNext() { return nextNode; };
void setNext(Node * nextNode) { this->nextNode = nextNode; };
private:
int object;
Node * nextNode;
};
/* The List class */
class List
{
public:
List();
void add (int addObject);
int get();
bool next();
friend void traverse(List list);
friend List addNodes();
private:
int size;
Node * headNode;
Node * currentNode;
Node * lastCurrentNode;
};
/* Constructor */
List::List()
{
headNode = new Node();
headNode->setNext(NULL);
currentNode = NULL;
lastCurrentNode = NULL;
size = 0;
}
/* add() class method */
void List::add (int addObject)
{
Node * newNode = new Node();
newNode->set(addObject);
if( currentNode != NULL )
{
newNode->setNext(currentNode->getNext());
currentNode->setNext( newNode );
lastCurrentNode = currentNode;
currentNode = newNode;
}
else
11. ecomputernotes.com Data Structures Lecture No. 03
___________________________________________________________________
Page 11 of 12
{
newNode->setNext(NULL);
headNode->setNext(newNode);
lastCurrentNode = headNode;
currentNode = newNode;
}
size ++;
}
/* get() class method */
int List::get()
{
if (currentNode != NULL)
return currentNode->get();
}
/* next() class method */
bool List::next()
{
if (currentNode == NULL) return false;
lastCurrentNode = currentNode;
currentNode = currentNode->getNext();
if (currentNode == NULL || size == 0)
return false;
else
return true;
}
/* Friend function to traverse linked list */
void traverse(List list)
{
Node* savedCurrentNode = list.currentNode;
list.currentNode = list.headNode;
for(int i = 1; list.next(); i++)
{
cout << "n Element " << i << " " << list.get();
}
list.currentNode = savedCurrentNode;
}
/* Friend function to add Nodes into the list */
List addNodes()
{
List list;
list.add(2);
list.add(6);
list.add(8);
12. ecomputernotes.com Data Structures Lecture No. 03
___________________________________________________________________
Page 12 of 12
list.add(7);
list.add(1);
cout << "n List size = " << list.size <<'n';
return list;
}
main()
{
List list = addNodes();
traverse(list);
}
The output of the example program is as follows:
List size = 5
Element 1 2
Element 2 6
Element 3 8
Element 4 7
Element 5 1