Skip to content

Theory of Programming

  • Home
  • Data Structures and Algorithms
    • Graph Theory
      • Graph Theory Basics
        • Theory and Implementation in C
        • Adjacency List Implementation in C++ STL
        • Adjacency List with String vertices using C++ STL
        • Adjacency List in C#
      • Breadth First Search (BFS) Algorithm
        • Theory and Implementation in C
        • BFS Algorithm using C++ STL
        • Algorithm using Queue
      • Snakes and Ladders Game Code
      • Depth First Search Algorithm
      • Bellman Ford Algorithm
        • Theory and Implementation in basic C++
        • Algorithm Implementation in C++ STL
      • Prim’s Algorithm
        • Theory and Implementation in basic C++
        • Algorithm Implementation in C++ STL
      • Dijkstra’s Algorithm
    • Tree Data Structures
      • Binary Indexed Tree (or) Fenwick Tree
      • Trie Tree
        • Trie Tree Implementation and Theory
        • Trie Tree using C++ Class
        • Trie Tree Practise – SPOJ – PHONELST
        • Trie Tree Practise – SPOJ – DICT
      • Compressed Trie Tree
      • N-ary tree or K-way tree data structure
      • Segment Trees
      • Binary Heaps
      • Binary Heaps and Heapsort Algorithm
    • Dynamic Programming
      • Introduction and Fibonacci Numbers
      • Kadane’s Algorithm
      • Edit Distance
    • Searching Algorithms
      • Binary Search Algorithm
      • Jump Search Algorithm
    • Sorting Algorithms
      • Quick Sort Algorithm
      • Merge Sort Algorithm
    • Math
      • Modular Arithmetic Properties
  • AI
    • MiniMax Algorithm
    • Minimax algorithm with Alpha-Beta Pruning
    • Iterative Deepening Depth First Search
    • Bidirectional Search
  • Java
    • Language Basics
      • An Introduction
      • Data Types, Input and Operators
      • If Else, Switch and Loops
      • Strings, StringBuffer and StringBuilder
      • Arrays in Java
      • Enum and Methods in Java
    • Introduction to OOP
      • Java Tutorials – Classes and Objects
      • Encapsulation in Java
      • Constructor and Overloading Methods
      • Inheritance
  • Interview Corner
    • Arrays
  • C++
    • Basics
      • Why should I learn C++?
      • C++ Programming Style and Structure
      • Variables, Initialization and Assignment
      • Writing Professional Code in C++
  • Team
    • Vamsi Sangam
      • My Life in a Nutshell
      • Favourite Quotes
      • Books Read
    • Punit Sharma
      • About Me
Theory of Programming

Tag: Arrays

Array Interview Questions

First missing integer in an unsorted array

Posted on December 17, 2017

Problem statement – Given an unsorted integer array, find the first missing positive integer. Example, If A = [-1, 4, 2, 3, 5], missing integer = 1. If A = [1, 5, 2, 3, 4, 7], missing integer = 6. If A = [-1, -2, -3, -4], missing integer = 1. Clues – Your solution […]

Array Interview Questions

Maximum sum contiguous sub-array

Posted on December 17, 2017

Find a contiguous sub-array whose sum is maximum. Using the dynamic programming based Kadane’s Algorithm, we can solve this in O(N) time.

Array Interview Questions

Find the majority element in an array

Posted on December 16, 2017December 31, 2017

Given an unsorted array, find the majority element. Majority element is defined as that element which occurs for more than N/2 times. If the majority element exists, there will only be one such element. We can do this in O(N) time by the Boyer–Moore majority voting algorithm.

Array Interview Questions

Find pivot element in a sorted and rotated array

Posted on December 16, 2017December 31, 2017

Problem Statement – Suppose we have a sorted array, and now we rotate it N times, find the pivot element. The pivot element would be the largest element. Also, can you calculate N? Clues – Solution should be O(log N) in time and O(1) in space. Can you think of  a binary search based solution […]

Array Interview Questions

Kth smallest element in an array

Posted on December 16, 2017December 31, 2017

Given an unsorted array of N elements, find the kth smallest element. This can be done in O(N) time and O(1) space by the Quickselect Algorithm. The Quickselect Algorithm is a divide-and-conquer based algorithm which rearranges the array such that the kth element is the kth smallest element in the array.

Theory of Programming on YouTube

Theory of Programming is shifting to YouTube!

Please visit the YouTube channel. Hoping you’ll support the YouTube channel just like you have greatly supported the website! 🙂

Recent Posts

  • Bidirectional Search January 21, 2018
  • Iterative Deepening Depth First Search (IDDFS) January 14, 2018
  • N-ary tree or K-way tree data structure January 14, 2018
  • Rotate matrix clockwise December 31, 2017
  • Print matrix in spiral order December 31, 2017

Like this website on Facebook..!

Like this website on Facebook..!

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 164 other subscribers

Categories

Archives

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 164 other subscribers

Proudly powered by WordPress | Theme: Sydney by aThemes.