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

Homework Answers

Answer #1

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:

Base address=250

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.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
C++ questions QUESTION 1 What kind of linked list begins with a pointer to the first...
C++ questions QUESTION 1 What kind of linked list begins with a pointer to the first node, and each node contains a pointer to the next node, and the pointer in the last node points back to the first node? A. Circular, singly-linked list. B. Circular, doubly-linked list. C. Singly-linked list. D. Doubly-linked list. E. None of the above.    QUESTION 2 _________ is not an advantage of linked lists when compared to arrays. A. Dynamic memory allocation. B. Efficient...
The output only produces the values from the first linkedlist and not the second. Please fix...
The output only produces the values from the first linkedlist and not the second. Please fix the code to produce the desired objective. Thanks for your help! Objective: Interleave Example: Define the calling list as a set of ordered nodes, $L1 = {4, 2, 8 ,5, 8}$, and define the list that is passed as a parameter as a set of ordered nodes, $L2 = {5, 1, 8, 4, 5, 9}$. L1.interleave(L2) yields the set ${4, 5, 2, 1, 8,...
1. Build a double linked list with 5 in the first node following the instructions: Insert...
1. Build a double linked list with 5 in the first node following the instructions: Insert a node with 3 at the top of the list Insert a node with 10 at the bottom of the list Insert a node with 7 between nodes with 5 and 10 2. Start deleting nodes from the list in the following order; Delete the node with 7 Delete the node with 3 Delete the node with 10 3. Print the resulting list forward...
Write the following program in MIPS: a) declare an array A of the following numbers: 3,...
Write the following program in MIPS: a) declare an array A of the following numbers: 3, 5, 8, 10, 12, 2, 76, 43, 90, 44 b) declare a variable called size which stores the number of element in array A, that is 10. c) write a subroutine to search for a number stored in an array and return true or false. In C++ the subroutine is as follows: search(array, size, number_To_Search) e.g. search(A, 10, 12) The subroutine should return 0...
IntList Lab Specifications You are required to come up with a single header file (IntList.h) that...
IntList Lab Specifications You are required to come up with a single header file (IntList.h) that declares and implements the IntNode class (just copy it exactly as it is below) as well as declares the IntList Class interface only. You are also required to come up with a separate implementation file (IntList.cpp) that implements the member functions of the IntList class. While developing your IntList class you must write your own test harness (within a file named main.cpp). Never implement...
Given the following unordered array: [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] [10]...
Given the following unordered array: [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] W X D T P N R Q K M E If the array was being sorted using the SHELL sort and the halving method, and sorting into ASCENDING order as demonstrated in the course content, list the letters in the resulting array, in order AFTER the FIRST pass. [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] [10]
   vi. Assume that a linked list stores the data, 20, 11, 13, 19, 12, 14...
   vi. Assume that a linked list stores the data, 20, 11, 13, 19, 12, 14 in that order. Assume that Node head references the first item in the list. What is the result to the linked list of       the following instructions? Assume that newNode          is a Node, already constructed. newNode.data = 1;                         newNode.next = head.next;                         head = newNode;       a. The value 1 is inserted into the linked list before 20       b. The...
Create a C++ project. Download and add the attached .h and .cpp to the project. Write...
Create a C++ project. Download and add the attached .h and .cpp to the project. Write an implementation file to implement the namespace declared in the attached CSCI361Proj5.h. Name the implementation file as YourNameProj5.cpp and add it to the project. Run the project to see your grade. .h file: // Provided by: ____________(your name here)__________ // Email Address: ____________(your email address here)________ // FILE: link.h // PROVIDES: A toolkit of 14 functions for manipulating linked lists. Each // node of...
Project 1 - NodeList write in c++ with 5 files: main.cpp List.h List.cpp ListNode.h ListNode.cpp Building...
Project 1 - NodeList write in c++ with 5 files: main.cpp List.h List.cpp ListNode.h ListNode.cpp Building upon the the ListNode/List code I would like you to extend the interface of a list to have these member functions as well. struct ListNode { int element; ListNode *next; } Write a function to concatenate two linked lists. Given lists l1 = (2, 3, 1)and l2 = (4, 5), after return from l1.concatenate(l2)the list l1should be changed to be l1 = (2, 3,...
Pinky and The Brain are great friends. They like to play games with numbers. This time,...
Pinky and The Brain are great friends. They like to play games with numbers. This time, Pinky has given The Brain a list of numbers and given him the task of determining if it is possible to choose a subset of them such that they sum is equal to another given number. Build an algorithm using dynamic programming to help The Brain with his problem. INPUT The first line corresponds to N, the amount of numbers given by Pinky The...