Page 394 - ComputerScience_Class_11
P. 394
3. ………………… is the process of combining two or more arrays.
4. Array can be initialised using ………………… as a separator surrounded by curly braces.
5. The ………………… class is used to take input from the user in arrays.
C. Answer the following questions:
1. How can you access the first element of an array?
2. What is a 2D array?
2. What do you mean by sorting?
3. Define bubble sort.
4. What is insertion sort?
5. Discuss the difference between static and dynamic array declarations with examples.
6. Explain the process of inserting an element in an array using Java. Write a program to demonstrate how insertion works in an
array.
7. Write the differences between bubble sort and selection sort
4. Explain the concept of merging two arrays in Java.
8. What is a linear search in Java? Write a Java program to perform linear search on an array.
D. Higher Order Thinking Skills (HOTS)
1. Imagine an array representing stock prices over time. How would you design an algorithm to find the best day to buy and sell
stocks to maximise profit? Explain the steps and justify the chosen approach.
2. Given an array of numbers, how could you design an algorithm to find the majority element (the element that appears more than
half the time)? Discuss the most efficient approach and its time complexity.
E. Case study-based questions.
Sanjay is building a Java program to manage employee data, using three separate arrays: one for names, one for ages and one for
salaries. He calculates total salary and identifies the highest salary, but the array structure becomes inefficient as the number of
employees increases. He realizes arrays are limited because they can only store one data type and don't resize dynamically.
Sanjay considers switching to ArrayLists to make the program more flexible, as they can dynamically grow in size, which would
simplify adding or removing records. An ArrayList is a resizable, dynamic array in Java that automatically manages its capacity,
allowing you to add, remove and access elements by index without needing to define a fixed size.
Based on the given case, answer the following questions:
1. Why is Sanjay using three separate arrays for storing employee names, ages and salaries?
a. Arrays can only store data of one type b. To make the program more efficient
c. Because arrays can store complex data types d. To follow the best practices of object-oriented programming
2. Which Java collection could Sanjay use instead of arrays for better flexibility in modifying employee data?
a. ArrayList b. LinkedList
c. HashMap d. TreeSet
3. How can Sanjay find the highest salary in the array?
a. Sort the array in descending order and select the first element
b. Iterate through the array and keeping track of the highest one
c. Use a binary search to find the highest salary
d. Use the max() method from the Math library
4. What is the main advantage of using an ArrayList over a regular array in Sanjay’s case?
a. ArrayLists are easier to sort b. ArrayLists automatically adjust their size
c. Arrays are faster in terms of performance d. ArrayLists require less memory compared to arrays
F. Write the Java program for the following:
1. Complete the given Java code to generate the following output:
ID Name Age
0 John 25
1 Sara 30
2 Mike 28
392 Touchpad Computer Science (Ver. 3.0)-XI

