Order Array2015 .pdf

File information


Original filename: Order Array2015.pdf
Title: Operating Systems CSC 522
Author: Sameh Elsharkawy

This PDF 1.5 document has been generated by Microsoft® PowerPoint® 2013, and has been sent on pdf-archive.com on 05/11/2015 at 21:47, from IP address 41.176.x.x. The current document download page has been viewed 638 times.
File size: 749 KB (32 pages).
Privacy: public file


Download original PDF file


Order Array2015.pdf (PDF, 749 KB)


Share on social networks



Link to this file download page



Document preview


Q1:
• int s(int[] arr) {

int s= 0;

for(int i=0; i<arr.length; i++) {

s = s + arr[i];

}

return s;
•}

Q2:
• int m(int[] arr) {

int m = arr[0];

for (int i=1; i<arr.length; i++) {

if (arr[i] > m) {

m = arr[i];

}

return m;
















Q3:
int f(int n, int[] a) {
for (int i=0; i<n; i++) {
for (int j=0; j<n; j++) {
for (int k=0; k<n; k++) {
if (i!=j && j!=k && i!=k) {
if (a[i]==a[j] && a[j]==a[k])
return 1;
}}}
return 0;
}
What does method f do?
What is the running time of f? Use the big-O notation.
If it takes 10 seconds to run f on array of size 100, how
long it takes to run it on the array of size 400.

Q4:
Rewrite the find method in array.cpp such that it:
returns the index of the element which is equal to searchKey,
returns -1 if there is no element in the array which is equal to
searchKey, and does not contain break statement.

Q5:
Write C++ program that that finds the
smallest odd number in a given array of
integers. What is the running time of the
algorithm?

Two-dimensional Arrays

4 x 11
columns
• Declaration:
int matrix[4][11];

rows

Element Access
• In order to access the j-th element
(column) of the i-th array (row)
column

matrix[i][j]
row

Initializing Two-dimensional Arrays
int arr[2][3] = { {1, 2, 3}, {4, 5, 6} };
1

2

3

4

5

6

• As with regular array size can be inferred from the
initialization
• Unlike regular array, this is only true for the number
of rows.
int arr[][3] = { {1, 2, 3}, {4, 5, 6} };

Example: Matrix Addition
#define MATRIX_SIZE 3
int main(void)
{
int a[][MATRIX_SIZE]={{1,2,3}, {4,5,6}, {7,8,9}};
int b[][MATRIX_SIZE]={{1,1,1}, {2,2,2}, {3,3,3}};
int c[MATRIX_SIZE][MATRIX_SIZE];
int i = 0, j = 0;
for (i = 0; i < MATRIX_SIZE; ++i)
for (j = 0; j < MATRIX_SIZE; ++j)
c[i][j] = a[i][j] + b[i][j];
/* print c */
...
return 0;
}


Related documents


order array2015
sp13 lab 6 quizzes
mm1cpm exam 1516
insceditorials
sparse inverse covariance
win213r lec arraysr 1

Link to this page


Permanent link

Use the permanent link to the download page to share your document on Facebook, Twitter, LinkedIn, or directly with a contact by e-Mail, Messenger, Whatsapp, Line..

Short link

Use the short link to share your document on Twitter or by text message (SMS)

HTML Code

Copy the following HTML code to share your document on a Website or Blog

QR Code

QR Code link to PDF file Order Array2015.pdf