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



Similar documents
Sequential Data Structures

DATA STRUCTURES USING C

Analysis of a Search Algorithm

10CS35: Data Structures Using C

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

ADTs,, Arrays, Linked Lists

PES Institute of Technology-BSC QUESTION BANK

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.

Data Structure [Question Bank]

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

Glossary of Object Oriented Terms

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

BCS2B02: OOP Concepts and Data Structures Using C++

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

Data Structures Fibonacci Heaps, Amortized Analysis

CSE 326, Data Structures. Sample Final Exam. Problem Max Points Score 1 14 (2x7) 2 18 (3x6) Total 92.

Binary Heap Algorithms

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

Linked Lists Linked Lists, Queues, and Stacks

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

Universidad Carlos III de Madrid

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

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

Node-Based Structures Linked Lists: Implementation

Data Structures and Data Manipulation

Lecture 12 Doubly Linked Lists (with Recursion)

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

CHAPTER 4 ESSENTIAL DATA STRUCTRURES

Bachelor of Games and Virtual Worlds (Programming) Subject and Course Summaries

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

Stacks. Linear data structures

Lecture 11 Doubly Linked Lists & Array of Linked Lists. Doubly Linked Lists

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

Introduction to Data Structures and Algorithms

Data Structures and Algorithm Analysis (CSC317) Intro/Review of Data Structures Focus on dynamic sets

KITES TECHNOLOGY COURSE MODULE (C, C++, DS)

Common Data Structures

- Easy to insert & delete in O(1) time - Don t need to estimate total memory needed. - Hard to search in less than O(n) time

LINKED DATA STRUCTURES

DATA STRUCTURE - STACK

Sample Questions Csci 1112 A. Bellaachia

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

Unordered Linked Lists

22c:31 Algorithms. Ch3: Data Structures. Hantao Zhang Computer Science Department

STACKS,QUEUES, AND LINKED LISTS

INTERNATIONAL JOURNAL OF PURE AND APPLIED RESEARCH IN ENGINEERING AND TECHNOLOGY

7.1 Our Current Model

Sequences in the C++ STL

Data Structures. Level 6 C Module Descriptor

3 Abstract Data Types and Search

Unit Write iterative and recursive C functions to find the greatest common divisor of two integers. [6]

The Union-Find Problem Kruskal s algorithm for finding an MST presented us with a problem in data-structure design. As we looked at each edge,

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

ALLIED PAPER : DISCRETE MATHEMATICS (for B.Sc. Computer Technology & B.Sc. Multimedia and Web Technology)

Linked Lists: Implementation Sequences in the C++ STL

Module 2 Stacks and Queues: Abstract Data Types

Linked List as an ADT (cont d.)

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

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

Exam study sheet for CS2711. List of topics

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

Chapter 3: Restricted Structures Page 1

GUJARAT TECHNOLOGICAL UNIVERSITY, AHMEDABAD, GUJARAT. Course Curriculum. DATA STRUCTURES (Code: )

Binary Search Trees. A Generic Tree. Binary Trees. Nodes in a binary search tree ( B-S-T) are of the form. P parent. Key. Satellite data L R

6. Storage and File Structures

Lecture 1: Data Storage & Index

University of Dayton Department of Computer Science Undergraduate Programs Assessment Plan DRAFT September 14, 2011

Converting a Number from Decimal to Binary

Java Software Structures

Atmiya Infotech Pvt. Ltd. Data Structure. By Ajay Raiyani. Yogidham, Kalawad Road, Rajkot. Ph : ,

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

Chapter 8: Structures for Files. Truong Quynh Chi Spring- 2013

Physical Data Organization

Algorithms and Data Structures Exercise for the Final Exam (17 June 2014) Stack, Queue, Lists, Trees, Heap

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

Copyright 2007 Ramez Elmasri and Shamkant B. Navathe. Slide 13-1

Algorithms and Data Structures

Project 4 DB A Simple database program

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

CompSci-61B, Data Structures Final Exam

AGARWAL COLLEGE & WEB SERVICES TRUST. In Collaboration with KARANATAKA STATE OPEN UNIVERSITY

A binary heap is a complete binary tree, where each node has a higher priority than its children. This is called heap-order property

Chapter 13 Disk Storage, Basic File Structures, and Hashing.

Chapter 8: Bags and Sets

DATA STRUCTURE - QUEUE

Chapter 13. Disk Storage, Basic File Structures, and Hashing

