# Vector ADT. A Vector stores a list of elements: Access via rank/index.

Save this PDF as:

Size: px
Start display at page:

## Transcription

1 Vector ADT A Vector stores a list of elements: Access via rank/index. Accessor methods: elementatrank(r), Update methods: replaceatrank(r, o), insertatrank(r, o), removeatrank(r) Generic methods: size(), isemtpy() Here r is of type integer, n, m are nodes, o is an object (data).

2 List ADT A List consists of a sequence of nodes: The nodes store arbitrary objects. Access via before/after relation between nodes. element 1 element 2 element 3 element 4 Accessor methods: first(), last(), before(n), after(n) Query methods: isfirst(n), islast(n) Generic methods: size(), isemtpy() Update methods: replaceelement(n, o), swapelements(n, m), insertbefore(n, o), insertafter(n, o), insertfirst(o), insertlast(o), remove(n) Here r is of type integer, n, m are nodes, o is an object (data).

3 Sequence ADT Sequence ADT is the union of Vector and List ADT: inherits all methods Additional methods: atrank(r): returns the node at rank r rankof(n): returns the rank of node n Elements can by accessed by: rank/index, or navigation between nodes Remarks The distinction between Vector, List and Sequence is artificial: every element in a list naturally has a rank Important are the different access methods: access via rank/index, or navigation between nodes

4 Singly Linked List A singly linked list provides an implementation of List ADT. Each node stores: next element (data) link to the next node element node Variables first and optional last point to the first/last node. Optional variable size stores the size of the list. first last element 1 element 2 element 3 element 4

5 Singly Linked List: size If we store the size on the variable size, then: size(): return size Running time:. If we do not store the size on a variable, then: size(): s = 0 m = first while m!= do s = s + 1 m = m.next done return s Running time: O(n).

6 Singly Linked List: insertafter insertafter(n, o): x = new node with element o x.next = n.next n.next = x if n == last then last = x size = size + 1 first n last A B C first n x last A B C Running time:. o

7 Singly Linked List: insertfirst insertfirst(o): x = new node with element o x.next = first first = x if last == then last = x size = size + 1 first first, x A B C o Running time:. A B C

8 Singly Linked List: insertbefore insertbefore(n, o): if n == first then insertfirst(o) else m = first while m.next!= n do m = m.next done insertafter(m, o) (error check m!= has been left out for simplicity) We need to find the node m before n: requires a search through the list Running time: O(n) where n the number of elements in the list. (worst case we have to search through the whole list)

9 Singly Linked List: Performance Operation Worst case Complexity size, isempty 1 first, last, after 2 before O(n) replaceelement, swapelements insertfirst, insertlast 2 insertafter insertbefore O(n) remove O(n) 3 atrank, rankof, elematrank O(n) replaceatrank O(n) insertatrank, removeatrank O(n) 1 size needs O(n) if we do not store the size on a variable. 2 last and insertlast need O(n) if we have no variable last. 3 remove(n) runs in best case in if n == first.

10 Stack with a Singly Linked List We can implement a stack with a singly linked list: top element is stored at the first node Each stack operation runs in time: push(o): insertfirst(o) pop(): o = first().element remove(first()) return o first (top) element 1 element 2 element 3 element 4

11 Queue with a Singly Linked List We can implement a queue with a singly linked list: front element is stored at the first node rear element is stored at the last node Each queue operation runs in time: enqueue(o): insertlast(o) first (top) dequeue(): o = first().element remove(first()) return o last (rear) element 1 element 2 element 3 element 4

12 Doubly Linked List A doubly linked list provides an implementation of List ADT. Each node stores: element (data) prev next link to the next node link to the previous node element node Special header and trailer nodes. Variable size storing the size of the list. header trailer element 1 element 2 element 3 element 4

13 Doubly Linked List: insertafter A B C o insertafter(n, o): m = n.next x = new node with element o x.prev = n x.next = m n.next = x m.prev = x size = size + 1 n A B n C x m

14 Doubly Linked List: insertbefore insertbefore(n, o): insertafter(n.prev, o) n A B C n.prev n A B C x o

15 Doubly Linked List: remove remove(n): p = n.prev q = n.next p.next = q q.prev = p size = size 1 n A B C D p q n A B C o

16 Doubly Linked List: Performance Operation Worst case Complexity size, isempty first, last, after before replaceelement, swapelements insertfirst, insertlast insertafter insertbefore remove atrank, rankof, elematrank O(n) replaceatrank O(n) insertatrank, removeatrank O(n) Now all operations of List ADT are : only operations accessing via index/rank are O(n)

17 Amortization Amortization is a tool for understanding algorithm complexity if steps have widely varying performance: analyses running time of a series of operations takes into account interaction between different operations The amortized running time of an operation in a series of operations is the worst-case running time of the series divided by the number of operations. Example: N operations in 1s, 1 operation in Ns Amortized running time: (N 1 + N)/(N + 1) 2 That is: per operation. N time N operations

18 Amortization Techniques: Accounting Method The accounting method uses a scheme of credits and debits to keep track of the running time of operations in a sequence: we pay one cyber-dollar for a constant computation time We charge for every operation some amount of cyber-dollars: this amount is the amortized running time of this operation When an operation is executed we need enough cyber-dollars to pay for its running time. N time \$ \$ \$ \$ \$ \$ \$ \$ \$ \$ \$ \$ \$ \$ \$ \$ \$ \$ N operations We charge: 2 cyber-dollars per operation The first N operations consume 1 dollar each. For the last operation we have N dollars saved. Amortized per operation.

19 Amortization, Example: Clearable Table Clearable Table supports operations: add(o) for adding an object to the table clear() for emptying the table Implementation using an array: add(o) clear() O(m) where m is number of elements in the table (clear() removes one by one every entry in the table)

20 Amortization, Example: Clearable Table time \$ \$ \$ \$ \$ \$ \$ \$ \$ \$ \$ \$ \$ \$ \$ \$ \$ \$ \$ \$ \$ \$ \$ \$ \$ \$ \$ \$ \$ \$ \$ \$ \$ \$ \$ \$ \$ \$ \$ \$ \$ \$ clear() clear() clear() We charge 2 per operation: add consumes 1; thus we save 1 per add. Whenever m elements are in the list, we have saved m dollars: we use the m dollars to pay for clear O(m) Thus amortized costs per operation are 2 dollars, that is,.

21 Array-based Implementation of Lists Uses array in circular fashion (as for queues): variable f points to first position variable l points one behind last position f l A A B C Adding elements runs in as long as the array is not full. When the array is full: we need to allocate a larger array B copy all elements from A to B set A = B (that is, from then on work further with B)

22 Array-based Implementation: Constant Increase Each time the array is full we increase the size by k elements: creating B of size n + k and copying n elements is O(n) Example: k = 3 time operations Every k-th insert operation we need to resize the array. Worst-case complexity for a sequence of m insert operations: m/k i=1 k i O(n 2 ) Average costs for each operation in the sequence: O(n).

23 Array-based Implementation: Doubling the Size Each time the array is full we double the size: creating B of size 2n and copying n elements is O(n) time \$ \$ \$ \$ \$ \$ \$ \$ \$ \$ \$ \$ \$ \$ \$ \$ \$ \$ \$ \$ \$ \$ \$ \$ \$ \$ \$ \$ \$ \$ \$ \$ \$ \$ \$ \$ \$ \$ \$ \$ \$ \$ \$ \$ \$ \$ \$ \$ operations

24 Array-based Implementation: Doubling the Size Each time the array is full we double the size: insert costs if the array is not full insert costs O(n) if the array is full (for rezise n 2n) We charge 3 cyber dollars per insert. After doubling the size n 2n: we have at least n times insert s without resize we save 2n cyber-dollars before the next resize Thus we have 2n cyber-dollars for the next resize 2n 4n. Hence the amortized costs for insert is 3:. (can also be used for fast queue and stack implementations)

