{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

solmidt_00

# solmidt_00 - CS3620 SPRING 2000 MIDTERM EXAM Malek Mouhoub...

This preview shows pages 1–2. Sign up to view the full content.

CS3620 – SPRING 2000 – MIDTERM EXAM Malek Mouhoub (02/29/99) Exercise 1 (6 pts) The input is an N by N matrix of numbers that is already in memory. Each individual row is increasing from left to right. Each individual column is increasing from top to bottom. Give an O ( N ) worst-case algorithm that decides if a number X is in the matrix. Solution Start from the top-right corner. With a comparaison, either a match is found, we go left, or we go down.Therefore, the number of comparisons is linear. Exercise 2 (6 pts) The function below returns true if there are three equal integers in the array A . int FindTriples (const Vector < int > { for (int i = 0; i < A.Length(); i++) for (int j = i + 1; j < A.Length(); j++) for (int k = j + 1; k < A.Length(); k++) if return 1; return 0; } 1. What is the running time of this function ? 2. If it takes ten seconds to run FindTriples on an array of 100 elements, approximately how long will it take to run on an array of 400 elements ? Solution

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 2

solmidt_00 - CS3620 SPRING 2000 MIDTERM EXAM Malek Mouhoub...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online