Introduction to Linked List: Review. Source:

Similar documents
BBM 201 DATA STRUCTURES

Data Structure. Recitation III

CSE 530A. B+ Trees. Washington University Fall 2013

Operations on Heap Tree The major operations required to be performed on a heap tree are Insertion, Deletion, and Merging.

Introduction to Linked Lists

CS127: B-Trees. B-Trees

Linked List in Data Structure. By Prof. B J Gorad, BECSE, M.Tech CST, PHD(CSE)* Assistant Professor, CSE, SITCOE, Ichalkaranji,Kolhapur, Maharashtra

Ashish Gupta, Data JUET, Guna

Data Structure Advanced

o Code, executable, and process o Main memory vs. virtual memory

Question Bank Subject: Advanced Data Structures Class: SE Computer

Advanced Database Systems

Database System Concepts

CSC 1600 Memory Layout for Unix Processes"

DOWNLOAD PDF LINKED LIST PROGRAMS IN DATA STRUCTURE

FORTH SEMESTER DIPLOMA EXAMINATION IN ENGINEERING/ TECHNOLIGY- OCTOBER, 2012 DATA STRUCTURE

Delhi Noida Bhopal Hyderabad Jaipur Lucknow Indore Pune Bhubaneswar Kolkata Patna Web: Ph:

Data Structures. Instructor: Tsung-Che Chiang

Linked-List Basic Examples. A linked-list is Linear collection of self-referential class objects, called nodes Connected by pointer links

Self-referential Structures and Linked List. Programming and Data Structure 1

Chapter 12: Query Processing

The combination of pointers, structs, and dynamic memory allocation allow for creation of data structures

Lecture 4: Elementary Data Structures Steven Skiena

Data Structure. IBPS SO (IT- Officer) Exam 2017

Database System Concepts, 6 th Ed. Silberschatz, Korth and Sudarshan See for conditions on re-use

Chapter 11: Indexing and Hashing

Algorithms and Data Structures

CS301 - Data Structures Glossary By

Chapter 12: Query Processing. Chapter 12: Query Processing

Lists (Section 5) Lists, linked lists Implementation of lists in C Other list structures List implementation of stacks, queues, priority queues

Chapter 12: Indexing and Hashing. Basic Concepts

Chapter 17. Disk Storage, Basic File Structures, and Hashing. Records. Blocking

CMPSCI 105: Lecture #12 Searching, Sorting, Joins, and Indexing PART #1: SEARCHING AND SORTING. Linear Search. Binary Search.

Chapter 12: Indexing and Hashing

Query Processing. Debapriyo Majumdar Indian Sta4s4cal Ins4tute Kolkata DBMS PGDBA 2016

Singly (Simply) Linked Lists

Programming, Data Structures and Algorithms Prof. Hema Murthy Department of Computer Science and Engineering Indian Institute of Technology, Madras

Heap Arrays and Linked Lists. Steven R. Bagley

Fundamental of I.T. (c) Application of computer *************

Linked Lists. Linked list: a collection of items (nodes) containing two components: Data Address (link) of the next node in the list

Linked Lists. Linked list: a collection of items (nodes) containing two components: Data Address (link) of the next node in the list

B-Trees. Based on materials by D. Frey and T. Anastasio

Solution: The examples of stack application are reverse a string, post fix evaluation, infix to postfix conversion.

Database System Concepts, 5th Ed. Silberschatz, Korth and Sudarshan See for conditions on re-use

Hashing IV and Course Overview

Data Structure for Language Processing. Bhargavi H. Goswami Assistant Professor Sunshine Group of Institutions

Multidimensional Indexes [14]

Chapter 11: Indexing and Hashing" Chapter 11: Indexing and Hashing"

Hash-Based Indexes. Chapter 11

Selection Queries. to answer a selection query (ssn=10) needs to traverse a full path.

Cpt S 122 Data Structures. Data Structures

Data Abstractions. National Chiao Tung University Chun-Jen Tsai 05/23/2012

Chapter 11: Indexing and Hashing

Information Science 2

File Systems. ECE 650 Systems Programming & Engineering Duke University, Spring 2018

CSE 332: Data Structures & Parallelism Lecture 7: Dictionaries; Binary Search Trees. Ruth Anderson Winter 2019

Intro to DB CHAPTER 12 INDEXING & HASHING

+ Abstract Data Types

CS 241 Data Organization Binary Trees

Bharati Vidyapeeth s College Of Engineering for Women Pune-43 Department E & TC. SE- Unit Test I Subject-DS

Dynamic Data Structures. John Ross Wallrabenstein

Data Structure Lecture#15: Non-Binary Trees 2 (Chapter 6) U Kang Seoul National University

ITEC2620 Introduction to Data Structures

Parallel Pointers: Graphs

Chapter 13: Query Processing

CSCI-1200 Data Structures Fall 2013 Lecture 9 Iterators & Lists

17CS33:Data Structures Using C QUESTION BANK

Lecture 5: Outline. I. Multi- dimensional arrays II. Multi- level arrays III. Structures IV. Data alignment V. Linked Lists

CSE 562 Database Systems

Indexing and Hashing

UNIT III BALANCED SEARCH TREES AND INDEXING

Inverted Indexes. Indexing and Searching, Modern Information Retrieval, Addison Wesley, 2010 p. 5

