Question

Interfaces 1. What is inside an interface definition? What does a class do to an interface...

Interfaces

1. What is inside an interface definition? What does a class do to an interface and what keyword is involved? How does a class do this to an interface (what should we find in the class)? Can an interface have a generic parameter? How do you instantiate an interface as an object? What methods can’t you use on an interface type?

Abstract Data Types
2. What does an ADT define? Does an ADT specify programming language and/or data structures to be used? What 2 data structures could did we learn we could use to implement a list ADT?

Searching and Big O
3. Explain in English how one does a binary search? If I was to Binary search an array for a particular number what must be true about the array before I start the binary search? What is the Big O of binary search? How does this differ from the Big O of a linear search? If I have a sorted array, in ascending order, and I want to search for the 5th biggest element in it, what is the Big O of this algorithm? If I have a sorted linked list, in ascending order, and I want to find the 5th biggest element in it, what is the big O of this algorithm? If I have a 2 Dimensional Array of size N by N unsorted, what is the Big O of finding a particular value in this 2 dimensional Array? What about a 3 dimensional Array of size N by N by N unsorted?

Recursion
4. How can we tell if a function is recursive? What must every recursive function have to ensure no infinite recursion? Write the recursive function to do factorial.

Sorting
5. What is the algorithm for bubble sort? What is the algorithm for Bucket Sort with arrays? What is the algorithm for Selection sort? What is the Big O of bubble and selection sort? What is the algorithm for shell sort and what is the optimization for shell sort and what is the Big O of shell sort with this optimization step? What is the recursive algorithm for merge sort? What are the 2 parts to MergeSort and Where does the recursive step occur? In the merging step, are the two arrays being merged already in sorted order (i.e. if we are merging array A and array B, is array A already sorted and is Array B already sorted?). What is the Big O of merge sort

Generics
6. Why are Generics important in Java, specifically, what do they allow us to do? What can you pass in for a Generic? What 2 functions have we learned that are guaranteed to be callable on a Generic type? How do we create an array of a Generic type?

List ADT, Array Implementation, and Linked Lists
7. What functionality is outlined in the List ADT. Implementing a List as a partially filled array in java, what will be your private variables? What two things does a Node have inside of it? What is a private inner class and why is node a private inner class in Linked List? What are the restrictions of creating an object of a private inner class (can a node object be created in main? If not where can it be created?). What is the beginning of the linked list called? What is the end of the linked list called? How can you tell if a node is the last node in a linked list? How can you find the first node in a linked list? What does an empty list look like? How do you traverse a linked list to (for example) print out all the contents of the linked list? What kind of loop do you use? What special cases must you check for when looping through a linked list?

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Q1 /Answer

Interface: an interface is a java concept which is used to implement abstraction. in an interface by deafault all methods are abstract. We camn not create an object of an interface. interface are always implemented in a java class.

Yes interface can be of generic type. Example of such interfaces are Comparable, Comparator

static methods are not allowed in interfaces.

an interface can contain public static final variables and abstract methods.

syntex

interface A

{

//abstract methods

}

class B implements A

{

//override unimplemented methods of A

}

Question 2 What does an ADT define? Does an ADT specify programming language and/or data structures to be used? What 2 data structures could did we learn we could use to implement a list ADT?

ADT: long form of ADT is Abstract Data Type . Here ADT means a concept which can be implemented in many ways. a data type which can be applicable on certain situation. the example of ADT are Arrays, Stack, Queue, LinkeList. yes an ADT specify data structure to be used like Stack is an ADT and also is a data structure. To implement a list ADT you can use Array and Link List datastructure.

Answer 3

A binary search or half-interval search algorithm finds the position of a specified value within a sorted array. In each step, the algorithm Compares the input key value with the key value of the middle element of the array. If the keys match, then a matching element has been found so its index, or position, is returned.

Algorithm

Binary Search ( int A[N] ):

Description: Here A is a sorted array having N elements. ITEM is the value to be searched. BEG denotes first element and END denotes last element in the array. MID denotes the middle value.

1.Set BEG = 1 and END = N

2.Set MID = (BEG + END) / 2

3.Repeat While (BEG <= END)and (A[MID]≠ITEM)

  1. If (ITEM < A[MID]) Then
  2. Set END = MID –1
  3. Else
  4. Set BEG = MID + 1

[End of If]

  1. Set MID = (BEG + END) / 2 [End of While Loop]
  2. If (A[MID] == ITEM) Then
  3. Print: ITEM exists at location MID
  4. Else
  5. Print: ITEM doesn‘t exist

[End of If]

13.Exit

The time complexity of binary search is O(log n)

using linked list time to find any element is O(1) in constant time.

4. How can we tell if a function is recursive? What must every recursive function have to ensure no infinite recursion? Write the recursive function to do factorial.

Answer

Recursive Function:

A function is said to be recursive if it calls itself.

every recursive function has some iteration . In each iteration it makes call to itself and there is always a termination condition to prevent infinite recursion.

consider following program of factorial using recursive function:

public class Factorial {

public static void main(String[] args)
{
Scanner sc= new Scanner(System.in);
System.out.print("enter the number);
num=sc.nextInt();
long factorial = fact(num);
System.out.println("Factorial of " + num + " = " + factorial);
}
public static long fact(int num)
{
if (num >= 1)
return num * fact(num - 1);
else
return 1;
}
}
Answer 5

1. Bubble Sort:

Bubble sort is a simple sorting algorithm. It works by repeatedly stepping through the list to be sorted, comparing two items at a time and swapping them if they are in the wrong order. The pass through the list is repeated until no swaps are needed, which indicates that the list is sorted. The algorithm gets its name from the way smaller elements "bubble" to the top of the list. Because it only uses comparisons to operate on elements, it is also known as comparison sort.

Algorithm: Bubble Sort( int A[ ] ):

Description: Here A is a n unsorted array having N elements.

1.Repeat For J = 1 to N

  1. Repeat For K = 1 to N-J
  2. If (A[K] > A[K+1])Then
  3. Interchange A[K] and A[K+1] [End of If]

[End of Step 2 For Loop]

[End of Step 1 For Loop]

5.Exit

Selection sort Algorithm:

Selection Sort ( int A[] ):

Description: Here A is a n unsorted array having N elements. 1.Repeat For J = 1 to N

  1. Set MIN = J
  1. Repeat For K = J+1 to N
  2. If (A[K] < A[MIN]) Then
  3. Set MIN = K

[End of If]

[End of Step 3 For Loop]

6.        Interchange A[J] and A[MIN]

[End of Step 1For Loop] 7.Exit

Time complexity of merge sort is O(nlogn ) in all cases

Add a comment
Know the answer?
Add Answer to:
Interfaces 1. What is inside an interface definition? What does a class do to an interface...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • SHORT ANSWER QUESTIONS Part 1 Classes Abstraction: What is Abstraction in terms of representation? Specifically what...

    SHORT ANSWER QUESTIONS Part 1 Classes Abstraction: What is Abstraction in terms of representation? Specifically what choices does one make when creating a class that is an example of Abstraction? Encapsulation: What is encapsulation? What is information hiding? What does a public interface to a class consist of (not in the sense of actual java interfaces but what the client uses to manipulate objects of the class) What is an object of a class? What is the constructor? How do...

  • 6 6. Merge Bubble Sort: a) How does the merge bubble sort break the array into...

    6 6. Merge Bubble Sort: a) How does the merge bubble sort break the array into sublists? b) What does it need to use for each sublist and then what does it do with all of the sublists? c) What is the Big-O notation for this sort? 7. Merge Sort: a) How does the merge sort use recursion to break the array into sublists? b) What happens to each of these sublists to get the final sorted list? c) What...

  • Program this in C There is a lot of sorting algorithms. So far, we have covered...

    Program this in C There is a lot of sorting algorithms. So far, we have covered selection and insertion sort. However, we only covered how selection sort is implemented using an array. Every sorting algorithm implemented using an array can also be implemented using a linked list. In this assignment, you will implement the selection sort algorithm using a linked list instead of an array. You will first create an interface for handling string items. Basically, you will need to...

  • //Generic interface that describes various searching and sorting //algorithms. Note that the type parameter is unbounded....

    //Generic interface that describes various searching and sorting //algorithms. Note that the type parameter is unbounded. However, //for these algorithms to work correctly, the data objects must //be compared using the method compareTo and equals. //In other words, the classes implementing the list objects //must implement the interface Comparable. The type parameter T //is unbounded because we would like to use these algorithms to //work on an array of objects as well as on objects of the classes //UnorderedArrayList and...

  • 1. What is the worst case time complexity of insertion into a binary search tree with...

    1. What is the worst case time complexity of insertion into a binary search tree with n elements? You should use the most accurate asymptotic notation for your answer. 2. A binary search tree is given in the following. Draw the resulting binary search tree (to the right of the given tree) after deleting the node with key value 8. 10 3. You have a sorted array B with n elements, where n is very large. Array C is obtained...

  • the two problems are related. Please explain your answer in full detail Problem 1: On input...

    the two problems are related. Please explain your answer in full detail Problem 1: On input a Binary Search Tree T show how to output an array that contains all the elements in T in sorted order. What's the running time of your algorithm? Does it perform any comparisons? Problem 2: Your classmate claims that they have an algorithm that on input n elements, constructs a Binary Search Tree T with those n elements using only O(n) comparisons. Can you...

  • Can you please help with the below? 1)   Which of the following is true about using...

    Can you please help with the below? 1)   Which of the following is true about using a 2-3-4 tree? a.   It is designed to minimize node visits while keeping to an O(log n) search performance b.   It is designed to self-balance as new values are inserted into the tree c.   As soon as a node becomes full, it performs the split routine d.   None of the above 2)   Which of the following is true about a binary search tree? a.  ...

  • Sorting Threads Assignment Overview Write a multithreaded sorting program in Java which uses the ...

    Sorting Threads Assignment Overview Write a multithreaded sorting program in Java which uses the merge sort algorithm. The basic steps of merge sort are: 1) divide a collection of items into two lists of equal size, 2) use merge sort to separately sort each of the two lists, and 3) combine the two sorted lists into one sorted list. Of course, if the collection of items is just asingle item then merge sort doesn’t need to perform the three steps,...

  • Question 7 0 / 10 points What is a Java Interface and what role can it...

    Question 7 0 / 10 points What is a Java Interface and what role can it have in developing Data Structures? Support your answer with an example of such an interface. No text entered - Question 8 (10 points) What is meant by a static data structure? In your opinion, what are the advantages and disadvantages of such structures? Do you feel that the advantages outweigh the disadvantages? Question 9 0 / 10 points Describe the basic operations that can...

  • 1. a. Using C++, represent the following graph using adjacency matrix, and implement depth first searching...

    1. a. Using C++, represent the following graph using adjacency matrix, and implement depth first searching (DFS) by stack (define it with class) to traverse the graph. 6 7 2 4 b. If starting with node 2, when node 7 is printed, what numbers are in the stack (for DFS)? Please draw the stack step by step to show how the numbers are pushed into and popped out of it. 2. a. Given a set of integer numbers as int...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT