CSE101 array/data structure questions and answers Graded A+
CSE101 array/data structure questions and answers Graded A+ Given an integer x and an array of numbers, find if two numbers in the array sum up to x. (Or, find the pair of numbers whose sum is closest to x.) - Array A[n], x 1.) Sort using Mergesort ------- O(nlogn) 2.) Initialize two index variables to find candidit a.) Initialize first to the leftmost index: l = 0 b.) Initializ second the rightmost index: r = n - 1 3.) While l r -----------O(n) a.) if A[l] + A[r] == x; return true b.) else if A[l] + A[r] sum; increm
Información del documento
- Subido en
- 8 de abril de 2026
- Número de páginas
- 16
- Escrito en
- 2025/2026
- Tipo
- Examen
- Contiene
- Preguntas y respuestas