2017, Fall Pusan National University Ki-Joune Li

Slides:



Advertisements
Similar presentations
CSCE 3110 Data Structures & Algorithm Analysis
Advertisements

Arrays 2008, Fall Pusan National University Ki-Joune Li.
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.
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
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.
Abstract Data Types (ADTs) and data structures: terminology and definitions A type is a collection of values. For example, the boolean type consists of.
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
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 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.
DATA STRUCTURES Queues ‘n Stacks Tries, Suffix Trees Heaps Sieve of Eratosthenes.
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.
Sparse Vectors & Matrices Jyh-Shing Roger Jang ( 張智星 ) CSIE Dept, National Taiwan University.
The median again The steps of our algorithm: Read the size of the list, N. Declare and instantiate an array of integers, "list". Read the elements of list.
CSCE 3110 Data Structures & Algorithm Analysis More on lists. Circular lists. Doubly linked lists.
Chap 2 Array ( 陣列 ). ADT In C++, class consists four components: –class name –data members : the data that makes up the class –member functions : the.
Programming Application in Civil Engineering
Data Structure Sang Yong Han
Lecture 5 of Computer Science II
2017, Fall Pusan National University Ki-Joune Li
Data Structures and Algorithms for Information Processing
Data Structures I (CPCS-204)
Two-Dimensional Arrays
The Design and Analysis of Algorithms
Design & Analysis of Algorithm Priority Queue
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 (陣列).
Program to search an element of array using linear search.
Array Array is a variable which holds multiple values (elements) of similar data types. All the values are having their own index with an array. Index.
LINKED LISTS CSCD Linked Lists.
Sorting Data are arranged according to their values.
Instructor: Mr.Vahidipour
Lecture 14: binary search and complexity reading:
CSCE 3110 Data Structures & Algorithm Analysis
Linked List (Part I) Data structure.
Further Data Structures
Sorting Data are arranged according to their values.
2018, Fall Pusan National University Ki-Joune Li
Lecture 15: binary search reading:
ArrayLists.
Fundamental Theorem of Algebra
Data Structures (CS212D) Week # 2: Arrays.
Multidimensional array
Arrays Week 2.
2018, Spring Pusan National University Ki-Joune Li
Introduction to Data Structure
EECE.2160 ECE Application Programming
2018, Fall Pusan National University Ki-Joune Li
Exercise 5 1. We learned bubble sort during class. This problem requires you to modify the code for bubble sorting method to implement the selection sorting.
OPIM 915 Fall 2010 Data Structures 23-38,
Data Structures Chapter 4: Linked Lists.
Introduction to data structures
A type is a collection of values
Java Basics – Arrays Should be a very familiar idea
Variable Storage Memory Locations (Logical) Variable Classes Stack
2019, Fall Pusan National University Ki-Joune Li
Presentation transcript:

2017, Fall Pusan National University Ki-Joune Li Arrays 2017, Fall Pusan National University Ki-Joune Li

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 ak, ak+1

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

Arrays Array Example : Polynomial 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];

Representation of Array Array of (Coefficient, Exponent): ((am,m),(am-1,m), … (a0,0)) Sparse Array : Example. 3.0x101-2.4x2+1.0x+9.6 : ((3.0,101),(-2.4,2),(1.0,1),(9.6,0)) MaxTerms Class Polynomial { private: static Term termArray[MaxTerms]; static int free; int Start, Finish; }; Class Term { friend Polynomial; private: float coef; float exp; }; free 3.0 101 -2.4 2 1.0 1 9.6 2.0 15 1.4 2 0.4 a.Start a.Finish b.Start b.Finish MaxTerms

Example : Adding two polynomials A = 3.0x101 - 2.4x2 + 1.0x + 9.6 3.0 101 -2.4 2 1.0 1 9.6 B = 4.0x15 + 1.4x2 + 0.4 4.0 15 1.4 2 0.4 C = 3.0 101 4.0 15 -1.0 2 1.0 1 10.0 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(LenA + LenB )

Sparse Matrix Sparse Matrix Matrix with many zero elements Two Representations 1 2 3 4 5 6 7 Row Col Value 2 1 5 4 6 7 3 Class MatrixElement { friend SparseMatrix; private: int row,col; int value; }; vs. But Row Major ! Class SparseMatrix { private: int nRows,nCols,nElements; MatrixElement smArray[MaxElements]; };

Transposing a Matrix: An Algorithm 6 2 1 5 4 value col row A’ row col value 1 4 2 5 6 Sort by (row, col) Exchange row  col 1 5 6 2 4 value col row AT Time Complexity : O(nElements + nElements log nElements) = O(nElements log nElements)

Transposing a Matrix: another Algorithm A.nCols= 6, A.nRows=7 A.nElements=5 AT row col value 1 4 2 5 6 row col value 4 1 1 4 2 2 6 5 1 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(nCols2·nRows) > O(nCols·nRows)

Transposing a Matrix: Another Improved Algorithm 7 6 5 4 3 2 1 index value col row AT index row col value 4.5 1 1.5 2 2.5 3 3.5 4 12.5 5 82.5 6 22.5 7 62.5 4.5 3 3.5 1 1.5 1 2.5 2 3 12.5 2 5 22.5 3 82.5 5 4 22.5 1 5 2 4 3 A Col Size 7 5 6 4 2 3 1 AT Row Start Time Complexity : O(nElements + ncol + nElements)