Arrays 2008, Fall Pusan National University Ki-Joune Li.

Slides:



Advertisements
Similar presentations
Stacks, Queues, and Linked Lists
Advertisements

CSCE 3110 Data Structures & Algorithm Analysis
Linear Lists – Array Representation
Data Structures ADT List
Chapter 3 – Lists A list is just what the name implies, a finite, ordered sequence of items. Order indicates each item has a position. A list of size 0.
§1 Abstract Data Type (ADT)
Processing Data in Collections Chapter Object Wrappers Collections can only hold objects. Primitive types ( int, double, float, etc.) are not objects.
1. List Static List: no adding or deleting Dynamic List: can add or delete items from the list Both static and dynamic lists: linear search, update item.
Computer Science 112 Fundamentals of Programming II Overview of Collections.
Chapter 6 Lists and Dictionaries CSC1310 Fall 2009.
Alon Efrat Computer Science Department University of Arizona SkipList.
Linked list Applications: Polynomial handling. Representing a polynomial using a linked list Store the coefficient and exponent of each term in nodes.
Foundation of Computing Systems Lecture 2 Linked Lists.
1 Linked Lists Gordon College Prof. Brinton. 2 Linked List Basics Why use? 1.Efficient insertion or deletion into middle of list. (Arrays are not efficient.
Array pair C++ array requires the index set to be a set of consecutive integers starting at 0 C++ does not check an array index to ensure that it belongs.
Data Abstraction and Encapsulation
Matrices CSE, POSTECH.
Priority Queues and Heaps. Overview Our last ADT: PriorityQueueADT A new data structure: heaps One more sorting algorithm: heapsort Priority Queues and.
Chapter 4.
Chapter 2. C++ Class A class name Data members Member functions Levels of program access –Public: section of a class can be accessed by anyone –Private:
Department of Computer Eng. & IT Amirkabir University of Technology (Tehran Polytechnic) Data Structures Lecturer: Abbas Sarraf Arrays.
Matrix table of values
Heaps and heapsort COMP171 Fall 2005 Part 2. Sorting III / Slide 2 Heap: array implementation Is it a good idea to store arbitrary.
Doubly Linked Lists Deleting from the end of the list – Have to traverse the entire list to stop right in front of tail to delete it, so O(n) – With head.
Data Structure (Part I) Chapter 2 – Arrays Data Abstraction and Encapsulation in C++ Section 1.3 –Data Encapsulation Also called information hiding.
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI CSCI 240 Abstract Data Types Dale Roberts, Lecturer
1 Chapter 3 Data Representation Part 1. 2 Goals Introduce the different ways in which data may be represented Concepts –Abstract data types –Formula-based,
Lists in Python.
COP2800 – Computer Programming Using JAVA University of Florida Department of CISE Spring 2013 Lecture 13 – Having Fun with Arrays in Java Webpage:
Data Structures Week 5 Further Data Structures The story so far  We understand the notion of an abstract data type.  Saw some fundamental operations.
CSCE 3110 Data Structures & Algorithm Analysis Arrays and Lists.
CHAPTER 3 Lists, Stacks, and Queues §1 Abstract Data Type (ADT) 【 Definition 】 Data Type = { Objects }  { Operations } 〖 Example 〗 int = { 0,  1, 
Chapter 2 1. Arrays Array: a set of index and value Data structure For each index, there is a value associated with that index. Eg. int list[5]: list[0],
Data Structure (Part II) Chapter 2 – Arrays. Matrix A matrix with 5 rows and 3 columns can be represented by n = 3 m = 5 We say this is a 5×3 matrix.
Linked List Containers. Linked List Example Polynomials –Interested in representing and manipulating polynomials –Polynomial defined as: Y = coef_n *
Pointers OVERVIEW.
Data Structure Sang Yong Han Chung-Ang University Spring
Data Structures & Algorithm Analysis Arrays. Array: a set of pairs (index and value) data structure For each index, there is a value associated with that.
ECE 103 Engineering Programming Chapter 24 Sorting Herbert G. Mayer, PSU CS Status 6/2/2015 Initial content copied verbatim from ECE 103 material developed.
Sparse Vectors & Matrices Jyh-Shing Roger Jang ( 張智星 ) CSIE Dept, National Taiwan University.
Data Structures Chapter 2: Arrays 2-1. Four components in a C++ Class –class name –data members: the data that makes up the class –member functions: the.
Linked Lists 2014, Fall Pusan National University Ki-Joune Li.
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI CSCI 240 Elementary Data Structures Array Lists Array Lists Dale.
Sparse Matrices Matrix  table of values. Sparse Matrices Matrix  table of values Row 2 Column 4 4 x 5 matrix.
Priority Queues CS 110: Data Structures and Algorithms First Semester,
2D Arrays Alina Solovyova-Vincent Department of Computer Science & Engineering University of Nevada, Reno Spring 2006.
Algorithms Lakshmish Ramaswamy. Merge Problem – Merge two sorted arrays such that the resultant array remains sorted Logic –Keep pointers to both arrays.
CSCE 3110 Data Structures & Algorithm Analysis More on lists. Circular lists. Doubly linked lists.
Linked List Containers. Useful Linked List Add-Ons Are there new variables/changes to the lists as they have been defined that could make our jobs as.
CSCI 51 Introduction to Programming March 10, 2009.
Chap 2 Array ( 陣列 ). ADT In C++, class consists four components: –class name –data members : the data that makes up the class –member functions : the.
CMSC 202 Computer Science II for Majors. CMSC 202UMBC Topics Templates Linked Lists.
Data Structure Sang Yong Han
2017, Fall Pusan National University Ki-Joune Li
Data Structures I (CPCS-204)
Chapter 3 Linear List (Sequential List)
CSCE 3110 Data Structures & Algorithm Analysis
Abstract Data Types Polynomials CSCI 240
CSCE 3110 Data Structures & Algorithm Analysis
Chap 2 Array (陣列).
Instructor: Mr.Vahidipour
CSCE 3110 Data Structures & Algorithm Analysis
Linked List (Part I) Data structure.
Further Data Structures
2018, Fall Pusan National University Ki-Joune Li
Fundamental Theorem of Algebra
2017, Fall Pusan National University Ki-Joune Li
2018, Fall Pusan National University Ki-Joune Li
Data Structures Chapter 4: Linked Lists.
2019, Fall Pusan National University Ki-Joune Li
Presentation transcript:

Arrays 2008, Fall Pusan National University Ki-Joune Li

STEMPNU 2 Most Basic Data Structure Primitive Elements : Integer, Float, String, etc.. Container of elements Ordered or not Duplicated or Not How to define the same object In fact, any container of elements is stored in ordered way. Only the interface makes it different a k, a k+1

STEMPNU 3 Operations Operation defines the interface (or nature) to the users Should be implemented, whatever the internal implementation Operations Unordered Maintenance : create a new container, Insert, Delete, Update (?) Search : search by atttributes Information or statistics : number of elements, max, min, etc. Ordered Operations for Unordered Container + Scan : get the k-th, the last, or the next elements Sorting Ordered container can be used as an unordered container

STEMPNU 4 Array Contains elements Ordered (or unordered) Set (No Order) Example : Polynomial Representation 1: float Coef[MaxDegree+1]; Representation 2: int degree; float *Coef; Coef=new float[degree+1]; Arrays

STEMPNU 5 Representation of Array Representation 3: Array of (Coefficient, Exponent): ((a m,m),(a m-1,m), … (a 0,0)) Sparse Array : Example. 3.0x x x+9.6 : ((3.0,101),(-2.4,2),(1.0,1),(9.6,0)) MaxTerms How to define the end ? MaxTerms Class Polynomial { private: static Term termArray[MaxTerms]; static int free; int Start, Finish; }; Class Term { friend Polynomial; private: float coef; float exp; }; a.Starta.Finish b.Startb.Finish free

STEMPNU 6 Example : Adding two polynomials A = 3.0x x x B = 4.0x x C = Termination Condition - Aptr > A.finish or Bptr > B.finish If Terminated by Aptr > A.finish Append the rest of B to the tail of B Time Complexity : O(Len A + Len B )

STEMPNU 7 Sparse Matrix Matrix with many zero elements Two Representations RowColValue vs. Class MatrixTerm { friend SparseMatrix; private: int row,col; int value; }; Class SparseMatrix { private: int nRows,nCols,nElements; MatrixElements smArray[MaxElements]; }; But Row Major !

STEMPNU 8 Transposing a Matrix row colvalue row colvalue Algorithm MatrixTranspose(SparseMatrix A) SparseMatrix B; swap(A.nRows,A.nCols); countB=0; if(A.nElements>0) { // for non-empty matrix for(c=0;c<A.nCols;c++) // for each element c of A for(i=0;i<A.nElements;i++) { // find elements in column c if(A.smArrays[i].col==c) { B.smArray[countB].row=c; B.smArray[countB].col=A.smArray[i].row; B.smArray[countB].value=A.smArrary[countB].value; ++countB; } } return B; end Algorithm Time Complexity : O(nCols·nElements) = O(nCols 2 ·nRows) > O(nCols·nRows) A A ATAT ATAT A.nCols= 6, A.nRows=7 A.nElements=5

STEMPNU 9 Transposing a Matrix: An Improved Algorithm row colvalue A A col row ATAT ATAT value col row A A Exchange row col Sort by (row, col) Time Complexity : O(n Elements + n Elements log n Elements ) = O(n Elements log n Elements )

STEMPNU 10 Transposing a Matrix: Another Improved Algorithm indexrowcolvalue A A indexvaluecolrow ATAT ATAT A T Row Size A T Row Start Time Complexity : O(n col + n col + n Elements )