LINEAR DATA STRUCTURES

Slides:



Advertisements
Similar presentations
Data Structures Through C
Advertisements

CHP-5 LinkedList.
Arithmetic Expressions Infix form –operand operator operand 2+3 or a+b –Need precedence rules –May use parentheses 4*(3+5) or a*(b+c)
Data Structures and Algorithms (60-254)
C o n f i d e n t i a l Developed By Nitendra NextHome Subject Name: Data Structure Using C Title : Overview of Stack.
1 Chapter 24 Lists Stacks and Queues. 2 Objectives F To design list with interface and abstract class (§24.2). F To design and implement a dynamic list.
Infix to postfix conversion Process the tokens from a vector infixVect of tokens (strings) of an infix expression one by one When the token is an operand.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Data Structures Stacks.
Stack  A stack is a linear data structure or abstract data type for collection of items, with the restriction that items can be added one at a time and.
DS.L.1 Lists, Stacks, and Queues (Review) Chapter 3 Overview Abstract Data Types Linked Lists, Headers, Circular Links Cursor (Array) Implementation Stacks.
DREAM VALLEY COLLEGE FOR GIRLS CENTRE FOR EDUCATIONAL EXECELLENCE ADD:-Near Railway spring factory, Sitholi, Gwalior (MP) AFFILATED TO:-JIWAJI UNIVERSITY.
Ceng-112 Data Structures ITurgut Kalfaoglu 1 Chapter 3 Stacks.
Fundamentals of Python: From First Programs Through Data Structures Chapter 14 Linear Collections: Stacks.
Comp 245 Data Structures Stacks. What is a Stack? A LIFO (last in, first out) structure Access (storage or retrieval) may only take place at the TOP NO.
1 Stacks Chapter 4 2 Introduction Consider a program to model a switching yard –Has main line and siding –Cars may be shunted, removed at any time.
CHAPTER 05 Compiled by: Dr. Mohammad Omar Alhawarat Stacks & Queues.
Review 1 Introduction Representation of Linear Array In Memory Operations on linear Arrays Traverse Insert Delete Example.
 STACK STACK  BASIC STACK OPERATIONS BASIC STACK OPERATIONS  PUSH ALGORITHM PUSH ALGORITHM  POP ALGORITHM POP ALGORITHM  EVALUATING A POSTFIX EXPRESSION.
For more notes and topics VISIT: IMPLEMENTATION OF STACKS eITnotes.com.
Stack Any Other Data Structure Array Linked List
Kovács Zita 2014/2015. II. félév DATA STRUCTURES AND ALGORITHMS 26 February 2015, Linked list.
Chapter 16 – Data Structures and Recursion. Data Structures u Built-in –Array –struct u User developed –linked list –stack –queue –tree Lesson 16.1.
Subject Name : Data Structure Using C Title : Linked Lists
Data Structures Chapter 6. Data Structure A data structure is a representation of data and the operations allowed on that data. Examples: 1.Array 2.Record.
1. Circular Linked List In a circular linked list, the last node contains a pointer to the first node of the list. In a circular linked list,
CHP-3 STACKS.
Circular linked list A circular linked list is a linear linked list accept that last element points to the first element.
Stacks A stack is a linear data structure that can be accessed only at one of its ends for storing and retrieving data LIFO (Last In First Out) structure.
Applications of Stack Maitrayee Mukerji. Stacks Last In First Out (LIFO List) ◦ FILO? Insertions and Deletions from the same end called the Top Push(),
© Oxford University Press All rights reserved. Data Structures Using C, 2e Reema Thareja.
Chapter 3 Lists, Stacks, Queues. Abstract Data Types A set of items – Just items, not data types, nothing related to programming code A set of operations.
 Chapter 7 introduces the stack data type.  Several example applications of stacks are given in that chapter.  This presentation shows another use called.
STACKS & QUEUES for CLASS XII ( C++).
Data Structure By Amee Trivedi.
G64ADS Advanced Data Structures
Top 50 Data Structures Interview Questions
Lectures linked lists Chapter 6 of textbook
Program based on queue & their operations for an application
Data Structure Interview Question and Answers
Data structures and algorithms
Infix to postfix conversion
Interview, Viva and Basic Questions of Data Structures
MEMORY REPRESENTATION OF STACKS
DATA STRUCTURES AND OBJECT ORIENTED PROGRAMMING IN C++
UNIT-3 LINKED LIST.
Homework 4 questions???.
Objectives In this lesson, you will learn to: Define stacks
Data Structures Interview / VIVA Questions and Answers
STACKS.
Stacks Chapter 4.
Data Structures – Week #3
Algorithms and Data Structures
Stack.
CSCE 210 Data Structures and Algorithms
LINKED LISTS CSCD Linked Lists.
CMSC 341 Lecture 5 Stacks, Queues
5.4 Additional Stack Applications
Arrays and Linked Lists
Linked Lists.
The List, Stack, and Queue ADTs
Stacks and Queues 1.
Chapter 17: Linked Lists.
Cs212: Data Structures Computer Science Department Lecture 6: Stacks.
Stacks.
(Part 2) Infix, Prefix & Postfix
DATA STRUCTURE.
Data Structures – Week #3
BY PROF. IRSHAD AHMAD LONE.
Presented by : Aman Gupta PGT CS KV No.1, Narimedu, Madurai
5.3 Implementing a Stack Chapter 5 – The Stack.
Presentation transcript:

LINEAR DATA STRUCTURES CLASSIFICATION LINEAR DATA STRUCTURES STACKS QUEUES LINKED LIST

STACKS Stacks hold objects, usually of the same type. It follows the concept of LIFO – last in first out. Stack is a linear list of items in which all additions and deletion are restricted to one end. In stack, insertion and deletion is possible on only one side of the stack. The other side is sealed.

EXCEPTIONS: Overflow exception: happens when there is no more room left to store a data item that is pushed Underflow exception: happens when the stack is empty and the user executed a pop operation

Arithmetic precedence is in increasing order: INFIX TO POSTFIX CONVERSION   If a token is an integer, write it into the output. If a token is an operator, push it to the stack, if the stack is empty. If the stack is not empty, you pop entries with higher or equal priority and only then you push that token to the stack. If a token is a left parentheses '(', push it to the stack If a token is a right parentheses ')', you pop entries until you meet '('. When you finish reading the string, you pop up all tokens which are left there. Arithmetic precedence is in increasing order: '+', '-', '*', '/'

Suppose we have an infix expression:2+(4+3. 2+1)/3 Suppose we have an infix expression:2+(4+3*2+1)/3. We read the string by characters. '2' - send to the output. '+' - push on the stack. '(' - push on the stack. '4' - send to the output. '3' - send to the output. '*' - push on the stack.

EVALUATING A POSTFIX EXPRESSION We read the tokens in one at a time. If it is an integer, push it on the stack If it is a binary operator, pop the top two elements from the stack, apply the operator, and push the result back on the stack. 5 9 3 + 4 2 * * 7 + * push(5); push(9); push(3); push(pop() + pop()) push(4); push(2); push(pop() * pop()) push(pop() * pop()) push(7) push(pop() + pop()) push(pop() * pop())

DRAWBACKS OF SEQUENTIAL MEMORY ALLOCATION This method suffers from both internal and external fragmentation. This makes it inefficient in terms of memory utilization. Increasing file size is difficult because it depends on the availability of contiguous memory at a particular instance. Size of the file is to be declared in advance.

WHY LINKED LIST This is very flexible in terms of file size. File size can be increased easily since the system does not have to look for a contiguous chunk of memory. This method does not suffer from external fragmentation. This makes it relatively better in terms of memory utilization.

WHAT IS LINKED LIST A Linked List is a linear collection of data elements called Nodes. Each node contains one or more data fields and a pointer to the next node The left part of the node which contains data may include a simple data type, an array, or a structure. The right part of the node contains a pointer to the next node (or address of the next node in sequence). The last node will have no next node connected to it, so it will store a special value called NULL. A Linked List also contains a pointer variable START which stores the starting address of the program.

STRUCTURE OF LL START stores the address of the first Node so the first data is stored at address 1 (H). The corresponding next stores the address of the next node which is 4. We will look at address 4 to fetch the data element (E). The process is repeated until NULL is reached.

CREATING A LL

INSERT AT BEGINNING

INSERT BEFORE ANY POSITION

INSERT AFTER ANY POSITION

INSERT AT END

DELETING NODES

DELETING AFTER ANY POSITION

TYPES OF LINKED LIST Circular Linked List  In a circular linked list the last node contains a pointer to the first node of the list. While traversing in a circular linked list we can begin at any node and traverse in any direction until we reach the node from where we started.   Doubly Linked List A doubly linked list is a two way linked list. This means that it contains 2 pointers NEXT and PREV. Hence a doubly linked list consists of 3 parts data, pointer to the next node and a pointer to the previous node