25 Array-based Lists: Performance The performance under assumption of the doubling strategy. Operation size, isempty first, last, after before replaceelement, swapelements insertfirst, insertlast insertafter insertbefore remove atrank, rankof, elematrank replaceatrank insertatrank, removeatrank Amortized Complexity O(n) O(n) O(n) O(n)

26 Comparison of the Amortized Complexities Operation Singly Doubly Array size, isempty first, last, after before O(n) replaceelement, swapelements insertfirst, insertlast insertafter O(n) insertbefore O(n) O(n) remove O(n) O(n) atrank, rankof, elematrank O(n) O(n) replaceatrank O(n) O(n) insertatrank, removeatrank O(n) O(n) O(n) singly linked lists (Singly) doubly linked lists (Doubly) array-based implementation with doubling strategy (Array)

27 Iterators Iterator allows to traverse the elements in a list or set. Iterator ADT provides the following methods: object(): returns the current object hasnext(): indicates whether there are more elements nextobject(): goes to the next object and returns it

28 Priority Queue ADT A priority queue stores a list of items: the items are pairs (key, element) the key represens the priority: smaller key = higher priority Main methods: insertitem(k, o): inserts element o with key k removemin(): removes item (k, o) with smallest key and returns its element o Additional methods: minkey(): returns but does not remove the smallest key minelement(): returns but does not remove the element with the smallest key size(), isempty()

29 Applications of Priority Queues Direct applications: bandwidth management in routers task scheduling (execution of tasks in priority order) Indirect applications: auxiliary data structure for algorithms, e.g.: shortest path in graphs component of other data structures

30 Priority Queues: Order on the Keys Keys can be arbitrary objects with a total order. Two distinct items in a queue may have the same key. A relation is called order if for all x, y, z: reflexivity: x x transitivity: x y and y z implies x z antisymmetry: x y and y x implies x = y Implementation of the order: external class or function Comparator ADT islessthan(x, y), islessorequalto(x, y) isequal(x, y) isgreaterthan(x, y), isgreaterorequalto(x, y) iscomparable(x)

31 Sorting with Priority Queues We can use a priority queue for soring as follows: Insert all elements e stepwise with insertitem(e, e) Remove the elements in sorted order using removemin() Algorithm PriorityQueueSort(A, C): Input: List A, Comparator C Output: List A sorted in ascending order P = new priority queue with comparator C while A.isEmpty() do e = A.remove(A.first()) P.insertItem(e, e) while P.isEmpty() do A.insertLast(P.removeMin()) Running time depends on: implementation of the priority queue

32 List-based Priority Queues Implementation with an unsorted List: Performance: insertitem is since we can insert in front or end removemin, minkey and minelement are O(n) since we have to search the whole list for the smallest key Implementation with an sorted List: Performance: insertitem is O(n) for singly/doubly linked list O(n) for finding the insert position for array-based list O(n) for insertatrank removemin, minkey and minelement are since the smallest key is in front of the list

### Algorithms and Data Structures

Basic Data Structures Page 1 BFH-TI: Softwareschule Schweiz Basic Data Structures Dr. CAS SD01 Basic Data Structures Page 2 Outline Data Structures and Abstract Data Types Linear Data Structures Implementing

### 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

### Algorithms and Data Structures

Priority Queues and Heaps Page 1 - Priority Queues and Heaps Dr. Fall 2008 Priority Queues and Heaps Page 2 Outline Priority Queues Heaps Heap-Based Priority Queues Bottom-Up Heap Construction Priority

### 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,

### 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

Unordered Linked Lists Derive class unorderedlinkedlist from the abstract class linkedlisttype Implement the operations search, insertfirst, insertlast, deletenode See code on page 292 Defines an unordered

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

### Stacks & Queues. Data structures and Algorithms

Stacks & Queues Data structures and Algorithms Acknowledgement: These slides are adapted from slides provided with Data Structures and Algorithms in C++ Goodrich, Tamassia and Mount (Wiley, 2004) Outline

Arrays and Linked Lists Data Structures and Algorithms Acknowledgement: These slides are adapted from slides provided with Data Structures and Algorithms in C++ Goodrich, Tamassia and Mount (Wiley, 2004)

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

Data Structures Using C++ 2E Chapter 5 Linked Lists Test #1 Next Thursday During Class Cover through (near?) end of Chapter 5 Objectives Learn about linked lists Become aware of the basic properties of

### 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

### 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

### Outline. The Stack ADT Applications of Stacks Array-based implementation Growable array-based stack. Stacks 2

Stacks Outline The Stack ADT Applications of Stacks Array-based implementation Growable array-based stack Stacks 2 Abstract Data Types (ADTs) An abstract data type (ADT) is an abstraction of a data structure

### 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

### Binary Heaps * * * * * * * / / \ / \ / \ / \ / \ * * * * * * * * * * * / / \ / \ / / \ / \ * * * * * * * * * *

Binary Heaps A binary heap is another data structure. It implements a priority queue. Priority Queue has the following operations: isempty add (with priority) remove (highest priority) peek (at highest

### Dictionaries and Hash Tables

Dictionaries and Hash Tables 0 1 2 3 025-612-0001 981-101-0002 4 451-229-0004 Dictionaries and Hash Tables 1 Dictionary ADT ( 8.1.1) The dictionary ADT models a searchable collection of keyelement items

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

### COURSE: B.TECH-ECE. IV Sem. Data structure Using C. b) Deletion of element in an array

COURSE: B.TECH-ECE. IV Sem Data structure Using C 1. Determine the formula to find the address location of an element in three dimensions array, suppose each element takes four bytes of space & elements

### What is a Dictionary? Dictionaries. Dictionary Keys. Dictionary Examples. Log File. Unordered Dictionary ADT. Container class

What is a Dictionary? Dictionaries Container class Stores key-element element pairs (like priority queue) Allows look-up (find) operation Allows insertion/removal of elements May be unordered or ordered

### 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

Linked List as an ADT (cont d.) Default constructor Initializes list to an empty state Destroy the list Deallocates memory occupied by each node Initialize the list Reinitializes list to an empty state

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

### 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

### 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

### Learning Outcomes. COMP202 Complexity of Algorithms. Binary Search Trees and Other Search Trees

Learning Outcomes COMP202 Complexity of Algorithms Binary Search Trees and Other Search Trees [See relevant sections in chapters 2 and 3 in Goodrich and Tamassia.] At the conclusion of this set of lecture

### 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

### 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

Linked Lists and Iterators Chapter 4 Click to proceed How To View This Presentation This presentation is arranged in outline format. To view the slides in proper order For each slide Read the entire slide

### 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).

### 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

### data structures and algorithms exercise class 2: some answers

data structures and algorithms 2016-2017 exercise class 2: some answers 1. Show step by step how the array A = [22, 15, 36, 20, 3, 9, 29] is sorted using selection sort, bubble sort, and merge sort. First

### Objective Specification, design and implementation of an ADT in C/C++. Using generic elements and iterators.

ADTs containers of generic elements and iterators Objective Specification, design and implementation of an ADT in C/C++. Using generic elements and iterators. Theoretical aspects Representation of an ADT

### 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

### Data Structures Using Java

Data Structures Using Java D. S. Malik P. S. Nair THOMSON COURSE TECHNOLOGY Australia Canada Mexico Singapore Spain United Kingdom United States TABLE OF Contents PREFACE XXV 1.Software Engineering Principles

### 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

### 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

### 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!

### Exam study sheet for CS2711. List of topics

Exam study sheet for CS2711 Here is the list of topics you need to know for the final exam. For each data structure listed below, make sure you can do the following: 1. Give an example of this data structure

### Binary Heap Algorithms

CS Data Structures and Algorithms Lecture Slides Wednesday, April 5, 2009 Glenn G. Chappell Department of Computer Science University of Alaska Fairbanks CHAPPELLG@member.ams.org 2005 2009 Glenn G. Chappell

### 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

### Linear ADTs. Restricted Lists. Stacks, Queues. ES 103: Data Structures and Algorithms 2012 Instructor Dr Atul Gupta

Linear DT-1: Restricted Lists Stacks, Queues tul Gupta Restricted Lists Stack Queue Circular queue Priority queue General Lists rrays Linked list Circular list Doubly linked list Linear DTs 1 Stacks Using

### 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

### 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

### Lecture 4. The Java Collections Framework

Lecture 4. The Java s Framework Chapters 6.3-6.4-1 - The Java s Framework We will consider the Java s Framework as a good example of how apply the principles of objectoriented software engineering (see

### Algorithms and Data Structures

Algorithms and Data Structures Lists and Arrays Marcin Sydow Web Mining Lab PJWSTK Marcin Sydow (Web Mining Lab PJWSTK) Algorithms and Data Structures 1 / 35 Topics covered by this lecture: Linked Lists

### Data Structures and Algorithms in C++

Data Structures and Algorithms in C++ Second Edition Michael T. Goodrich Department of Computer Science University of California, Irvine Roberto Tamassia Department of Computer Science Brown University

### 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

### 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.

### Binary Trees (1) Outline and Required Reading: Binary Trees ( 6.3) Data Structures for Representing Trees ( 6.4)

1 Binary Trees (1) Outline and Required Reading: Binary Trees ( 6.3) Data Structures for Representing Trees ( 6.4) COSC 2011, Fall 2003, Section A Instructor: N. Vlajic Binary Tree 2 Binary Tree tree with

### Writing programs to solve problem consists of a large. how to represent aspects of the problem for solution

Algorithm Efficiency & Sorting Algorithm efficiency Big-O notation Searching algorithms Sorting algorithms 1 Overview 2 If a given ADT (i.e. stack or queue) is attractive as part of a solution How will

### V.S.B. ENGINEERING COLLEGE, KARUR. Academic Year: (ODD Semester) Department of Computer Science and Engineering

V.S.B. ENGINEERING COLLEGE, KARUR Academic Year: 2016-2017 (ODD Semester) Department of Computer Science and Engineering Question Bank (2013 Regulations) S.No. Name of the Subject / Lab Semester Page No.

### Memory Management. Memory Areas and their use. Memory Manager Tasks: Free List Implementations. acquire release

Memory Management Memory Areas and their use Memory Manager Tasks: acquire release Free List Implementations Singly Linked List Doubly Linked List Buddy Systems Memory Management Memory areas: In languages

### Data Structures Fibonacci Heaps, Amortized Analysis

Chapter 4 Data Structures Fibonacci Heaps, Amortized Analysis Algorithm Theory WS 2012/13 Fabian Kuhn Fibonacci Heaps Lacy merge variant of binomial heaps: Do not merge trees as long as possible Structure:

### INTERNATIONAL EDITION. Problem Solving with C++ Data Abstraction & SIXTH EDITION. Walls and Mirrors. Frank M. Carrano Timothy Henry

INTERNATIONAL EDITION Data Abstraction & Problem Solving with C++ Walls and Mirrors SIXTH EDITION Frank M. Carrano Timothy Henry Operator Meaning Associativity Usage * multiply left expr * expr / divide

### 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:

### CSE 326, Data Structures. Sample Final Exam. Problem Max Points Score 1 14 (2x7) 2 18 (3x6) 3 4 4 7 5 9 6 16 7 8 8 4 9 8 10 4 Total 92.

Name: Email ID: CSE 326, Data Structures Section: Sample Final Exam Instructions: The exam is closed book, closed notes. Unless otherwise stated, N denotes the number of elements in the data structure

### 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

### Lecture 6b Linked List Variations. Similar but not the same

Lecture 6b Linked List Variations Similar but not the same Linked List Variations: Overview The linked list implementation used in List ADT is known as Singly (Single) Linked List Each node has one pointer

### 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

### Automated C++ Program Generator using English Language Interface

Automated C++ Program Generator using English Language Interface Ambuj Kumar ambuj.ambujkumar@gmail.com and Prof. (Mrs.) Saroj Kaushik saroj@cse.iitd.ernet.in Department of Computer Science & Engineering

### AS-2261 M.Sc.(First Semester) Examination-2013 Paper -fourth Subject-Data structure with algorithm

AS-2261 M.Sc.(First Semester) Examination-2013 Paper -fourth Subject-Data structure with algorithm Time: Three Hours] [Maximum Marks: 60 Note Attempts all the questions. All carry equal marks Section A

### Priority Queues. Client, Implementation, Interface. Priority Queues. Abstract Data Types

Client, Implementation, Interface Priority Queues Priority Queue ADT Binary heaps Heapsort Reference: Chapter 6, Algorithms in Java, 3 rd Edition, Robert Sedgewick. Separate interface and implementation

### Stacks. Stacks (and Queues) Stacks. q Stack: what is it? q ADT. q Applications. q Implementation(s) CSCU9A3 1

Stacks (and Queues) 1 Stacks Stack: what is it? ADT Applications Implementation(s) 2 CSCU9A3 1 Stacks and ueues A stack is a very important data structure in computing science. A stack is a seuence of

### 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

### 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

### Hash Tables. Dr. Aiman Hanna Department of Computer Science & Software Engineering Concordia University, Montreal, Canada

Hash Tables Dr. Aiman Hanna Department of Computer Science & Software Engineering Concordia University, Montreal, Canada These slides has been extracted, modified and updated from original slides of :

### Algorithms and Data Structures Written Exam Proposed SOLUTION

Algorithms and Data Structures Written Exam Proposed SOLUTION 2005-01-07 from 09:00 to 13:00 Allowed tools: A standard calculator. Grading criteria: You can get at most 30 points. For an E, 15 points are

### 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

### 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

### CMPS 102 Solutions to Homework 1

CMPS 0 Solutions to Homework Lindsay Brown, lbrown@soe.ucsc.edu September 9, 005 Problem..- p. 3 For inputs of size n insertion sort runs in 8n steps, while merge sort runs in 64n lg n steps. For which

1 ADTs,, Arrays, Linked Lists Outline and Required Reading: ADTs ( 2.1.2) Arrays ( 1.5) Linked Lists ( 4.3.1, 4.3.2) COSC 2011, Fall 2003, Section A Instructor: N. Vlajic Abstract Data Type (ADT) 2 abstract

### State Space Problem Definition

Blind Search State Space Problem Definition One widely used way to describe problems is by listing or describing all possible states. Solving a problem means moving through the state space from a start

### Data Structures. Level 6 C30151. www.fetac.ie. Module Descriptor

The Further Education and Training Awards Council (FETAC) was set up as a statutory body on 11 June 2001 by the Minister for Education and Science. Under the Qualifications (Education & Training) Act,

### Definition. E.g. : Attempting to represent a transport link data with a tree structure:

The ADT Graph Recall the ADT binary tree: a tree structure used mainly to represent 1 to 2 relations, i.e. each item has at most two immediate successors. Limitations of tree structures: an item in a tree

### Data Structures in the Java API

Data Structures in the Java API Vector From the java.util package. Vectors can resize themselves dynamically. Inserting elements into a Vector whose current size is less than its capacity is a relatively

### 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

### ECE 250 Data Structures and Algorithms MIDTERM EXAMINATION 2008-10-23/5:15-6:45 REC-200, EVI-350, RCH-106, HH-139

ECE 250 Data Structures and Algorithms MIDTERM EXAMINATION 2008-10-23/5:15-6:45 REC-200, EVI-350, RCH-106, HH-139 Instructions: No aides. Turn off all electronic media and store them under your desk. If

### Java Software Structures

INTERNATIONAL EDITION Java Software Structures Designing and Using Data Structures FOURTH EDITION John Lewis Joseph Chase This page is intentionally left blank. Java Software Structures,International Edition

### Lecture 4. The Java Collections Framework

Lecture 4. The Java s Framework Chapters 6.3-6.4-1 - Outline Introduction to the Java s Framework Iterators Interfaces Classes Classes - 2 - The Java s Framework We will consider the Java s Framework as

### 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)

### 2 Exercises and Solutions

2 Exercises and Solutions Most of the exercises below have solutions but you should try first to solve them. Each subsection with solutions is after the corresponding subsection with exercises. 2.1 Sorting

### Outline motivation hash functions collision handling. Courtesy to Goodrich, Tamassia and Olga Veksler 1

Hash Table Outline motivation hash functions collision handling Courtesy to Goodrich, Tamassia and Olga Veksler Instructor: Yuzhen Xie 1 Log File vs Search Table Method Log File Search Table size, isempty

### Algorithms and Data Structures

Recursion Page 1 - Recursion Dr. Fall 2008 Recursion Page 2 Outline Introduction Simple Problems Time Complexity and Optimization Advanced Problems Recursion Introduction Page 3 Outline Introduction Simple

### 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

### 6 March 2007 1. Array Implementation of Binary Trees

Heaps CSE 0 Winter 00 March 00 1 Array Implementation of Binary Trees Each node v is stored at index i defined as follows: If v is the root, i = 1 The left child of v is in position i The right child of

### 5. A full binary tree with n leaves contains [A] n nodes. [B] log n 2 nodes. [C] 2n 1 nodes. [D] n 2 nodes.

1. The advantage of.. is that they solve the problem if sequential storage representation. But disadvantage in that is they are sequential lists. [A] Lists [B] Linked Lists [A] Trees [A] Queues 2. The

### 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

### 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

### Bhakta Kavi Narsinh Mehta University, Junagadh

Bhakta Kavi Narsinh Mehta University, Junagadh Draft Syllabus for B.Sc. (Computer Science) Bachelor of Science (Computer Science) (Semester - 1) Effective From June - 2016 B.Sc. (C.S.) (Semester - 1) CS-101:

### Sorting revisited. Build the binary search tree: O(n^2) Traverse the binary tree: O(n) Total: O(n^2) + O(n) = O(n^2)

Sorting revisited How did we use a binary search tree to sort an array of elements? Tree Sort Algorithm Given: An array of elements to sort 1. Build a binary search tree out of the elements 2. Traverse

### Node-Based Structures Linked Lists: Implementation

Linked Lists: Implementation CS 311 Data Structures and Algorithms Lecture Slides Monday, March 30, 2009 Glenn G. Chappell Department of Computer Science University of Alaska Fairbanks CHAPPELLG@member.ams.org

### Lecture 4. The Java Collections Framework

Lecture 4. The Java s Framework Chapters 6.3-6.4-1 - Outline Introduction to the Java s Framework Iterators Interfaces, Classes and Classes of the Java s Framework - 2 - Outline Introduction to the Java

### 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

### Sequences in the C++ STL

CS 311 Data Structures and Algorithms Lecture Slides Wednesday, November 4, 2009 Glenn G. Chappell Department of Computer Science University of Alaska Fairbanks CHAPPELLG@member.ams.org 2005 2009 Glenn

### Recursion, Search, Selection. Cheng, Wei COMP June 12, Title

Recursion, Search, Selection Cheng, Wei COMP110-001 June 12, 2014 Title Today Introduction to Recursion Introduction to Search & Selection Not a major focus of the final exam But you should be able to

### CS 253: Algorithms. Chapter 8. Sorting in Linear Time. Credit: Dr. George Bebis

CS 5: Algorithms Chapter 8 Sorting in Linear Time Credit: Dr. George Bebis How Fast Can We Sort? How Fast Can We Sort? Insertion sort: O(n ) Bubble Sort, Selection Sort: (n ) Merge sort: (nlgn) Quicksort:

### 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.