Outline. Computer Science 331. Stack ADT. Definition of a Stack ADT. Stacks. Parenthesis Matching. Mike Jacobson

Lecture 11 Array of Linked Lists

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!

Analysis of Algorithms I: Binary Search Trees

CompuScholar, Inc. Alignment to Utah's Computer Programming II Standards

A Comparison Of Shared Memory Parallel Programming Models. Jace A Mogill David Haglin

2) Write in detail the issues in the design of code generator.

Algorithms and Data Structures

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING LESSON PLAN

Data Structures Using C++

A binary search tree or BST is a binary tree that is either empty or in which the data element of each node has a key, and:

Binary Search Trees CMPSC 122

Transcription:

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 data structure OO programming allows implementation details to be hidden from user/client

Examples Already Discussed ADT: sorted list op1 op2 op3 ADT: unsorted list op1 op2 op3 Other ADTs in 281 Stack Queue Priority Queue Tree Graph Hash table Definitions Abstract Data Type: mathematical model of a data type and operations defined on the model that is accessed only through an interface separate the conceptual transformations that our programs perform on data from any particular data structure representation and algorithm implementation

An abstract data type is realized by a concrete data structure, which is modeled in C++ by a class. Abstract class Concrete class Foundational Data Structure Most ADTs are built upon some base data structure Base data structure is not viewed as an ADT itself, but an alternative implementation Foundational, base data structures come in two flavors: arrays (vectors) (singly) linked lists Foundational Data Structure Logical sequential storage a collection of n objects of some type T each object in the list is called an element Must have: insert a new element remove a previously inserted element Typically have: construct an empty list count the number of elements May have: destroy or copy the list reverse one list, concatenate two lists, etc. etc.

Arrays in C++ Problems with C++ array implementation no bounds checking 0 to n- 1, rather than 1 to n size static and fixed at compile time Better than Arrays: Vectors rank: number of elements before e in S 1 st ele is rank 0, last ele is rank n-1 vector: linear sequence that supports access to elements by their ranks extendable: automatic doubling of storage space when overflow condition is reached Vector ADT size(): return number of elements in vector isempty(): return T if vector is empty, F otherwise elematrank(r): return the element at rank r replaceatrank(r,e): replace the element at rank r with element e insertatrank(r,e): insert a new element e at rank r removeatrank(r): remove the element at rank r

Vector ADT: Array-based size(): O( ) isempty(): O( ) elematrank(r): O( ) replaceatrank(r,e): O( ) insertatrank(r,e): O( ) removeatrank(r): O( ) Vector ADT: Extension When n = N (size = capacity) allocate new array B of size 2N copy A[i] to B[i] for i = 0 N-1 deallocate A, and let A = B See code fragments 5.2 and 5.3 (esp. insertatrank and overflow) for detail Vector ADT: Extension Amortization: although doubling size of vector seems expensive, cost is paid over time so insertion of n items is O(n)

Linked Lists in C++ Sequence of dynamically allocated storage elements Each node has: data member (called an element) pointer to its successor Many variations Book uses pointer to head only List ADT size(): return number of nodes in list isempty(): return T if list is empty, F otherwise elematpos(p): return the element at position p replaceatpos(p,e): replace the element at position p with element e insertafter(p,e): insert a new element e after position p insertbefore(p,e): insert a new element e before position p removeat(p): remove the element at position p List ADT size(): O( ) isempty(): O( ) elematpos(p): O( ) replaceatpos(p,e): O( ) insertafter(p,e): O( ) insertbefore(p,e): O( ) removeat(p): O( )

Summary: Foundational Data Structures Arrays (Vectors) Linked Lists size() size() isempty() isempty() elematrank(r) elematpos(p) replaceatrank(r,e) replaceatpos(p,e) insertatrank(r,e) insertafter(p,e) removeatrank(r) insertbefore(p,e) removeat(p) Wrap-up Questions Name advantages of using arrays Name advantages of using linked lists How do you implement a multi- dimensional array? How do you implement a sparse matrix? What s the advantage of using a tail pointer? What s an advantage of using a doubly- linked list over singly linked list? Common Bugs Arrays Index variable is not initialized Bounds not checked Memory leak (pointer to array elements not de-allocated) When removed, pointer to array elements not removed Linked List Head and tail not initialized to NULL Accessing de-allocated element Memory leak (de-allocation doesn t walk down list) Extraction or insertion loses pointer, e.g. delete last element, but prev next not set to null)