Introduction to Indexing 2. Acknowledgements: Eamonn Keogh and Chotirat Ann Ratanamahatana

Sample Question Paper

Types II. Hwansoo Han

! A relational algebra expression may have many equivalent. ! Cost is generally measured as total elapsed time for

Chapter 13: Query Processing Basic Steps in Query Processing

DATA STRUCTURES AND ALGORITHMS

Hashing file organization

ECE 650 Systems Programming & Engineering. Spring 2018

Chapter 11: Indexing and Hashing

CS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University

Hash-Based Indexes. Chapter 11 Ramakrishnan & Gehrke (Sections ) CPSC 404, Laks V.S. Lakshmanan 1

Chapter 3: The Efficiency of Algorithms. Invitation to Computer Science, C++ Version, Third Edition

Query Processing & Optimization

Chapter 17: Linked Lists

ECE 2400 Computer Systems Programming, Fall 2018 PA2: List and Vector Data Structures

Chapter 12: Indexing and Hashing

CS61C Machine Structures. Lecture 4 C Pointers and Arrays. 1/25/2006 John Wawrzynek. www-inst.eecs.berkeley.edu/~cs61c/

Tree-Structured Indexes

DATA STRUCTURE UNIT I

COP 3502 Spring 2018 Study Union Review

Computer Science 9608 (Notes) Chapter: 4.1 Computational thinking and problem-solving

Objective Questions for Online Practical Exams under CBCS Scheme Subject: Data Structure-I (CS-113)

File Systems: Fundamentals

Linked List. April 2, 2007 Programming and Data Structure 1

Data and File Structures Laboratory

Extra: B+ Trees. Motivations. Differences between BST and B+ 10/27/2017. CS1: Java Programming Colorado State University

Database Technology. Topic 7: Data Structures for Databases. Olaf Hartig.

CS 237 Meeting 19 10/24/12

Transcription:

Introduction to Linked List: Review Source: http://www.geeksforgeeks.org/data-structures/linked-list/

Linked List Fundamental data structures in C Like arrays, linked list is a linear data structure Unlike arrays, linked list elements are not stored at contiguous location, the elements are linked using pointers

Array vs Linked List

Why Linked List-1 Advantages over arrays Dynamic size Ease of insertion or deletion Inserting a new element in an array of elements is expensive, because room has to be created for the new elements and to create room existing elements have to be shifted For example, in a system if we maintain a sorted list of IDs in an array id[]. id[] = [1000, 1010, 1050, 2000, 2040] If we want to insert a new ID 1005, then to maintain the sorted order, we have to move all the elements after 1000 Deletion is also expensive with arrays until unless some special techniques are used. For example, to delete 1010 in id[], everything after 1010 has to be moved

Why Linked List-2 Drawbacks of Linked List Random access is not allowed. Need to access elements sequentially starting from the first node. So we cannot do binary search with linked lists Extra memory space for a pointer is required with each element of the list

Representation in C A linked list is represented by a pointer to the first node of the linked list The first node is called head If the linked list is empty, then the value of head is null Each node in a list consists of at least two parts 1. Data 2. Pointer to the next node In C, we can represent a node using structures

First Simple Linked List in C

Linked List Traversal In the previous program, we created a simple linked list with three nodes Let us traverse the created list and print the data of each node

Inserting A Node Methods to insert a new node in linked list 1. At the front of the linked list 2. After a given node 3. At the end of the linked list

A 4 step process New node can be added before the head of the given linked list Newly added node becomes the new head of the linked list Let us call the function that adds at the front of the list is push() The push() must receive a pointer to the head pointer, because push must change the head pointer to point to the new node Add a node at the front

Add a node after a given node A 5 step process We are a given pointer to a node New node is inserted after the given node

A 6 step process New node can be added after the last node of the given linked list Since a linked list is typically represented by the head of it, we have traverse the list till end and then change the next of last node to new node Add a node at the end

Deleting A Node Let us formulate the problem statement to understand the deletion process. Given a key, delete the first occurrence of this key in linked list To delete a node from linked list, we need to do following steps: Find previous node of the node to be deleted Change next of previous node Free memory for the node to be deleted Since every node of linked list is dynamically allocated using malloc() in C, we need to call free() for freeing memory allocated for the node to be deleted

Deleting A Node

Union & Intersection of Two Linked Lists Problem Statement: Given two linked lists, create union & intersection lists that contain union and intersection of the elements present in the given lists Order of elements in output lists doesn t matter Intersection (list1, list2) Initialize result list as NULL Traverse list1 and look for its each element in list2 If the element is present in list2, then add the element to result Union (list1,list2) Initialize result list as NULL Traverse list1 and add all of its elements to result Traverse list2: if an element of list2 is already present in result then do not insert it to the result, otherwise insert

Union & Intersection of Two Linked Lists

Link of the Codes Linked List Traversal: http://www.geeksforgeeks.org/linked-list-set-1-introduction/ Linked List Insertion: http://www.geeksforgeeks.org/linked-list-set-2-inserting-a-node/ Linked List Deletion: http://www.geeksforgeeks.org/linked-list-set-3-deleting-node/ Union & Intersection of Two Linked Lists: http://www.geeksforgeeks.org/union-and-intersection-of-two-linked-lists/