創作內容

0 GP

University - Array

作者:野兔Peko│2014-12-23 19:45:20│巴幣:0│人氣:209
  • Array: a set of index and value
  • ADT( abstract data type):
    For each index, there is a value associated with that index. (Their relationship is the linear.)
  • Representation (possible)
    Implemented by using consecutive memory.

Ordered (linear) list
(item1, item2, item3, …, itemn)

Operations on Ordered List ( Linear List)
(1) Finding the length, n , of the list. (找list長度)
(2) Reading the items in a list from left to right (or right to left).
     (從左讀到右)
(3) Retrieving the ith element from a list, 0 ≦i<n. (抓第i個)
(4) Replacing (Storing) the item in the ith position of a list,   
     0≦i<n. (存到第i個)
(5) Inserting a new item in the ith position of list, 0 ≦i ≦n. The items previously numbered  i, i+1, …, n-1 to become items numbered i+1, i+2, …, n (插入新item到第i個)
(6) Deleting an item from the ith position of a list, 0 ≦i<n. The items numbered i+1, …, n-1 to become items numbered i, i+1, …, n-2. (刪除第i個item)

Polynomial(多項式)
Example:
A(X)=3X200+2X2+4, B(X)=X4+10X3+3X2+1

class polynomial
{
objects: a1xe1+…+anxen;  a set of ordered pairs of <ei ,ai> where ai∈Coefficient and ei∈ Exponent We assume that Exponent consists of integers ≥ 0
public:
Polynomial();
// return the polynomial p(x) = 0
int operator!();
// if *this is the zero polynomial, return 1; else return 0;
Coefficient Coef(Exponent e);
// return the coefficient of e in *this
Exponent LeadExp();
// return the largest exponent in *this
Polynomial Add(Polynomial poly);
// return the sum of the polynomials *this and poly
Polynomial Mult(Polynomial poly);
// return the product of the polynomials *this and poly
float Eval(float f);
// Evaluate the polynomial *this at f and return the result
}; end of Polynomial

Polynomial Representation I
(浪費空間 => 當多項式是sparse時)
#define MAX_Degree 201
Private:
int degree;
float coef[MAX_DEGREE+1];

B(X)=X4+10X3+3X2+1

Waste space when the degree of the polynomial is much smaller than Max_Degree
A(X)=3X200+2X2+4

Polynomial Representation II
(相當於是第一種表示法的兩倍)

#define MAX_TERMS 100 /* size of terms array */
Class polynomial;//forward declaration
Class term {               
    friend polynomial;   
          private:  float coef;                    
       int expon;
};

Class Polynomial { private:  term terms[MAX_TERMS];
                                                 int avail = 0, int start, finish;
                                }

A(X)=2X1000+1
B(X)=X4+10X3+3X2+1

twice as much as 1 when all the items are nonzero


Sparse Matrix(稀疏矩陣)

A matrix is called sparse if it consists of many zero entries (矩陣內很多0 稱稀疏矩陣)
用二維陣列會浪費空間
Space complexity is O(m×n)

Sparse Matrix Representation
  1. Use triple <row, column, value>
  2. Store triples row by row (按照列一列一列儲存)
  3. For all triples within a row, their colum indices are in ascending order. (相同row,儲存順序依照column由小到大來存放)
  4. Must know the numbers of rows and columns and the number of nonzero elements (必須知道row, col,及非零項有那些)


Class term
{   
                       friend
Class SparseMatrix;
                      private:                                 
                                 int col;                                 
                                 int row;
                                 int value;
}
In class SparseMatrix
{
                      private:
                                 int Rows, Cols, Terms;
                                 term sA[MaxTerms];
}



引用網址:https://home.gamer.com.tw/TrackBack.php?sn=2693274
All rights reserved. 版權所有,保留一切權利

相關創作

留言共 0 篇留言

我要留言提醒:您尚未登入,請先登入再留言

喜歡★yn210112 可決定是否刪除您的留言,請勿發表違反站規文字。

前一篇:University -... 後一篇:University -...

追蹤私訊切換新版閱覽

作品資料夾

d88931122所有巴友
歡迎諸君來參觀老僧小屋,內含Steam與Google Play遊戲、Line貼圖、3D角色模組看更多我要大聲說12小時前


face基於日前微軟官方表示 Internet Explorer 不再支援新的網路標準,可能無法使用新的應用程式來呈現網站內容,在瀏覽器支援度及網站安全性的雙重考量下,為了讓巴友們有更好的使用體驗,巴哈姆特即將於 2019年9月2日 停止支援 Internet Explorer 瀏覽器的頁面呈現和功能。
屆時建議您使用下述瀏覽器來瀏覽巴哈姆特:
。Google Chrome(推薦)
。Mozilla Firefox
。Microsoft Edge(Windows10以上的作業系統版本才可使用)

face我們了解您不想看到廣告的心情⋯ 若您願意支持巴哈姆特永續經營,請將 gamer.com.tw 加入廣告阻擋工具的白名單中,謝謝 !【教學】