Microsoft Word - data_mid1611_and_sol.docx

Similar documents
Explain each of the following terms. (12%) (a) O(n 2 ) (b) protected in C++ language (c) sparse matrix 7. Write

ENGG1410-F Tutorial 6

Microsoft PowerPoint - Lecture7II.ppt

2/80 2

ebook39-5

C++ 程式設計

Microsoft Word - Final Exam Review Packet.docx

!##$!% "&! %( $#!##)!& $!##*!##*! "

Microsoft Word - template.doc

Open topic Bellman-Ford算法与负环

TX-NR3030_BAS_Cs_ indd

Fuzzy Highlight.ppt

2015 Chinese FL Written examination

國 立 政 治 大 學 教 育 學 系 2016 新 生 入 學 手 冊 目 錄 表 11 國 立 政 治 大 學 教 育 學 系 博 士 班 資 格 考 試 抵 免 申 請 表 論 文 題 目 申 報 暨 指 導 教 授 表 12 國 立 政 治 大 學 碩 博 士 班 論

#$%# & (! )! *! +! +! &! +!! * &! * )!! +, )! + &)!) $! )!+ *! +. &) #!/ #! #$$% & #$$ & #0#1! ) * # #$$( &! ) * +,!

Ps22Pdf


Microsoft Word 管理學

cs p3.ps, page Preflight ( S indd )

Microsoft Word - 105碩博甄簡章.doc


States and capital package

Important Notice SUNPLUS TECHNOLOGY CO. reserves the right to change this documentation without prior notice. Information provided by SUNPLUS TECHNOLO

Process Data flow Data store External entity 6-10 Context diagram Level 0 diagram Level 1 diagram Level 2 diagram

untitled

Historical Fund Prices_TC_mt_2017.pdf

ebook14-4

中 文 摘 要 一 个 蛋 白 质 去 折 叠 可 视 化 系 统 的 设 计 与 实 现 中 文 摘 要 蛋 白 质 的 生 物 功 能 由 其 三 维 结 构 所 决 定, 而 蛋 白 质 通 过 特 定 的 折 叠 机 制 行 成 稳 定 的 空 间 结 构 当 前 生 物 科 学 领 域 一

Microsoft PowerPoint - Eisenstein_ABET_Presentation_Beijing_Oct_2007-Chinese.ppt [兼容模式]

Microsoft PowerPoint - string_kruse [兼容模式]

C C C The Most Beautiful Language and Most Dangerous Language in the Programming World! C 2 C C C 4 C Project 30 C Project 3 60 Project 40

Abstract After over ten years development, Chinese securities market has experienced from nothing to something, from small to large and the course of


!!! "#$ %"% " & ( ) * +,-.- " / 01 " 2 +,-.- +,1.- ( ) * "#$ " 34 " /5 6-6 "#

K7VT2_QIG_v3

國立中山大學學位論文典藏.PDF

MDP2016_hk_class2_preview

4. 每 组 学 生 将 写 有 习 语 和 含 义 的 两 组 卡 片 分 别 洗 牌, 将 顺 序 打 乱, 然 后 将 两 组 卡 片 反 面 朝 上 置 于 课 桌 上 5. 学 生 依 次 从 两 组 卡 片 中 各 抽 取 一 张, 展 示 给 小 组 成 员, 并 大 声 朗 读 卡

2015年下半年全国教师资格笔试《地理学科知识与教学能力》备考指导

Improved Preimage Attacks on AES-like Hash Functions: Applications to Whirlpool and Grøstl

Strings

ch_code_infoaccess

CC213

Microsoft Word - 100碩士口試流程

Microsoft Word doc

Microsoft Word - 09.數學 docx

麻将竞赛规则 world.indd

Abstract There arouses a fever pursuing the position of being a civil servant in China recently and the phenomenon of thousands of people running to a

山东2014第四季新教材《会计基础》冲刺卷第二套

Guide to Install SATA Hard Disks

Microsoft Word - C-pgm-ws2010.doc

1.第二卷第二期p1

2010

101 年 全 國 高 職 學 生 實 務 專 題 製 作 競 賽 暨 成 果 展 報 告 書 題 目 :Beat CNN`s Report, 驚 艷 外 國 人 的 嘴 - 皮 蛋 之 大 改 造 指 導 老 師 : 林 佩 怡 參 賽 學 生 : 胡 雅 吟 楊 椀 惇 張 毓 津 許 巧 文

全国计算机技术与软件专业技术资格(水平)考试

c_cpp

软件测试(TA07)第一学期考试



untitled

2010

WTO

2017 CCAFL Chinese in Context

Fun Time (1) What happens in memory? 1 i n t i ; 2 s h o r t j ; 3 double k ; 4 char c = a ; 5 i = 3; j = 2; 6 k = i j ; H.-T. Lin (NTU CSIE) Referenc

從詩歌的鑒賞談生命價值的建構

Microsoft PowerPoint - STU_EC_Ch04.ppt


考试大2011年高考试题答案

概述

!"#$!"%&!"$!""( )( )( #( "#*!&#) %&*!(+,- %.!/( )( #( ,-2 89 /

AL-M200 Series

致遠管理學院法規提案單

第1章 簡介

! "# $ %& ( "# $ %& ) * $ %& + $ %& * $ %& -,)

11页词库答案

<4D F736F F D205F FB942A5CEA668B443C5E9BB73A740B5D8A4E5B8C9A552B1D0A7F75FA6BFB1A4ACFC2E646F63>

Microsoft Word - HSK使用手册.doc

Microsoft Word - cjfg_jy0201.doc

Microsoft Word - 把时间当作朋友(2011第3版)3.0.b.06.doc

國立中山大學學位論文典藏

Microsoft Word 記錄附件

UDC The Policy Risk and Prevention in Chinese Securities Market

ebook70-5

LEETCODE leetcode.com 一 个 在 线 编 程 网 站, 收 集 了 IT 公 司 的 面 试 题, 包 括 算 法, 数 据 库 和 shell 算 法 题 支 持 多 种 语 言, 包 括 C, C++, Java, Python 等 2015 年 3 月 份 加 入 了 R

% % % % % % ~

ebook39-6

Agenda 大 纲 FIFO data-structures 先 进 先 出 ( FIFO) 数 据 结 构 (= First In First Out) Heap data-structures 堆 结 构 Non-static methods 非 静 态 方 法 (= object metho

提问袁小兵:

中国科学技术大学学位论文模板示例文档

Gerotor Motors Series Dimensions A,B C T L L G1/2 M G1/ A 4 C H4 E

Microsoft Word - HC20138_2010.doc

3. 給 定 一 整 數 陣 列 a[0] a[1] a[99] 且 a[k]=3k+1, 以 value=100 呼 叫 以 下 兩 函 式, 假 設 函 式 f1 及 f2 之 while 迴 圈 主 體 分 別 執 行 n1 與 n2 次 (i.e, 計 算 if 敘 述 執 行 次 數, 不

第六章 中国中等收入者调查的三个发现

106 曾 夢 涵 / 南 台 學 報 第 37 卷 第 4 期 2012 年 12 月 壹 前 言 蘇 軾 因 烏 臺 詩 案, 而 貶 謫 黃 州, 身 為 罪 人, 苦 悶 之 情, 不 言 而 喻, 初 到 黃 州, 人 生 地 不 熟, 幸 有 知 州 徐 大 受, 對 蘇

! "#$! " # $%%&#! ()*+, - %& - %.,/ - /!! ! " ! #0 $ % &0 123.! 4(5 $%%& %3 &$!!!!!!!!!!!!!!! % % - /&%.&.33!!! &! 3%% - 3 % -

K301Q-D VRT中英文说明书141009


1.ai

Microsoft PowerPoint - CH 04 Techniques of Circuit Analysis

untitled

Transcription:

Department of Computer Science and Engineering National Sun Yat-sen University Data Structures - Middle Exam, Nov. 14, 2016 1. Explain each of the following terms. (16%) (a) private in C++ language (b) template in C++ language (c) generalized lists (d) sparse matrix 2. Calculate the addressing formula for the element a[i][j][k] in an array declared as a[5][4][7]. Suppose that the address of a[0][0][0] is 300 and each element requires four bytes. Give the answers for the row-major representation and the column-major representation. (10%) 3. In the following sparse matrix a[ ][ ], all elements other than those on the major diagonal and the diagonals immediately above and below this one are zero. Suppose the elements in the band formed by these three diagonals are represented by rows in a linear array b, with a[0][0] being stored in b[0]. Suppose that b[k] stores the value of a[i][j], 0 i, j n-1. Please calculate the addressing formula for k with i and j. (10%) x x zero zero x x 4. Explain the meaning of an equivalence class. (6%) 5. Transform the prefix expression ++A BCD/+EF GHI to infix and postfix expressions. Draw its expression tree. (10%) 6. Please present the method to transform an infix expression to a postfix expression with the help of a stack. And illustrate your method with the example ((A-(B+C))*D)*(E+F). Note that you have to describe your method, but do not write a program. If there is no description of your method, you will get no point. (12%) 7. Write a C/C++ function to perform the selection sort for sorting the input elements into nondecreasing order. (12%) void Sel_Sort(int a[ ], int n) - 1 -

// a[ ]: the element array to be sorted. n: number of elements Please write the body of Sel_Sort ( ). } // end of Sel_Sort ( ) 8. Write a C/C++ function to perform Push and Pop operations of a stack implemented with an array. (12%) int top; // top pointer of the stack int capacity=100; // size of the stack char s[100]; // array for the stack void Push(char x) // Push (add) x to the stack. Before the push operation, // you have to check if the stack is full. (a) Please write the body of Push( ). } // end of Push( ) char Pop( ) // Remove the top element from the stack, and return the removed element. // Before the pop operation, you have to check if the stack is empty. (b) Please write the body of Pop( ). } // end of Pop( ) 9. Write a C++ function to reverse a singly linked list. For example, suppose that the give list X=(x 1, x 2,, x n-1, x n ). After the reversing process, the list will become (x n, x n-1,, x 2, x 1 ). (12%) class ChainNode int data; ChainNode *link; }; class Chain ChainNode *first; // first node of the list void Reverse( ) // Reverse the list. ChainNode *p, *c; // p:previous, c:current Please write the body of Reverse ( ). } // end of Reverse ( ) }; - 2 -

Answer: 1. (a) private: 用來保保護 class 內部的成成員 ( 變數與與函式 ), 只只有 classs 內部成員可可使用 (b) template: class 的樣板, 可以用一個個代稱來來代表資料料型態的名名稱, 之後便便可以該該樣板來使使用不同的的資料型態, 通常使使用在 function 或 class 中, 以一一個樣板板來代替多多種資料型型態 (c) generalized lists: 一種 list, 每一個 node 的資料內容容是一個 atom 或其他 list( 或 null list) (d) sparse matrix: 稀疏矩陣, 矩陣內大大部分元素素為 0, 少少數儲存具具備有意義的的值 ( 非零零的值 ) 2. row-major 300+(i 4 7+j 7+ +k) 4 column-major 300+ +(i+j 5+k 5 4) 4 3. k= k=3i+( (j-i)=2i+j 4. equivalence class: 等價類, 一個集合合內的元素素可透過反反身性 對對稱性及遞移移性而相相互聯結的的類別 5. Infix: A+[ [B*C*D-( E+F)/(G* *H)]+I Postfix: ABC*D*EF+GH*/-+ +I+ 6. 轉換方法法如下 : (1) 遇到數字字時, 直接 output (2) 遇到左括括號或運算算符號, 則 push 放入到 stack 中 (3) 遇到右括括號, 則把把相對應到到的左括號號上的運算算符號 pop 出來 (4) 若在放入入運算符號號的過程中, 遇到 stack topp 運算符符號優先順順序較高時, 則把高高的優先順順序先 pop 出來, 再把目前前的運算符符號 push 到 stack - 3 -

(5) 最後, 在將 stack 剩下的運算符號 pop 出來 操作範例如下 : Token Output Stack ( ( ( (( A A (( - A ((- ( A ((-( B AB ((-( + AB ((-(+ C ABC ((-(+ ) ABC+ ((- ) ABC+- ( * ABC+- (* D ABC+-D (* ) ABC+-D* * ABC+-D* * ( ABC+-D* *( E ABC+-D*E *( + ABC+-D*E *(+ F ABC+-D*EF *(+ ) ABC+-D*F+ * ABC+-D*EF+* 最後得到 postfix expression 為 ABC+-D*EF+* 7. void Sel_Sort (int a[ ], int n) // sort the n integers a[0]~a[n-1] into nondecreasing order for ( int i = 0; i < n; i++) - 4 -

int j = i; // find the smallest in a[i] to a[n-1] for (int k = i+1; k < n; k++) if (a[k] < a[j]) j = k; // swap(a[i], a[j]); int temp = a[i]; a[i] = a[j]; a[j] = temp; } } // end of Sel_Sort ( ) 8. void Push (char x) // Push (add) x to the stack. Before the push operation, // you have to check if the stack is full. if (top == capacity - 1) throw "Stack Overflows"; s[++top] = x; } // end of Push( ) char Pop( ) // Remove the top element from the stack, and return the removed element. // Before the pop operation, you have to check if the stack is empty. if (top == -1) throw "Stack is empty. Cannot delete." char x=s[top]; top--; return x; } // end of Pop( ) 9. void Reverse( ) // Reverse the list. ChainNode *p, *c; // p:previous, c:current c = first p = 0; // before current while (c) ChainNode *r = p; p = c; c = c ->link; // moves to next node p->link = r; // reverse the link } first = p; } // end of Reverse ( ) - 5 -