data structures and algorithms:#
For each of your solutions please provide a short explanation as to why you believe your solution works properly. This is not formally required, so I will not reduce marks if you choose not to provide any explanations. However, in case the explanations are provided, my feedback will be more meaningful as I will be able to see your line of thought.
1 Most frequently occurring number:
Design an O(n) algorithm whose input is a sorted array A of integer numbers. The program should print the most frequent element of A. For example, in the array A = [1,2,2,5,7,7,7,8], 1 occurs once, 2 occurs twice, 5 occurs once, 7 occurs three times,and 8 occurs once. Hence, the most frequently occurring element is 7. If there are two or more most frequently occurring elements, the algorithm can be print anyone of them (e.g. the first one).
Solution to Question 1
2 Number of distinct elements in a sorted array
Design an O(n) algorithm whose input is a sorted array A of integer numbers. The program should print the number of distinct elements of A. For example, in the array A = [1,2,2,5,7,7,7,8], as in the previous section, the number of distinct elements is 5 which are 1,2,5,7,8.
Solution to Question 2
3 Number of distinct elements in an arbitrary array
Design an O(n2) algorithm whose input is an array A of integer numbers (not necessarily sorted). The program should print the number of distinct elements of A
Solution to Question 3
4 Three distinct elements of a sorted array
Design an O(logn) algorithm whose input is a sorted array A of integer numbers. The algorithm should print YES if A contains at least 3 distinct numbers and NO otherwise. Hint: Compare the first and the last elements and then use binary search.
DescriptionIn this final assignment, the students will demonstrate their ability to apply two ma
Path finding involves finding a path from A to B. Typically we want the path to have certain properties,such as being the shortest or to avoid going t
Develop a program to emulate a purchase transaction at a retail store. Thisprogram will have two classes, a LineItem class and a Transaction class. Th
1 Project 1 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of
1 Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of