Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Assignment#6 – Linear Data Structure Due Date: Midnight of April 21 (Saturday) P

ID: 3712050 • Letter: A

Question

Assignment#6 – Linear Data Structure

Due Date:       Midnight of April 21 (Saturday)

Purpose:         The purpose of this assignment is to help you:

Understand search and sort
Understand Generic method, Generic interface, Generic class and Hash table

Instructions: Be sure to read the following general instructions carefully:

This assignment should be completed individually by all the students. You are encouraged to demonstrate your solution during lab session, and submit your solution through the dropbox. You must name your submission according to the following rule: studentID(yourlastname)_ASSnumber.zip. e.g., 300123456(smith)_ASS#7.zip

Question 1[10 marks]

Use a concrete example to explain how generic methods can be overloaded [3 marks]
Explain following terms [1 mark per term]

ICollection
Array
IList
Load factor
Hash-table collision
Space/time trade-off in hashing
dictionary

Question 2[10 marks]

Linear search algorithm searches each element in an array sequentially. If the search key does not match an element in the array, the algorithm tests each element and, when the end of the array is reached, informs the user that the search key is not present. If the search key is in the array, the algorithm tests each element until it finds one that matches the search key and returns the index of that element.

Write a generic method, Search, that searches an array using linear search algorithm. Method Search should compare the search key with each element in its array parameter until the search key is found or until the end of the array is reached. If the search key is found, return its location in the array; otherwise return -1.

Write a test app that inputs and searches an int array and a double array. Provide buttons that the user can click to randomly generate int and double values. Display the generated values in a TextBox, so the user knows what values they can search for. [Hint: use (T: IComparable<T>) in the where clause for method search so that you can use method CompareTo to compare the search key to the elements in the array]

c# programming

Explanation / Answer

Generic Methods are methods which has its own type parameters. It is used to express the dependencies among the types of different arguments(or return type) to a method.

Lets understand the generic method overloading with the help opf an example program code

namespace genericsDemo

{

public class Demo

{

public void GetData<T>(T obj)

{

Console.WriteLine("Data<T>",+obj.GetType().Name);

}

public void GetData(int x)

{

  Console.WriteLine("Data",+x.GetType().Name);

}

  public void GetNextData<T>(T obj)

{

GetData(obj);

}

}

class Prog

{

static void main(String args[])

{

Demo dobj= new dobj();

dobj.GetData("Test Text"); //This call will go to Getdata<T>(T obj) since we are passing a string

dobj.GetData(40);//This call will go to Getdata(int x) since we are passing an integer value

dobj.GetNextData(34);//This call go to GetNextData<T>(T obj) directly

}

}

ie, at rutime the compiler will decide the best method after checking the types of arguments.

ICollection:It defines enumerators,synchronization methods and size for all collections.

Syntax: public interface ICollection : IEnumerable

Array:  An array is a fixed-size sequential collection of homogenious elements(elements of same data type). Or in simple words we can say an array is a collection of variables of the same type stored at continuous memory locations.

eg: int[] array = new int[5];

Ilist: It is an abstraction that allows various types of list to be used with through a single reference type. ie, Its an interface abstraction.

LoadFactor: The load factor is a metric of how full the hash table is allowed to fill before its capacity is automatically get increased. When the no of entries in the hash table exceeds the product of currentcapacity and load factor,rehashing is needed.

Hash Table Collision: This situation occurs when more than one data pointed to the same hash table location. There arr certain solutions for hash table collisions.

Space/Time trade off in hashing : This is a case where an algorithm or program trades increased space usage with decreased time in hashing.

Dictionary: As same as in Python,dictionary  is a collection of Key-Value pairs, where key is like word and value is like definition.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote