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
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...
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,...
Question 2: Write a C program that read 100 integers from the attached file (integers.txt) into...
Question 2: Write a C program that read 100 integers from the attached file (integers.txt) into an array and copy the integers from the array into a Binary Search Tree (BST). The program prints out the following: The number of comparisons made to search for a given integer in the BST And The number of comparisons made to search for the same integer in the array Question 3 Run the program developed in Question 2 ten times. The given values...
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...
This assignment will give you the opportunity to practice building a Web page. From this web...
This assignment will give you the opportunity to practice building a Web page. From this web page you will learn the necessary HTML tags needed for assignment #5. Using the reference material in the Lessons and Resources provided at the course Web site and available at other sites on the Internet, your task is to create a single Web page (filename: "mypage.html"), and upload it (eventually, when you are done it) to the directory specified in Assignment #3. This web...
The table below gives the list price and the number of bids received for five randomly...
The table below gives the list price and the number of bids received for five randomly selected items sold through online auctions. Using this data, consider the equation of the regression line, yˆ=b0+b1xy^=b0+b1x, for predicting the number of bids an item will receive based on the list price. Keep in mind, the correlation coefficient may or may not be statistically significant for the data given. Remember, in practice, it would not be appropriate to use the regression line to make...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT