C# algorithm

COIS 2020H S61 2015 Assignment 2
As with assignment 1, your assignment should be completed in C# using visual studio
You should zip up your assignment files (feel free to give me the full solution directories) into your username.zip (or rar) and submit on blackboard.
1. A) Create a doubly linked list and populate it with 100 elements. These elements represent NPC’s in a game, they should have an ID and a position (x, y). They exist in a grid that is 32×32 (0,0 to 31, 31), and they should be generated at a random location. The ‘player’ should start at position 15,15. Run your program in a loop. Every iteration through the loop the player moves one unit in any direction, and the NPC’s move one unit in any direction. Take into account walls etc.

B) At each iteration find all the elements within a distance of 10 of the player. Time how long this takes.

C) At each iteration of the list sort it based on the distance from the player (you can either make a new list each time, or do an in place sort), then read in all of the elements within a distance of 10 from the player.

D) Which is faster B or C? Which scales better/worse, with more elements or an increasing grid size? It’s up to you to decide how many iterations and how much testing you want to do to answer these questions.

2. A) Write a recursive function that reverses the order of a doubly linked list (you can use the same doubly linked list from Question 1, and the text has source code for a doubly linked list).

READ ALSO :   stereotype is the tool of prejudging individuals' characteristics

B) Load up two doubly linked lists with 200 million identical small integer elements (say 0 – 15). Calculate the sum. Compare the timing for treating one list as a stack, and the other as a queue. (Destroy each element as you process it;that’s why you need two lists).
3. A) Create a Binary tree with 20 million elements. It should be (nearly) complete and balanced.

B) Traverse the tree in inorder using recursion, time it.

C) Traverse the tree using breadth first (which is not inorder), time it.

D) Compare the timing of B and C.

COIS 2020H S61 – For Brian Srivastava
Your assignment files should be zipped into single file named your username.zip, and submitted on blackboard.
Questions 1 and 3 are programming questions and you should have a source file as well as testing documentation.
Assignments are to be done individually.
1. a) Write a program (including timing measurements) for the following scenario. Generate 20 million random numbers, one at a time, and insert them into an array that doubles every time it runs out of space (starting size of 2), into an array that can hold 20 million elements from creation, and a linked list that can hold 20 million elements. You should do this both for integers and floating point numbers. (The numbers should be regular integers or floats). Compare the time required for each of the six scenarios, and explain the differences. You will need to write your own way to double an array size (it’s up to you how to do this), don’t use an ArrayList.

READ ALSO :   Leo Tolstoy's War and Peace

b) Do a brute force in order search through each of these to find the largest number. Again, compare the timings for all 6 scenarios.
2. You do not need to implement this, just describe the algorithm.
a) Assume you have a robot with a light sensor and you want it to follow a trace (i.e. line) on the ground drawn with a thick marker. Design 2 different algorithms to follow this line and compare their efficiency. (The problem is a search one – if the line bends you need to find it again). Describe/draw/illustrate some worst, or at least bad cases and best case scenarios for your algorithms.
b) Consider the same problem but in 3 dimensions, e.g. a radar array (which produces something like a cone) searching through a sphere around an aircraft looking for incoming missiles or other aircraft.
3. Attached to this assignment is a file titled “A1BoyNames.txt” it is 536 lines long, but some lines have two names separated by a comma. Read in each name into a container structure of your choosing.
a. Using a binary search, and a hash function of some sort attempt to find the names Brian, Bryan, Iain, Ian, and Stefan.

b. Modify your program to search for partial matches (e.g. Bryant would match Bryan and Brian would match Ian).

This list was taken from http://www.world-english.org/boys_names_list.htm. You can manipulate the source data however you want to make it easier to read in.
Place this order with us and get 18% discount now! to earn your discount enter this code: special18 If you need assistance chat with us now by clicking the live chat button.