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
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...
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.
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...
How to read and print all contents in a binary file using a Binary Search Tree...
How to read and print all contents in a binary file using a Binary Search Tree inorder traversal in C. Additionally, how to search using a Binary Search Tree to display the specific Athlete and his/her information. An example would be a sports record binary file that consist of name of athlete, height , weight, championships won. Athlete: Michael Jordan Height: 6’6” Weight : 205 lbs Championships won: 6 =================== Athlete: LeBron James Height: 6’8” Weight: 250 lbs Championships won:...
Some questions about Binary Tree's What a binary search tree is and what its advantages/disadvantages are?...
Some questions about Binary Tree's What a binary search tree is and what its advantages/disadvantages are? What trees and binary trees are? How data is inserted into a binary tree? What full and complete binary trees look like? How to perform pre, in, and post-order traversals of a tree?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT