# Common Data Structures

Save this PDF as:

Size: px
Start display at page:

## Transcription

1 Data Structures 1 Common Data Structures Arrays (single and multiple dimensional) Linked Lists Stacks Queues Trees Graphs You should already be familiar with arrays, so they will not be discussed. Trees and Graphs will be discussed later.

2 Data Structures 2 Linked Lists A linked list is a linear set of nodes with the following properties: Each node has at least two fields, the key and the next. th element of the list. The next field of the th element points to the The first element of the linked list is called the head, and the last element the tail. The head contains no data, and the next field of the tail points to NULL. The key field contains the data we are actually interested in. What exactly is meant by things like points to and NULL depends on the implementation used. head A L I S T

3 Data Structures 3 Linked List Operations There are several operations that we must be able to do on a linked list: Insert a node Delete a node Find an element with key There are other operations which might be useful: Move an element Swap two elements We will talk about a few of these next, and give one possible way to implement a linked list (in part, anyway).

4 Data Structures 4 Linked List: C++ Declaration struct node { char key; struct node *next; } struct node *head; head = new node; head->next = NULL; This creates an empty linked list. In this implementation, we have the tail point to NULL, which is usually defined to be 0. Thus, if the next field of an element is 0, we know we have reached the tail. Here point to means that. We really used pointers. We will see shortly that we don t need to use actual pointers to implement a linked list.

5 Data Structures 5 Linked List: JAVA Declaration The JAVA implementation is similar to the C++ one. public class node { public char key; public node next; } node head = new node(); head.next = NULL;

6 Data Structures 6 Linked List: Insert The simplest insert would always place the new item at the front (or back) of the list. One may also want to insert elements in the middle of the list. To insert X between I and S: //C++ //JAVA struct node *A; node A; A=new node; A=new node(); A->key = X; A.Key=X; A->next = I->next; A.next=I.next; I->next = A; I.next=A; X I S head A L I X S T Only two references need to be changed no matter how long the list is. How does this compare with arrays?

7 Data Structures 7 Linked List: Delete Deleting a node is very simple. We just need to change one pointer. However, we need to know which node points to the node we wish to delete. Assuming we know that node points to node, we can delete by: // C++ // JAVA i->next = x->next; i.next=x.next; head A L I X S T Only one reference needs to be changed, no matter how long the list is. How does this compare with an array? Note: There is a slight problem with the C++ code. What is it?

8 Data Structures 8 Linked List: Moving a node Moving a node consist of a delete operation follow by an insert operation. Example: Move T from the end of the list to the beginning: head A L I S T head A L I S T head T A L I S Again, this requires changing only 3 references, no matter how long the list is. What about with arrays?

9 Data Structures 9 Comparison: Linked Lists and Arrays A linked list can grow and shrink during its lifetime, and its maximum size doesn t need to be specified in advance. In contrast, arrays are always of fixed size. We can rearrange, add, and delete items from a linked list with only a constant number of operations. With arrays, these operations are generally linear in the size of the array. To find the th entry of a linked list, we need to follow pointers, which requires operations. With an array, this takes only one operation. Similarly, it may not be obvious how large a linked list is, whereas we always know the size of an array. (This problem can be eliminated very easily. How?)

10 Data Structures 10 Other Linked Lists A doubly linked list is like a linked list, but each node also has a previous field, which points to the nodes predecessor. head A L I S T This can simplify searching, and makes the deletion operation (potentially) easier. There is obviously added storage cost, and the number of instructions needed for the various operations approximately doubles. Circular-linked list: The last node points to the first node. It can be single or doubly linked list. It can be implemented with a fixed or moving head. head A L I S T

11 Data Structures 11 Linked Lists without Pointers Instead of using pointer to implement linked lists, we can use arrays. We won t look at this in depth, but it is not too hard to imagine how we could do it. There are a few complications in this type of implementation, but they can easily be worked around. Example: next key S L A I T head A L I S T z

12 Data Structures 12 Linked Lists Summary Linked lists are data structures that are in many ways similar to arrays. Inserting, deleting or accessing items in linked lists are operations which can be performed. Insertion and deletion can be done in constant time. Finding an element in a linked list generally takes linear time. This is true whether we are trying to find an element whose value is, or we are trying to find the th element on the list. It is this last fact that can limit the usefulness of linked lists.

13 Data Structures 13 Stacks A Stack is a sequential organization of items in which the last element inserted is the first element removed. They are often referred to as LIFO, which stands for last in first out. Examples: letter basket, stack of trays, stack of plates. The only element of a stack that may be accessed is the one that was most recently inserted. There are only two basic operations on stacks, the push (insert), and the pop (read and delete). push pop Stack

14 Data Structures 14 Stacks: Push and Pop The operation push( ) places the item onto the top of the stack. The operation pop() removes the top item from the stack, and returns that item. We need some way of detecting an empty stack (This is an underfull stack). In some cases, we can have pop() return some value that couldn t possibly be on the stack. Example: If the items on the stack are positive integers, we can return -1 in case of underflow. In other cases, we may be better off simply keeping track of the size of the stack. In some cases, we will also have to worry about filling the stack (called overflow). One way to do this is to have push( ) return 1 if it is successful, and 0 if it fails.

15 Data Structures 15 An Example Stack Operations Assume we have a stack of size 3 which holds integers between -100 and 100. Here is a series of operations, and the results. Operation Stack Contents Return create () push(55) (55) 1 push(-7) (-7,55) 1 push(16) (16,-7,55) 1 pop (-7,55) 16 push(-8) (-8,-7,55) 1 push(23) (-8,-7,55) 0 pop (-7,55) -8 pop (55) -7 pop () 55 pop () 101

16 Data Structures 16 Implementing Stacks: Array Stacks can be implemented with an array and an integer that stores the array index of the top of the stack. Empty stack has, and a full stack has, where is the size of the array. To push, increment the counter, and write in the array position. To pop, decrement the counter.

17 Data Structures 17 Example of Array Implementation of Stack We use an array to store the elements and a variable to keep track of the top. The last column, labeled R is the result of the function call. Operation p E0 E1 E2 E3 E4 R create -1????? push(55) 0 55???? 1 push(-7) ??? 1 push(16) ?? 1 pop ?? 16 push(-8) ?? 1 pop ?? -8 pop ?? -7 Notice that some values are still in the array, but are no longer considered to be in the stack. In general, elements are garbage if. Why don t we erase the element (i.e. set it to some default value.)?

18 Data Structures 18 Example Application of Stacks Stacks can be used to check a program for balanced symbols (such as!#",(),[ ]). Example:! ()" is legal, as is! ()(!\$" )", whereas! ((" and! (" ) are not (so simply counting symbols does not work). If the symbols are balanced correctly, then when a closing symbol is seen, it should match the most recently seen unclosed opening symbol. Therefore, a stack will be appropriate. The following algorithm will do the trick: While % there is still input: = next symbol (% if is an opening symbol) push(% ) else //% is a closing symbol if (Stack.Empty) report an error else& = pop() if(! Match(%,& )) report an error If (! Stack.Empty) report an error

19 Data Structures Input:! ( ) " Read!, so push! Examples Read (, so push (. Stack has! ( Read ), so pop. popped item is ( which matches ). Stack has now!. Read ", so pop; popped item is! which matches ". End of file; stack is empty, so the string is valid. 2. Input:! ( ) (! ) " " (This will fail.) 2. Input:! (! " )! " ( ) " (This will succeed.) 3. Input:! ( ) " ) (This will fail.)

20 Data Structures 20 Stack: C++ Array Implementation The following is a C++ stack that holds items of type ItemType class Stack { private: ItemType *stack; int p; public: Stack(int max=100) {stack = new ItemType[max]; p = 0; } Stack() {delete stack; } void push(itemtype v) { stack[p++] = v; } ItemType pop() {return stack[--p]; } int empty() {return!p; } };

21 Data Structures 21 Stack: JAVA Array Implementation The following is a JAVA stack that holds items of type ItemType public class Stack { private ItemType[] stack; private int p; public Stack(int max) { stack = new ItemType[max]; p = 0; } public void push(itemtype v) { stack[p++] = v; } public ItemType pop() { return stack[--p]; } public int empty() { return!p; } };

22 Data Structures 22 Operator Precedence Parsing We can use the stack class we just defined to parse and evaluate mathematical expressions like: ' ( *) +, -( (/.0 1 2# First, we transform it to postfix notation (How would you do this?): ( ( 7 + ( Then, the following C++ routine uses a stack to perform this evaluation: char c; Stack acc(50); int x; while (cin.get(c)) { x = 0; while (c == ) cin.get(c); if (c == + ) x = acc.pop() + acc.pop(); if (c == * ) x = acc.pop() * acc.pop(); while (c>= 0 && c<= 9 ) {x = 10*x + (c- 0 ); cin.get(c); } acc.push(x); } cout << acc.pop() << \n ;

23 Data Structures 23 Stack Implementation: C++ Linked Lists We can use linked lists to implement stacks. The head of the list represents the top of the stack. Example After43 % 5 76,83 %95 ;:,83 %95 *< 43 % 5 7=,, we have: Head A B C D ItemType pop () { ItemType x = head->key; head=head->next; return x; } void push(itemtype x) { node *x; x=new node; x->key = X; insert(x); } Note: Slight error in pop. What is it?

24 Data Structures 24 Stack Implementation: JAVA Linked Lists We assume head points to the first element of the list, and is the top of the stack. public ItemType pop () { ItemType x = head.key; head=head.next; return x; } public void push(itemtype x) { node A=new node(); A.key = x; A.next=head; head=a; }

25 Data Structures 25 Linked Lists Arrays Stack Implementation: Array or Linked List? Use 1 pointer extra memory per item. If an item is an integer, that means twice as much space is used. If an item is a structure/class consisting of many objects, it is only a small price to pay. Are unlimited in size. Allocate a constant amount of space, some of which may never be used. The amount of wasted memory is the number of unused elements times the size of the item, which could be large in some cases. The maximum size is determined when the stack is created. Which is better? Why?

26 Data Structures 26 Stack Applications Recursion removal can be done with stacks. Reversing things is easily done with stacks. Procedure call and procedure return is similar to matching symbols: When a procedure returns, it returns to the most recently active procedure. When a procedure call is made, save current state on the stack. On return, restore the state by popping the stack.

27 Data Structures 27 Queues A Queue is a sequential organization of items in which first element entered is first removed. They are often referred to as FIFO, which stands for first in first out. Examples: standing in a line, printer queue. The basic operations are: insert( ) places at the beginning of the queue. remove() returns and deletes the item at the end of the queue. Example: Operation Queue Return CreateQueue () insert(7) (7) insert(8) (7,8) insert(5) (7,8,5) remove() (8,5) 7 remove() (5) 8

28 Data Structures 28 Operating systems: Queue Applications Queue of jobs or processes ready to run (waiting for CPU): Queues of processes waiting for I/O. Files sent to printer Simulation of real-world queuing systems: Customers in a grocery store, bank, etc. Orders in a factory Hospital emergency room or doctor s office Telephone calls for airline reservations, customer orders, information, etc. Problem applications: B %, and pairs 7CEDF indicating that event C Topological ordering: given a sequence of should occur prior to F, provide a schedule.

29 Data Structures 29 Queues: Naive Implementation Using array: Store items in an array. The head it the first element, and the tail is indicated by a variable tail. insert( ) is easy: increment C HG, and insert element. remove() is inefficient: all elements have to be shifted. Thus, remove isi. a b c d tail = 3 remove a b c d tail = 3 update tail b c d tail = 2 How can we improve this?

30 Data Structures 30 Queues: A Better Implementation Keep track of both the head and the tail. To remove, increment JE&K B. a b c d remove a b c d tail = 3 head = 0 tail = 3 update head b c d head = 1 tail = 3 There is still a problem. What is it, and how can we fix it?

31 Data Structures 31 Queues: Circular Array Implementation Previous implementation isi L per operation, which is great. However, after inserts (where is the size of the array), the array is full even if the queue is logically nearly empty. Solution: Use wraparound to reuse the cells at the start of the array. To 1M& > B, add one, but if that goes past end, reset to zero. How do you detect a full or empty queue? We will give a simplified implementation for the queue data structure. A better implementation would detect an empty (full) queue before performing a dequeue (enqueue) operation.

32 Data Structures 32 Queue C++ Declaration Here is a C++ declaration of an integer queue using a circular array: class Queue { private: int *queue; int cap,head,tail; public: Queue(int s=100) { cap= s; queue = new int[cap]; head = 0; tail = 0; } Queue() { delete queue; } void Enqueue(int v) { queue[tail] = v; tail = (tail+1) % cap; } int Dequeue() { int t = queue[head]; head = (head + 1) % cap; return t; } int Empty() {return (head == tail ); } int Full() {return (head == ((tail+1)%cap)); } };

33 Data Structures 33 Queue JAVA Declaration public class Queue { private int[] queue; private int cap,head,tail; public Queue(int s) { cap=s; queue = new int[cap]; head = 0; tail = 0; i } public void Enqueue(int v) { queue[tail] = v; tail = (tail+1) % cap; } public int Dequeue() { int t = queue[head]; head = (head + 1) % cap; return t; } public int Empty() { return (head == tail ); } public int Full() { return (head == ((tail+1)%cap)); } };

34 Data Structures 34 Example of Queue Using Circular Array 5 Here we use an array OQP9 to store the elements and the variables (head) and (tail) to keep track of the beginning and end of the queue. The value R is the return value of the operation. Operation h t E0 E1 E2 E3 R create 0 0???? insert(55) ??? insert(-7) ?? insert(16) ? remove() ? 55 insert(-8) remove() remove() insert(11) Note that some of the values remain physically in the array, but are logically no longer in the queue.

35 Data Structures 35 Queues: Linked List Implementation We can maintain JR&\$ S and C HG pointers. & : advance JE&\$LB. % > & : add to end of list and adjust C HG. front tail A B C D The details are not very hard to work out, so will not be presented.

### DATA STRUCTURES USING C

DATA STRUCTURES USING C QUESTION BANK UNIT I 1. Define data. 2. Define Entity. 3. Define information. 4. Define Array. 5. Define data structure. 6. Give any two applications of data structures. 7. Give

### 1) The postfix expression for the infix expression A+B*(C+D)/F+D*E is ABCD+*F/DE*++

Answer the following 1) The postfix expression for the infix expression A+B*(C+D)/F+D*E is ABCD+*F/DE*++ 2) Which data structure is needed to convert infix notations to postfix notations? Stack 3) The

### Module 2 Stacks and Queues: Abstract Data Types

Module 2 Stacks and Queues: Abstract Data Types A stack is one of the most important and useful non-primitive linear data structure in computer science. It is an ordered collection of items into which

### QUEUES. Primitive Queue operations. enqueue (q, x): inserts item x at the rear of the queue q

QUEUES A queue is simply a waiting line that grows by adding elements to its end and shrinks by removing elements from the. Compared to stack, it reflects the more commonly used maxim in real-world, namely,

### 12 Abstract Data Types

12 Abstract Data Types 12.1 Source: Foundations of Computer Science Cengage Learning Objectives After studying this chapter, the student should be able to: Define the concept of an abstract data type (ADT).

Linked Lists Linked Lists, Queues, and Stacks CSE 10: Introduction to C Programming Fall 200 Dynamic data structure Size is not fixed at compile time Each element of a linked list: holds a value points

### TIE-20106 1 TIE-20106 2

TIE-20106 1 1 List structures In this chapter, a few simple data structures (stack and queue) that can be implemented with arrays and/or lists are covered. Two more complex structures based on lists are

### CS104: Data Structures and Object-Oriented Design (Fall 2013) October 24, 2013: Priority Queues Scribes: CS 104 Teaching Team

CS104: Data Structures and Object-Oriented Design (Fall 2013) October 24, 2013: Priority Queues Scribes: CS 104 Teaching Team Lecture Summary In this lecture, we learned about the ADT Priority Queue. A

### Data Structures and Algorithms Stacks and Queues

Data Structures and Algorithms Stacks and Queues Chris Brooks Department of Computer Science University of San Francisco Department of Computer Science University of San Francisco p.1/23 6-0: Stacks and

### 10CS35: Data Structures Using C

CS35: Data Structures Using C QUESTION BANK REVIEW OF STRUCTURES AND POINTERS, INTRODUCTION TO SPECIAL FEATURES OF C OBJECTIVE: Learn : Usage of structures, unions - a conventional tool for handling a

### Data Structures Using C++ 2E. Chapter 5 Linked Lists

Data Structures Using C++ 2E Chapter 5 Linked Lists Doubly Linked Lists Traversed in either direction Typical operations Initialize the list Destroy the list Determine if list empty Search list for a given

### CHAPTER 4 ESSENTIAL DATA STRUCTRURES

CHAPTER 4 ESSENTIAL DATA STRUCTURES 72 CHAPTER 4 ESSENTIAL DATA STRUCTRURES In every algorithm, there is a need to store data. Ranging from storing a single value in a single variable, to more complex

### Introduction to Data Structures

Introduction to Data Structures Albert Gural October 28, 2011 1 Introduction When trying to convert from an algorithm to the actual code, one important aspect to consider is how to store and manipulate

### UNIVERSITI MALAYSIA SARAWAK KOTA SAMARAHAN SARAWAK PSD2023 ALGORITHM & DATA STRUCTURE

STUDENT IDENTIFICATION NO UNIVERSITI MALAYSIA SARAWAK 94300 KOTA SAMARAHAN SARAWAK FAKULTI SAINS KOMPUTER & TEKNOLOGI MAKLUMAT (Faculty of Computer Science & Information Technology) Diploma in Multimedia

### Data Structure. Lecture 3

Data Structure Lecture 3 Data Structure Formally define Data structure as: DS describes not only set of objects but the ways they are related, the set of operations which may be applied to the elements

### Stacks. Linear data structures

Stacks Linear data structures Collection of components that can be arranged as a straight line Data structure grows or shrinks as we add or remove objects ADTs provide an abstract layer for various operations

### Data Structures. Topic #4

Topic #4 Today s Agenda Stack and Queue ADTs What are they Like Ordered Lists, are position oriented Use of Data Structures for Stacks and Queues arrays (statically & dynamically allocated) linear linked

Chapter 7 Linked Lists In order to use linked lists, you need to learn how to allocate memory dynamically on the heap and you need to learn about objects. Recall that local variables are temporary which

### Krishna Institute of Engineering & Technology, Ghaziabad Department of Computer Application MCA-213 : DATA STRUCTURES USING C

Tutorial#1 Q 1:- Explain the terms data, elementary item, entity, primary key, domain, attribute and information? Also give examples in support of your answer? Q 2:- What is a Data Type? Differentiate

### CmpSci 187: Programming with Data Structures Spring 2015

CmpSci 187: Programming with Data Structures Spring 2015 Lecture #12 John Ridgway March 10, 2015 1 Implementations of Queues 1.1 Linked Queues A Linked Queue Implementing a queue with a linked list is

### Algorithms and Data Structures

Algorithms and Data Structures Part 2: Data Structures PD Dr. rer. nat. habil. Ralf-Peter Mundani Computation in Engineering (CiE) Summer Term 2016 Overview general linked lists stacks queues trees 2 2

### Linked Lists, Stacks, Queues, Deques. It s time for a chainge!

Linked Lists, Stacks, Queues, Deques It s time for a chainge! Learning Goals After this unit, you should be able to... Differentiate an abstraction from an implementation. Define and give examples of problems

### Chapter 3: Restricted Structures Page 1

Chapter 3: Restricted Structures Page 1 1 2 3 4 5 6 7 8 9 10 Restricted Structures Chapter 3 Overview Of Restricted Structures The two most commonly used restricted structures are Stack and Queue Both

### Sequential Data Structures

Sequential Data Structures In this lecture we introduce the basic data structures for storing sequences of objects. These data structures are based on arrays and linked lists, which you met in first year

### Stack Allocation. Run-Time Data Structures. Static Structures

Run-Time Data Structures Stack Allocation Static Structures For static structures, a fixed address is used throughout execution. This is the oldest and simplest memory organization. In current compilers,

### csci 210: Data Structures Stacks and Queues

csci 210: Data Structures Stacks and Queues Summary Topics stacks and queues as abstract data types implementations arrays linked lists analysis and comparison application: searching with stacks and queues

### Stacks, Queues and Linked Lists

Stacks, Queues and Linked Lists Adnan Aziz 1 Dynamic sets CLRS Part III, page 197 In mathematics, a set is a well-defined collection of elements (elements could be numbers, functions, geometric shapes);

### Boolean Expressions, Conditions, Loops, and Enumerations. Precedence Rules (from highest to lowest priority)

Boolean Expressions, Conditions, Loops, and Enumerations Relational Operators == // true if two values are equivalent!= // true if two values are not equivalent < // true if left value is less than the

### Introduction to Data Structures and Algorithms

Introduction to Data Structures and Algorithms Chapter: Elementary Data Structures(1) Lehrstuhl Informatik 7 (Prof. Dr.-Ing. Reinhard German) Martensstraße 3, 91058 Erlangen Overview on simple data structures

### MAX = 5 Current = 0 'This will declare an array with 5 elements. Inserting a Value onto the Stack (Push) -----------------------------------------

=============================================================================================================================== DATA STRUCTURE PSEUDO-CODE EXAMPLES (c) Mubashir N. Mir - www.mubashirnabi.com

### Queues Outline and Required Reading: Queues ( 4.2 except 4.2.4) COSC 2011, Fall 2003, Section A Instructor: N. Vlajic

Queues Outline and Required Reading: Queues ( 4. except 4..4) COSC, Fall 3, Section A Instructor: N. Vlajic Queue ADT Queue linear data structure organized according to first-in/first-out (FIFO) principle!

### Data Structure with C

Subject: Data Structure with C Topic : Tree Tree A tree is a set of nodes that either:is empty or has a designated node, called the root, from which hierarchically descend zero or more subtrees, which

### 4.3 Stacks and Queues. Pushdown Stacks. Data Structures and Data Types. Collections

Data Structures and Data Types 4.3 Stacks and Queues Data types Set values. Set operations on those values. Some are built in to Java: int, double, char,... Most are not: Complex, Picture, Charge, Stack,

Chapter 4: Linked Lists Data Abstraction & Problem Solving with C++ Fifth Edition by Frank M. Carrano Preliminaries Options for implementing an ADT List Array has a fixed size Data must be shifted during

### Data Structures and Data Manipulation

Data Structures and Data Manipulation What the Specification Says: Explain how static data structures may be used to implement dynamic data structures; Describe algorithms for the insertion, retrieval

### Course: Programming II - Abstract Data Types. The ADT Stack. A stack. The ADT Stack and Recursion Slide Number 1

Definition Course: Programming II - Abstract Data Types The ADT Stack The ADT Stack is a linear sequence of an arbitrary number of items, together with access procedures. The access procedures permit insertions

### Chapter 13. Pointers and Linked Lists

Chapter 13 Pointers and Linked Lists Overview 13.1 Nodes and Linked Lists 13.2 Stacks and Queues Slide 13-2 13.1 Nodes and Linked Lists Nodes and Linked Lists n A linked list is a list that can grow and

### Stack & Queue. Darshan Institute of Engineering & Technology. Explain Array in detail. Row major matrix No of Columns = m = u2 b2 + 1

Stack & Queue Explain Array in detail One Dimensional Array Simplest data structure that makes use of computed address to locate its elements is the onedimensional array or vector; number of memory locations

### PES Institute of Technology-BSC QUESTION BANK

PES Institute of Technology-BSC Faculty: Mrs. R.Bharathi CS35: Data Structures Using C QUESTION BANK UNIT I -BASIC CONCEPTS 1. What is an ADT? Briefly explain the categories that classify the functions

### Quiz 4 Solutions EECS 211: FUNDAMENTALS OF COMPUTER PROGRAMMING II. 1 Q u i z 4 S o l u t i o n s

Quiz 4 Solutions Q1: What value does function mystery return when called with a value of 4? int mystery ( int number ) { if ( number

### Chapter 7: Queues and Deques

Chapter 7: Queues and Deques After the stack, the next simplest data abstraction is the queue. As with the stack, the queue can be visualized with many examples you are already familiar with from everyday

### DATA STRUCTURE - QUEUE

DATA STRUCTURE - QUEUE http://www.tutorialspoint.com/data_structures_algorithms/dsa_queue.htm Copyright tutorialspoint.com Queue is an abstract data structure, somewhat similar to stack. In contrast to

### St S a t ck a ck nd Qu Q eue 1

Stack and Queue 1 Stack Data structure with Last-In First-Out (LIFO) behavior In Out C B A B C 2 Typical Operations Pop on Stack Push isempty: determines if the stack has no elements isfull: determines

### Class Overview. CSE 326: Data Structures. Goals. Goals. Data Structures. Goals. Introduction

Class Overview CSE 326: Data Structures Introduction Introduction to many of the basic data structures used in computer software Understand the data structures Analyze the algorithms that use them Know

### Stacks. Data Structures and Data Types. Collections

Data Structures and Data Types Data types Set values. Set operations on those values. Some are built in to Java: int, double, char,... Most are not: Complex, Picture, Charge, Stack, Queue, Graph,... Data

### UIL Computer Science for Dummies by Jake Warren and works from Mr. Fleming

UIL Computer Science for Dummies by Jake Warren and works from Mr. Fleming 1 2 Foreword First of all, this book isn t really for dummies. I wrote it for myself and other kids who are on the team. Everything

### Programming with Data Structures

Programming with Data Structures CMPSCI 187 Spring 2016 Please find a seat Try to sit close to the center (the room will be pretty full!) Turn off or silence your mobile phone Turn off your other internet-enabled

### 7.1 Our Current Model

Chapter 7 The Stack In this chapter we examine what is arguably the most important abstract data type in computer science, the stack. We will see that the stack ADT and its implementation are very simple.

### Abstract Data Type. EECS 281: Data Structures and Algorithms. The Foundation: Data Structures and Abstract Data Types

EECS 281: Data Structures and Algorithms The Foundation: Data Structures and Abstract Data Types Computer science is the science of abstraction. Abstract Data Type Abstraction of a data structure on that

### Analysis of a Search Algorithm

CSE 326 Lecture 4: Lists and Stacks 1. Agfgd 2. Dgsdsfd 3. Hdffdsf 4. Sdfgsfdg 5. Tefsdgass We will review: Analysis: Searching a sorted array (from last time) List ADT: Insert, Delete, Find, First, Kth,

### Comp 245 Data Structures. 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 random access to other elements within the stack An

### CS412/CS413. Introduction to Compilers Tim Teitelbaum. Lecture 34: Memory Management 16 Apr 08

CS412/CS413 Introduction to Compilers Tim Teitelbaum Lecture 34: Memory Management 16 Apr 08 CS 412/413 Spring 2008 Introduction to Compilers 1 Outline Explicit memory management Garbage collection techniques

### International Journal Of Engineering Research & Management Technology

International Journal Of Engineering Research & Management Technology ISSN: 2348-4039 September- 2014 Volume 1, Issue-5 Dynamic Implementation Using Linked List Karuna Department of Information and Technology

### LC-3 Data Structures. Textbook chapter 10

LC-3 Data Structures Textbook chapter 10 LC-3 data structures Abstract data structures are Defined by the rules for inserting and extracting data In this section, we will talk about The array The stack

### Data Structures and Algorithms(3)

Ming Zhang Data Structures and Algorithms Data Structures and Algorithms(3) Instructor: Ming Zhang Textbook Authors: Ming Zhang, Tengjiao Wang and Haiyan Zhao Higher Education Press, 2008.6 (the "Eleventh

### CS0213 DATA STRUCTURES AND ALGORITHM LAB USING C & C++ LABORATORY MANUAL II - CSE III - SEMESTER ACADEMIC YEAR:

CS0213 DATA STRUCTURES AND ALGORITHM LAB USING C & C++ LABORATORY MANUAL II - CSE III - SEMESTER ACADEMIC YEAR: 2012-2013 SCHOOL OF COMPUTER SCIENCE & ENGINEERING SRM UNIVERSITY, SRM NAGAR, KATTANKULATHUR-603203.

### 1. The memory address of the first element of an array is called A. floor address B. foundation addressc. first address D.

1. The memory address of the first element of an array is called A. floor address B. foundation addressc. first address D. base address 2. The memory address of fifth element of an array can be calculated

### Data Structure [Question Bank]

Unit I (Analysis of Algorithms) 1. What are algorithms and how they are useful? 2. Describe the factor on best algorithms depends on? 3. Differentiate: Correct & Incorrect Algorithms? 4. Write short note:

Arrays, Singly-Linked Lists, Stacks, Queues, Doubly-Linked Lists, Deques Slide Set 5: Learning Goals Differentiate an abstraction from an implementation. Define and give examples of problems that can be

### Data Structures and Algorithms

Data Structures and Algorithms Lecture 4 2016 Stacks and... 1/28 1 2 Circular Linked 3 Queue Syntax and Functions in C++ 4 Stacks and... 2/28 FIFO and LIFO Outline Data structures can be specialized versions

### Stacks. The stack ADT Stack Implementation. Stack Examples. using arrays using generic linked lists using List ADT. EECS 268 Programming II 1

Stacks The stack ADT Stack Implementation using arrays using generic linked lists using List ADT Stack Examples 1 Stacks and Queues Linear data structures each item has specific first, next, and previous

### What is a Stack? Stacks and Queues. Stack Abstract Data Type. Java Interface for Stack ADT. Array-based Implementation

Stacks and Queues What is a Stack? Stores a set of elements in a particular order Accessed in Last-In In-First-Out (LIFO) fashion Real life examples: Pile of books PEZ dispenser Cup trays in cafeteria

### Big O and Limits Abstract Data Types Data Structure Grand Tour. http://gcc.gnu.org/onlinedocs/libstdc++/images/pbds_different_underlying_dss_1.

Big O and Limits Abstract Data Types Data Structure Grand Tour http://gcc.gnu.org/onlinedocs/libstdc++/images/pbds_different_underlying_dss_1.png Consider the limit lim n f ( n) g ( n ) What does it

### Symbol Tables. IE 496 Lecture 13

Symbol Tables IE 496 Lecture 13 Reading for This Lecture Horowitz and Sahni, Chapter 2 Symbol Tables and Dictionaries A symbol table is a data structure for storing a list of items, each with a key and

### Cpt S 223. School of EECS, WSU

Abstract Data Types 1 Topics Abstract Data Types (ADTs) Some basic ADTs: Lists Stacks Queues 2 Primitive Data Type vs. Abstract Data Types Primitive DT: ADT: programmer progra ammer Interface (API) e.g.,

### Chapter 8: I/O Organization and Interrupts

Chapter 8: I/O Organization and Interrupts I. CUSP has 5 I/O Devices A. Keyboard B. Display screen, CRT C. Printer D. Tape drive E. Timer II. I/O Ports A. CUSP has 4096 8-bit ports. Many are unused-this

### Course: Programming II - Abstract Data Types. The ADT Queue. (Bobby, Joe, Sue, Ellen) Add(Ellen) Delete( ) The ADT Queues Slide Number 1

Definition Course: Programming II - Abstract Data Types The ADT Queue The ADT Queue is a linear sequence of an arbitrary number of items, together with access procedures. The access procedures permit addition

### Collections & Data Structures. CS 3: Computer Programming in Java

Collections & Data Structures CS 3: Computer Programming in Java Objectives The concept of a collection Separating the interface from the implementation Dynamic data structures Linked lists Queues and

### PROGRAMMING CONCEPTS AND EMBEDDED PROGRAMMING IN C, C++ and JAVA: Lesson-4: Data Structures: Stacks

PROGRAMMING CONCEPTS AND EMBEDDED PROGRAMMING IN C, C++ and JAVA: Lesson-4: Data Structures: Stacks 1 STACK A structure with a series of data elements with last sent element waiting for a delete operation.

### CSE373: Data Structures and Algorithms Lecture 1: Introduction; ADTs; Stacks/Queues. Linda Shapiro Spring 2016

CSE373: Data Structures and Algorithms Lecture 1: Introduction; ADTs; Stacks/Queues Linda Shapiro Registration We have 180 students registered and others who want to get in. If you re thinking of dropping

### System Software Prof. Dr. H. Mössenböck

System Software Prof. Dr. H. Mössenböck 1. Memory Management 2. Garbage Collection 3. Linkers and Loaders 4. Debuggers 5. Text Editors Marks obtained by end-term exam http://ssw.jku.at/misc/ssw/ 1. Memory

### Questions 1 through 25 are worth 2 points each. Choose one best answer for each.

Questions 1 through 25 are worth 2 points each. Choose one best answer for each. 1. For the singly linked list implementation of the queue, where are the enqueues and dequeues performed? c a. Enqueue in

### Queues and Stacks. Atul Prakash Downey: Chapter 15 and 16

Queues and Stacks Atul Prakash Downey: Chapter 15 and 16 Queues Queues occur in real life a lot. Queues at checkout Queues in banks In software systems: Queue of requests at a web servers Properties of

### BM267 - Introduction to Data Structures

BM267 - Introduction to Data Structures 3. Elementary Data Structures Ankara University Computer Engineering Department BLM267 1 Objectives Learn about elementary data structures - Data structures that

### Data Structures. Jaehyun Park. CS 97SI Stanford University. June 29, 2015

Data Structures Jaehyun Park CS 97SI Stanford University June 29, 2015 Typical Quarter at Stanford void quarter() { while(true) { // no break :( task x = GetNextTask(tasks); process(x); // new tasks may

### 1 Abstract Data Types Information Hiding

1 1 Abstract Data Types Information Hiding 1.1 Data Types Data types are an integral part of every programming language. ANSI-C has int, double and char to name just a few. Programmers are rarely content

### Announcements. FINAL EXAM Monday May 21, 1:30pm Review Session. Wednesday May 16, 7-9pm

Announcements FINAL EXAM Monday May 21, 1:30pm Review Session Wednesday May 16, 7-9pm 1 Recitation 12 Root Finding, Sorting, Stacks, Queues 2 Outline Linked Lists Sorting Queues 3 Object References Let

Universidad Carlos III de Madrid Algorithms and Data Structures (ADS) Bachelor in Informatics Engineering Computer Science Department Lists, Stacks and Queues. Authors: Isabel Segura Bedmar April 2011

### Data Structures and Algorithms

Data Structures and Algorithms CS245-2016S-04 Stacks and Queues David Galles Department of Computer Science University of San Francisco 04-0: Abstract Data Types An Abstract Data Type is a definition of

### CSE373: Data Structures and Algorithms Lecture 1: Introduction; ADTs; Stacks/Queues. Nicki Dell Spring 2014

CSE373: Data Structures and Algorithms Lecture 1: Introduction; ADTs; Stacks/Queues Nicki Dell Spring 2014 Registration We have 140 students registered and 140+ on the wait list! If you re thinking of

### Data Structure and Algorithm I Midterm Examination 120 points Time: 9:10am-12:10pm (180 minutes), Friday, November 12, 2010

Data Structure and Algorithm I Midterm Examination 120 points Time: 9:10am-12:10pm (180 minutes), Friday, November 12, 2010 Problem 1. In each of the following question, please specify if the statement

### This lecture. Abstract data types Stacks Queues. ADTs, Stacks, Queues 1. 2004 Goodrich, Tamassia

This lecture Abstract data types Stacks Queues ADTs, Stacks, Queues 1 Abstract Data Types (ADTs) An abstract data type (ADT) is an abstraction of a data structure An ADT specifies: Data stored Operations

### Data Structures Using C++ 2E. Chapter 7 Stacks

Data Structures Using C++ 2E Chapter 7 Stacks Stacks Data structure Elements added, removed from one end only Last In First Out (LIFO) FIGURE 7-1 Various examples of stacks Data Structures Using C++ 2E

### The first step in solving a problem recursively is to formulate a recursive definition of the problem.

Chapter 8 Recursion The subject of this chapter is recursion, an implicit application of the stack ADT. A recursive method is a method that carries out its task by making a call(s) to itself. Each recursive

### Data Structures. value. key. 5 Alpha. 3 Beta. 7 Gamma

Data Structures key value 5 Alpha 10 2 7 5 1 4 9 3 6 8 3 Beta 7 Gamma Sequence Associative e.g., C-Arrays, std::vector, std::deque, std::list e.g., C-Arrays, std::map, std::set, std::unordered_map Data

### Home Page. Data Structures. Title Page. Page 1 of 24. Go Back. Full Screen. Close. Quit

Data Structures Page 1 of 24 A.1. Arrays (Vectors) n-element vector start address + ielementsize 0 +1 +2 +3 +4... +n-1 start address continuous memory block static, if size is known at compile time dynamic,

### Introduction to data structures

Notes 2: Introduction to data structures 2.1 Recursion 2.1.1 Recursive functions Recursion is a central concept in computation in which the solution of a problem depends on the solution of smaller copies

STACKS,QUEUES, AND LINKED LISTS Stacks Queues Linked Lists Double-Ended Queues Case Study: A Stock Analysis Applet 1 Stacks Astack is a container of objects that are inserted and removed according to the

### Chapter 7. Arrays and Collections. Instructor s Manual Table of Contents. At a Glance. Chapter Overview. Chapter Objectives.

C# Programming: From Problem Analysis to Program Design, 2nd ed. 7-1 Chapter 7 Arrays and Collections At a Glance Instructor s Manual Table of Contents Chapter Overview Chapter Objectives Instructor Notes

### Memory Allocation. Static Allocation. Dynamic Allocation. Memory Management. Dynamic Allocation. Dynamic Storage Allocation

Dynamic Storage Allocation CS 44 Operating Systems Fall 5 Presented By Vibha Prasad Memory Allocation Static Allocation (fixed in size) Sometimes we create data structures that are fixed and don t need

C++ How to Program, 8/e 1992-2012 by Pearson Education, Inc. 1992-2012 by Pearson Education, Inc. 1992-2012 by Pearson Education, Inc. We ve studied fixed-size data structures such as one-dimensional arrays

### Last not not Last Last Next! Next! Line Line Forms Forms Here Here Last In, First Out Last In, First Out not Last Next! Call stack: Worst line ever!

ECE 551 C++ Programming, Data structures, and Algorithms Abstract Data Type: Stack Last In First Out (LIFO) 1 2 2 1 4 3 1 3 4 Stacks in Programming Worst line ever! 5 3 1 5 Stacks are not useful for waiting

### COMPUTER SCIENCE. Paper 1 (THEORY)

COMPUTER SCIENCE Paper 1 (THEORY) (Three hours) Maximum Marks: 70 (Candidates are allowed additional 15 minutes for only reading the paper. They must NOT start writing during this time) -----------------------------------------------------------------------------------------------------------------------

### Overview of Data Structures

UNIT 3 Concrete Data Types Classification of Data Structures Concrete vs. Abstract Data Structures Most Important Concrete Data Structures Arrays Records Linked Lists Binary Trees Overview of Data Structures

### University of Illinois at Urbana-Champaign Department of Computer Science. First Examination

University of Illinois at Urbana-Champaign Department of Computer Science First Examination CS 225 Data Structures and Software Principles Fall 2007 7p-9p, Thursday, October 4 Name: NetID: Lab Section

### Lecture 12 Doubly Linked Lists (with Recursion)

Lecture 12 Doubly Linked Lists (with Recursion) In this lecture Introduction to Doubly linked lists What is recursion? Designing a node of a DLL Recursion and Linked Lists o Finding a node in a LL (recursively)

### Data Structures and Algorithms. Lab 1. Hands on Data Structures Using C++ Stacks and Queues

Data Structures and Algorithms Lab 1 Hands on Data Structures Using C++ Stacks and Queues Dr. Rabie A. Ramadan Notes: Students must read this document before the lab and make their code ready for compilation.