NOTE: You are NOT required to write a program for this problem. We wish to determine whether at least one three-of-a-kind exists in a hand of N cards, where a three-of-a-kind is three of the same value. Assume the cards have values 1 – 13. For example, the hand with card values {11, 5, 11, 5, 5} does have at least one three-of-a-kind. For each of the following algorithms (A and B), find the simplified total Big-O run time as a function of the number of cards (N). Explain your answers based on each of the bulleted items and how they contribute to the total run time.
Algorithm A:
• Create a “count” array of size N that stores, for each card in the hand, the number of cards with that card’s value. It is initialized to be filled with 1’s because we know there is at least 1 of each card.
• For each card in the hand:
- Compare its value to the value of every other card.
- Each time the two values match, increment the corresponding “count” element for this card.
• If at least one value in the final “count” array is 3 or greater, there is a three-of-a-kind because at least 3 cards match that given card’s value.
Example: With card values {11, 5, 11, 5, 5}, the values in the “count” array would become {2, 3, 2, 3, 3}, and there is at least one three-of-a-kind.
Algorithm B:
• Create a “count” array of size 13 that stores, for each possible card value, the number of cards in the hand that have that value (1 – 13). It is initialized to be filled with 0’s
• For each card in the hand with value v, use v-1 as an index to increment the corresponding element in “count”. For example, if a card has value 13, increment “count” element #12.
• If at least one value in the final “count” array is 3 or greater, there is a three-of-a-kind because at least 3 cards have that given value.
Example: With card values {11, 5, 11, 5, 5}, the values in the “count” array would become {0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 2, 0, 0}, and there is at least one three-of-a-kind.
Algorithm A :
Create a count array of size N and it is initially filled with 1s because there is atleast one of each card.
We have the array, hand, which is of size N.
Now we loop over the array hand,
for a_card in hand: We are looping over
for any_other_card in hand: the hand array
if a_card == any_other_card: twice. This runs in
increment count[a_card] and count[any_other_card] by 1 O(N2) time.
Now we search over the count array to check if any element is greater than or equal to 3. This is a linear search and it is performed in O(N) time.
Therefore, the total run time = O(N2) + O(N)
= O(N2) [from the definition of Big O notation]
Algorithm B:
Create an array of size 13 and it is initially filled with 0s.
We have the array, hand, which is of size N.
Now we loop over the array hand,
for a_card in hand: Here we are looping over
number = number on the card the hand array only once.
increment the value of (number-1) index of count array by 1 This runs in O(N) time.
Now we search over the count array to check if any element is greater than or equal to 3. This is a linear search and it is performed in O(N) time.
Therefore, the total run time = O(N) +O(N)
= O(N) [from the definition of Big O notation]
NOTE: You are NOT required to write a program for this problem. We wish to determine...
NOTE: You are NOT required to write a program for this problem. We wish to determine whether at least one three-of-a-kind exists in a hand of N cards, where a three-of-a-kind is three of the same value. Assume the cards have values 1 – 13. For example, the hand with card values {11, 5, 11, 5, 5} does have at least one three-of-a-kind. For each of the following algorithms (A and B), find the simplified total Big-O run time as...
Complete a program In C#: some code is included, you edit the areas that have not been filled. For your C# program you will complete code that plays the War card game. In this game, the deck of cards is evenly divided among two players. The players are not allowed to look at the cards in their hand. On each round of the game, both players lay down the top card from their hand. The player with the higher value...
Need help writing this program! Thanks in advance. Project4 Specifications: Determine Poker Hand A poker hand can be stored in a two-dimensional array. The statement: Dim aryintCards(4,14) as Integer (See AryCardExample.xlsx excel spreadsheet) declares an array which the first subscript 1-4 are the four suits and the second subscript ranges over the card denominations: 1-14: Ace, 2, ..., 10, Jack, Queen, King, Ace (repeated). First subscript of 0 is Total of each denomination. Second subscript of 0 is Total of...
required to write an assembly program to find the maximum of anarray of integers by doing the following:1. Prompt user to input array size n (n <= 10)2. Prompt user to input element values of array A one by one3. Display the result on the console.This program must at least include one function. The main program will read the valuesof the array (as user inputs the element values) and stores them in the memory (datasegments section) and at the end...
Write a Java program that reads 5 integers, each of which is in the range of 1 and 13 representing a simplified poker card with no suit. Your program should then print the ranking of the hand with card number(s) besides the ranking. The rankings to determine are Four of a Kind(4 of the 5 cards of the same rank), Full House(3 of the 5 cards of the same rank, and 2 cards of another rank), Straight(5 cards of sequential...
1. Write a static method named mode that takes an array of integers as a parameter and that returns the value that occurs most frequently in the array. Assume that the integers in the array appear in sorted order. For example, if a variable called list stores the following values: ist -3, 1, 4, 4, 4, 6, 7,8, 8, 8, 8, 9, 11, 11, 11, 12, 14, int 141i Then the call of mode (li array, appearing four times. st,...
Suppose you have a sorted array of positive and negative integers and would like to determine if there exist some value of x such that both x and -x are in the array. Consider the following three algorithms: Algorithm #1: For each element in the array, do a sequential search to see if its negative is also in the array. Algorithm #2:For each element in the array, do a binary search to see if its negative is also in the...
Suppose you have a sorted array of positive and negative integers and would like to determine if there exist some value of x such that both x and -x are in the array. Consider the following three algorithms: Algorithm #1: For each element in the array, do a sequential search to see if its negative is also in the array. Algorithm #2:For each element in the array, do a binary search to see if its negative is also in the...
"Red Dog" in C++
Problem 1 Red Dog (Points: 100/100) We will be writing a program that lets you play the game "Red Dog". A description of the game can be found here: https://en.wikipedia.org/wiki/Red dog_(card game). This is also sometimes termed an "in-between" Acey Deucey. Red Dog is a game that is played with a standard 52-card deck. Suits are not considered in the game, all that matters is the order of cards, which from high to low runs Ace...
Java programing Write a program that deals a deck of card into 4 hands – Each hand having 13 cards. The program should be doing the followings use an array to randomly select 52 cards and deal it into 4 hands. Print each hand unsorted Identify the face value of each hand and display it. You should create a class called Card, and all the methods should be defined within the card class. Hints – Import below java utility to...