Question

# 1. An array has an index of [5] at the starting address of 200. It has...

1. An array has an index of [5] at the starting address of 200. It has 3 words per memory cell, determine loc[3],loc[4] and NE. (3 Marks: 1 mark for each)

2. A 2-D array defined as A[10 , 5] requires 4 words of storage space for each element. Calculate the address of A[4,3] given the base address as 250

• If the array is stored in Row-major form •

If the array is stored in Column-major form

3. Write a method for the following using the data structure Linked List. void append(Node list1, Node list2) If the list1 is {22, 33, 44, 55} and list2 is {66, 77, 88, 99} then append(list1, list2) will change list1 to {22, 33, 44, 55, 66, 77, 88, 99}. (5 Marks: 1mark for each correct step)

4. Write a method for the following using the data structure Linked List. int sum(Node list) If the list is {25, 45, 65, 85} then sum(list) will return 220. (5 Marks: 1mark for each correct step)

5. Trace the following code showing the contents of the Linked List L after each call L.add(50); L.add(60); L.addFirst(10); L.addLast(100); L.set(1, 20); L.remove(1); L.remove(2); L.removeFirst(); L.removeLast(); (10 Marks: 1 mark for each correct answer) L.addFirst(10);

6. Compare and contrast the following data structures.

•Array and Linked List NOTICE

1.The answer to the first and second question is not writing a program

2.Please put numbers for each answer ex 1 2

language is javascript

Sol:

2. Row Major:

Base address = 250.

Size of 1 cell = 4 words.

Words in a row = 5*4 = 20 words.

Words between A[0,0] and A[0,5] = 20.

Words between A[0,0] and A[3,5] = 20*4 = 80.

Words between A[4,0] and A[4,3] = 3*4 = 12.

Words between A[0,0] and A[4,3] = 80+12 = 92.

Address of A[4,3] = 250+92 = 342.

Column Major:

Size of 1 cell= 4 words

Words in a column=10*4= 40 words.

Words between A[0,0] and A[9,0] = 40.

Words between A[0,0] and A[9,2] = 40*3 = 120.

Words between A[0,3] and A[4,3] = 4*4 = 16.

Words between A[0,0] and A[4,3] = 120+16 = 136.

Address of A[4,3] = 250+136 = 386.

#### Earn Coins

Coins can be redeemed for fabulous gifts.