Question

In: Computer Science

Q1 A- How linear search and binary search work? What is their time complexity? B- What...

Q1

A- How linear search and binary search work? What is their time complexity?

B- What is a single linked list? What are the pros and cons of the linked list when comparing to parallel arrays?

Q2

A- What is a register? How registers work together with ALU and Control Unit to execute a program? What is the fetch-execute cycle?

B- What is the difference to implement a control unit using microprogrammed or hardwired approaches? What is clock cycle? What are different addressing modes?

Solutions

Expert Solution

Q1)

A)

Linear search and binary search:


The linear search is a searching algorithm that is used to search for an element in the given data structure.

The linear search checks each element and moves to the next element in a sequential manner.

The binary search is a searching algorithm that is used to search for an element in the given data structure.

For the binary search the list of elements must be in sorted order.

It begins the search with the middle of the sorted list.

It determines whether the search element is greater or less than the middle element.

This helps in finding whether the search element is present in the first half or the second half of the list.

This process repeats until the element is found.

These are the linear and binary search algorithms.

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

Where n is the number of elements in the list.

B)

A single linked list is a variant of linked list that is unidirectional.

It can be traversed only in one direction.

The nodes in the single linked list have two fields in it.

The first field is the data field that has the value of the element in it.

The second field is the pointer to the next node.

Pros:

The linked lists are dynamic structures.

They can be used to dynamically allocate memory and store the data in it.

The memory need not be allocated in a contiguous manner.

The parallel arrays are fixed in size and it leads to memory waste.

The memory needs to be allocated in a contiguous blocks for parallel arrays.

Cons:

The linked list occupies extra memory for storing the pointer data that points to the next node.

In the linked list, the elements can not be accessed directly.

To access an element, the list has to be traversed from the first node till the node that needs to be accessed.

The parallel arrays do not need any additional memory for storing the pointer fields.

It is possible to access the required element directly using its index value in case of parallel arrays.

Note:

Please see that as per the guidelines, only single question can be answered when multiple questions are present.

In case of multiple choice type questions, upto 4 can be answered. Thank you.


Related Solutions

1. What is the Big-O run-time of linear search and binary search in the best, average...
1. What is the Big-O run-time of linear search and binary search in the best, average and worst cases?       Linear Search                  Binary Search Best: Worst: Average: 2. What is the Big-O runtime of the following linked list methods? addFirst() toString() What is the Big-O runtime of the below Stack method? isSorted(Node n) 3. What is the Big-O runtime of the below methods: Method A: Stack Copy Constructor Option 1 public Stack(Stack<T> original) { if(original == null) { return; }...
What is the Average time complexity of sequential search algorithm in a linked list?
What is the Average time complexity of sequential search algorithm in a linked list?
Write a program to show the difference between linear search and binary search. Show the input...
Write a program to show the difference between linear search and binary search. Show the input test data for your program and the output produced by your program which clearly show that binary search is faster than linear search
Rank the algorithms from slowest to fastest. . Bubble Sort Linear Search Binary Search Shellsort
Rank the algorithms from slowest to fastest. . Bubble Sort Linear Search Binary Search Shellsort
Iterative Linear Search, Recursive Binary Search, and Recursive Selection Sort I need it in Java with...
Iterative Linear Search, Recursive Binary Search, and Recursive Selection Sort I need it in Java with comments and I need the input file to be placed with Scanner not BufferedReader Please help I need Class River Class CTRiver and Class Driver Class River describes river’s name and its length in miles. It provides accessor methods (getters) for both variables, toString() method that returns String representation of the river, and method isLong() that returns true if river is above 30 miles...
IN JAVA: I am using binary and linear search methods in java. How can I Generate...
IN JAVA: I am using binary and linear search methods in java. How can I Generate a new array with 10000 elements, and initialize the elements to random values using Math.random() and how can i sort the array using Arrays.sort(). I just need examples, no exact code is necessary. The array must be of doubles.
Correct this Binary Search (C++) // This program demostrates linear search algorithm #include <iostream> using namespace...
Correct this Binary Search (C++) // This program demostrates linear search algorithm #include <iostream> using namespace std; // Binary search algorith // f is the first , l is the last , t is the target int binarySearch(int stgrade[], int f, int l, int t) { while (f <= l) { int m = f + (l - l) / 2; // Check if x is present at mid if (stgrade[m] == t) return m; // If x greater, ignore...
Beginning with an empty binary search tree, what binary search tree is formed when you insert...
Beginning with an empty binary search tree, what binary search tree is formed when you insert the following values in the given order – consider there alphabetical position for comparison. a. W, T, N, J, E, B, A b. W, T, N, A, B, E, J c. A, B, W, J, N, T, E d. B, T, E, A, N, W, J Alphabetical positions: A-1, B-2, E-5, J-10, N-14,T-20,W-23
PLEASE READ CAREFULY AND EXPLAIN YOUR WORK: (JavaScript) only Search the Tree: A binary search tree...
PLEASE READ CAREFULY AND EXPLAIN YOUR WORK: (JavaScript) only Search the Tree: A binary search tree is a data structure that consists of JavaScript objects called "nodes". A tree always has a root node which holds its own integer value property and can have up to two child nodes (or leaf nodes), a left and right property. A leaf node holds a value attribute and, likewise, a left and right attribute each potentially pointing to another node in the binary...
What is the auxiliary space and space complexity for a dynamic programming algorithm with time complexity...
What is the auxiliary space and space complexity for a dynamic programming algorithm with time complexity of O(n^2)? Justify.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT