Previous Year Questions: ARRAY

  Q1: Let A be an array containing integer values. The distance of A is defined as the minimum number of elements in A that must be replaced with another integer so that the resulting array is sorted in non-decreasing order. The distance of the array  [2,5,3,1,4,2,6] is _____   (2024 SET-  2)
(a) 1
(b) 2
(c) 3
(d) 4
Ans : (c)
Sol :
Given array: [2, 5, 3, 1, 4, 2, 6]
Indices:  0  1  2  3  4  5  6
Values:   2  5  3  1  4  2  6
The array with sorted indices:
Indices:  0  1  2  3  4  5  6
Values:   2  2  3  3  4  4  6
Number of elements out of order: 3

Q2: What is the worst-case number of arithmetic operations performed by recursive binary search on a sorted array of size n?  (2021 SET-2) 
(a)Previous Year Questions: ARRAY
(b)Previous Year Questions: ARRAY
(c)  Previous Year Questions: ARRAY
(d) Previous Year Questions: ARRAY
Ans:(b)
Sol:

Worst-case number of arithmetic operations performed by recursive binary search on a sorted array is given by the following recurrence relation: 

Previous Year Questions: ARRAY

Previous Year Questions: ARRAY
Previous Year Questions: ARRAY

Previous Year Questions: ARRAY
Previous Year Questions: ARRAY

Q3:  Let P be an array containing n integers. Let t be the lowest upper bound on the number of comparisons of the array elements, required to find the minimum and maximum values in an arbitrary array of n elements. Which one of the following choices is correct?  (2021 SET1)
(a) Previous Year Questions: ARRAY
(b) Previous Year Questions: ARRAY
(c) 
Previous Year Questions: ARRAY
(d) Previous Year Questions: ARRAY
Ans: (c)
Sol :
The answer is a stub!

Tournament Method:

  • Imagine using merge sort and you'd divided the array elements in pairs of two, every element is compared with each other.
  • The largest(or smallest if preferred) is selected out each pairs and the winners are copied to a new array and the procedure it repeated till we have one element remaining.

 For this, 
At first we need Previous Year Questions: ARRAY  comparisons(sincePrevious Year Questions: ARRAY  pairs), then Previous Year Questions: ARRAY so on this sums to nn , an AP 

Previous Year Questions: ARRAY

  • For finding the smallest element we would use the losers left out in the first round  Previous Year Questions: ARRAYlosers to be precise.
  • We again use this procedure with an intention for finding smaller amongst all, (worst losers will be the best winners in these rounds, ironical indeed).

For this,
We need, Previous Year Questions: ARRAYat first since we are pitting losers against losers comparisons then, Previous Year Questions: ARRAY

so on which sums  uptoPrevious Year Questions: ARRAY.
Previous Year Questions: ARRAY 

Previous Year Questions: ARRAY
The number  of comparisons needed is at least  Previous Year Questions: ARRAY if we consider the elements to be distinct.

Q4:  If an array A contains the items 10,4, 7,23,67,12 and 5 in that order, what will be the resultant array A after third pass of insertion sort?   (2020)
(a)  67,12,10,5,4,7,23
(b)  4,7,10,23,67,12,5
(c)  4,5,7,67,10,12,23
(d)  10,7,4,67,23,12,5 

Ans:(b)
Sol:

Previous Year Questions: ARRAY
 Pass1 will be applied on the first 2 

elements. 

Previous Year Questions: ARRAY
Previous Year Questions: ARRAY
Previous Year Questions: ARRAY

Q5:  Consider a 2-dimensional array x with 10 rows and 4 columns, with each element storing a value equivalent to the product of row number and column number. The array is stored in row-major format. If the first element x[0] [0] occupies the memory location with address 1000 and each element occupies only one memory location, which all locations (in decimal) will be holding a value of 10?  (2020)
(a) 1018,1091
(b)  1022,1041
(c)  1017,1036
(d)  1000,1399
Ans: (c)
Sol:  We can only get 10 from following combinations:
1×10 - NOT POSSIBLE (column out of range)
2×5 - NOT POSSIBLE (column out of range)
5×2 - POSSIBLE

Using 1-based indexing:
x[5][2] ⇒ (5×2 = 10)

Convert to 0-based index → x[4][1]

Address calculation (row-major):
x[4][1] = 1000 + (4×4 + 1) = 1000 + 17 = 1017

Similarly, second address from options:
x[9][0] = 1000 + (9×4 + 0) = 1000 + 36 = 1036

Final Answer: (c) 1017, 1036

The document Previous Year Questions: ARRAY is a part of the Computer Science Engineering (CSE) Course Programming and Data Structures.
All you need of Computer Science Engineering (CSE) at this link: Computer Science Engineering (CSE)

FAQs on Previous Year Questions: ARRAY

1. What is an array in computer science?
Ans. An array in computer science is a data structure that stores a collection of elements of the same data type in contiguous memory locations. Each element in the array is accessed by its index.
2. How is an array different from a linked list?
Ans. An array stores elements in contiguous memory locations, allowing for fast random access. In contrast, a linked list stores elements in non-contiguous memory locations connected by pointers, making sequential access faster but random access slower.
3. What is the time complexity for accessing an element in an array?
Ans. The time complexity for accessing an element in an array is O(1) as it can be done in constant time by directly accessing the element's memory location using its index.
4. Can the size of an array be changed dynamically in most programming languages?
Ans. No, the size of an array is usually fixed upon initialization in most programming languages. If dynamic sizing is required, other data structures like dynamic arrays or lists can be used.
5. How can we initialize an array in programming languages like C++ or Java?
Ans. In C++, an array can be initialized using braces {} with the elements separated by commas. In Java, an array can be initialized using the new keyword followed by the type and size of the array.
Explore Courses for Computer Science Engineering (CSE) exam
Get EduRev Notes directly in your Google search
Related Searches
Free, Previous Year Questions: ARRAY, shortcuts and tricks, Previous Year Questions: ARRAY, past year papers, Summary, Objective type Questions, Previous Year Questions with Solutions, Sample Paper, Previous Year Questions: ARRAY, Exam, Important questions, ppt, pdf , Viva Questions, Extra Questions, mock tests for examination, study material, Semester Notes, practice quizzes, video lectures, MCQs;