This strategy is doomed to fail since it misses on the fact that there can be an element in both left half and right half such that its total frequency exceeds those of individual modes of left half and right half. Consider the array :
left half right half

The left half has mode 2(frequency 3), & the right half has mode 5(frequency 3), So his algorithm would consider 2 & 5 for overall mode, however it is to be noted that the element 3 has overall frequency 4, which should make it the mode despite having lower frequencies in left and right sub arrays. Morever since, the function only returns mode and not its frequency, we have no means of deciding whether the mode from left half has more frequency than the mode in right half or vice-versa.
The problem with this algo is as we continue to subdivide arrays, it will only give correct result if the mode occurs at consecutive places:
| Recursion level 0 | 1 2 2 3 3 2 3 3 5 5 5 1 | |||||||||||
| Recursion level 1 | 1 2 2 3 3 2 | 3 3 5 5 5 1 | ||||||||||
| Recursion level 2 | 1 2 2 | 3 3 2 | 3 3 5 | 5 5 1 | ||||||||
| Recursion level 3 | 1 | 2 2 | 3 | 3 2 | 3 | 3 5 | 5 | 5 1 | ||||
| Recursion level 4 | 1 | 2 | 2 | 3 | 3 | 2 | 3 | 3 | 5 | 5 | 5 | 1 |
Thus we keep recurring as above table until finally we get subarray of size 1. But, now what? These individual subarrays of size 1 would have mode same as their only element. Combining them to get mode of subarray of size 1 or subarray of size 2 with same elements would work fine, but it won't work other wise. Consider these case of recorsion level 3:
CASE 1: We have subarray [1], since it is the only element, the mode would be 1.
CASE 2: We have subarray [2,2], which is divided as [2] & [2], each having mode 2 and this could be aggregated to get overall mode 2.
CASE 3: We have subarray [3,2], which is divided as [3] & [2], having mode 3 & 2 respectively. Now we have an ambiguity to chose whether 3 or 2 or both as the mode for the subarray of size 2. This is where the algorithm would fail.
Thus the ambiguity in aggregating the mode from left half & right half dooms this algorithm to fail.
1) (5 pts) Consider the problem of finding the mode (most frequently occurring value) in an...
Attempts: Score:/1 11. Chapter aseb06t, Section .3, Problem 022 The most frequently occurring value of a data set is called the a. mean b. mode Oc. None of the other answers are correct. d. range
Problem 5: Gambler's Ruin Our old friend John Doe who tried his luck at blackjack back in Homework 2 now decides to win a small fortune using slot machines mstead. Having ganed some wisdom from his previous outings, he starts off small with just one dollar. He plays the slot machines in the following way He always inserts one dollar into the slot machines After playing it, the machine returns two dollars with probability p and returns nothing with probability...
This lab will use 2D arrays, recursive algorithms, and logical thinking. The following grid of hashes(#) and dots(.) is a 2D array representation of a maze # # # # # # # # # # # # # . . . # . . . . . . # . . # . # . # # # # . # # # # . # . . . . # . # # . . . . #...
Problem 5: Recurrence relations and detailed analysis of recursive algorithm efficiency g(n: non-negative integer) 1. if n ≤ 1 then return n 2. else return (5 * g(n─1) ─ 6 * g(n─2)) MergeSort divides the array to be sorted into two equal halves, calls itself recursively on each half to sort that subarray, and then calls the Merge algorithm to merge the two sorted halves in linear time. This leads to its two recurrence relations T(n)=2T(n/2)+cn, n>1;...
18.1 Lab Lesson 11 (Part 1 of 1) Part of lab lesson 11 There in one part to lab lesson 11. The entire lab will be worth 100 points. Lab lesson 11 part 1 is worth 100 points For part 1 you will have 80 points if you enter the program and successfully run the program tests. An additional 20 points will be based on the style and formatting of your C++ code. Style points The 20 points for coding...
please explain/ comment
3. Eight Queens Write a program that places eight queens on a chessboard (8 x 8 board) such that no queen is "attacking" another. Queens in chess can move vertically, horizontally, or diagonally. How you solve this problem is entirely up to you. You may choose to write a recursive program or an iterative (i.e., non-recursive) program. You will not be penalized/rewarded for choosing one method or another. Do what is easiest for you. 3.1. Output Below...
The Problem A robot is asked to navigate a maze. It is placed at a certain position (the starting position) in the maze and is asked to try to reach another position (the goal position). Positions in the maze will either be open or blocked with an obstacle. Positions are identified by (x,y) coordinates. At any given moment, the robot can only move 1 step in one of 4 directions. Valid moves are: ● Go North: (x,y) -> (x,y-1) ●...
hello there, i have to implement this on java processing. can someone please help me regarding that? thanks War is the name of a popular children’s card game. There are many variants. After playing War with a friend for over an hour, they argue that this game must never end . However! You are convinced that it will end. As a budding computer scientist, you decide to build a simulator to find out for sure! You will implement the logic...
================Data Structures C++=============== – Implement the Eight Queens Problem This is an object oriented program. This is #1 on page 187 of your book with ONE difference, I’m requiring you add a client program to test your code (a main). If you have the old book the question says “Complete the Queen and Board class for the Eight Queens problem.” On page 179 of your book is a function placeQueens that solves the Eight Queens problem. On page 180 of...
Assignment 2 In this assignment, you will write two short programs to solve problems using recursion. 1. Initial Setup Log in to Unix. Run the setup script for Assignment 2 by typing: setup 2 2. Towers of Hanoi Legend has it that in a temple in the Far East, priests are attempting to move a stack of disks from one peg to another. The initial stack had 64 disks threaded onto one peg and arranged from bottom to top by...