DATA STRUCTURES ACM EXECUTIVE BODY 2k11.  A series of elements of same type  Placed in contiguous memory locations  Can be individually referenced.

Slides:



Advertisements
Similar presentations
Data Structures Through C
Advertisements

Stacks, Queues, and Linked Lists
. STL: C++ Standard Library (continued). STL Iterators u Iterators are allow to traverse sequences u Methods  operator*  operator->  operator++, and.
Data Structures Lecture 13: QUEUES Azhar Maqsood NUST Institute of Information Technology (NIIT)
Starting Out with C++: Early Objects 5/e © 2006 Pearson Education. All Rights Reserved Starting Out with C++: Early Objects 5 th Edition Chapter 18 Stacks.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 18: Stacks And Queues.
 Abstract Data Type Abstract Data Type  What is the difference? What is the difference?  Stacks Stacks  Stack operations Stack operations  Parsing.
Copyright © 2014, 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Eighth Edition by Tony Gaddis,
Lists A list is a finite, ordered sequence of data items. Two Implementations –Arrays –Linked Lists.
©Brooks/Cole, 2003 Chapter 12 Abstract Data Type.
Implementing and Using Stacks
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Sixth Edition Chapter 18: Stacks and.
Standard Template Library (STL) Overview – Part 1 Yngvi Bjornsson.
CMSC 202 Lesson 24 Iterators and STL Containers. Warmup Write the class definition for the templated Bag class – A bag has: Random insertion Random removal.
1 Stack Data : a collection of homogeneous elements arranged in a sequence. Only the first element may be accessed Main Operations: Push : insert an element.
Lecture 11 Standard Template Library Stacks, Queue, and Deque Lists Iterators Sets Maps.
1 Stacks – Chapter 3 A stack is a data structure in which all insertions and deletions of entries are made at one end, called the top of the stack. Alternatively,
Stack and Queue.
ISOM MIS 215 Module 3 – Stacks and Queues. ISOM Where are we? 2 Intro to Java, Course Java lang. basics Arrays Introduction NewbieProgrammersDevelopersProfessionalsDesigners.
Data Structures Using C++ 2E
Chapter 3 List Stacks and Queues. Data Structures Data structure is a representation of data and the operations allowed on that data. Data structure is.
Containers Overview and Class Vector
Data Structures. The Stack: Definition A stack is an ordered collection of items into which new items may be inserted and from which items may be deleted.
Stacks 1. Stack  What is a stack? An ordered list where insertions and deletions occur at one end called the top. Also known as last-in-first-out (LIFO)
DATA STRUCTURES AND ALGORITHMS Lecture Notes 12 Prepared by İnanç TAHRALI.
Main Index Contents 11 Main Index Contents Week 3 – The Vector Container.
Copyright © 2012 Pearson Education, Inc. Chapter 18: Stacks And Queues.
Generic Programming Using the C++ Standard Template Library.
Cosc237/data structures1 Data Types Every data type has two characteristics: 1.Domain - set of all possible values 2.set of allowable operations Built-in.
C++ STL CSCI 3110.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 18 Stacks and Queues.
Friends & Standard Template Library CSCI3110 Advanced Data Structures Lecturer: Dr. Carroll and Nan Chen.
Stacks And Queues Chapter 18.
1 Linked-list, stack and queue. 2 Outline Abstract Data Type (ADT)‏ Linked list Stack Queue.
CS342 Data Structures End-of-semester Review S2002.
Standard Template Library The Standard Template Library was recently added to standard C++. –The STL contains generic template classes. –The STL permits.
Introduction to the Standard Template Library (STL) A container class holds a number of similar objects. Examples: –Vector –List –Stack –Queue –Set –Map.
Lecture 11 Standard Template Library Lists Iterators Sets Maps.
Starting Out with C++ Early Objects Seventh Edition by Tony Gaddis, Judy Walters, and Godfrey Muganda Chapter 18: Stacks and Queues.
Lecture 7 : Intro. to STL (Standard Template Library)
Computer Science and Software Engineering University of Wisconsin - Platteville 11.Standard Template Library Yan Shi CS/SE 2630 Lecture Notes.
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.
Data Structures for Midterm 2. C++ Data Structure Runtimes.
Data Structures. Abstract Data Type A collection of related data is known as an abstract data type (ADT) Data Structure = ADT + Collection of functions.
C++ Review STL CONTAINERS.
CSCI 383 Object-Oriented Programming & Design Lecture 25 Martin van Bommel.
Collection types CS Chakrabarti Motivation  Thus far the only collection types we have used are vector and matrix  Problem #1: given an input.
Glenn Stevenson CSIS 113A MSJC CSIS 123A Lecture 3 Vectors.
Unit VI.  C++ templates are a powerful mechanism for code reuse, as they enable the programmer to write code (classes as well as functions) that behaves.
1 The Standard Template Library The STL is a collection of Container classes These are class templates for containers. A container is an object that stores.
List Structures What is a list? A homogeneous collection of elements with a linear relationship between the elements linear relationship - each element.
 In general, Queue is line of person waiting for their turn at some service counter like ticket window at cinema hall, at bus stand or at railway station.
Mark Redekopp David Kempe
Cpt S 122 – Data Structures Abstract Data Types
Queues.
Data Structure By Amee Trivedi.
G64ADS Advanced Data Structures
Set Collection A Bag is a general collection class that implements the Collection interface. A Set is a collection that resembles a Bag with the provision.
Data Structure Interview Question and Answers
DATA STRUCTURES AND OBJECT ORIENTED PROGRAMMING IN C++
Standard Template Library (STL)
Stacks and Queues.
Prof. Michael Neary Lecture 7: The STL Prof. Michael Neary
CMSC 341 Lecture 5 Stacks, Queues
structures and their relationships." - Linus Torvalds
Final Exam Review COP4530.
Lab4 problems More about templates Some STL
structures and their relationships." - Linus Torvalds
Presentation transcript:

DATA STRUCTURES ACM EXECUTIVE BODY 2k11

 A series of elements of same type  Placed in contiguous memory locations  Can be individually referenced by adding an index to a unique identifier  Example: Sort 10^7 numbers ranging from 100 to 200. ARRAY

 Abstract Data Types (ADTs) or data structures or collections store data and allow various operations on the data to access and change it  Why Abstract? ◦ Specify the operations of the data structure and leave implementation details to later  Every collection ADT provides a way to : insert, remove, find and access a data item Abstract Data Type (ADT)

 Last In First Out (LIFO)  Operations ◦ Push ◦ Pop ◦ Top ◦ isEmpty (Underflow) ◦ isFull (Overflow) STACK Data 4 Data 3 Data 2 Data 1

 Infix to Postfix Conversion  Matching tags in XML/HTML  Undo sequence in a text editor  Implementing functional calls (Recursion)  History of Web Browsers Applications of Stack

 Balancing Of Parenthesis ◦ Given a sequence of ‘(‘ and ‘)’ ◦ Validate the sequence ◦ A sequence is valid if for every ‘(‘, there is a counter-balancing ‘)’ which occurs only later in the sequence ◦ Examples  (()()()) : Valid  (()(() : Invalid  )()()( : Invalid Problems

 Nearest Smaller Element ◦ Given a sequence of integers ◦ For every integer, output the nearest integers to the left and to the right which are smaller to it. ◦ If there is no such number, output -1. ◦ Example  (-1,1) (-1,-1) (1,4) (1,-1) (4,-1) Problems

 Maximum Rectangle Area in a Histogram  Maximum Rectangular Area = 4x6 = 24 Problems

 Water Harvesting ◦ Find the maximum volume of water that can be collected in between the adjacent buildings ◦ Maximum Volume Of Water Collected = = 9 Problems

 First In First Out (FIFO)  Operations ◦ Enqueue (Insert) ◦ Dequeue (Remove) ◦ Front ◦ Rear / Back ◦ isEmpty ◦ isFull Queue Data 1Data 2Data 3Data 4

 Operating System Job Scheduling  Breadth First Traversal of a Graph  Level Order Traversal of a Binary Tree Applications

 Print first 100 numbers comprising only of 1s, 3s and 5s.  The first few numbers in the sequence are  1,3,5,  11,13,15,31,33,35,51,53,55,  111,113,115,131,133,135,151,153,155,311, and so on. Problem

9/14/2015 Circular Queue  Complete use of space  Uses single, fixed size buffer, as if it were connected from end to beginning

 An generalized queue, for which elements can be added to or removed from either the front or the rear.  Operations: ◦ PushBack ◦ PushFront ◦ PopBack ◦ PopFront ◦ Front ◦ Back Deque

 Given an array and an integer k, find the maximum element for each and every sub- array of size k  Example: ◦ a = [ 8, 5, 10, 7, 9, 4, 15, 12, 19, 13 ] ◦ k = 4 ◦ Output : [ 10, 10, 10, 15, 15, 19, 19 ] Problems on Deque

 Input Restricted Deque ◦ Deletion can be made from both ends ◦ Insertion can be made at one end only  Output Restricted Deque ◦ Insertion can be made at both ends ◦ Deletion can be made at one end only Variations of Deque

 Standard Template Library  Part of ISO standard C++ library  Why Use STL ◦ Reduces Development time ◦ Highly Reliable Code ( no or small amount of debugging effort required ) ◦ Highly Robust ( Container size grows automatically ) ◦ Portable and easily maintainable STL

 Templates allow the usage of generic types ◦ Advantage: no need of writing the same code all over again for a different data type  Example: ◦ template // X can represent any data type that support the operations class ABC { ABC() { } public: getMax(X a, X b) { return (a > b ? a: b); } }; ABC a; max_val = a.getMax(15.30, 53.12); Templates

 Including the library ◦ #include  Declaration ◦ stack s;  Push Operation ◦ s.push(5);  Pop Operation ◦ s.pop();  Access the Top Element ◦ int x = s.top();  Check if Stack is Empty ◦ if ( s.empty() ) cout<< “ Stack is Empty ” << endl; STL - Stack

 Including the library ◦ #include  Declaration ◦ queue q;  Push Operation ◦ q.push(5);  Pop Operation ◦ q.pop();  Access the Top Element ◦ int x = q.front();  Check if Stack is Empty ◦ if ( q.empty() ) cout<< “ Queue is Empty ” << endl; STL - Queue

 Including the library ◦ #include  Declaration ◦ deque dq;  Push Operation ◦ dq.push_back(5); ◦ dq.push_front(5);  Pop Operation ◦ dq.pop_back(); ◦ dq.pop_front();  Access the front and back elements ◦ int x = dq.front(); int y = dq.back();  Check if Stack is Empty ◦ if ( dq.empty() ) cout<< “ Deque is Empty ” << endl; STL - Deque

9/14/2015 STL-Map Introduction  Associative data structure ◦ a value is associated with the key  Stores the values in an order, sorted by the key values.  Internally implemented as a balanced BST  Multimap is used if multiple associated entries are allowed for same key values.

9/14/2015 STL- Map  Including the library ◦ #include  Declaring a map ◦ map m;  Inserting a value ◦ m.insert( pair ("abc", 2); ◦ m["abc"]=2;  Finding a value ◦ if( m.find("abc") != m.end() ) cout << "Not found" << endl;  Clear all entries ◦ m.clear();

9/14/2015 STL- Pair and Vector  Vector ◦ Dynamic array of variables, struct or objects of same type ◦ Resizes itself when inserting or erasing an element  Pair ◦ A simple associative container consisting of a 2- tuple of data elements or objects, denoted by ‘first' and ‘second'

9/14/2015 STL- Vector  Including the library ◦ #include  Declaration ◦ vector v; //1-D ◦ vector v[10000] ; //2-D  Pushing a value ◦ v.push_back(5); //1-D ◦ v[i].push_back(5); //2-D  Removing a value ◦ v.pop_back(); //1-D  Accessing an element at position i ◦ int x= v[i]; //1-D  Clear all entries ◦ v.clear(); //1-D

9/14/2015 STL- Pair  Including the library ◦ #include  Declaration ◦ pair p;  Definition ◦ p = make_pair("abc",10);  Accessing the elements ◦ p.first ◦ p.second

9/14/2015 STL-Set  Used to store unique elements in a sorted order  Elements in a set can't be modified once they has been inserted. But they can be inserted or removed from the container.  Internally implemented as balanced BST  Multiset can be used to allow duplicate entries

9/14/2015 STL-Set  Library to be included ◦ #include  Declaration ◦ set s;  Inserting an element ◦ s.insert(5);  Removing an element ◦ s.erase(5);  Get the size of the set ◦ int x= s.size();

9/14/2015 Useful functions  int a[]={1,2,2,3,5};  vector v ( a, a+5 ) ; ◦ sort ( a, a+5 );// sort an array ◦ sort ( v.begin(), v.end() );// sort a vector ◦ next_permutation( a, a+5 );  find next permutation of elements of array ◦ prev_permutation( a, a+5 ); ◦ lower_bound( v.begin(), v.end(), 2);  find the first occurence of a value in a sorted container ◦ upper_bound( v.begin(), v.end(), 2 );

9/14/2015 Using Iterators  Used with map, vector and set  Iterator:  vector ::iterator it;//declaration  it = v.begin();// points to start of the container  it = v.end(); //points to end of the container ◦ Other operations:  it++ ;  it-- ;  it != m.end() ;  Reverse Iterator:  iterates in a reverse fashion from end to beginning  vector ::reverse_iterator it;  it = v.rbegin();  it = v.rend();

If you have any problem solving a question or understanding some concept, feel free to bug us, we will be happy to debug you… ACM Executive body o Nimesh Ghelani: o Prem Kamal: o Utkarsh Raj: o Rishikesh Jha: o Vivek Verma: o Nischal Kumar: o Chandan Agarwal: o Sanket Singhal: o Aparajita Choudhary: o Bhavini Mishra: Happy Coding… 9/14/2015