Question

   vi. Assume that a linked list stores the data, 20, 11, 13, 19, 12, 14...

       vi. Assume that a linked list stores the data, 20, 11, 13, 19, 12, 14 in that order. Assume that Node head references the first item in the list. What is the result to the linked list of       the following instructions? Assume that newNode          is a Node, already constructed.

    newNode.data = 1;

                            newNode.next = head.next;

                            head = newNode;

          a. The value 1 is inserted into the linked list before 20

          b. The value 1 is inserted into the linked list after 11 and before 13

          c. The value 1 is inserted into the linked list before 11 and it is now at the head of the list

          d. The value 1 is inserted into the linked list after 20 and the rest of the list is lost

          e. None of the above

    1. Suppose we have a stack S and a queue Q. Draw the contents of both S and Q at each step.           Stack S;

                Queue Q;

                S.push(3); S.push(2); S.push(1)

                Q.enqueue(3); Q.enqueue(2); Q.enqueue(1);

                int x = S.pop(); int y = Q.dequeue();

                Q.enqueue(x); S.push(y);

                Q.enqueue(Q.dequeue());      

                S.push(Q.peek()); // peek() function reads the front of a queue without deleting it

    1. Using stack, check if the following expression is correct or not. Show the steps:

                                        a+((b+3)-(c*d)+e

    1. Using stack convert the infix expression (A * B + C) + C ^ (F + G) to equivalent postfix expression.
    1. Show how you can search for the key value 70, in the following array of data using binary search.

    30, 70, 10, 15, 80, 20, 90, 11, 12

    1. Show the steps to sort the following data using Selection sort algorithm.

    10

    5

    11

    8

    7

    1. What are the factors you will consider to select the proper data structures and memory allocation mechanism when building an algorithm

    Homework Answers

    Answer #1
    1. What are the problems of performing the following operations in an Array:
    • Insertion in the middle
    • Removing elements from the beginning/middle/end

      - Insertion and deletion are quite difficult in an array as the elements are stored in consecutive memory locations and the shifting operation is costly.

    When is it appropriate to use an array data structures?
    Ans - In arrays, the elements can be accessed randomly by using the index number.

    What is the major disadvantage of using an array data structure?
    Ans -

    • The number of elements to be stored in an array should be known in advance.
    • An array is a static structure (which means the array is of fixed size). Once declared the size of the array cannot be modified. The memory which is allocated to it cannot be increased or decreased.
    • Insertion and deletion are quite difficult in an array as the elements are stored in consecutive memory locations and the shifting operation is costly.
    • Allocating more memory than the requirement leads to wastage of memory space and less allocation of memory also leads to a problem.

    Write the differences between a linked list and an array?
    Ans -
    Array -

    Array elements can be accessed randomly using the array index.

    Memory is allocated during the compile time (Static memory allocation).

    LinkedList -

    Random accessing is not possible in linked lists. The elements will have to be accessed sequentially.

    Memory is allocated during the run-time (Dynamic memory allocation)



    4. Answer the following questions:

                i. It is easy to insert and delete elements in Linked List over Array. True

                ii. Random data access is not allowed in a typical implementation of Linked Lists. True

                iii. The size of an array has to be pre-decided whereas the size of a linked list can change during run time. True

                iv. Which of the following is not a dynamic data structure?

    c. Array.

                v. In general, Linked Lists allow (choose the correct one) :

                a. Insertions and removals anywhere.

                vi. Assume that a linked list stores the data, 20, 11, 13, 19, 12, 14 in that order. Assume that Node head references the first item in the list. What is the result to the linked list of       the following instructions? Assume that newNode          is a Node, already constructed.

    newNode.data = 1;

                            newNode.next = head.next;

                            head = newNode;

          c. The value 1 is inserted into the linked list before 11 and it is now at the head of the list

    Following ss are the answers of the questions until the last one -

    Know the answer?
    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
    Similar Questions
    c++ data structures linked list delete node bool deleteNode(int); pass this method an id to delete....
    c++ data structures linked list delete node bool deleteNode(int); pass this method an id to delete. Return true or false to indicate success or failure. Delete the memory the node was using The algorithm for deleting a Node to a Linked List (general case): ● Begin at the head. ● Compare the id to the current node. ● If search id > current id, stop. ● Detach the current Node ○ current->previous->next = current->next ○ current->next->previous = current->previous ● Deallocate...
    1. Create a linked list using the Node class that contains the first million prime numbers...
    1. Create a linked list using the Node class that contains the first million prime numbers (primes4.txt). It should have a menu with these options: 1 = Search for a Number (let the user enter a number to search for) 2 = Add a new Number (let the user enter a number and add it to the head of the list) 3 = Delete a Number (let the user enter a number and delete it if found) 4 = Exit...
    In this code, I build a single-linked list using a node class that has been created....
    In this code, I build a single-linked list using a node class that has been created. How could I change this code to take data of type T, rather than int. (PS: ignore the fact that IOHelper.getInt won't work for the type T... ie second half of main). Here's my code right now: public class SLList { public SLNode head = null; public SLNode tail = null; public void add(int a) {// add() method present for testing purposes SLNode newNode...
    Java Please [(1)] A palindrome is a string that reads the same forwards as backwards. Using...
    Java Please [(1)] A palindrome is a string that reads the same forwards as backwards. Using only a fixed number of stacks and queues, the stack and queue ADT functions, and a fixed number of int and char variables, write an algorithm to determine if a string is a palindrome. Assume that the string is read from standard input one character at a time. The algorithm should output true or false as appropriate [(2)] Let Q be a non-empty queue,...
    Data Structures using C++ Searching a Linked List Here are the declarations for a simple unsorted...
    Data Structures using C++ Searching a Linked List Here are the declarations for a simple unsorted linked list of ints that ends in a null pointer. //=============================================================== class Cell { friend class UList; private: int data; Cell* next; Cell( int dt, Cell* nx=nullptr ) : data(dt), next(nx) {} }; //=============================================================== class UList { private: Cell* head = nullptr;    // stationary head pointer. Cell* scan = nullptr;          // for walking down the List. Cell* follow = nullptr; public: void find( int...
    Adding large numbers with linked list Requirement - in C++ - use file for the input...
    Adding large numbers with linked list Requirement - in C++ - use file for the input (nums.txt) - (recommended) use only one linked list to hold intermediate answer and final answer. You may use another one to reverse the answer. - store the num reversely in the linked list. For example, the num 123 is stored as 3 (at first node), 2 (at second node) and 1 (at third node) in the linked list. - write a function that performs...
    Code in JAVA The requirements are as follows: The input will be in a text file...
    Code in JAVA The requirements are as follows: The input will be in a text file whose name is given by arg[0] of main(). It will contain a fully-parenthesized infix expression containing only: "(", ")", "+", "-" and integers. Need help on the main and fixing the Queue. //Input: ( ( 1 + 2 ) - ( ( 3 - 4 ) + ( 7 - 2 ) ) ) ( ( 1 + 2 ) - ( 3 -...
    my code has several functions; delete and backward functions are not working, rewrite the code for...
    my code has several functions; delete and backward functions are not working, rewrite the code for both functions and check them in the main: #include<iostream> #include<cassert> using namespace std; struct nodeType {    int info;    nodeType *link; }; class linkedList { public:    void initializeList();    bool isEmptyList();    void print();    int length();    void destroyList();    void insertFirst(int newItem);    void insertLast(int newItem);    int front();    linkedList();    void copyList(const linkedList otherList);    void insertNewValue(int value);...
    Create a C++ project. Download and add the attached .h and .cpp to the project. Write...
    Create a C++ project. Download and add the attached .h and .cpp to the project. Write an implementation file to implement the namespace declared in the attached CSCI361Proj5.h. Name the implementation file as YourNameProj5.cpp and add it to the project. Run the project to see your grade. .h file: // Provided by: ____________(your name here)__________ // Email Address: ____________(your email address here)________ // FILE: link.h // PROVIDES: A toolkit of 14 functions for manipulating linked lists. Each // node of...
    The main goal is to implement two recursive methods, each is built to manipulate linked data...
    The main goal is to implement two recursive methods, each is built to manipulate linked data structures. To host these methods you also have to define two utterly simplified node classes. 1.) Add a class named BinaryNode to the project. This class supports the linked representation of binary trees. However, for the BinaryNode class Generic implementation not needed, the nodes will store integer values The standard methods will not be needed in this exercise except the constructor 2.) Add a...
    ADVERTISEMENT
    Need Online Homework Help?

    Get Answers For Free
    Most questions answered within 1 hours.

    Ask a Question
    ADVERTISEMENT