01-MIDTERMS-ITC04-REVIEWER.pdf

Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...

Full Transcript

UNIVERSIDAD DE DAGUPAN SCHOOL OF INFORMATION TECHNOLOGY EDUCATION ITC04 | DATA STRUCTURES & ALGORITHM MIDTERM EXAM REVIEWER MULTIPLE CHOICES: Choose from among the choices the answer that best fits the requirement. Write...

UNIVERSIDAD DE DAGUPAN SCHOOL OF INFORMATION TECHNOLOGY EDUCATION ITC04 | DATA STRUCTURES & ALGORITHM MIDTERM EXAM REVIEWER MULTIPLE CHOICES: Choose from among the choices the answer that best fits the requirement. Write your answers in UPPERCASE format. 1. Given the following code snippet: int[] arr1 = {1, 2, 3}; int[] arr2 = new int; arr2 = arr1; arr2 = 10 System.out.println(arr1); What will the output be? A) 1 B) 10 C) 0 D) An error will occur at runtime. 2. Which of the following code snippets will result in a compilation error? A) Int[] numbers = new int; numbers = 1; B) double[] fractions = {1.2, 2.4, 3.6}; System.out.println(fractions); C) char letters[] = new char; letters = 'A'; D) String[] names = new String; names = "Alice"; names = 123; 3. What will be the output of the following code? int[] arr = {1, 2, 3, 4}; System.out.println(arr[arr.length - 1]); A) 1 B) 4 C) 3 D) An error will occur 4. Analyze the following code: String[] fruits = {"Apple", "Banana", "Orange"}; System.out.println(fruits[fruits.length]); What will happen when this code is executed? A) It prints Orange. B) It prints null. C) An ArrayIndexOutOfBoundsException will be thrown. D) It prints the length of the array. 5. Analyze the following scenario: If the base address in a 1D integer array arr is 2000, and each integer takes 4 bytes, what will be the address of the 5th element (arr)? A) 2004 B) 2020 C) 2016 D) 2008 6. Identify the issue in the following computed addressing formula in a 1D Array: Address = Base Address + (Index + 1) * Element Size A) It will compute the wrong address for the first element. B) It skips over even elements. C) It results in a runtime error for negative indices. D) It correctly computes addresses for all elements. 1ST Semester Academic Year: 2024-2025 1 7. If ArrayKo is an integer array having 6 elements with a base address of 1000, and each integer occupies 2 bytes, what happens if you try to access A? A) It will access memory at address 1012. B) It will access memory at address 1016. C) It will result in an out-of-bounds error if the array has more than 6 elements. D) It will access memory at address 1018. 8. Compare the following two formulas for computing element addresses. Which one is correct? Formula 1: Address = Base Address + (Index * Element Size) Formula 2: Address = Base Address + (Index * (Element Size + 1)) A) Formula 1 B) Formula 2 C) Both are correct D) Neither is correct 9. Given a char array letters having 10 elements with a base address of 3000, what is the address of letters? A) 3008 B) 3009 C) 3010 D) 3016 10. A 2D array is being used to represent a seating arrangement in a cinema hall. Analyze the following code snippet and determine the purpose of the array elements: int seats [ ] [ ] = new int ; seats = 1; A) It stores the price of tickets for each seat. B) It marks seat (2,5) as occupied. C) It stores the age of the person sitting at that seat. D) It reserves 15 seats in row 10. 11. Analyze why arrays are often used to implement matrix operations in scientific computing. A) Arrays allow flexible memory allocation during runtime. B) Arrays are the only data structure that supports nested loops. C) Arrays provide contiguous memory storage, which improves cache performance for matrix operations. D) Arrays are easier to resize compared to other data structures. 12. Analyze the following scenario: You need to implement a list where elements are frequently inserted and deleted at both the head and tail. Which type of linked list would be the most efficient solution? A) Singly linked list B) Doubly linked list C) Circular linked list D) Static array 13. A circular linked list is used to manage tasks in a round-robin scheduling algorithm. What is the primary reason for choosing this type of linked list? A) It reduces the memory required to store the list. B) It allows the traversal to restart from the beginning after reaching the end. C) It stores tasks in sorted order automatically. D) It eliminates the need for pointers. 14. Consider a linked list that stores student records. If frequent insertions need to happen in the middle of the list, which data structure is more efficient: a linked list or an array? Why? A) Array, because it allows random access. B) Linked list, because insertion in the middle is faster without shifting elements. C) Array, because it uses less memory. D) Linked list, because it sorts the data automatically. 15. Analyze the scenario where a circular doubly linked list is used. If you are at a particular node, which operations can you perform more efficiently compared to a singly linked list? A) Move only forward through the list. B) Move backward and forward through the list. C) Delete a node from the head without traversal. D) Insert elements only at the tail efficiently. 1ST Semester Academic Year: 2024-2025 2 16. How do you access the third element of the following integer array in Java? int[] numbers = {5, 10, 15, 20}; A) numbers B) numbers C) numbers D) numbers 17. If an array has 10 elements, what is the index of the last element? A) 9 B) 10 C) 8 D) Depends on the content of the array 18. What will the following code print? int[] values = {1, 2, 3, 4, 5}; System.out.println(values); A) 1 B) 2 C) 0 D) An error will occur 19. What is the base address of an array? A) The index of the first element. B) The memory address of the first element. C) The index of the last element. D) The size of the array. 20. In the computed addressing formula for 1D arrays, what does A represent? A) The base address of the array. B) The address of the last element. C) The first index of the array. D) The size of the array. 21. Which formula is used to compute the address of an element in a 1D array? A) Address = Base Address + (Index * Size of Element) B) Address = Index + Size of Element C) Address = Base Address - Index D) Address = Base Address / (Index + 1) 22. What does the size of an element refer to in computed addressing? A) The total size of the array. B) The number of elements in the array. C) The memory size of a single element. D) The index of the element. 23. If the base address of an integer array is 1000, and each integer takes 4 bytes, what will be the address of the 3rd element (A)? A) 1008 B) 1004 C) 1002 D) 1012 24. In the formula Address = Base Address + (Index * Size of Element), what does the index represent? A) The number of bytes in the element. B) The position of the element in the array. C) The base address of the element. D) The memory size of the array. 25. What formula is commonly used to calculate the address of an element in a row-major 2D array? A) Address = Base Address + (Row * Size of Row + Column) * Size of Element B) Address = Base Address + Row + Column + Size of Element C) Address = Base Address + (Column * Size of Element) D) Address = (Base Address / Row) * Column 26. Which of the following correctly declares an integer array in Java? A) int arr() B) int[] arr = new int; C) int arr[] = {1, 2, 3, 4, 5]; D) arr = int 1ST Semester Academic Year: 2024-2025 3 27. What does the following declaration represent: double[] prices = new double;? A) It creates a double array with 3 initialized elements. B) It declares and instantiates an array but with uninitialized elements. C) It initializes the array with default values of 0.0. D) It declares an array with fixed values. 28. What will happen if you try to access an index beyond the size of the array? A) The program will print "null." B) The compiler will generate a syntax error. C) A runtime exception will be thrown. D) It will assign the value zero by default. 29. Which of the following correctly initializes an array of strings? A) String[] names = {"Alice", "Bob", "Charlie"}; B) String names() = new String(3); C) String names = new String[]; D) String names = {"Alice", "Bob", "Charlie"} 30. What is the index of the first element in an array? A) 0 B) 1 C) -1 D) Depends on the array type 31. What does the base address represent in a 2D array? A) The address of the first element in the first row and column (A). B) The size of the entire array. C) The address of the last element in the array. D) The sum of the row and column addresses. 32. In a 2D integer array with 4 rows and 5 columns, how many elements does the array contain? A) 9 B) 10 C) 20 D) 5 33. If the base address of a 2D array is 1000, and each element occupies 4 bytes, what is the address of the element at A in row-major order? (Assume 5 columns per row.) A) 1012 B) 1024 C) 1028 D) 1032 34. What would the computed address be for A in a 4x5 row-major 2D array with a base address of 3000? A) 3020 B) 3028 C) 3034 D) 3068 35. What is the relationship between physical address and logical address? A) They are always identical. B) Logical addresses are generated by the CPU and translated into physical addresses by the MMU. C) Physical addresses are stored on the CPU registers. D) Logical addresses are used only by operating systems, not programs. 36. In a circular linked list, what makes it different from a normal singly linked list? A) The last node points back to the first node. B) Each node contains two data fields. C) It allows random access to elements. D) It does not use pointers to store elements. 37. What is a doubly linked list? A) A list where each node points only to the next node. B) A list where each node points to both the next and previous nodes. C) A list where all nodes are connected in a single loop. D) A list where nodes store only data, not addresses. 1ST Semester Academic Year: 2024-2025 4 38. Which type of linked list is typically used for round-robin scheduling? A) Singly linked list B) Doubly linked list C) Circular linked list D) Static array 39. What is a singly linked list? A) A list where each node has pointers to both the next and previous nodes. B) A list where each node points only to the next node in the sequence. C) A circular list where each node points back to the first node. D) A list with fixed-size elements stored in memory blocks. 40. What does each node in a singly linked list contain? A) Data, a pointer to the next node, and a pointer to the previous node B) Data and a pointer to the next node C) Only data D) Only a pointer to the next node 41. What is a doubly linked list? A) A list where each node has a pointer to the next node only. B) A list where each node has pointers to both the next and previous nodes. C) A list where nodes are arranged in a circular manner. D) A fixed-size list stored in contiguous memory. 42. What does each node in a doubly linked list typically contain? A) Data and a pointer to the next node B) Data, a pointer to the next node, and a pointer to the previous node C) Only data D) A pointer to the previous node only 43. What is a circular linked list? A) A list where each node points to the next node, and the last node points to NULL. B) A list where each node points to itself. C) A list where the last node points back to the first node. D) A list with fixed-size elements stored in contiguous memory. 44. In a circular linked list, how can you identify the end of the list? A) The last node points to NULL. B) The last node points to the first node. C) Each node has a counter. D) There is no distinct end; it is circular. 45. Which of the following is a common application of a circular linked list? A) Implementing stacks B) Round-robin scheduling in operating systems C) Storing static data D) Managing memory allocation 46. Which of the following statements about physical addresses is true? A) Physical addresses refer to locations in the virtual memory. B) Physical addresses are determined by the operating system only. C) Physical addresses indicate exact locations in the RAM. D) Physical addresses change every time the computer is restarted. 47. Which component translates a logical address to a physical address? A) Memory Management Unit (MMU) B) Arithmetic Logic Unit (ALU) C) Disk Controller D) Direct Memory Access (DMA) 48. Why is a sparse matrix representation preferred over a normal matrix? A) It increases the number of non-zero elements. B) It reduces the time required for matrix operations. C) It saves memory by only storing non-zero elements. D) It ensures that the matrix is symmetric. 1ST Semester Academic Year: 2024-2025 5 49. What is a singly linked list? A) A linked list where each node points to the previous node. B) A linked list where each node points to the next node only. C) A list where all nodes are connected to each other in a circle. D) A list where each node has two pointers. 50. Which of the following linked lists allows bidirectional traversal? A) Singly linked list B) Doubly linked list C) Circular linked list D) Static linked list PREPARED BY: ARNALDY D. FORTIN, MBA, MCS SITE, FACULTY 1ST Semester Academic Year: 2024-2025 6

Use Quizgecko on...
Browser
Browser