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
    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,...
    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...
    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 -...
    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...
    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...
    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);...
    ALL CODE MUST BE IN C++ Before you begin, you must write yourself a LinkedList class...
    ALL CODE MUST BE IN C++ Before you begin, you must write yourself a LinkedList class and a Node class (please name your classes exactly ​as I did here). Please follow the below specifications for the two classes. Node.cpp ● This must be a generic class. ● Should contain a generic member variable that holds the nodes value. ● Should contain a next and prev Node* as denoted here. ● All member variables should be private. ● Use public and...
    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...
    Java question, Please answer everything. Thank you Answer the following questions as briefly (but completely) as...
    Java question, Please answer everything. Thank you Answer the following questions as briefly (but completely) as possible: What is a checked exception, and what is an unchecked exception? What is NullPointerException? Which of the following statements (if any) will throw an exception? If no exception is thrown, what is the output? 1: System.out.println( 1 / 0 ); 2: System.out.println( 1.0 / 0 ); Point out the problem in the following code. Does the code throw any exceptions? 1: long value...
    IntList Lab Specifications You are required to come up with a single header file (IntList.h) that...
    IntList Lab Specifications You are required to come up with a single header file (IntList.h) that declares and implements the IntNode class (just copy it exactly as it is below) as well as declares the IntList Class interface only. You are also required to come up with a separate implementation file (IntList.cpp) that implements the member functions of the IntList class. While developing your IntList class you must write your own test harness (within a file named main.cpp). Never implement...
    ADVERTISEMENT
    Need Online Homework Help?

    Get Answers For Free
    Most questions answered within 1 hours.

    Ask a Question
    ADVERTISEMENT