Home Author
Author

nikoo28

  • Linked ListMisc

    Implementation of a stack

    by nikoo28
    2 minutes read

    An implementation of stack is similar to that of a Linked List. We will try to discuss the basic operations in a stack discussed in this post. MAIN OPERATIONS ON A STACK:- push( int ) :- Inserts a data into the stack pop :- Returns the topmost data from the stack AUXILIARY OPERATIONS ON A STACK int Top( ) :- returns the topmost element on the stack int Size( ) :- returns the total size of the stack int isStackEmpty( ) :- returns true if the stack is empty The…

    0 FacebookTwitterLinkedinWhatsappEmail
  • MiscTheory

    What is Segmentation Fault?

    by nikoo28
    2 minutes read

    From Wikipedia: A segmentation fault occurs when a program attempts to access a memory location that it is not allowed to access, or attempts to access a memory location in a way that is not allowed (for example, attempting to write to a read-only location, or to overwrite part of the operating system). Segmentation is one approach to memory management and protection in the operating system. It has been superseded by paging for most purposes, but much of the terminology of segmentation is still used, “segmentation fault” being an example.…

    0 FacebookTwitterLinkedinWhatsappEmail
  • Question: You are given the head pointer to 2 single Linked Lists, and both of the lists converge at a certain point and then advance forward. We need to find the address of the node, at which both of the Linked Lists meet. Input: 4 -> 8 -> 15 ->                               42 -> 99     16 -> 23 -> Output: 42 Suppose there are two single Linked Lists both of which intersect at some point and become a single Linked list. The head or start pointer of both the lists…

    0 FacebookTwitterLinkedinWhatsappEmail
  • Many of us must have heard of the clause “Real Programmers code in C” and it is faster than any other language because “it is close to the machine“. What is so special about this language that makes it different from any other language. Let us try to explore this answer to some extent. There isn’t much that’s special about C. That’s one of the reasons why it’s fast. Newer languages which have support for garbage collection, dynamic typing and other facilities which make it easier for the programmer to…

    0 FacebookTwitterLinkedinWhatsappEmail
  • Question: Write a program to check if the given Linked List is a palindrome or not? Input: 1.> 4, 8, 15, 16, 23, 42 2.> 4, 8, 15, 16, 15, 8, 4 Output: 1.> IS NOT A PALINDROME 2.> IS A PALINDROME What is a Palindrome? According to Wikipedia, A palindrome is a word, phrase, number, or other sequence of symbols or elements, whose meaning may be interpreted the same way in either forward or reverse direction. Thus, numbers like 121, 1331, 98711789 are palindromes. Similarly, Linked Lists can be…

    0 FacebookTwitterLinkedinWhatsappEmail
  • Question: Given a Linked List, we need to find the middle of the list and print the number. Input: 4, 8, 15, 16, 23, 42, 99 Output: 16 This is a very basic question and is a part of a bigger problem. However, there are several approaches to solve the above problem. BRUTE-FORCE APPROACH In this approach, we count the number of nodes in the list for each of the node and see whether it is the middle. Time Complexity: O(n2) Space Complexity: O(1) MORE SIMPLIFIED APPROACH In this approach,…

    0 FacebookTwitterLinkedinWhatsappEmail
  • Linked ListMisc

    Reverse a Linked List in pairs.

    by nikoo28
    1 minutes read

    Question: Write a program to reverse a Linked List in pairs. That means we should reverse the 1st and 2nd numbers, 3rd and 4th numbers and so on. Input: 4, 8, 15, 16, 23, 42 Output: 8, 4, 16, 15, 42, 23 The basic idea behind solving this problem is that we need to traverse the entire list and we need to keep on swapping the values of 2 adjacent nodes. Since we need to reverse the values in pairs, it is also clear that we need to move 2…

    0 FacebookTwitterLinkedinWhatsappEmail

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More