Preview

Nt1420 Unit 6

Good Essays
Open Document
Open Document
1145 Words
Grammar
Grammar
Plagiarism
Plagiarism
Writing
Writing
Score
Score
Nt1420 Unit 6
CMDA5103/MAY2009-F/FA

INSTRUCTIONS: 1. THERE ARE SIX (6) QUESTIONS IN THIS PAPER. 2. ANSWER FIVE (5) QUESTIONS ONLY. Question 1 Arrays are used when storing a large number of values. You are required to create an array named a and answer the following questions regarding array manipulation. a. Write a method fillRandom(int[] a, int min, int max), fill the array a with a random integer value. (Note: Math.random() returns a double in the range of 0.0 and 1.0, therefore it is cast to an integer number, between the minimum and maximum value). [6 marks] b. Write the Bubble sort method to sort array a into descending order. [10 marks] c. In the quicksort, an algorithm an element is chosen from the unsorted list. This element is called the
…show more content…
class Link { public int iData; // data item public double dData; // data item public Link next; // next link in list // ------------------------------------------------------------public Link(int id, double dd) // constructor { iData = id; // initialize data dData = dd; // ('next' is automatically } // set to null) // ------------------------------------------------------------public void displayLink() // display ourself { System.out.print("{" + iData + ", " + dData + "} "); } } // end class Link //////////////////////////////////////////////////////////////// class LinkList { private Link first; // ref to first link on list // ------------------------------------------------------------public LinkList() // constructor { first = null; // no links on list yet } // ------------------------------------------------------------public boolean isEmpty() // true if list is empty { return …show more content…
Assume characters are compared based on alphabetical order. Explain your answer. [5 marks] [TOTAL: 20 MARKS] 5

CMDA5103/MAY2009-F/FA

Question 6 A hash table is a data structure that uses an array as its internal storage container. Items are added to the array based on the integer generated by a hash function. A hash function produces an integer based on some properties of the object. In Java hash functions are encapsulated via the hashcode method in the Object class and that many classes override.

To add an Object to a hash table:

1. call its hashcode method to obtain an int, x 2. modulus x by the length of the hash table to obtain an index, i 3. go to index i in the hash tables native array 4. if that element is null, place the Object in that element 5. if that element is not null a collision has occurred. Collisions can be resolved in many ways. 6. In this hash table collisions are resolved via linear probing. Check the element at index i +1 7. If the element at i + 1 is null, add the item at that element, if not continue to check elements until an open spot is found, by adding 1 to the index to be checked. If the end of the array is reached then

You May Also Find These Documents Helpful

  • Good Essays

    Nt1310 Unit 4

    • 313 Words
    • 2 Pages

    1) Block B in Fig. 6-31 weighs 603 N. The coefficient of static friction between block and table is 0.32; angle θ is 33°; assume that the cord between B and the knot is horizontal. Find the maximum weight of block A for which the system will be stationary.…

    • 313 Words
    • 2 Pages
    Good Essays
  • Satisfactory Essays

    Nt1310 Unit 4

    • 775 Words
    • 4 Pages

    Part III PHYSICS HSE II Time:2Hours Max:60 Scores 1. Three identical charges each +q are placed at the corners of an equilateral triangle of side d cm. Calculate the force on a +ive charge +2q at the centroid of the triangle. 2 2.If the earth is supposed to be a metallic sphere,its capacity will be nearly (a) 700pf (b) 700 microfarad (c) 700f (d) 6.4 X10^6 f 1score 3. write the relation between dielectric constant and electric susceptibility. 1score 4. A box encloses an electric dipole consisting of charge 5micro C and -5micro C and of length 10cm. What is the total electric flux through the box? 2scores 5. Find the ratio of the p.d that must be applied across the (1)parallel (2) series combination of two identical capacitors so that the energy stored in the two cases becomes the same. 2 scores 6.(a)…

    • 775 Words
    • 4 Pages
    Satisfactory Essays
  • Good Essays

    Nt1330 Unit 4

    • 4542 Words
    • 19 Pages

    ________ is typically not referred to as a buffer type in critical chain project management.…

    • 4542 Words
    • 19 Pages
    Good Essays
  • Good Essays

    Nt1310 Unit 5

    • 368 Words
    • 2 Pages

    the ratio of resistors on one side of the bridge is one while the ratio of resistors on the other side is infinity…

    • 368 Words
    • 2 Pages
    Good Essays
  • Good Essays

    Nt1330 Unit 5

    • 800 Words
    • 4 Pages

    1. Is an external wall within 900mm of an allotment boundary to another property, 1.8m to another building that isn’t a class 10 building, or 3m from a brush fence?…

    • 800 Words
    • 4 Pages
    Good Essays
  • Good Essays

    Nt1310 Unit 12

    • 348 Words
    • 2 Pages

    All electrical work from and including motor control centers/panels to and including motors and other electrically operated equipment, which is included in the Specification for Mechanical Work or other work, does not form part of the…

    • 348 Words
    • 2 Pages
    Good Essays
  • Good Essays

    Nt1310 Unit 6

    • 297 Words
    • 2 Pages

    8. The reactance offered by a capacitor to alternating current of frequency 50 Hz is 20 Q. If frequency is increased to 100 Hz, then reactance becomes -----------------.…

    • 297 Words
    • 2 Pages
    Good Essays
  • Better Essays

    Nt1310 Unit 4

    • 3614 Words
    • 15 Pages

    The program is trying to collect the value of a "void" function into an integer variable.…

    • 3614 Words
    • 15 Pages
    Better Essays
  • Satisfactory Essays

    Nt1310 Unit 7

    • 458 Words
    • 2 Pages

    Identify the three IP address classes, the default subnet mask used with each, and the number of hosts for each.…

    • 458 Words
    • 2 Pages
    Satisfactory Essays
  • Satisfactory Essays

    Nt1310 Unit 7

    • 189 Words
    • 1 Page

    This video addresses an employee taking a service call from an unhappy customer. Answer the following questions:…

    • 189 Words
    • 1 Page
    Satisfactory Essays
  • Satisfactory Essays

    Nt1330 Unit 3

    • 273 Words
    • 2 Pages

    1. Identify and explain key trends that are occurring in computer peripheral devices? How do these trends affect business uses of computers?…

    • 273 Words
    • 2 Pages
    Satisfactory Essays
  • Good Essays

    Array Structure Proposal

    • 574 Words
    • 3 Pages

    An array is a variable that holds multiple values of the same kind. Nearly every…

    • 574 Words
    • 3 Pages
    Good Essays
  • Good Essays

    Deciding which data structure to then write it in java was challenging cause you have to make sure that the steps are in the right sequence for the program to work.…

    • 605 Words
    • 3 Pages
    Good Essays
  • Powerful Essays

    Careercup Top 150 Questions

    • 30242 Words
    • 121 Pages

    Interview Questions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 Chapter 1 Chapter 2 Chapter 3 Chapter 4 Chapter 5 Chapter 6 Chapter 7 Chapter 8 Chapter 9 Chapter 10 Chapter 11 Chapter 12 Chapter 13 Chapter 14 Applied Mathematics. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 Arrays & Hash Tables. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 Bit Manipulation . . . . . . . . . . . . . .…

    • 30242 Words
    • 121 Pages
    Powerful Essays
  • Powerful Essays

    Linked List

    • 3270 Words
    • 14 Pages

    – Must know the pointer to the first element of the list (called start, head, etc.).…

    • 3270 Words
    • 14 Pages
    Powerful Essays