Question

In: Computer Science

[Point: 10] The instance of a list ADT using array is L = (10, 20, 30,...

  1. [Point: 10] The instance of a list ADT using array is L = (10, 20, 30, 40, 50, 60). Find the output of following code segment or what is returned by each statement.

remove(30);         

find(50):               

insert(7, 3):          

findKth(4)            

  1. [Point: 5] The complexity of remove operation from a LIST ADT using array implementation is O(N). Explain why?
  2. [Point: 10] Show that the running time for the following segment of code is O(N3) without using the rule for loop. Make sure to count each statement that takes one unit of time.

sum = 0;

for( i = 0; i < n; i++ )

for( j = 0; j < n; j++ )

            for( k = 0; k < n; k++ )

sum++;

Solutions

Expert Solution

Answer 1) :

remove(30) : it return the list array after removeing 30 .

[ 10, 20, 40, 50, 60]

find(50) : it return the position of 50 in array means 5.

insert(7, 3) : it return an array list after insert 7 at 3rd position.

[ 10, 20, 7, 30, 40, 50, 60]

findKth(4) : it return the value of 4th position in list array. means 40.

Answer 2) : The complexity of remove operation is O(n) because first it search the element in array list then delete this element, so, it will O(n).

For example : remove(30) : first it search the element 30 in array in O(n) time and delete the element in O(1) time and then shift the element of array in O(n) time. So, the total time is O(n)+O(1)+O(n) = O(n).

Answer 3) :

sum = 0;

for( i = 0; i < n; i++ )

for( j = 0; j < n; j++ )

            for( k = 0; k < n; k++ )

sum++;

Proof :

i = 0, j = 0, k = 0 to k = n (n times)

i = 0, j = 1, k = o to k =n (n times)

.

.

.

i = n, j = n, k = 0 to k = n (n times)

so, the sum++ statement will execute n^3 times . so the complexity = O(N^3).


Related Solutions

Write an array-based implementation of the ADT list that expands the size of the array of...
Write an array-based implementation of the ADT list that expands the size of the array of list entries as needed so that the list can always accommodate a new entry. Also reduce the size of the array as needed to accommodate several removals. When the size of the array is greater than 20 and the number of entries in the list is less than half the size of the array, reduce the size of the array so that it is...
Implement a Bag ADT using Dynamic Array structure as underlying data storage for Bag ADT. RESTRICTIONS:...
Implement a Bag ADT using Dynamic Array structure as underlying data storage for Bag ADT. RESTRICTIONS: Not allowed to use ANY built-in Python data structures and their methods. You must solve by importing the DynamicArray class and using class methods to write solution. Also not allowed to directly access any variables of the DynamicArray class (like self.size, self.capacity and self.data in part 1). All work must be done by only using class methods. Below is the Bag ADT starter code...
1. Implement the graph ADT using the adjacency list structure. 2. Implement the graph ADT using...
1. Implement the graph ADT using the adjacency list structure. 2. Implement the graph ADT using the adjacency matrix structure. LANGUAGE IS IN JAVA Comment for any questions Data structures and algorithms
In C++ write an implementation of the ADT sorted list that uses a resizable array (vector...
In C++ write an implementation of the ADT sorted list that uses a resizable array (vector class of C++ STL) to represent the list items.
Question: Write an implementation of the ADT sorted list that uses a resizable array (vector class...
Question: Write an implementation of the ADT sorted list that uses a resizable array (vector class of C++ STL) to represent the list items. Anytime the list becomes full, double the size of the array.
3.1 Implement the stack ADT using array (4 marks) 3.1.1 Implement the pop() operation in the...
3.1 Implement the stack ADT using array 3.1.1 Implement the pop() operation in the stack (1 mark) Implement a stack class named Stack2540Array using array. The starter code is as follows. The instance variables and most operations are provided. You need to implement the pop operation. Make sure that your program checks whether the stack is empty in the pop operation. import java . io .*; import java . util .*; public class Stack2540Array { int CAPACITY = 128; int...
Implement the ADT character string as the class LinkedString by using a linked list of characters....
Implement the ADT character string as the class LinkedString by using a linked list of characters. Include the following LinkedString constructors and methods: LinkedString(char[] value) Allocates a new character linked list so that it represents the sequence of characters currently contained in the character array argument. LinkedString(String original) Initializes a new character linked list so that it represents the same sequence of characters as the argument. char charAt(int index) Returns the char value at the specified index. The first character...
Classes (Percentage) No of Students 0 < 10 10 10 < 20 20 20 < 30...
Classes (Percentage) No of Students 0 < 10 10 10 < 20 20 20 < 30 25 30 < 40 15 40 < 50 20 50 < 60 35 60 < 70 45 70 < 80 10 80 < 90 15 90 < 100 5 2.1 Determine the: 2.1.1 Mean number of marks (1 mark) 2.1.2 Median number of marks 2.1.3 Modal number of marks 2.2 Calculate the standard deviation
Implement a Priority Queue (PQ) using an UNSORTED LIST. Use an array size of 10 elements....
Implement a Priority Queue (PQ) using an UNSORTED LIST. Use an array size of 10 elements. Use a circular array: Next index after last index is 0. Add the new node to next available index in the array. When you add an element, add 1 to index (hit max index, go to index 0). Test if array in full before you add. When you remove an element, from the list, move the following elements to the left to fill in...
Please write in JAVA 1. Given the following array-based ADT list called colorList whose elements contain...
Please write in JAVA 1. Given the following array-based ADT list called colorList whose elements contain strings             red, orange, yellow, blue, indigo, violet write the statement to insert the String element “pink” to the end of the list. Assume the front of the list is on the left. 2. Outline the basic steps to remove a node from the beginning of a list. Completed answers will be given an immediate upvote :)
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT