Questions
def sequentialSearch(theList, item):     #**** to be changed:     # counts the iterations of the while...

def sequentialSearch(theList, item):
    #**** to be changed:
    # counts the iterations of the while loop and returns this value
    found = False
    index = 0
    while index < len(theList) and not found:
        if theList[index] == item:
            found = True
        index = index + 1  
    return found                  

def binarySearch(theList, item):
    #**** to be changed:
    # counts the iterations of the while loop and returns this value
    startIndex = 0
    endIndex = len(theList)- 1
    found = False
    while startIndex <= endIndex and not found:
        middleIndex = (startIndex + endIndex)//2
        if item == theList[middleIndex]:  
            found = True
        elif item > theList[middleIndex]:
            startIndex = middleIndex + 1
        else:                             
            endIndex = middleIndex - 1
    return found   

# program for testing the search algorithms
dataSet = [-200, -190, -180, -170, -160, -110, -105, -74, -30, -17, -12, -1, 4, 5, 13, 26, 37, 42, 62, 96, 100, 110, 120,130]

print("\nSuccessful sequential search - all elements of the data set")  
totalComparisons = 0
#**** to be completed:
#     list traversal on the dataSet list:
#     for each item: perform a sequential search and
#                    display the number of comparisons,
#     count the total number of comparisons
print("Average number of comparisons: "+str(totalComparisons/len(dataSet)))
  
print("\nUn-successful sequential search")
target = 196                 # target not in the dataSet
comparisons = 0 #**** to be changed: perform a sequential search for target
print ("target " + str(target), "\t comparisons used " + str(comparisons))

print("\nSuccessful binary search - all elements of the data set")
totalComparisons = 0
#**** to be completed:
#     list traversal on the dataSet list:
#     for each item: perform a binary search and
#                    display the number of comparisons,
#     count the total number of comparisons
print("Average number of comparisons: "+str(totalComparisons/len(dataSet)))

print("\nUn-successful binary search")
target = 196                 # target not in the dataSet
comparisons = 0 #**** to be changed: perform a binary search for target
print ("target " + str(target), "\t comparisons used " + str(comparisons))

make some change to the python according to the comment line and complete the following question.

Sequential Search Algorithm

Binary Search Algorithm

Successful searches

Successful searches

Average number of comparisons

Average number of comparisons

Maximum number of comparisons

found at index _____________

Maximum number of comparisons

found at index _____________

Minimum number of comparisons

found at index____________

Minimum number of comparisons

found at index____________

Un-Successful search

Un-Successful search

Number of comparisons

Number of comparisons

  1. What is the size n of the data set used?
  2. What is the worst case for sequential search?
  3. What is the best case for sequential search?
  4. Is the worst case for sequential search O(n)?
  1. What is the best case for binary search?
  1. What is the worst case for binary search?
  1. Is the worst case for binary search O(log n)?

In: Computer Science

Do the type-D and JK flip flops respond to the same clock edge? Explain how toggle...

Do the type-D and JK flip flops respond to the same clock edge?

Explain how toggle mode is the same as division by two.

What is the difference between a synchronous input (D, J, or K) and an asynchronous input (PR or CLR)?

*please no handwritten answers

In: Computer Science

Table Product: PROD_ID PROD_NAME PROD_PRICE PROD_VENDOR 1101 Table 100 2 1102 Chair 80 3 1103 Armchair...

Table Product:

PROD_ID

PROD_NAME

PROD_PRICE

PROD_VENDOR

1101

Table

100

2

1102

Chair

80

3

1103

Armchair

90

2

1104

Nightstand

110

1

1105

Bed

200

3

1106

Dresser

150

3

1107

Daybed

190

2

1108

Ash Table

120

2

1109

Cherry Table

130

2

1110

Table - High

100

2

1111

Office Chair

110

3

Table Vendor:

VEND_ID

VEND_NAME

VEND_ST

1

Green Way Inc

GA

2

Forrest LLC

NC

3

AmeriMart

NC

Please write the SQL script and provide screenshots of results for these below queries. Please include the SQL in text format, and all screenshots in one single document.

  1. Find the total number of table products
  2. Find the average price of all tables
  3. Find the total number of products from each vendor
  4. Find the average prices by vendors (please include vendor names in the query result)
  5. Find the average prices by states

In: Computer Science

Language: C++ In your main(), use printf() to print out the floating point values for some...

Language: C++
In your main(), use printf() to print out the floating point values for
   some hex data.
   a. To print 1.0, do
         printf("One:      %f\n",0x3FF0000000000000);
      The compiler will give you a warning about the argument being a different
      type than the format, but that is ok.
   b. To print 2.0, do
         printf("Two:      %f\n",0x4000000000000000);
      Remember, to multiply by two, you just add one to the exponent.
   c. Print 4.0, 8.0, and 16.0 (with nice labels, of course).
   d. We can also go the other way. To divide by two, just decreas the 
      exponent by one.  So for 1/2, do
         printf("Half:     %f\n",0x3FE0000000000000);
   e. Print 1/4, 1/8, 1/16.
   f. Negative values have a 1 in the leading bit instead of 0.  A leading 1
      in the bits for a hex digit has value 8, so -1.0 is BFF0000000000000.
      So to print -1.0, do
         printf("Neg One:      %f\n",0xBFF0000000000000);
   g. Print -2, -4, -8, -1/2, -1/4, -1/8 (with nice labels, of course).

In: Computer Science

In a BestFriendSimulation driver class, define and initialize a reference variable called myBestFriends referencing an ArrayList...

In a BestFriendSimulation driver class, define and initialize a reference variable called myBestFriends referencing an ArrayList ofBestFriend objects. Then, create a menu that will continue to display itself, and process the requests of the user, until the user requests to exit the menu (loop).

The menu should have 5 menu options:

1.) Add a BestFriend to the arrayList called myBestFriends; 2.) Change a BestFriend in the arrayList; 3.) Remove a BestFriend from the arrayList; 4.) Display all the objects in the myBestFriends arrayList. 5.) Exit

For each of these menu options, be sure to prompt the user for the necessary information such as BestFriend's first name, last name, nickname, and cell phone number.

Hint: In order to be able to change a BestFriend's information or remove a BestFriend from the arrayList, you will have to create a loop that will search the myBestFriends arrayList from beginning to end, and store the index position of the BestFriend that will be updated or removed. If the desired BestFriend is not found, a -1 will be returned from the search, or a not found flag will be set. If the BestFriend is found, use that index position to either change or remove that object from the myBestFriends arrayList.

Make sure you test each of your menu options, and then select the option that prints the table immediately afterwards, to ensure the PhoneBook looks correctly.

1. Create the BestFriend Domain Class
Define and/or instantiate the private static and non-static fields.

Create the constructor

public class BestFriend

{ private static int friendNumber = 0;

     private int friendIdNumber;

     private String firstName;

     private String lastName;

     private String nickName;

     private String cellPhoneNumber;

     public BestFriend (String aFirstName, String aLastName, String aNickName, String aCellPhoneNumber)

    {    firstName = aFirstName;

         lastName = aLastName;

         nickName = aNickName;

         cellPhoneNumber = aCellPhoneNumber;
friendNumber++;

friendIdNumber = friendNumber;

    }

    public String toString( )

    {   

         return friendIdNumber + ". " + nickName + " "  + firstName + " " + lastName + " " + cellPhoneNumber;

    }


Create the set methods (setters)
Create the get methods (getters)

public boolean equals(Object another)
{
      if (another instanceof BestFriend )
     {


     BestFriend anotherBFF = (BestFriend) another;
      if (firstName.equalsIgnoreCase(anotherBFF.firstName) &&
          lastName.equalsIgnoreCase(anotherBFF.lastName)
   //     && nickname.equalsIgnoreCase(anotherBFF.nickName) &&
   //      cellphone.equalsIgnoreCase(anotherBFF.cellPhone))
              return true;
}

         return false;

}





2. Create the BestFriendSimulation Driver Class:
Instantiate an arrayList  called myBFFs

Create a Do …… While loop to create a menu of 5 choices (add, change, remove, display, exit)
Allow the user to input the choice.
Use an if statement (or switch) to execute the user’s choice.

There are many ways to accomplish this task:

Technique #1.) Create a Helper class that defines the arrayList of BestFriends in its constructor, and then also defines the add, change, display, remove, and error methods as instance methods. Instantiate the Helper class from the driver (main) class. Also in the driver class, create the loop to display and process the menu options. When any specific menu option is selected, call the method from the Helper class.

Technique #2.) Instantiate the driver class in the main method (instantiate its own self). Then, define instance methods in the driver class for the add, change, display, remove, and error methods. Call them from the menu loop.

Technique #3.) In the driver class, create static methods for the add, change, display, remove, and error methods. Call them from the menu loop.

In any of the above 3 techniques, the arrayList of BestFriends can be defined as a global variable, so that it does not have to be passed as a parameter to each of the add, change, display, remove, and error methods. Similarly, the Scanner keyboard object should also be defined as a global variable too.

The alternative to defining the arrayList and Scanner keyboard as global variables is to pass these as parameters to each method call. For example:

addBFF(myBFFs, keyboard);

In: Computer Science

Intro to Python 1. Draw a structure chart for one of the solutions to the programming...

Intro to Python

1. Draw a structure chart for one of the solutions to the programming projects of Chapters 4 and 5. The program should include at least two function definitions other than the main function.

2.Describe the processes of top-down design and stepwise refinement. Where does the design start, and how does it proceed?

In: Computer Science

// C++ Doubly linked list class clinknode{ friend class DList; public:     clinknode(){next = prev=0;data =0;}...

// C++ Doubly linked list

class clinknode{

friend class DList;

public:

    clinknode(){next = prev=0;data =0;}

protected:

    clinknode *next;

    clinknode *prev;

    int data;

}

class DList{

public:

DList(){first = last = 0;}

void insertFront(int key);

bool found(int key){ return search(key)!=0;}

void deleteAll(int key);

// other list functions...

private:

clinknode *search(int);

clinknode *first;

clinknode *last;

}

(20 points) Write the code for the deleteAll (int key) member function. It takes a key value and deletes all of the data in the list with that value. Make sure to preserve the integrity of the list. If no member with that value is in the list, this function should do nothing.

In: Computer Science

This is done using Visual Basic. Add three text boxes and three buttons to the form....

This is done using Visual Basic.

Add three text boxes and three buttons to the form. Set the second and third text boxes' Multiline, ReadOnly, and ScrollBars properties to True, True, and Vertical, respectively. The user will enter a number in the first text box and them click the first button. The first buttons click event procedure should write the number on a seperate line in a sequential access file. The second button's click event procedure should read the entire sequential access file at once, and display the file's contents in the third text box; display each number on a separate line. Code the procedures. Save the solution and start the application. Use the first button to write any six numbers to the file. Then, use the second and third buttons to display the contents of the file in their respective text boxes. Close the solution.

In: Computer Science

Use nested for loops to generate the following patterns: C++ ***** ***** ***** (no space between...

Use nested for loops to generate the following patterns: C++

*****

*****

*****

(no space between rows of asterisks)

*

**

***

****

*****

(Again, no empty lines between rows)

*

**

***

**

*

(no lines between rows)

Last one, let the user pick the pattern by specifying the number of rows and columns.

In: Computer Science

In C#, declare structure named Person. The structure should have the following attributes of first name,...

In C#, declare structure named Person. The structure should have the following attributes of first name, last name, zip code, and phone number.

In: Computer Science

CSS and HTML multiple choice Which of the following are true for vector images? They have...

CSS and HTML multiple choice

Which of the following are true for vector images?

They have to be rasterized eventually.

They are good for photorealism.

They are good for drawing shapes and logos.

They are stored inefficiently.

They are resolution independent.

They are effectively bitmaps.

They are stored efficiently.

In: Computer Science

using Java progam Q1: What will be the value of x after the following code is...

using Java progam
Q1: What will be the value of x after the following code is executed?

int x = 10;

while (x < 100)

{

x += 100;

}

Q2: What will be the value of x after the following statements are executed?

int x = 10;

switch (x)

{

case 10:

x += 15;

case 12:

x -= 5;

break;

default:

x *= 3;

}

Q3: What is the output of the following progm?
public static void main(String [] args) {
System.out.print("A");
processRequest();
System.out.print("B");
System.out.print("C");
showMenu();
System.out.print("D");
}
public static void showMenu() {
System.out.print("Q");
}
public static void eraseFile()
{
System.out.print("T");
}
public static void processRequest()
{
System.out.print("2");
}

Q4: Write a method declaration called discount which accepts 2 integers as the formal parameters. The two parameters represent the original price and sale price. The method returns the discount value i.e. the difference between the original price and sale price as an integer.

Q5: Write a program that takes two integer variables and prints the largest number using if-else statements.

Q6: public static ______testNumber(int x)
{
if ( x<100 )

{
return "The number is less than 100";
}

else

{
return "The number is greater or equal 100";

}
}

Q7: Write a program using a conditional operator (&&, ||, !)

1. which takes input from user for variables x and y.

2. it should give an output if and only if two numbers are equal, otherwise prompt message numbers are not equal.

Q8: Write a program to print a table of two using a loop.

Q9: Is the call to the method installApplication() below, valid?: Yes/No?

public static void main(String [] args)

{
installApplication("Angry Birds", "version 1.2");
}
public static void installApplication(String appName, int appVersion)

{
// rest of method not important
}

Q10: What will be the values of ans, x, and y after the following statements are executed?

int ans = 35, x = 50, y = 50;

if (x >= y)

{

ans = x + 10;

x -= y;

}

else

{

ans = y + 10;

y += x;

}

In: Computer Science

Write a Java method that removes any duplicate elements from an ArrayList of integers. The method...

Write a Java method that removes any duplicate elements from an ArrayList of integers. The method has the following header(signature):

public static void removeDuplicate(ArrayList<Integer> list)

Write a test program (with main method) that prompts the user to enter 10 integers to a list and displays the distinct integers separated by exactly one space. Here is what the input and output should look like:

     Enter ten integers: 28 4 2 4 9 8 27 1 1 9

     The distinct integers are 28 4 2 9 8 27 1

In: Computer Science

(YOU don't need to write the client class I already have it, just need this) You...

(YOU don't need to write the client class I already have it, just need this)

You are provided with Main.java that is a client for this program.

You will create THREE files-- GameCharacter.java, ShieldMaiden.java, and Dragon.java

First: You must Create an interface called GameCharacter WITH JUST PROTOTYPES, NO IMPLEMENTATIONS

A GameCharacter has a few functions associated with it

1) takeHit: decreases the character's health. It should return an int representing damage taken (hit points)

2) heal: increases the character's health. Should return an int representing amount healed (i.e. hit points)

3) getHealth: returns the total current health the character has (i.e. hit points)

4) isAlive: determines if the character is dead. Should return true if the character is dead, and false if not.

Second: Then create two classes. One should be named Dragon, and the other should be named ShieldMaiden (i.e. warrior) that IMPLEMENT Game Character. Give them each private variables for health. The constructor should take in an initial amount to set health to.

Third: Implement the interface functions for these two classes (Dragon and ShieldMaiden). To make the game more interesting, the dragon's takeHit should hurt the dragon a random number from 10 to 20 inclusive and the ShieldMaiden's takeHit should hurt the shieldMaiden a random number from 15 to 25 inclusive. Furthermore, the dragon's heal should only heal the dragon a random number from 1 to 10 inclusive but the ShieldMaiden's heal should heal the ShieldMaiden a random number from 8 to 20 inclusive. A character is dead when they get negative health.

In: Computer Science

planning and strategic planning

planning and strategic planning

In: Computer Science