0% found this document useful (0 votes)
47 views3 pages

Linked List

A linked list is a data structure where each node contains data and a pointer to the next node. Linked lists allow dynamic sizes and efficient insertions/deletions compared to arrays. Memory is used efficiently as nodes can be scattered. Random access is slower than arrays. Linked lists include singly linked lists where each node has a next pointer, doubly linked lists where each node has next and previous pointers, and circular linked lists where the last node points to the first. Stacks are used to evaluate expressions, manage function calls and return addresses, and implement undo/redo functions and backtracking algorithms.

Uploaded by

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

Linked List

A linked list is a data structure where each node contains data and a pointer to the next node. Linked lists allow dynamic sizes and efficient insertions/deletions compared to arrays. Memory is used efficiently as nodes can be scattered. Random access is slower than arrays. Linked lists include singly linked lists where each node has a next pointer, doubly linked lists where each node has next and previous pointers, and circular linked lists where the last node points to the first. Stacks are used to evaluate expressions, manage function calls and return addresses, and implement undo/redo functions and backtracking algorithms.

Uploaded by

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

Lecture 3

Linked List-

A linked list is a data structure that consists of a sequence of elements, called nodes, where each
node contains two parts: the data and a reference (or pointer) to the next node in the sequence. The
last node in the list typically points to null, indicating the end of the list.

Linked lists are used in computer programming and data structures because they offer several
advantages over arrays in certain scenarios:

​ Dynamic Size: Unlike arrays, linked lists can dynamically grow and shrink during program
execution, as memory for each new node can be allocated separately. This makes them
suitable for situations where the size of the data is not known beforehand or may change over
time.
​ Efficient Insertions and Deletions: Inserting or deleting elements in a linked list is generally
more efficient than in an array, especially in large lists. In a linked list, you can simply adjust
the pointers to add or remove a node, while in an array, you may need to shift elements to
make space for a new element or close a gap after removing an element.
​ Memory Utilization: Linked lists use memory more efficiently than arrays, particularly in
situations where memory allocation is costly. In an array, you need contiguous memory blocks
to store elements, while linked lists use individual memory blocks (nodes) that can be
scattered across the memory.
​ No Pre-allocation Needed: In arrays, you often need to pre-allocate a fixed amount of
memory to hold the elements, which can lead to either wasted space or the need to resize the
array (which can be expensive). Linked lists do not have this limitation and can dynamically
allocate memory for each new element.

However, linked lists also have some drawbacks compared to arrays:

​ Random Access: Accessing an element in a linked list is slower than in an array because
you have to traverse the list from the beginning to find the desired node. In contrast, arrays
allow direct access using an index, which is much faster.
​ Memory Overhead: Linked lists require extra memory for storing the pointers/references to
the next nodes. This overhead can be significant compared to the actual data being stored in
the list.

**The linked list we discussed above is also referred to as a Singly linked List-

Doubly Linked list -


A doubly linked list is a type of linked list in which each node contains two pointers: one that points to
the next node in the list, and another that points to the previous node in the list. This allows for
bidirectional traversal of the list.

Circular Linked list -

A circular linked list is a variation of a linked list in which the last node points back to the first node,
creating a circular structure. This means that there is no "end" node in a circular linked list, as the last
node points to the first node, forming a loop.

Implementation code and problem discussed - LinkedList.zip

Lecture 4
1. Expression evaluation: Stacks are used to evaluate expressions, particularly in converting infix
expressions to postfix expressions for easier evaluation.

2. Function call stack: During the execution of a program, function calls and their local variables are
managed using a stack-like structure called the call stack.

3. Undo/Redo functionality: Stacks can be used to implement undo and redo functionality in
applications that require a history of actions.

4. Backtracking algorithms: Many backtracking algorithms use stacks to keep track of the current state
and explore different paths.

The simplicity and efficiency of the stack data structure make it a valuable tool for solving a wide
range of problems in computer science and programming.

You might also like