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

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

View Full Document Right Arrow Icon
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
Background image of page 1

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

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 11/15/2010 for the course CS 340 taught by Professor Dr.malek during the Fall '10 term at University of Regina.

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 Right Arrow Icon
Ask a homework question - tutors are online